org.hackystat.sensorbase.resource.sensordatatypes
Class SdtManager

java.lang.Object
  extended by org.hackystat.sensorbase.resource.sensordatatypes.SdtManager

public class SdtManager
extends java.lang.Object

Provides a manager for the SensorDataType resource. As with all of the Resource managers the methods in this class can be grouped into three general categories, of which this Manager uses the following:

See https://jaxb.dev.java.net/guide/Performance_and_thread_safety.html for info on JAXB performance and thread safety.

All public methods of this class are synchronized so that we can maintain the cache along with the underlying persistent store in a thread-safe fashion.

Author:
Philip Johnson

Field Summary
(package private)  DbManager dbManager
          The DbManager associated with this server.
static java.lang.String sensorDataTypeIndexCloseTag
          The SensorDataTypeIndex close tag.
static java.lang.String sensorDataTypeIndexOpenTag
          The SensorDataTypeIndex open tag.
(package private)  Server server
          The Server associated with this SdtManager.
 
Constructor Summary
SdtManager(Server server)
          The constructor for SdtManagers.
 
Method Summary
 void deleteSdt(java.lang.String sdtName)
          Ensures that the passed sdtName is no longer present in this Manager.
 java.lang.String getSensorDataTypeIndex()
          Returns the XML string containing the SensorDataTypeIndex with all defined SDTs.
 java.lang.String getSensorDataTypeString(java.lang.String sdtName)
          Returns the XML String representation of a SensorDataType, given its name.
 boolean hasSdt(java.lang.String sdtName)
          Returns true if the passed SDT name is defined.
 java.lang.String makeSensorDataType(SensorDataType sdt)
          Returns the passed SensorDataType instance as a String encoding of its XML representation.
 SensorDataType makeSensorDataType(java.lang.String xmlString)
          Takes a String encoding of a SensorDataType in XML format and converts it to an instance.
 SensorDataTypeIndex makeSensorDataTypeIndex(java.lang.String xmlString)
          Takes a String encoding of a SensorDataTypeIndex in XML format and converts it to an instance.
 SensorDataTypeRef makeSensorDataTypeRef(SensorDataType sdt)
          Returns a SensorDataTypeRef instance constructed from a SensorDataType instance.
 java.lang.String makeSensorDataTypeRefString(SensorDataType sdt)
          Returns the passed SensorDataType instance as a String encoding of its XML representation as a SensorDataTypeRef object.
 void putSdt(SensorDataType sdt)
          Updates the Manager with this SDT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

Server server
The Server associated with this SdtManager.


dbManager

DbManager dbManager
The DbManager associated with this server.


sensorDataTypeIndexOpenTag

public static final java.lang.String sensorDataTypeIndexOpenTag
The SensorDataTypeIndex open tag.

See Also:
Constant Field Values

sensorDataTypeIndexCloseTag

public static final java.lang.String sensorDataTypeIndexCloseTag
The SensorDataTypeIndex close tag.

See Also:
Constant Field Values
Constructor Detail

SdtManager

public SdtManager(Server server)
The constructor for SdtManagers. Loads in default data and sets up the in-memory caches.

Parameters:
server - The Server instance associated with this SdtManager.
Method Detail

getSensorDataTypeIndex

public java.lang.String getSensorDataTypeIndex()
Returns the XML string containing the SensorDataTypeIndex with all defined SDTs. Uses the in-memory cache of SensorDataTypeRef strings.

Returns:
The XML string providing an index to all current SDTs.

getSensorDataTypeString

public java.lang.String getSensorDataTypeString(java.lang.String sdtName)
Returns the XML String representation of a SensorDataType, given its name.

Parameters:
sdtName - The name of the SDT.
Returns:
Its string representation, or null if not found.

putSdt

public void putSdt(SensorDataType sdt)
Updates the Manager with this SDT. Any old definition with this name is overwritten. Updates in-memory caches and persistent store.

Parameters:
sdt - The SensorDataType.

hasSdt

public boolean hasSdt(java.lang.String sdtName)
Returns true if the passed SDT name is defined.

Parameters:
sdtName - A SensorDataType name
Returns:
True if a SensorDataType with that name is already known to this SdtManager.

deleteSdt

public void deleteSdt(java.lang.String sdtName)
Ensures that the passed sdtName is no longer present in this Manager.

Parameters:
sdtName - The name of the SDT to remove if currently present.

makeSensorDataType

public final SensorDataType makeSensorDataType(java.lang.String xmlString)
                                        throws java.lang.Exception
Takes a String encoding of a SensorDataType in XML format and converts it to an instance.

Parameters:
xmlString - The XML string representing a SensorDataType
Returns:
The corresponding SensorDataType instance.
Throws:
java.lang.Exception - If problems occur during unmarshalling.

makeSensorDataTypeIndex

public final SensorDataTypeIndex makeSensorDataTypeIndex(java.lang.String xmlString)
                                                  throws java.lang.Exception
Takes a String encoding of a SensorDataTypeIndex in XML format and converts it to an instance. Note that this does not affect the state of any SdtManager instance.

Parameters:
xmlString - The XML string representing a SensorDataTypeIndex.
Returns:
The corresponding SensorDataTypeIndex instance.
Throws:
java.lang.Exception - If problems occur during unmarshalling.

makeSensorDataType

public final java.lang.String makeSensorDataType(SensorDataType sdt)
                                          throws java.lang.Exception
Returns the passed SensorDataType instance as a String encoding of its XML representation. Final because it's called in constructor.

Parameters:
sdt - The SensorDataType instance.
Returns:
The XML String representation.
Throws:
java.lang.Exception - If problems occur during translation.

makeSensorDataTypeRefString

public final java.lang.String makeSensorDataTypeRefString(SensorDataType sdt)
                                                   throws java.lang.Exception
Returns the passed SensorDataType instance as a String encoding of its XML representation as a SensorDataTypeRef object. Final because it's called in constructor.

Parameters:
sdt - The SensorDataType instance.
Returns:
The XML String representation of it as a SensorDataTypeRef
Throws:
java.lang.Exception - If problems occur during translation.

makeSensorDataTypeRef

public SensorDataTypeRef makeSensorDataTypeRef(SensorDataType sdt)
Returns a SensorDataTypeRef instance constructed from a SensorDataType instance.

Parameters:
sdt - The SensorDataType instance.
Returns:
A SensorDataTypeRef instance.