net.sourceforge.fluxion.datasource.utils
Class BeanUtils

java.lang.Object
  extended by net.sourceforge.fluxion.datasource.utils.BeanUtils

public class BeanUtils
extends java.lang.Object

A utility class, containing methods for manipulating owl in tems of the underlying javabean model. Static methods exist in this class to look for various annotations, and work out whether a bean can be queried directly, and so on.

Version:
0.2
Author:
Tony Burdett
See Also:
QueryUtils

Constructor Summary
BeanUtils()
           
 
Method Summary
static java.lang.String getBeanInstanceUniqueId(java.lang.Object beanInstance)
          Get the Unique Id for a given beanInstance.
static java.lang.Class<?> getClassFromFilter(java.lang.Class<? extends Filter> filterClass)
           
static java.lang.Class<? extends Filter> getFilterFromClass(java.lang.Class<?> beanClass)
          Get the filter paired to this bean class.
static java.lang.Class getRelatedBeanClass(org.semanticweb.owl.model.OWLClass owlClass, org.semanticweb.owl.model.OWLOntology ontology)
          Looks for the value of the RelatedBean annotation on the given OWL class.
static java.lang.reflect.Method getRelatedBeanMethod(java.lang.Class beanClass, org.semanticweb.owl.model.OWLProperty owlProperty, org.semanticweb.owl.model.OWLOntology ontology)
          Looks up the value of the relatedMethod annotation on the given OWL property.
static boolean isBeanClass(org.semanticweb.owl.model.OWLClass owlClass, org.semanticweb.owl.model.OWLOntology ontology)
          Checks whether the passed class has a "RelatedBean" annotation.
static boolean isBeanMethod(org.semanticweb.owl.model.OWLProperty owlProperty, org.semanticweb.owl.model.OWLOntology ontology)
          Checks whether the given property has a "relatedMethod" annotation attached
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanUtils

public BeanUtils()
Method Detail

getBeanInstanceUniqueId

public static java.lang.String getBeanInstanceUniqueId(java.lang.Object beanInstance)
                                                throws MissingElementException
Get the Unique Id for a given beanInstance. This id is acquired by looking up the bean class description, finding the method(s) labelled "@UniqueId" and labelling the instance with the value of this method. If there are no "@Uniqueid" methods, a (hopefully) unique id is created using the class name and the current time in milliseconds. Note that this is not flaawless, and clients should probably check that this individual does not exist before using this id.

Parameters:
beanInstance - the bean instance we want a unique id for
Returns:
the String representing the unique id
Throws:
MissingElementException - if there is a problem with the beanInstance supplied

isBeanClass

public static boolean isBeanClass(org.semanticweb.owl.model.OWLClass owlClass,
                                  org.semanticweb.owl.model.OWLOntology ontology)
Checks whether the passed class has a "RelatedBean" annotation. Returns true if the RelatedBean annotation was found, false otherwise.

Parameters:
owlClass - the owlClass being assessed
ontology - the ontology to search against
Returns:
true if a RelatedBean annotation was found, false otherwise

getRelatedBeanClass

public static java.lang.Class getRelatedBeanClass(org.semanticweb.owl.model.OWLClass owlClass,
                                                  org.semanticweb.owl.model.OWLOntology ontology)
                                           throws OWLTransformationException,
                                                  MissingElementException
Looks for the value of the RelatedBean annotation on the given OWL class. Returns the class that matches the name given by the RelatedBean annotation if found. Throws a MissingElementException if an OWL class which has no RelatedBean annotation is passed - so BeanUtils.isBeanClass() should always be called to check this class before calling this method.

Parameters:
owlClass - the owlClass we want the bean for
ontology - the ontology that contains the OWLClass we're retrieving the bean class for
Returns:
the RelatedBean class
Throws:
OWLTransformationException - if there was a problem with loading class specified by the RelatedBean annotation
MissingElementException - if there is no RelatedBean annotationon the class

isBeanMethod

public static boolean isBeanMethod(org.semanticweb.owl.model.OWLProperty owlProperty,
                                   org.semanticweb.owl.model.OWLOntology ontology)
Checks whether the given property has a "relatedMethod" annotation attached

Parameters:
owlProperty - the owl property being inspected
ontology - the ontology containing this OWLProperty
Returns:
true if this property has a relatedMethod attached, false otherwise

getRelatedBeanMethod

public static java.lang.reflect.Method getRelatedBeanMethod(java.lang.Class beanClass,
                                                            org.semanticweb.owl.model.OWLProperty owlProperty,
                                                            org.semanticweb.owl.model.OWLOntology ontology)
                                                     throws OWLTransformationException,
                                                            MissingElementException
Looks up the value of the relatedMethod annotation on the given OWL property. Returns the Method the matches the name of the relatedMethod annotation if found. Throws a MissingElementException if an OWL property which has no relatedMethod annotation is passed - BeanUtils.isBeanMethod() should be called first to avoid this exception.

Parameters:
beanClass - the bean we're looking up methods on
owlProperty - the property we want to look up the relatedMethod for
ontology - the ontology containing this OWLProperty
Returns:
the relevant method
Throws:
OWLTransformationException - if there is a problem accessing the owl
MissingElementException - if the relatedMethod annotation

getFilterFromClass

public static java.lang.Class<? extends Filter> getFilterFromClass(java.lang.Class<?> beanClass)
                                                            throws OWLTransformationException,
                                                                   MissingElementException
Get the filter paired to this bean class. If no filter is present, a MissingElementException is returned. If the filter is present but cannot be loaded, an OWLTransformationException is thrown

Parameters:
beanClass - the bean class being inspected for associated filters
Returns:
the relevant filter class
Throws:
OWLTransformationException - if the filter cannot be found, or if the value of the annotation points to a class which is not a Filter
MissingElementException - if there is no FilterAnn present on the given bean class

getClassFromFilter

public static java.lang.Class<?> getClassFromFilter(java.lang.Class<? extends Filter> filterClass)
                                             throws MissingElementException,
                                                    java.lang.ClassNotFoundException
Throws:
MissingElementException
java.lang.ClassNotFoundException


Copyright © 2010. All Rights Reserved.