org.biopax.paxtools.controller
Class PropertyEditor<D extends BioPAXElement,R>

java.lang.Object
  extended by org.biopax.paxtools.controller.SimplePropertyAccessor<D,R>
      extended by org.biopax.paxtools.controller.PropertyEditor<D,R>
All Implemented Interfaces:
PropertyAccessor<D,R>
Direct Known Subclasses:
EnumeratedPropertyEditor, ObjectPropertyEditor, PrimitivePropertyEditor, StringPropertyEditor

public abstract class PropertyEditor<D extends BioPAXElement,R>
extends SimplePropertyAccessor<D,R>

This is the base class for all property editors. Each property controller is responsible for manipulating a certain property for a given class of objects (domain).


Field Summary
protected  java.lang.reflect.Method addMethod
          This variable stores the method to invoke for adding the given value to the property managed by this commander.
protected  java.lang.Class<D> domain
          This is the Class representing the domain of the property.
protected static org.apache.commons.logging.Log log
           
protected  boolean multipleCardinality
          This is false if there is a cardinality restriction of one on the property.
protected  java.lang.String property
          Local OWL name of the property
protected  java.lang.Class<R> range
          This is the Class representing the range of the property.
protected  java.lang.reflect.Method removeMethod
          This variable stores the method for removing the value of the property on a given bean.
protected  java.lang.reflect.Method setMethod
          This variable stores the method to invoke for setting a property to the to the given value.
 
Fields inherited from class org.biopax.paxtools.controller.SimplePropertyAccessor
getMethod
 
Constructor Summary
PropertyEditor(java.lang.String property, java.lang.reflect.Method getMethod, java.lang.Class<D> domain, java.lang.Class<R> range, boolean multipleCardinality)
           
 
Method Summary
 void addMaxCardinalityRestriction(java.lang.Class<? extends D> domain, int max)
          Sets a maximum cardinality for a domain.
protected  void checkRestrictions(R value, D bean)
          Checks if the bean and the value are consistent with the cardinality rules of the model.
static
<D extends BioPAXElement,R>
PropertyEditor<D,R>
createPropertyEditor(java.lang.Class<D> domain, java.lang.String property)
          This method creates a property reflecting on the domain and property.
protected static java.lang.Class detectRange(java.lang.reflect.Method getMethod)
          Given the multiple cardinality feature, the range of the get method is returned.
 java.lang.reflect.Method getAddMethod()
          Returns the addMethod.
 java.lang.Class<D> getDomain()
          Returns the domain of the property.
 java.lang.reflect.Method getGetMethod()
          Returns SimplePropertyAccessor.getMethod.
 java.lang.Integer getMaxCardinality(java.lang.Class<? extends D> restrictedDomain)
          Return the maximum cardinality that is defined for the property to which editor is belong.
 java.lang.reflect.Method getPrimarySetMethod()
          Returns the primary set method of the editor.
 java.lang.String getProperty()
          Returns the property name.
 java.lang.Class<R> getRange()
          Returns the range of the editor.
 java.lang.reflect.Method getRemoveMethod()
          Returns the removeMethod.
 java.lang.reflect.Method getSetMethod()
          Returns the setMethod.
 R getUnknown()
          Gets the unknown value.
protected  void invokeMethod(java.lang.reflect.Method method, D bean, R value)
          Calls the method onto bean with the value as its parameter.
protected  boolean isInstanceOfAtLeastOne(java.util.Set<java.lang.Class<? extends BioPAXElement>> classes, java.lang.Object value)
          Checks if value is an instance of one of the classes given in a set.
 boolean isMultipleCardinality()
          Checks if the property to which editor is assigned has multiple cardinality.
protected  R parseValueFromString(java.lang.String value)
           
 void removeValueFromBean(R value, D bean)
          Removes the value from the bean using the default removeMethod.
 void removeValueFromBean(java.util.Set<R> values, D bean)
          Removes the values from the bean using the removeValueFromBean(Object, BioPAXElement) for each value in the set.
 void setValueToBean(R value, D bean)
          Sets the value to the bean using the default setMethod if value is not null.
 void setValueToBean(java.util.Set<R> values, D bean)
           
 java.lang.String toString()
           
 
Methods inherited from class org.biopax.paxtools.controller.SimplePropertyAccessor
getValueFromBean, isMultipleCardinality, isUnknown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log

setMethod

protected java.lang.reflect.Method setMethod
This variable stores the method to invoke for setting a property to the to the given value. If multiple cardinality, the returned method is expected to have a Set as its only parameter.


addMethod

protected java.lang.reflect.Method addMethod
This variable stores the method to invoke for adding the given value to the property managed by this commander. In the case of multiple cardinality, the method is expected to have a range as its only parameter, otherwise expected to be null.


removeMethod

protected java.lang.reflect.Method removeMethod
This variable stores the method for removing the value of the property on a given bean. In the case of multiple cardinality, this method is expected to have a range as its only parameter, otherwise expected to be null


property

protected final java.lang.String property
Local OWL name of the property


domain

protected java.lang.Class<D extends BioPAXElement> domain
This is the Class representing the domain of the property.


range

protected java.lang.Class<R> range
This is the Class representing the range of the property. It is by default an object.


multipleCardinality

protected final boolean multipleCardinality
This is false if there is a cardinality restriction of one on the property.

Constructor Detail

PropertyEditor

public PropertyEditor(java.lang.String property,
                      java.lang.reflect.Method getMethod,
                      java.lang.Class<D> domain,
                      java.lang.Class<R> range,
                      boolean multipleCardinality)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

createPropertyEditor

public static <D extends BioPAXElement,R> PropertyEditor<D,R> createPropertyEditor(java.lang.Class<D> domain,
                                                                                   java.lang.String property)
This method creates a property reflecting on the domain and property. Proper subclass is chosen based on the range of the property.

Parameters:
domain - paxtools level2 interface that maps to the corresponding owl level2.
property - to be managed by the constructed controller.
Returns:
a property controller to manipulate the beans for the given property.

detectRange

protected static java.lang.Class detectRange(java.lang.reflect.Method getMethod)
Given the multiple cardinality feature, the range of the get method is returned.

Parameters:
getMethod - default method
Returns:
the range as a class

getAddMethod

public java.lang.reflect.Method getAddMethod()
Returns the addMethod.

Returns:
the add method.

getGetMethod

public java.lang.reflect.Method getGetMethod()
Returns SimplePropertyAccessor.getMethod.

Returns:
the get method

getProperty

public java.lang.String getProperty()
Returns the property name.

Returns:
the proterty name as a string

getRemoveMethod

public java.lang.reflect.Method getRemoveMethod()
Returns the removeMethod.

Returns:
the remove method

getSetMethod

public java.lang.reflect.Method getSetMethod()
Returns the setMethod.

Returns:
the set method

addMaxCardinalityRestriction

public void addMaxCardinalityRestriction(java.lang.Class<? extends D> domain,
                                         int max)
Sets a maximum cardinality for a domain.

Parameters:
domain - domain on which restriction will be set
max - cardinality
See Also:
isMultipleCardinality()

getMaxCardinality

public java.lang.Integer getMaxCardinality(java.lang.Class<? extends D> restrictedDomain)
Return the maximum cardinality that is defined for the property to which editor is belong.

Parameters:
restrictedDomain - domain to be checked for the cardinality
Returns:
an integer indicating the maximum cardinality

isInstanceOfAtLeastOne

protected boolean isInstanceOfAtLeastOne(java.util.Set<java.lang.Class<? extends BioPAXElement>> classes,
                                         java.lang.Object value)
Checks if value is an instance of one of the classes given in a set. This method becomes useful, when the restrictions have to be checked for a set of objects. e.g. check if the value is in the range of the editor.

Parameters:
classes - a set of classes to be checked
value - value whose class will be checked
Returns:
true if value belongs to one of the classes in the set

getUnknown

public R getUnknown()
Gets the unknown value. In an object property or enumeration context a value is regarded to be unknown if it is null (unset); in a primitive property context it depends (can be e.g., BioPAXElement.UNKNOWN_FLOAT)

Returns:

removeValueFromBean

public void removeValueFromBean(R value,
                                D bean)
Removes the value from the bean using the default removeMethod.

Parameters:
value - to be removed from the bean
bean - bean from which the value is going to be removed

removeValueFromBean

public void removeValueFromBean(java.util.Set<R> values,
                                D bean)
Removes the values from the bean using the removeValueFromBean(Object, BioPAXElement) for each value in the set.

Parameters:
values - to be removed from the bean
bean - bean from which the value is going to be removed

invokeMethod

protected void invokeMethod(java.lang.reflect.Method method,
                            D bean,
                            R value)
Calls the method onto bean with the value as its parameter. In this context method can be one of these three: set, add, or remove.

Parameters:
method - method that is going to be called
bean - bean onto which the method is going to be applied
value - the value which is going to be used by method

parseValueFromString

protected R parseValueFromString(java.lang.String value)

setValueToBean

public void setValueToBean(R value,
                           D bean)
Sets the value to the bean using the default setMethod if value is not null.

Parameters:
value - to be set to the bean
bean - to which the value is to be set

setValueToBean

public void setValueToBean(java.util.Set<R> values,
                           D bean)

checkRestrictions

protected void checkRestrictions(R value,
                                 D bean)
Checks if the bean and the value are consistent with the cardinality rules of the model. This method is important for validations.

Parameters:
value - Value that is related to the object
bean - Object that is related to the value

getPrimarySetMethod

public java.lang.reflect.Method getPrimarySetMethod()
Returns the primary set method of the editor. It is the setMethod for a property of single cardinality, and the addMethod method for a property of multiple cardinality.

Returns:
the method to be primarily used for setting a value to an object.

getDomain

public java.lang.Class<D> getDomain()
Returns the domain of the property.

Specified by:
getDomain in interface PropertyAccessor<D extends BioPAXElement,R>
Returns:
the domain of the editor

getRange

public java.lang.Class<R> getRange()
Returns the range of the editor.

Specified by:
getRange in interface PropertyAccessor<D extends BioPAXElement,R>
Returns:
a class

isMultipleCardinality

public boolean isMultipleCardinality()
Checks if the property to which editor is assigned has multiple cardinality.

Specified by:
isMultipleCardinality in interface PropertyAccessor<D extends BioPAXElement,R>
Returns:
true if editor belongs to a multiple cardinality property.


Copyright © 2011 BioPAX. All Rights Reserved.