Java2OWL
Class IndividualWrapper

Object
  extended by IndividualWrapper

public class IndividualWrapper
extends Object

The instances of this class maintain the correspondences between Java-objects and OWL-individuals.

If OWL-individuals are created from Java-objects then there is a one-to-one correspondence between the two. If, however, Java-objects are created from OWL-individuals then, due to multi-inheritance of OWL and mono-inheritance of Java, a particular OWL-individual may be mapped to several Java-objects. An example is the Amphibious-vehicle as subclass of ship and surface vehicle. It would be mapped to both a Java Ship and a Java SurfaceVehicle.

All methods are thread safe. The monitor is the individual wrapper itself.


Method Summary
 void activateSynchronisation(boolean log)
          activates Java <-> OWL synchronisation for all objects in the individual wrapper.
 void deactivateSynchronisation(boolean log)
          activates Java <-> OWL synchronisation for all object in the individual wrapper.
 Set<Object> getDataPropertyValues(OWLDataProperty property)
          gets a data property value for a data property which has no corresponding field in the objects, or null if an error occurred.
 Object getFirstObject()
          returns the first Java object.
 OWLNamedIndividual getIndividual()
          returns the individual.
 String getName()
          returns a string of the kind 'individual name <-> object name_1, ..., object name_n'
 Object getObject(Class jcl)
          returns the first object in the stored objects which is an instance of the given class.
 IndividualWrapper[] getObjectPropertyValues(OWLObjectProperty property)
          gets object properties value for an object property which has no corresponding field in the objects.
 Object[] getObjects()
          returns all the Java objects.
 String getObjectsString()
          returns the objects as a |-separated string.
 boolean reclassify(boolean forceReclassification)
          This method can reclassify the Java objects if the changed attributes puts them into another OWL-concept.
 boolean setDataPropertyValue(OWLDataProperty property, Object value)
          sets a data property value for a data property which has no corresponding field in the objects.
 void setFieldValue(String name, Object value)
          puts the value into all object's fields with the given name
 boolean setObjectPropertyValue(OWLObjectProperty property, Object value)
          sets an object property value for an object property which has no corresponding field in the objects.
 void synchroniseWithOWL()
          synchronises the attributes of all objects with the properties of the individual.
 String toString()
          returns a string representation of the individual wrapper.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getIndividual

public OWLNamedIndividual getIndividual()
returns the individual.


getObjects

public Object[] getObjects()
returns all the Java objects.


getObject

public Object getObject(Class jcl)
returns the first object in the stored objects which is an instance of the given class.

Parameters:
jcl - a Java class
Returns:
the first object which is an instance of the given class or null, if none could be found,

getFirstObject

public Object getFirstObject()
returns the first Java object. No check is performed to ensure that there is a first object at all.


setDataPropertyValue

public boolean setDataPropertyValue(OWLDataProperty property,
                                    Object value)
sets a data property value for a data property which has no corresponding field in the objects.

The value is forwarded to the ontology.

Returns:
true if the operation succeeded.

setObjectPropertyValue

public boolean setObjectPropertyValue(OWLObjectProperty property,
                                      Object value)
sets an object property value for an object property which has no corresponding field in the objects.

The value is forwarded to the ontology.

Returns:
true if the operation succeeded.

getDataPropertyValues

public Set<Object> getDataPropertyValues(OWLDataProperty property)
gets a data property value for a data property which has no corresponding field in the objects, or null if an error occurred.

The value is forwarded to the ontology.

Returns:
the set of data values as Java objects (maybe wrapper objects for numbers).

getObjectPropertyValues

public IndividualWrapper[] getObjectPropertyValues(OWLObjectProperty property)
gets object properties value for an object property which has no corresponding field in the objects.

Parameters:
property - an OWLObjectProperty
Returns:
an array of IndividualWrappers for the property's role fillers.

setFieldValue

public void setFieldValue(String name,
                          Object value)
puts the value into all object's fields with the given name

Parameters:
name - the name of a field of some of the objects.
value - the object to be put into the field.

Objects without such a field or if the field is not accessible, are ignored.

This method can be used to put pointer-equal values into the corresponding fields of all objects.


getObjectsString

public String getObjectsString()
returns the objects as a |-separated string.

The method uses the toString() method of the objects.


activateSynchronisation

public void activateSynchronisation(boolean log)
activates Java <-> OWL synchronisation for all objects in the individual wrapper.

Parameters:
log - if 'true' then the activation is logged.

All previous changes which have not yet been synchronised get synchronised.


deactivateSynchronisation

public void deactivateSynchronisation(boolean log)
activates Java <-> OWL synchronisation for all object in the individual wrapper.

Parameters:
log - if 'true' then the deactivation is logged.

synchroniseWithOWL

public void synchroniseWithOWL()
synchronises the attributes of all objects with the properties of the individual.


reclassify

public boolean reclassify(boolean forceReclassification)
This method can reclassify the Java objects if the changed attributes puts them into another OWL-concept.

Example: Consider a class Student with attribute semester.
Consider a subclass Freshman which are Students in their first semester.
Consider a student Paul in the second semester, which is put back into the first semester. Now the instance Paul of the class Student should become an instance Paul of the class Freshman.

In detail:
First the OWLIndividual is realised by the OWL-reasoner, thus getting the lowest classes in the OWL hierarchy. Then it searches the OWL classes upwards to find the lowest classes which have corresponding Java classes. For all these classes C:

No change to the object is done if something goes wrong.

The reclassification has a nondeterminism in the algorithm:
Suppose the individual I has an object property P with filler F (an OWL individual) Suppose F is mapped to two or more Java Objects o1,o2,... If property P has a setter S with argument type T, then it is not clear which of the objects o1,o2,... to be filled into S.
The algorithm chooses the first one whose type is T or a subtype of T.
If none of the objects has an appropriate type then an error is generated.

Parameters:
forceReclassification - if this flag is false then reclassification is done only if some attributes have been changed since the last reclassification.
Returns:
true if the operation succeeded.

getName

public String getName()
returns a string of the kind 'individual name <-> object name_1, ..., object name_n'


toString

public String toString()
returns a string representation of the individual wrapper.

Overrides:
toString in class Object