org.concord.biologica.engine
Class World

java.lang.Object
  |
  +--org.xml.sax.HandlerBase
        |
        +--org.concord.biologica.engine.EngineObject
              |
              +--org.concord.biologica.engine.World
All Implemented Interfaces:
org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, java.io.Serializable

public final class World
extends EngineObject
implements java.io.Serializable, org.xml.sax.DocumentHandler

This class represents a BioLogica world. There is a single world per BioLogica file. An object of this class will generate the following property change events:

Version:
$Revision: 1.3 $ $Date: 2002/03/11 16:50:21 $
Author:
$Author: dima $
See Also:
EngineProp.ID, EngineProp.CURRENT_SPECIES, EngineProp.DELETED, EngineProp.DIRTY, EngineProp.FILE, EngineProp.ENVIRONMENT_ADDED, EngineProp.ENVIRONMENT_REMOVED, EngineProp.FAMILY_ADDED, EngineProp.FAMILY_REMOVED, EngineProp.LOCKED_STATE, EngineProp.ORGANISM_ADDED, EngineProp.ORGANISM_REMOVED, EngineProp.SPECIES_ADDED, EngineProp.SPECIES_REMOVED, EngineProp.TERRAIN_ADDED, EngineProp.TERRAIN_REMOVED, PropertyChangeListener, Serialized Form

Fields inherited from class org.concord.biologica.engine.EngineObject
AUTOMATIC_LOCKED, AUTOMATIC_LOCKED_STRING, changes, deleted, FALSE, id, lockedState, MANUAL_AND_AUTOMATIC_LOCKED, MANUAL_AND_AUTOMATIC_LOCKED_STRING, MANUAL_LOCKED, MANUAL_LOCKED_STRING, NULL_ID, TRUE, UNLOCKED, UNLOCKED_STRING, xmlElementContext
 
Constructor Summary
World()
          Creates a new world, as when creating a new world that has no associated file yet.
World(java.io.File aFile)
          Creates a new world with by opening the given file and retrieving the contents of the file.
World(java.lang.String urlString)
          Creates a new world with by opening the given url and retrieving the contents of the url file.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receive notification of character data.
 void close()
          Close the current engine, which is identical to delete -- I think!
 void delete()
          Delete this object, notifying parent objects and deleting any child objects.
 void delete(boolean notifyChange)
           
 void deleteAllFamilies(boolean notifyChange, boolean deleteChildren)
           
 void deleteAllOrganisms(boolean notifyChange)
           
 void deleteSpecifiedFamilies(java.util.Vector familyList, boolean notifyChange, boolean deleteChildren)
           
 void deleteSpecifiedOrganisms(java.util.Vector orgList, boolean notifyChange)
           
 void endDocument()
          Handle notification that a document parse has ended.
 void endElement(java.lang.String anElementName)
          Handle notification that the parsing of the given element has ended.
 Species getCurrentSpecies()
          Get the current species.
 java.util.Enumeration getEnvironments()
          Returns an enumeration over the vector of environments in this engine.
 java.util.Enumeration getFamilies()
          Returns an enumeration over the vector of families in this engine.
 java.io.File getFile()
          Return the current world file.
 java.lang.String getName()
          Return the name of this world.
 int getNumberOfEnvironments()
          Return the number of environments.
 int getNumberOfFamilies()
          Return the number of families.
 int getNumberOfOrganisms()
          Return the number of organisms.
 int getNumberOfSpecies()
          Return the number of species.
 int getNumberOfTerrains()
          Return the number of terrains of this world.
 java.util.Enumeration getOrganisms()
          Returns an enumeration over the vector of organisms in this world.
 java.util.Enumeration getSpecies()
          Returns an enumeration over the vector of species in this world.
 java.util.Enumeration getTerrains()
          Returns an enumeration over the world's terrains.
 World getWorld()
          Get the world containing this object.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable white space character data.
 void initLoadImages()
           
 void initLoadImages(java.lang.String s)
           
 boolean isDirty()
          Return the dirty state of this engine.
 void save()
          Save the world state to the current file.
 void saveAs(java.io.File aFile)
          Save As the world state to the new given file.
 void setAutomaticLocked(boolean automaticLocked)
          Set or unset the automatic locked state of this object, leaving other components of the locked state untouched.
 void setCurrentSpecies(Species aSpecies)
          Set the current species.
 void setDirty()
          Set the dirty state of this engine to true.
 void setFile(java.io.File aFile)
          Set file.
 void setLockedState(int aLockedState)
          Set the locked state of the object, recursively setting the locked state of children objects.
 void setManualLocked(boolean manualLocked)
          Set or unset the manual locked state of this object, leaving other components of the locked state untouched.
 void startDocument()
          Handle notification that a new document parse has started.
 void startElement(java.lang.String anElementName, org.xml.sax.AttributeList amap)
          Handle notification that the parser has hit the start of a new element with the given name and attributes.
 java.lang.String toString()
          Return a string representation of this object, usually the object's name.
 void writeToStream(java.io.PrintWriter stream)
          Writes this object to the given stream in XML format.
 
Methods inherited from class org.concord.biologica.engine.EngineObject
addPropertyChangeListener, getID, getLockedState, getLockedStateAsString, isAutomaticLocked, isDeleted, isLocked, isManualLocked, notifySelected, release, removePropertyChangeListener, setID, setLockedStateAsString
 
Methods inherited from class org.xml.sax.HandlerBase
error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xml.sax.DocumentHandler
processingInstruction, setDocumentLocator
 

Constructor Detail

World

public World()
Creates a new world, as when creating a new world that has no associated file yet.


World

public World(java.io.File aFile)
Creates a new world with by opening the given file and retrieving the contents of the file.

Parameters:
aFile - File - file to be opened to create this world, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal
InternalEngineException - - multiple Engine objects detected in process

World

public World(java.lang.String urlString)
Creates a new world with by opening the given url and retrieving the contents of the url file.

Parameters:
urlString - String - file to be opened to create this world, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal
InternalEngineException - - multiple Engine objects detected in process
Method Detail

delete

public void delete()
Delete this object, notifying parent objects and deleting any child objects.

When this method is called, a property change event is generated for the property named EngineProp.DELETED.

Overrides:
delete in class EngineObject

delete

public void delete(boolean notifyChange)

deleteSpecifiedFamilies

public void deleteSpecifiedFamilies(java.util.Vector familyList,
                                    boolean notifyChange,
                                    boolean deleteChildren)

deleteAllFamilies

public void deleteAllFamilies(boolean notifyChange,
                              boolean deleteChildren)

deleteSpecifiedOrganisms

public void deleteSpecifiedOrganisms(java.util.Vector orgList,
                                     boolean notifyChange)

deleteAllOrganisms

public void deleteAllOrganisms(boolean notifyChange)

toString

public java.lang.String toString()
Return a string representation of this object, usually the object's name.

Overrides:
toString in class EngineObject
Returns:
String - string representation of object

getWorld

public World getWorld()
Get the world containing this object.

Overrides:
getWorld in class EngineObject
Returns:
World - the world containing this object, never null.

getName

public java.lang.String getName()
Return the name of this world. The name of a world is the path of the filename of the world.

Returns:
String - filename of this world's file, may be null

isDirty

public boolean isDirty()
Return the dirty state of this engine. Dirty means the engine has been modified since the last save or open.

Returns:
boolean - dirty (true) or not dirty (false)

setDirty

public void setDirty()
Set the dirty state of this engine to true. Only this object can set its dirty state to false as that only happens when the engine state is saved or a new engine is created.

When this method is successful, a property change event is fired for the property named EngineProp.DIRTY.

Throws:
java.lang.IllegalArgumentException - - input argument illegal

getFile

public java.io.File getFile()
Return the current world file.
Returns:
File - the current file, may be null

setFile

public void setFile(java.io.File aFile)
Set file. I'm not sure if this method makes sense, as instead you should probaby only specify the file when opening or saving a file. So this method may be removed in the future.

When this property is changed, a property change event is fired for the property named EngineProp.FILE.

Parameters:
aFile - File - the new file, may be null

setAutomaticLocked

public void setAutomaticLocked(boolean automaticLocked)
Set or unset the automatic locked state of this object, leaving other components of the locked state untouched. Recursively sets the automatic locked state of children of this object.

When this property is changed, a property change event is fired for the property named EngineProp.LOCKED_STATE.

Overrides:
setAutomaticLocked in class EngineObject
Parameters:
automaticLocked - boolean - object should be automatic locked (true) or not (false)

setManualLocked

public void setManualLocked(boolean manualLocked)
Set or unset the manual locked state of this object, leaving other components of the locked state untouched. Recursively sets the manual locked state of children of this object.

When this property is changed, a property change event is fired for the property named EngineProp.LOCKED_STATE.

Overrides:
setManualLocked in class EngineObject
Parameters:
manualLocked - boolean - object should be manually locked (true) or not (false)

setLockedState

public void setLockedState(int aLockedState)
Set the locked state of the object, recursively setting the locked state of children objects.

When this property is changed, a property change event is fired for the property named EngineProp.LOCKED_STATE.

Overrides:
setLockedState in class EngineObject
Parameters:
aLockedState - int - new locked state of this object
Throws:
java.lang.IllegalArgumentException - - new locked state invalid

getSpecies

public java.util.Enumeration getSpecies()
Returns an enumeration over the vector of species in this world.

Returns:
Enumeration - an enumeration over the species in this world

initLoadImages

public void initLoadImages()

initLoadImages

public void initLoadImages(java.lang.String s)

getNumberOfSpecies

public int getNumberOfSpecies()
Return the number of species.

Returns:
int - the number of species in this world

getCurrentSpecies

public Species getCurrentSpecies()
Get the current species.
Returns:
Species - current species in this world, may be null

setCurrentSpecies

public void setCurrentSpecies(Species aSpecies)
Set the current species.
Parameters:
aSpecies - Species - a species, may be null

getEnvironments

public java.util.Enumeration getEnvironments()
Returns an enumeration over the vector of environments in this engine.

Returns:
Enumeration - an enumeration over the environments in this engine

getNumberOfEnvironments

public int getNumberOfEnvironments()
Return the number of environments.

Returns:
int - the number of environments in this engine

getNumberOfOrganisms

public int getNumberOfOrganisms()
Return the number of organisms.

Returns:
int - the number of organisms in this world

getOrganisms

public java.util.Enumeration getOrganisms()
Returns an enumeration over the vector of organisms in this world.

Returns:
Enumeration - an enumeration over the organisms in this world

getNumberOfFamilies

public int getNumberOfFamilies()
Return the number of families.

Returns:
int - the number of families in this engine

getFamilies

public java.util.Enumeration getFamilies()
Returns an enumeration over the vector of families in this engine.

Returns:
Enumeration - an enumeration over the families in this engine

getNumberOfTerrains

public int getNumberOfTerrains()
Return the number of terrains of this world.

Returns:
int - the number of terrains of this world

getTerrains

public java.util.Enumeration getTerrains()
Returns an enumeration over the world's terrains.

If there are no terrains in this world, an enumeration with no elements is returned.

Returns:
Enumeration - an enumeration over the vector of terrains of this world, never null

saveAs

public void saveAs(java.io.File aFile)
Save As the world state to the new given file.

Parameters:
aFile - File - file to use in saving
Throws:
java.lang.IllegalArgumentException - - file not a valid file

save

public void save()
Save the world state to the current file.


startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Handle notification that a new document parse has started.
Specified by:
startDocument in interface org.xml.sax.DocumentHandler
Overrides:
startDocument in class org.xml.sax.HandlerBase
Following copied from interface: org.xml.sax.DocumentHandler
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Handle notification that a document parse has ended.
Specified by:
endDocument in interface org.xml.sax.DocumentHandler
Overrides:
endDocument in class org.xml.sax.HandlerBase
Following copied from interface: org.xml.sax.DocumentHandler
Throws:
org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.

startElement

public void startElement(java.lang.String anElementName,
                         org.xml.sax.AttributeList amap)
                  throws org.xml.sax.SAXException
Handle notification that the parser has hit the start of a new element with the given name and attributes.

For internal elements (elements that are non-EngineObject instance variables of this object), call xmlElementContext.startElement() and xmlElementContext will receive the remaining element notifications. For external elements (elements that are EngineObject instance variables of this object), create an object of the appropriate class and that object will receive the remaining element notifications.

Specified by:
startElement in interface org.xml.sax.DocumentHandler
Overrides:
startElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - name of element
amap - AttributeList - an attribute list

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character data.
Specified by:
characters in interface org.xml.sax.DocumentHandler
Overrides:
characters in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Receive notification of ignorable white space character data.
Specified by:
ignorableWhitespace in interface org.xml.sax.DocumentHandler
Overrides:
ignorableWhitespace in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

endElement

public void endElement(java.lang.String anElementName)
                throws org.xml.sax.SAXException
Handle notification that the parsing of the given element has ended.
Specified by:
endElement in interface org.xml.sax.DocumentHandler
Overrides:
endElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - the element name

close

public void close()
Close the current engine, which is identical to delete -- I think!

writeToStream

public void writeToStream(java.io.PrintWriter stream)
                   throws java.io.IOException
Writes this object to the given stream in XML format. Usually this method is used to write the object to a file for saving it, but that is potentially not the only use.

We could supply a default implementation that knows how to write the id value. But that convenience is not chosen because it's never correct to use just this implementation of these methods, so I'd rather have a compilation fail if a derived class fails to implement this method.

The inverse of this method is a constructor that takes a org.xml.sax.Parser argument and other arguments.

Overrides:
writeToStream in class EngineObject
Parameters:
stream - PrintWriter - print stream
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
java.io.IOException - - an IO error occurred in java libraries