sl
Class DefaultOntology

java.lang.Object
  extended bysl.DefaultOntology
All Implemented Interfaces:
Ontology

public final class DefaultOntology
extends java.lang.Object
implements Ontology

A simple implementation of the Ontology interface. Instances of this class keeps all the ontology data in memory, and don't support an external archive format.

Version:
$Date: 2003/10/09 13:00:37 $ $Revision: 1.1.1.1 $
Author:
Giovanni Rimassa - Universita` di Parma

Field Summary
private  java.util.Map roleClasses
           
private  java.util.Map schemas
           
 
Fields inherited from interface sl.Ontology
ANY_SLOT, ANY_TYPE, BINARY_TYPE, BOOLEAN_TYPE, BYTE_TYPE, CHARACTER_TYPE, DATE_TYPE, DOUBLE_TYPE, FLOAT_TYPE, FRAME_SLOT, INTEGER_TYPE, LONG_TYPE, M, NAME_OF_SEQUENCE_FRAME, NAME_OF_SET_FRAME, O, PRIMITIVE_SLOT, SEQUENCE_SLOT, SET_SLOT, SHORT_TYPE, STRING_TYPE
 
Constructor Summary
DefaultOntology()
          Default constructor.
 
Method Summary
 void addRole(java.lang.String roleName, SlotDescriptor[] slots)
          Adds a new role to this ontology, without a user defined Java class to represent it.
 void addRole(java.lang.String roleName, SlotDescriptor[] slots, java.lang.Class newClass)
          Adds a new role to this ontology, with a user defined Java class to represent it.
private  void addSchemaToTable(java.lang.String roleName, FrameSchema fs)
           
private  void buildFromObject(Frame f, FrameSchema fs, java.lang.Object o, java.lang.Class theRoleClass)
           
private  java.lang.Object castPrimitiveValue(java.lang.Object value, java.lang.String type)
           
 void check(Frame f)
          Checks whether a given frame is correct with respect to this ontology.
 void check(java.lang.Object o, java.lang.String roleName)
          Checks whether a given Java object is correct with respect to the given role in this ontology.
private  void checkClass(java.lang.String roleName, java.lang.Class c)
           
private  java.lang.Class checkGetAndSet(java.lang.String name, java.lang.Class c)
           
private  java.lang.Class checkGetAndSet2(java.lang.String name, java.lang.Class c)
          This method checks for correct get and set methods for the current descriptor and retrieves the implementation type.
 java.lang.Object create(Frame f)
          Creates an object, starting from a given frame.
 Frame createFrame(java.lang.Object o, java.lang.String roleName)
          Creates a frame from a given Java Object representing an instance of a given role.
 java.util.List createObject(java.util.List v)
          Creates a List of Java objects from the given list of frame.
private  java.lang.Object createSingleObject(Frame f)
           
private  java.lang.reflect.Method findMethodCaseInsensitive(java.lang.String name, java.lang.Class c)
           
 void fromMetaOntologyRepresentation(AnOntology o)
          Initialize this ontology based on the passed meta-ontology
 java.lang.String fromSL0String(java.lang.String str)
          This method initialized this ontology object on the basis of its representation as an SL-0 expression.
private  int getArgumentLength(java.lang.reflect.Method m)
           
private  java.lang.Class getArgumentType(java.lang.reflect.Method m, int no)
           
 java.lang.Class getClassForRole(java.lang.String roleName)
          Provides the Java class associated with this ontological role.
private  java.lang.Class getReturnType(java.lang.reflect.Method m)
           
 java.lang.String getRoleName(java.lang.Class c)
           
 SlotDescriptor[] getSlots(java.lang.String roleName)
          Get the descriptions for all the slots that define the structure of a given ontological role.
 java.util.List getVocabulary()
           
private  java.lang.Object initObject(Frame f, java.lang.Object entity, java.lang.Class theRoleClass)
           
 boolean isRole(java.lang.String roleName)
          Checks whether a given string is the name of a role in this ontology.
 void joinOntology(Ontology o)
          Adds to this ontology all roles included into another ontology
(package private)  FrameSchema lookupSchema(java.lang.String name)
           
 AnOntology toMetaOntologyRepresentation(java.lang.String ontologyName)
          Return an object representing this ontology in terms of the JADE-Meta-Ontology and that is suitable to be encoded as a String and, for instance, become the content of an ACLMessage.
 java.lang.String toSL0String(java.lang.String ontologyName)
          Writes the ontology represented by this Ontology object as an SL-0 expression.
 java.lang.String toString()
          Return a String representing this ontology Object by calling the method toSL0String() and catching any exception.
private  java.lang.String translateName(java.lang.String name)
          if name starts with UNNAMED_PREFIX, it removes it
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

schemas

private java.util.Map schemas

roleClasses

private java.util.Map roleClasses
Constructor Detail

DefaultOntology

public DefaultOntology()
Default constructor.

Method Detail

lookupSchema

FrameSchema lookupSchema(java.lang.String name)

addRole

public void addRole(java.lang.String roleName,
                    SlotDescriptor[] slots)
             throws OntologyException
Adds a new role to this ontology, without a user defined Java class to represent it.

Specified by:
addRole in interface Ontology
Parameters:
roleName - The name of this role (names are case preserving but the match is case insensitive).
slots - An array of descriptors; each one of them describes a slot of the role, providing:
  • The name of the slot.
  • The category of the slot
  • The type of the slot.
  • The optionality of the slot (i.e. whether a value is required or not).
  • The position of the slot (implicitly defined by the position in the array).
Throws:
OntologyException
See Also:
jade.onto.Ontology#addRole(String roleName, SlotDescriptor[] slots)

addRole

public void addRole(java.lang.String roleName,
                    SlotDescriptor[] slots,
                    java.lang.Class newClass)
             throws OntologyException
Adds a new role to this ontology, with a user defined Java class to represent it.

Specified by:
addRole in interface Ontology
Parameters:
roleName - The name of this role (names are case preserving but the match is case insensitive).
slots - An array of descriptors; each one of them describes a slot of the role, providing:
  • The name of the slot.
  • The category of the slot
  • The type of the slot.
  • The optionality of the slot (i.e. whether a value is required or not).
  • The position of the slot (implicitly defined by the position in the array).
Throws:
OntologyException
See Also:
jade.onto.Ontology#addRole(String roleName, SlotDescriptor[] slots, Class c)

joinOntology

public void joinOntology(Ontology o)
                  throws OntologyException
Adds to this ontology all roles included into another ontology

Specified by:
joinOntology in interface Ontology
Parameters:
o - The Ontology object whose roles will be added
Throws:
OntologyException
See Also:
jade.onto.Ontology#joinOntology(Ontology o)

createObject

public java.util.List createObject(java.util.List v)
                            throws OntologyException
Creates a List of Java objects from the given list of frame.

Specified by:
createObject in interface Ontology
Parameters:
v - A List of Frame objects, from which a List of Java objects is built.
Returns:
A newly created List of Java objects, each Java object corresponding to a Frame and representing an entity in the domain.
Throws:
OntologyException - If a Frame does not represent an instance of any role in the current ontology, or if the registered class does not follow the rules for representing a role.
See Also:
jade.onto.Ontology#createObject(List v)

createSingleObject

private java.lang.Object createSingleObject(Frame f)
                                     throws OntologyException
Throws:
OntologyException

createFrame

public Frame createFrame(java.lang.Object o,
                         java.lang.String roleName)
                  throws OntologyException
Creates a frame from a given Java Object representing an instance of a given role.

Specified by:
createFrame in interface Ontology
Parameters:
o - The Java object, from which the Frame will be built.
roleName - The name of the role represented in this ontology by the class of the given object. Note that the role name does not necessarily coincide with the name of the class representing the role. For this reason the role name must be explicitly indicated.
Returns:
A Frame object representing an instance of the given role, built from the given Object.
Throws:
OntologyException - If the given role does not exist, or the given object is not of the correct class.
See Also:
jade.onto.Ontology#createFrame(Object o, String roleName)

check

public void check(Frame f)
           throws OntologyException
Checks whether a given frame is correct with respect to this ontology.

Specified by:
check in interface Ontology
Parameters:
f - The Frame object to check.
Throws:
OntologyException - If the check fails.
See Also:
jade.onto.Ontology#check(Frame f)

check

public void check(java.lang.Object o,
                  java.lang.String roleName)
           throws OntologyException
Checks whether a given Java object is correct with respect to the given role in this ontology.

Specified by:
check in interface Ontology
Parameters:
o - The Java object to check.
roleName - The role against which to check the given object.
Throws:
OntologyException - If the check fails.
See Also:
jade.onto.Ontology#check(Object o, String roleName)

isRole

public boolean isRole(java.lang.String roleName)
               throws OntologyException
Checks whether a given string is the name of a role in this ontology.

Specified by:
isRole in interface Ontology
Parameters:
roleName - The name of the role to check.
Returns:
true if a role with the given name exists, false otherwise.
Throws:
OntologyException
See Also:
jade.onto.Ontology#isRole(String roleName)

getSlots

public SlotDescriptor[] getSlots(java.lang.String roleName)
                          throws OntologyException
Get the descriptions for all the slots that define the structure of a given ontological role.

Specified by:
getSlots in interface Ontology
Parameters:
roleName - The name of the ontological role to examine.
Returns:
The descriptors for the selected ontology role.
Throws:
OntologyException
See Also:
jade.onto.Ontology#getSlots(String roleName)

getRoleName

public java.lang.String getRoleName(java.lang.Class c)
                             throws OntologyException
Specified by:
getRoleName in interface Ontology
Returns:
the name of the role represented by the passed class as registered in this ontology
Throws:
OntologyException - if no role is found for this class
See Also:
jade.onto.Ontology#getRoleName(Class c)

getVocabulary

public java.util.List getVocabulary()
Specified by:
getVocabulary in interface Ontology
Returns:
a List including the names of all the roles in the ontology, i.e. the Vocabulary used by the ontology
See Also:
jade.onto.Ontology#getVocabulary()

getClassForRole

public java.lang.Class getClassForRole(java.lang.String roleName)
Provides the Java class associated with this ontological role. This class is usually the class used by the create() method to instantiate objects. A useful technique is returning an interface or an abstract class, while using concrete subclasses to create objects.

Specified by:
getClassForRole in interface Ontology
Returns:
the Java class that plays this ontological role (e.g. DFAgentDescription.class

translateName

private java.lang.String translateName(java.lang.String name)
if name starts with UNNAMED_PREFIX, it removes it

Returns:
the name of a method, given the name of a slot

checkGetAndSet

private java.lang.Class checkGetAndSet(java.lang.String name,
                                       java.lang.Class c)
                                throws OntologyException
Throws:
OntologyException

getArgumentLength

private int getArgumentLength(java.lang.reflect.Method m)
Returns:
the number of arguments of the method m

getReturnType

private java.lang.Class getReturnType(java.lang.reflect.Method m)

getArgumentType

private java.lang.Class getArgumentType(java.lang.reflect.Method m,
                                        int no)

checkGetAndSet2

private java.lang.Class checkGetAndSet2(java.lang.String name,
                                        java.lang.Class c)
                                 throws OntologyException
This method checks for correct get and set methods for the current descriptor and retrieves the implementation type. This check is for slots of category SET_SLOT or SEQUENCE_SLOT.

For every SlotDescriptor of category SET_SLOT or SEQUENCE_SLOT and named XXX, with elements of type T, the class must have two accessible methods, with the following signature:

Throws:
OntologyException

checkClass

private void checkClass(java.lang.String roleName,
                        java.lang.Class c)
                 throws OntologyException
Throws:
OntologyException

initObject

private java.lang.Object initObject(Frame f,
                                    java.lang.Object entity,
                                    java.lang.Class theRoleClass)
                             throws OntologyException
Throws:
OntologyException

castPrimitiveValue

private java.lang.Object castPrimitiveValue(java.lang.Object value,
                                            java.lang.String type)
                                     throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

buildFromObject

private void buildFromObject(Frame f,
                             FrameSchema fs,
                             java.lang.Object o,
                             java.lang.Class theRoleClass)
                      throws OntologyException
Throws:
OntologyException

addSchemaToTable

private void addSchemaToTable(java.lang.String roleName,
                              FrameSchema fs)

findMethodCaseInsensitive

private java.lang.reflect.Method findMethodCaseInsensitive(java.lang.String name,
                                                           java.lang.Class c)
                                                    throws OntologyException
Throws:
OntologyException

fromSL0String

public java.lang.String fromSL0String(java.lang.String str)
                               throws CodecException,
                                      OntologyException
Description copied from interface: Ontology
This method initialized this ontology object on the basis of its representation as an SL-0 expression. This expression is based on the JADE-Meta-Ontology encoded in the package jade.onto.JadeMetaOntology
Specified by:
fromSL0String in interface Ontology
Parameters:
str - is the SL-0 expression representing this ontology
Returns:
the name of the ontology
Throws:
CodecException
OntologyException
See Also:
Ontology.fromSL0String(String)

fromMetaOntologyRepresentation

public void fromMetaOntologyRepresentation(AnOntology o)
                                    throws OntologyException
Description copied from interface: Ontology
Initialize this ontology based on the passed meta-ontology

Specified by:
fromMetaOntologyRepresentation in interface Ontology
Parameters:
o - is a JADE-Meta-Ontology
Throws:
OntologyException
See Also:
Ontology.fromMetaOntologyRepresentation(AnOntology)

toString

public java.lang.String toString()
Return a String representing this ontology Object by calling the method toSL0String() and catching any exception. Notice that this method ignores the name of the ontology and, therefore, the method toSL0String() should be preferred, instead.

Returns:
the String representing this ontology, or null if any exception occurs.

toMetaOntologyRepresentation

public AnOntology toMetaOntologyRepresentation(java.lang.String ontologyName)
Description copied from interface: Ontology
Return an object representing this ontology in terms of the JADE-Meta-Ontology and that is suitable to be encoded as a String and, for instance, become the content of an ACLMessage.

Specified by:
toMetaOntologyRepresentation in interface Ontology
Parameters:
ontologyName - is the name of this ontology. It cannot be either null or an empty String.
Returns:
a JADE-Meta-Ontology
See Also:
Ontology.toMetaOntologyRepresentation(String)

toSL0String

public java.lang.String toSL0String(java.lang.String ontologyName)
                             throws OntologyException
Writes the ontology represented by this Ontology object as an SL-0 expression.

Specified by:
toSL0String in interface Ontology
Parameters:
ontologyName - the name of this ontology
Returns:
a String that is an SL-0 expression representing this ontology
Throws:
OntologyException
See Also:
Ontology.toSL0String()

create

public java.lang.Object create(Frame f)
                        throws OntologyException
Description copied from interface: Ontology
Creates an object, starting from a given frame. This method can just create the object ignoring its argument, or it can use the frame to select the concrete class to instantiate.

Specified by:
create in interface Ontology
Parameters:
f - A frame containing initialization data for the object.
Returns:
A Java object, instance of the proper class (either the class returned by getClassForRole(), or one of its subclasses).
Throws:
OntologyException


Copyright © 2000-2003 BT Exact Technologies. All Rights Reserved.