com.tensegrity.composite.persistence
Class FormatIDMap

java.lang.Object
  extended bycom.tensegrity.composite.persistence.FormatIDMap

public final class FormatIDMap
extends java.lang.Object

The FormatIDMap class pools all types of Format implementations. These are Paint-, Stroke-, Font- and MarkerFormats. While the class FormatPool helps to avoid multiple instation of the same format, this class is meant as utility class while serializing and building Primitives. When serializing primitives you obtain a id-string from FormatIDMap by calling the getTypeId-method. When all primitives are written to the attributelist, you can obtain the list of used formats (getTypeList()) and add their attribute representation to the attributelist. When building primitives from an xml file, you need to read in all stored formats, add them to the FormatIDMap and then, while building the primitive instances, obtain the stored format instance from this class.

Version:
$Id: FormatIDMap.java,v 1.6 2005/12/12 15:20:46 MichaelKegel Exp $
Author:
GillesIachelini

Field Summary
static java.lang.String idPrefixFont
          Constant prefix strings for string id's.
static java.lang.String idPrefixMarker
          Constant prefix strings for string id's.
static java.lang.String idPrefixPaint
          Constant prefix strings for string id's.
static java.lang.String idPrefixStroke
          Constant prefix strings for string id's.
 
Method Summary
static void addFormat(Format format, java.lang.String id)
          Associates a format to a given id.
static void addFormats(AttributeList list)
          This method adds all previously stored format instances to the given AttributeList by writing out Attributes where the name is obtained from keyIterator() and the value created by FormatUtilities.getAttributeSetFromFormat(Object).
static void addIdFormat(java.lang.String id, Format format)
          Associates a id to a given format reference.
static void clear()
          Clears the internally used map instances.
static Format getFormat(java.lang.String id)
          Returns an instance of Format to a given id string.
static java.lang.String getId(Format format)
          Returns the string id associated with a format.
static java.util.Iterator keyIterator()
          Returns a set view of the keys contained in the FormatIDMap.
static void readFormats(AttributeList list)
           
static void useThreadLocal()
          A call to this method configures the FormatIDMap to make use of the ThreadLocal class hence a map is created for each Thread the FormatIDMap is used by.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idPrefixMarker

public static final java.lang.String idPrefixMarker
Constant prefix strings for string id's.

See Also:
Constant Field Values

idPrefixPaint

public static final java.lang.String idPrefixPaint
Constant prefix strings for string id's.

See Also:
Constant Field Values

idPrefixStroke

public static final java.lang.String idPrefixStroke
Constant prefix strings for string id's.

See Also:
Constant Field Values

idPrefixFont

public static final java.lang.String idPrefixFont
Constant prefix strings for string id's.

See Also:
Constant Field Values
Method Detail

useThreadLocal

public static final void useThreadLocal()
A call to this method configures the FormatIDMap to make use of the ThreadLocal class hence a map is created for each Thread the FormatIDMap is used by.
Notice: This configuration must be done before the FormatIDMap is in use by any Thread.

See Also:
ThreadLocal

addFormat

public static final void addFormat(Format format,
                                   java.lang.String id)
Associates a format to a given id. This allows the retrieval of associated id's to a given format while serializing primitives.

Parameters:
format - the format.
id - the id associated to the format.

addIdFormat

public static final void addIdFormat(java.lang.String id,
                                     Format format)
Associates a id to a given format reference. This allows the retrieval of a format instance for a given string id while building primitives from attributelists.

Parameters:
id - the id to associate with the format.
format - the format.

getId

public static final java.lang.String getId(Format format)
Returns the string id associated with a format. Use this method to identify the id string, while serializing the formats of a primitive. If there is no id string found, a new id string is created, added to the map and returned.

Parameters:
format - the format description.
Returns:
the id string associated to the given description.

getFormat

public static final Format getFormat(java.lang.String id)
Returns an instance of Format to a given id string. Use this method to retrieve the Format instance while building Primitive instances from XML-files.

Parameters:
id - the id string.
Returns:
an instance of Format.

keyIterator

public static final java.util.Iterator keyIterator()
Returns a set view of the keys contained in the FormatIDMap.

Returns:
a set view of the keys contained in the FormatIDMap.

clear

public static final void clear()
Clears the internally used map instances. Note: This method must be called whenever you start to use this class.


addFormats

public static final void addFormats(AttributeList list)
                             throws AttributeException,
                                    ConstraintViolationException,
                                    SerializeException
This method adds all previously stored format instances to the given AttributeList by writing out Attributes where the name is obtained from keyIterator() and the value created by FormatUtilities.getAttributeSetFromFormat(Object).

Parameters:
list - the AttributeList to add the serialized formats to.
Throws:
AttributeException - thrown whenever the add of an attribute fails.
ConstraintViolationException - thrown whenever the add of an attribute fails.
SerializeException - thrown if FormatUtilities.getAttributeSetFromFormat(Object) fails.

readFormats

public static final void readFormats(AttributeList list)
                              throws BuildException
Throws:
BuildException


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.