Class BeanOntology

  • All Implemented Interfaces:
    Serializable, Serializable

    public class BeanOntology
    extends Ontology
    Extension of Ontology that allows to build the ontological elements adding directly the classes of the corresponding JavaBeans. The BeanOntology internally needs to use its introspector BeanIntrospector. A typical pattern to create an ontology extending the BeanOntology is the following:

     public class MyOntology extends BeanOntology {
    private static Ontology theInstance = new MyOntology(ONTOLOGY_NAME); public static Ontology getInstance() { return theInstance; } private MyOntology(String name) { super(name); try { add("com.acme.rocket.ontology"); add(C1.class); add(C2.class); } catch (OntologyException e) { e.printStackTrace(); } } }

    The ontology MyOntology will be built creating the hierarchy of ontological items defined by the beans in package com.acme.rocket.ontology plus the two beans C1 and C2. An ontological bean is a class implementing either Concept or Predicate Example:

     public class CD extends Item {
    
         private String title;
         protected List tracks;
    
         public String getTitle() {
             return title;
         }
    
         public void setTitle(String t) {
             title = t;
         }
    
         @AggregateSlot(cardMin = 1)
         public List getTracks() {
             return tracks;
         }
    
         public void setTracks(List l) {
             tracks = l;
         }
     }
    
     

    A set of annotatons allow to customize the ontological properties of the slots.
    Author:
    Paolo Cancedda
    See Also:
    Concept, Predicate, Element, Slot, SuppressSlot, AggregateSlot, Result, AggregateResult, Ontology, BasicOntology, Serialized Form
    • Constructor Detail

      • BeanOntology

        public BeanOntology​(String name)
        Create an Ontology with the given name. The BasicOntology is automatically added as the base ontology.
        Parameters:
        name - The identifier of the ontology.
      • BeanOntology

        public BeanOntology​(String name,
                            Ontology base)
        Create an Ontology with the given name that extends the ontology base, which must have BasicOntology in its hierarchy.
        Parameters:
        name - The identifier of the ontology.
        base - The base ontology.
      • BeanOntology

        public BeanOntology​(String name,
                            Ontology[] base)
        Create an Ontology with the given name that extends the base set of ontologies. At least one of the base ontologies must extend the ontology BasicOntology.
        Parameters:
        name - The identifier of the ontology.
        base - The base ontologies
    • Method Detail

      • add

        public void add​(Class clazz)
                 throws BeanOntologyException
        Adds to the ontology the schema built from the class clazz. The class must implement either Concept or Predicate.
        Parameters:
        clazz - class from which to build the ontological schema
        Throws:
        BeanOntologyException
      • add

        public void add​(String pkgname)
                 throws BeanOntologyException
        Adds all the ontological beans (the ones which implement either Concept or Predicate) found in the specified package.
        Parameters:
        pkgname - name of the package containing the beans
        Throws:
        BeanOntologyException
      • add

        public void add​(Class clazz,
                        boolean buildHierarchy)
                 throws BeanOntologyException
        Adds to the ontology the schema built from the class clazz. The class must implement either Concept or Predicate.
        Parameters:
        clazz - class from which to build the ontological schema
        buildHierarchy - if true, build the full hierarchy ontological elements. Otherwise, build a set of flat unrelated elements
        Throws:
        BeanOntologyException
      • add

        public void add​(String pkgname,
                        boolean buildHierarchy)
                 throws BeanOntologyException
        Adds all the ontological beans (the ones which implement either Concept or Predicate) found in the specified package.
        Parameters:
        pkgname - name of the package containing the beans
        buildHierarchy - if true, build the full hierarchy ontological elements. Otherwise, build a set of flat unrelated elements
        Throws:
        BeanOntologyException