org.concord.biologica.engine
Class ImportContext

java.lang.Object
  |
  +--org.concord.biologica.engine.ImportContext

public final class ImportContext
extends java.lang.Object

This class represents a context for a set of objects being imported into an active BioLogica process.

Specifically, this class maintains a mapping of old object ids to object references. This diagram shows what the objects look like in the File on the left side and what the objects look like after they've been read into an existing BioLogica process.

			File							BioLogica Process

		object 1						object 435
			no object references			no object references
		object 2						object 567
			reference to object 1			reference to object 435
		object 3						object 798
			reference to object 1			reference to object 435
			reference to object 2			reference to object 567
		object 4						object 876
			reference to object 3			reference to object 798
 
So the mapping of old IDs to new objects would be:
			Old ID				New Object Reference

				1				reference to object 435
				2				reference to object 567
				3				reference to object 798
				4				reference to object 876
 
As additional objects are read in, this mapping is added to and used.

Of course, this implies that objects are written to the file originally in a parent to child order, as that's the only way to avoid cycles.

This object fires no property change events, as this object is created and used and then deleted all within the process of opening and reading in one file. So no other object has a chance to add itself to this object as a listener.

This class works by maintaining an array of objects that have been read into the world where the index of an object into that array is the id of that object in the world file. But the id of the object after it has been created in this process will normally not be the same as it was in the file. In other words, the id of the object is changed as it is read into this process from the file. This class maintains the mapping of the old ids to the new objects.

Version:
$Revision: 1.1.1.1 $ $Date: 2001/04/28 00:39:13 $
Author:
$Author: ed $

Constructor Summary
ImportContext()
          Creates a new ImportContext.
 
Method Summary
 void addObject(EngineObject engineObject, int oldID)
          Add an object to the engine's array of objects, reallocating the array to a larger size if necessary.
 EngineObject getObject(int id)
          Get an object given its old id in the world file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImportContext

public ImportContext()
Creates a new ImportContext.
Throws:
InternalEngineException - - multiple Engine objects detected in process
Method Detail

getObject

public EngineObject getObject(int id)
Get an object given its old id in the world file.

Parameters:
id - int - id of the object to get, must be 0 to Integer.MAX_VALUE
Returns:
EngineObject - object with the given id, may be null
Throws:
java.lang.IllegalArgumentException - - object with id not found

addObject

public void addObject(EngineObject engineObject,
                      int oldID)
Add an object to the engine's array of objects, reallocating the array to a larger size if necessary. Grow the array by 1024 for now, but perhaps it should be a larger increment in the future?

Parameters:
engineObject - EngineObject - object to add, may not be null
oldID - int - the old id the object had (NOT the id it has now)
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
InternalEngineException - - oldID was more than 1024 greater than array size