wyvern.kernel.properties
Class PropertyPrinter

java.lang.Object
  extended bywyvern.kernel.properties.PropertyPrinter

public final class PropertyPrinter
extends java.lang.Object

This class provides methods for printing properties, both for debugging and for writing things out to map files.

Version:
1.0, Jan 27, 1998
Author:
Steve Yegge

Method Summary
static java.util.LinkedList externalize(GameObject obj)
          Produces a text-serialized (XML) version of the object and its properties.
static java.util.LinkedList indentLineList(java.util.LinkedList lines)
          Prepends 2 spaces to the beginning of every line in the list.
static boolean isDefaultProperty(java.lang.String property, GameObject obj)
          Returns true if this is a default property for the given class.
static java.util.LinkedList printArchProperty(java.lang.String name, Archetype arch)
          Externalizes an archetype property.
static java.util.LinkedList printBeanProperty(java.lang.String property, java.lang.Object value)
          Print the value of a "Bean" property.
static java.util.LinkedList printGameObjectProperty(java.lang.String name, GameObject obj)
          When a property is a GameObject, such as a MonsterInventory, we tell the object to externalize itself, and then we surgically add the "name=whatever" attribute into the element tag.
static java.util.LinkedList printNormalBeanProperty(java.lang.String property, java.lang.Object value)
          Prints a regular old bean property.
static java.util.LinkedList printPListBeanProperty(java.lang.String name, PropertyList value)
          Externalizes a plist-based bean property.
static java.util.LinkedList printProperty(java.lang.String key, java.lang.Object value)
          Returns a String description of a property.
static java.util.LinkedList printSelfExternalizable(java.lang.String name, java.lang.Object val)
          Gives a self-externalizable object a chance to print its own data.
static java.lang.String stripBase(java.lang.String name)
          Strips the standard property directory from the name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

printProperty

public static java.util.LinkedList printProperty(java.lang.String key,
                                                 java.lang.Object value)
Returns a String description of a property.

Parameters:
key - a (String) property name
value - the value for the property (can be null)
Returns:
a list of lines comprising the externalized property

printBeanProperty

public static java.util.LinkedList printBeanProperty(java.lang.String property,
                                                     java.lang.Object value)
Print the value of a "Bean" property.

Parameters:
property - a property with an arbitrary object for a value (a.k.a. a "bean value" )
value - the property value, which we use introspection to examine.
Returns:
a list of lines comprising the bean property

printNormalBeanProperty

public static java.util.LinkedList printNormalBeanProperty(java.lang.String property,
                                                           java.lang.Object value)
Prints a regular old bean property.


printGameObjectProperty

public static java.util.LinkedList printGameObjectProperty(java.lang.String name,
                                                           GameObject obj)
When a property is a GameObject, such as a MonsterInventory, we tell the object to externalize itself, and then we surgically add the "name=whatever" attribute into the element tag.

Parameters:
name - the property name
obj - the property value
Returns:
a list of lines comprising the externalized value

printPListBeanProperty

public static java.util.LinkedList printPListBeanProperty(java.lang.String name,
                                                          PropertyList value)
Externalizes a plist-based bean property.


printSelfExternalizable

public static java.util.LinkedList printSelfExternalizable(java.lang.String name,
                                                           java.lang.Object val)
Gives a self-externalizable object a chance to print its own data.

Parameters:
name - the property name
val - the bean value
Returns:
the lines list for the object.

stripBase

public static java.lang.String stripBase(java.lang.String name)
Strips the standard property directory from the name.

Parameters:
name - the property name
Returns:
the class name, suitable for writing to the stream

printArchProperty

public static java.util.LinkedList printArchProperty(java.lang.String name,
                                                     Archetype arch)
Externalizes an archetype property.

Parameters:
name - the property name, e.g. "spell". Can be null if the arch has no property name, as is the case for items in an externalized ItemList.
arch - the Archetype
Returns:
a list of lines comprising the externalized property

indentLineList

public static java.util.LinkedList indentLineList(java.util.LinkedList lines)
Prepends 2 spaces to the beginning of every line in the list. This is a bit on the expensive side, but since saving maps doesn't (or shouldn't) happen on the server thread, it's probably OK.

Parameters:
lines - the line list to indent
Returns:
a new list consisting of the indented lines

externalize

public static java.util.LinkedList externalize(GameObject obj)
Produces a text-serialized (XML) version of the object and its properties. The resulting text can be parsed by the MapLoader and PropertyParser classes.

Before writing the object, we call getDefaultProperties() and don't write any properties on the object that are considered defaults by the object's class.

Transient properties are not written to the stream.

This method is called by MapObject.externalize(), so it's the default persistence implementation for game objects. GameObject.externalize() is a convenience method so that objects can override the default behavior.

Parameters:
obj - the object to serialize
Returns:
a LinkedList containing the lines to write

isDefaultProperty

public static boolean isDefaultProperty(java.lang.String property,
                                        GameObject obj)
Returns true if this is a default property for the given class. We don't want to write default properties to the map, because load-times are already really painful.

Parameters:
obj - the object being externalized
property - the property to check for being a default
Returns:
true if the property is a default and shouldn't be written