org.jadv.basic
Class SavedObject

java.lang.Object
  |
  +--org.jadv.basic.SavedObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
JAdvObject, LevelDesc

public class SavedObject
extends java.lang.Object
implements java.io.Serializable

This class implements the main Object, that is stored inside the ObjectManager

Author:
neitzel
See Also:
Serialized Form

Field Summary
private  java.util.HashMap _Attributes
           
private  boolean _changed
           
private  java.lang.String _id
           
private  java.lang.String _name
           
private  SavedObject _next
           
private  SavedObject _prev
           
private  boolean _valid
           
static ObjectManager ObjMan
           
private static java.security.SecureRandom seeder
           
 
Constructor Summary
SavedObject()
          Constructor of SavedObject
 
Method Summary
static void addEvent(Event evt)
          Add an event to the EventQueue of the game
 boolean canBeSwapped()
          Returns true, if the object can be swapped out!
 void create()
          This function is only called, when the object is created!
static java.util.HashMap createAttributes(org.jdom.Element el)
          Create a HashMap with all attributes, that are given in the Element!
static SavedObject createObject(org.jdom.Element desc)
          Create a new Object out of a xml-Description!
static SavedObject createObject(java.util.HashMap desc)
          Create a new Object out of a xml-Description!
static java.lang.String createUUID(java.lang.Object obj)
          Creates a new unique ID.
 void destroyObject()
          Destroy this object (Object will be deleted completly!)
static SavedObject findObject(java.lang.String id)
          Find object with the given ID
 java.lang.String getAttribute(java.lang.String Name)
          Get the Attribute with the name
 java.util.HashMap getAttributes()
          Returns all Attributes
 boolean getAutoStart()
          Return, if the Object should be loaded at Serverstart
 java.lang.String getDeveloper(java.lang.String cname)
          Returns the responsible developer of a class.
 java.lang.String getId()
          Get the ID of the Object
 int getIntAttribute(java.lang.String Name)
          Get an int-Value of an Attribute!
 int getIntAttribute(java.lang.String Name, int def)
          Get an int-Value of an Attribute!
 java.lang.String getName()
          Get the name of the object.
 SavedObject getNext()
          Get the next object of the internal List
 SavedObject getPrev()
          Get the previous Object of the internal List
private static java.security.SecureRandom getSeeder()
          Returns the internal SecureRandom seeder!
static java.lang.String hexFormat(int value, int length)
          Convert an integer value into hex-format with length chars (e.g. hexFormat(31,3) ==> 01F)
 void init(java.util.HashMap attribs)
          Initialisation of the object!
 boolean isChanged()
          Returns if this Object is changed or not!
 boolean isValid()
          Returns if this Object is valid or not!
static SavedObject loadObject(java.util.HashMap desc)
           
 void markChanged()
          Mark the object as changed - the object must be saved!
 void markNotChanged()
          Mark the object as not changed - the object must not be saved!
static void mergeAttributes(java.util.HashMap attribs, java.util.HashMap oldAttribs)
          mergeAttributes Merge the Attributes of two Objects into each other!
 void removeFromList()
          This object is removed from the list of all SavedObjects.
static SavedObject replaceObject(org.jdom.Element el)
          Delete an object and create a new one instead ...
static SavedObject replaceObject(java.util.HashMap attribs)
          Delete an object and create a new one instead ...
 void save()
          Save this Object!
 void saveObject()
           
 java.lang.String setAttribute(java.lang.String Name, java.lang.String Value)
          setAttribute(name, value) Set the Attribute name := value This function returns the old value!
 void setId(java.lang.String id)
          setId(id) Set the ID of the Object
 void setIntAttribute(java.lang.String name, int val)
          Set an int-value inside an Attribute.
 void setName(java.lang.String name)
          setName(name) Set the internal name of the Object
 void storeAfter(SavedObject obj)
          storeAfter(obj) This function is internaly used from the ObjectManager.
 void swapOut()
          swapOut() If an Object is no longer used, call this function!
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_next

private SavedObject _next

_prev

private SavedObject _prev

_id

private java.lang.String _id

_changed

private boolean _changed

_name

private java.lang.String _name

_valid

private boolean _valid

ObjMan

public static ObjectManager ObjMan

seeder

private static java.security.SecureRandom seeder

_Attributes

private java.util.HashMap _Attributes
Constructor Detail

SavedObject

public SavedObject()
Constructor of SavedObject

See Also:
Object.Object()
Method Detail

addEvent

public static void addEvent(Event evt)
Add an event to the EventQueue of the game

Parameters:
evt - - the event to add.

canBeSwapped

public boolean canBeSwapped()
Returns true, if the object can be swapped out!

Returns:
boolean

create

public void create()
This function is only called, when the object is created! (This is needed for stuff, that must be done once, e.g. moving into the right location)


createAttributes

public static java.util.HashMap createAttributes(org.jdom.Element el)
Create a HashMap with all attributes, that are given in the Element!

Parameters:
el - - Element with all attributes inside
Returns:
HashMap The Attribute Hashmap

createObject

public static SavedObject createObject(org.jdom.Element desc)
Create a new Object out of a xml-Description!

Parameters:
desc - - Description of the Object
Returns:
The new SavedObject

createObject

public static SavedObject createObject(java.util.HashMap desc)
Create a new Object out of a xml-Description!

Parameters:
desc - - Description of the Object
Returns:
The new SavedObject

createUUID

public static java.lang.String createUUID(java.lang.Object obj)
Creates a new unique ID.

Returns:
String The unique ID

destroyObject

public void destroyObject()
Destroy this object (Object will be deleted completly!)


findObject

public static SavedObject findObject(java.lang.String id)
Find object with the given ID

Parameters:
id - - id of the object
Returns:
SavedObject - The Object

getAttribute

public java.lang.String getAttribute(java.lang.String Name)
Get the Attribute with the name

Parameters:
Name - - Name of the attribute
Returns:
String - the Value of the attribute

getAttributes

public java.util.HashMap getAttributes()
Returns all Attributes

Returns:
HashMap All Attributes

getAutoStart

public boolean getAutoStart()
Return, if the Object should be loaded at Serverstart

Returns:
boolean - true if the Object should be loaded

getDeveloper

public java.lang.String getDeveloper(java.lang.String cname)
Returns the responsible developer of a class. In the moment, all we recognize: - not "org.jadv" -> Not a Game-Class! - org.jadv.player. -> is the name of the Player!

Parameters:
cname - - The name of the class
Returns:
String - The name of the developer

getId

public java.lang.String getId()
Get the ID of the Object

Returns:
String

getIntAttribute

public int getIntAttribute(java.lang.String Name,
                           int def)
Get an int-Value of an Attribute!

Parameters:
Name - - Name of the attribute
def - - default value of the attribute
Returns:
int Value of the attribute

getIntAttribute

public int getIntAttribute(java.lang.String Name)
Get an int-Value of an Attribute!

Parameters:
Name - - Name of the attribute
Returns:
int Value of the attribute

getName

public java.lang.String getName()
Get the name of the object.

Returns:
String - Name of the object

getNext

public SavedObject getNext()
Get the next object of the internal List

Returns:
SavedObject

getPrev

public SavedObject getPrev()
Get the previous Object of the internal List

Returns:
SavedObject

getSeeder

private static java.security.SecureRandom getSeeder()
Returns the internal SecureRandom seeder!

Returns:
SecureRandom

hexFormat

public static java.lang.String hexFormat(int value,
                                         int length)
Convert an integer value into hex-format with length chars (e.g. hexFormat(31,3) ==> 01F)

Parameters:
value - - value to convert to hex format
length - - length of target hex-String
Returns:
String - hex-String

init

public void init(java.util.HashMap attribs)
Initialisation of the object! This is called every time, the object is loaded into memory!

Parameters:
attribs - - The attributes of the object

isValid

public boolean isValid()
Returns if this Object is valid or not!

Returns:
boolean

isChanged

public boolean isChanged()
Returns if this Object is changed or not!

Returns:
boolean

loadObject

public static SavedObject loadObject(java.util.HashMap desc)

markChanged

public void markChanged()
Mark the object as changed - the object must be saved!


markNotChanged

public void markNotChanged()
Mark the object as not changed - the object must not be saved!


mergeAttributes

public static void mergeAttributes(java.util.HashMap attribs,
                                   java.util.HashMap oldAttribs)
mergeAttributes Merge the Attributes of two Objects into each other!

Parameters:
attribs - - HashMap of new new Object
oldAttribs - - HashMap of old Object

removeFromList

public void removeFromList()
This object is removed from the list of all SavedObjects. DO NOT call this function on your own!


replaceObject

public static SavedObject replaceObject(org.jdom.Element el)
Delete an object and create a new one instead ...

Parameters:
el - - Element of Attributes of new Object
Returns:
SavedObject - the newly created object

replaceObject

public static SavedObject replaceObject(java.util.HashMap attribs)
Delete an object and create a new one instead ...

Parameters:
attribs - - Attributes of new Object
Returns:
SavedObject - the newly created object

save

public void save()
Save this Object!

If you store attributes inside local variables (for speed reasons), you have to write a save() function, that stores all variables inside the HashMap again.


saveObject

public void saveObject()

setAttribute

public java.lang.String setAttribute(java.lang.String Name,
                                     java.lang.String Value)
setAttribute(name, value) Set the Attribute name := value This function returns the old value!

Parameters:
Name -
Value -
Returns:
String

setId

public void setId(java.lang.String id)
setId(id) Set the ID of the Object

Parameters:
id -

setIntAttribute

public void setIntAttribute(java.lang.String name,
                            int val)
Set an int-value inside an Attribute.

Parameters:
name -
val -

setName

public void setName(java.lang.String name)
setName(name) Set the internal name of the Object

Parameters:
name -

storeAfter

public void storeAfter(SavedObject obj)
storeAfter(obj) This function is internaly used from the ObjectManager. You should not call it on your own. All SavedObjects are stored inside one large double linked List!

Parameters:
obj -

swapOut

public void swapOut()
swapOut() If an Object is no longer used, call this function!

Returns:
boolean