unsw.cse.mica.data
Class LocalTypeManager

java.lang.Object
  extended by unsw.cse.mica.data.LocalTypeManager
All Implemented Interfaces:
TypeManager

public class LocalTypeManager
extends java.lang.Object
implements TypeManager

A class representing a local copy of the type hierarchy for mob types. It can be constructed via XML from either a stream or a file.

Author:
waleed

Field Summary
 
Fields inherited from interface unsw.cse.mica.data.TypeManager
TYPE_MOB
 
Constructor Summary
LocalTypeManager()
           
 
Method Summary
 boolean addType(java.lang.String typeName, java.lang.String persistence, java.lang.String[] parents)
           
 java.util.Set getAllTypeNames()
          We make a new set because the set returned by keySet() is still backed by the map and can thus mess with our internal state.
 java.util.Set getAncestors(java.lang.String typeName)
          Get a set containing the names of all ancestors of the given type.
 java.util.Set getChildren(java.lang.String typeName)
          Get a set containing the names of all children (immediate descendants) of the given type.
 java.util.Set getDescendants(java.lang.String typeName)
          Get a set containing the names of all descendants of the given type.
 java.util.Set getParents(java.lang.String typeName)
          Get a set containing the names of all parents (immediate ancestors) of the given type.
 java.lang.String getPersistence(java.lang.String typeName)
          Get the default persistence mode for this type.
 boolean hasType(java.lang.String typeName)
          Does the type manager know about the given type?
 boolean isATypeOf(Mob mob, java.lang.String parentName)
          Is the mob an instance of typeName? This is true if isATypeOf(mob.getType(), typeName) is true.
 boolean isATypeOf(java.lang.String typeName, java.lang.String parentName)
          Is one type a subtype of another? A type is a subtype of another if the types are the same or if is a descendant of it
 void loadTypesDirectory()
          Load from the default directory, if it exists, otherwise do nothing.
 void loadTypesDirectory(MicaProperties args)
          Load a typemanager from the directory specified by the arguments.
 void loadTypesDirectory(java.lang.String abstypedir)
          Load from the directory specified.
 void readTypeFile(java.io.File file)
          Reads an XML file describing the relation between types
 java.lang.String toString()
           
 java.lang.String toXML()
           
 java.lang.String toXML(java.lang.String initIndent, java.lang.String otherIndent)
          Create an XML representation of the type manager
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalTypeManager

public LocalTypeManager()
Method Detail

hasType

public boolean hasType(java.lang.String typeName)
Description copied from interface: TypeManager
Does the type manager know about the given type?

Specified by:
hasType in interface TypeManager
Returns:
true if the type is known, false otherwise

isATypeOf

public boolean isATypeOf(java.lang.String typeName,
                         java.lang.String parentName)
Description copied from interface: TypeManager
Is one type a subtype of another? A type is a subtype of another if the types are the same or if is a descendant of it

Specified by:
isATypeOf in interface TypeManager
Returns:
true if typeName is a subtype of parentName, false otherwise

isATypeOf

public boolean isATypeOf(Mob mob,
                         java.lang.String parentName)
Description copied from interface: TypeManager
Is the mob an instance of typeName? This is true if isATypeOf(mob.getType(), typeName) is true.

Specified by:
isATypeOf in interface TypeManager
Returns:
true if the mob is an instance of the given type, false otherwise

getPersistence

public java.lang.String getPersistence(java.lang.String typeName)
Description copied from interface: TypeManager
Get the default persistence mode for this type.

Specified by:
getPersistence in interface TypeManager
Returns:
the default persistence mode for this type, or null if no default persistence is specified.

getAllTypeNames

public java.util.Set getAllTypeNames()
We make a new set because the set returned by keySet() is still backed by the map and can thus mess with our internal state.

Specified by:
getAllTypeNames in interface TypeManager
Returns:
a set containing all the known type names for this type manager

getParents

public java.util.Set getParents(java.lang.String typeName)
Get a set containing the names of all parents (immediate ancestors) of the given type.

Specified by:
getParents in interface TypeManager
Parameters:
typeName -
Returns:
a set containing the names of all the parents of the given type

getChildren

public java.util.Set getChildren(java.lang.String typeName)
Get a set containing the names of all children (immediate descendants) of the given type.

Specified by:
getChildren in interface TypeManager
Parameters:
typeName -
Returns:
a set containing the names of all the children of the given type

getAncestors

public java.util.Set getAncestors(java.lang.String typeName)
Description copied from interface: TypeManager
Get a set containing the names of all ancestors of the given type.

Specified by:
getAncestors in interface TypeManager
Parameters:
typeName - the type for which the ancestors are requested
Returns:
a set containing the names of all the ancestors of the given type

getDescendants

public java.util.Set getDescendants(java.lang.String typeName)
Description copied from interface: TypeManager
Get a set containing the names of all descendants of the given type.

Specified by:
getDescendants in interface TypeManager
Parameters:
typeName - the type for which the descendants are requested
Returns:
a set containing the names of all the descendants of the given type

addType

public boolean addType(java.lang.String typeName,
                       java.lang.String persistence,
                       java.lang.String[] parents)
                throws TypeException
Throws:
TypeException

loadTypesDirectory

public void loadTypesDirectory()
                        throws TypeException
Load from the default directory, if it exists, otherwise do nothing.

Throws:
TypeException

loadTypesDirectory

public void loadTypesDirectory(MicaProperties args)
                        throws TypeException
Load a typemanager from the directory specified by the arguments. The directory searched is micaHome/typePath. micaHome is specified by a parameter whose key is the value of MicaConstants.PARAM_MICA_HOME (if present), otherwise micaHome is specified as the value of MicaConstants.DEFAULT_MICA_HOME. typePath is specified by a parameter whose key is the value of MicaConstants.PARAM_TYPE_PATH (if present), otherwise typePath is specified as the value of MicaConstants.DEFAULT_TYPE_PATH.

Throws:
TypeException

loadTypesDirectory

public void loadTypesDirectory(java.lang.String abstypedir)
                        throws TypeException
Load from the directory specified.

Parameters:
abstypedir -
Throws:
TypeException

readTypeFile

public void readTypeFile(java.io.File file)
                  throws TypeException
Reads an XML file describing the relation between types

Parameters:
file - The File that is loaded.
Throws:
TypeException

toString

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

toXML

public java.lang.String toXML()

toXML

public java.lang.String toXML(java.lang.String initIndent,
                              java.lang.String otherIndent)
Description copied from interface: TypeManager
Create an XML representation of the type manager

Specified by:
toXML in interface TypeManager
Parameters:
initIndent - the per-line indent for the entire XML string (which may be multi-line)
otherIndent - additioanl indentation for nested elements
Returns:
a string that is an XML representation of the current state of the type manager