|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.xml.sax.helpers.DefaultHandler
gov.nih.nlm.util.ObjectXMLSerializer
public class ObjectXMLSerializer
This class is used to provide an XML serialization scheme for ANY java object. This class is thread-safe. It uses only local variables and some static HashMap. Any multi-threaded application can create one instance of this class and then safely call the toXML and fromXML methods in overlapping threads without worrying that it will cause conflicts.
| Nested Class Summary | |
|---|---|
static interface |
ObjectXMLSerializer.NotPersistentIfTransient
Objects should implement this if they are to be ignored by the serializer and are marked as transient members. |
static interface |
ObjectXMLSerializer.Primitive
Anything implementing this method should also have a static newInstance(String) method. |
| Field Summary | |
|---|---|
HashMap |
objects_seen_read
|
| Constructor Summary | |
|---|---|
ObjectXMLSerializer()
Instantiates an empty ObjectXMLSerializer. |
|
| Method Summary | |
|---|---|
void |
characters(char[] chars,
int start,
int length)
Implementation of DefaultHandler API. |
static Character |
CharacterValueOf(String data)
The Character class does not have a
valueOf(String) method,
this method takes its place in reconstructing primitive values. |
void |
clear()
Clears the various class fields for the next round. |
protected void |
clearObject()
Clears the object stack. |
static Date |
DateValueOf(String data)
The Date classes do not have a valueOf(String) method,
this method takes its place in reconstructing primitive values. |
void |
endElement(String namespace_uri,
String simple_name,
String qualified_name)
Implementation of DefaultHandler API. |
Object |
forceNewInstance(Class c)
This method is responsible for finding a constructor and forcing it to create an intitial object. |
Object |
fromXML(Reader reader)
Creates an object from the XML representation indicated by the specified Reader. |
Object |
fromXML(Reader reader,
boolean validating)
Creates an object from the XML representation indicated by the specified Reader. |
Object |
fromXML(String file)
Creates an object from the XML representation indicated by the specified file name. |
Object |
fromXML(String file,
boolean validating)
Creates an object from the XML representation indicated by the specified file name. |
protected Object |
getObject()
Returns the top object on the object Stack. |
static void |
main(String[] argv)
The main method performs a self-QA test |
void |
startElement(String namespace_uri,
String simple_name,
String qualified_name,
Attributes attrs)
Handles opening tags. |
static String |
StringValueOf(String data)
The String classes do not have a valueOf(String) method,
this method takes its place in reconstructing primitive values. |
String |
toXML(Object obj)
Converts an object to an XML representation. |
String |
toXML(Object obj,
String indent)
Converts an object to an XML representation with the specified level of indenting. |
| Methods inherited from class org.xml.sax.helpers.DefaultHandler |
|---|
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public HashMap objects_seen_read
| Constructor Detail |
|---|
public ObjectXMLSerializer()
ObjectXMLSerializer.
| Method Detail |
|---|
public void clear()
public static Character CharacterValueOf(String data)
Character class does not have a
valueOf(String) method,
this method takes its place in reconstructing primitive values.
data - a String
Character in the first position of the specified Stringpublic static Date DateValueOf(String data)
Date classes do not have a valueOf(String) method,
this method takes its place in reconstructing primitive values. Here,
dates are represented as the string value of the long obtained
by calling Date.getTime().
data - a String representation of a date
Date corresponding to that stringpublic static String StringValueOf(String data)
String classes do not have a valueOf(String) method,
this method takes its place in reconstructing primitive values.
data - the input String
String
public String toXML(Object obj)
throws Exception
obj - an object to convert
Exception - if conversion fails
public String toXML(Object obj,
String indent)
throws Exception
obj - an object to convertindent - a String containing space characters
Exception - if conversion fails
public Object fromXML(String file)
throws Exception
file - an XML file name
Exception - if conversion fails
public Object fromXML(String file,
boolean validating)
throws Exception
file - an XML file namevalidating - a flag indicating whether or not a validating parser should be used
Exception - if conversion fails
public Object fromXML(Reader reader)
throws Exception
Reader.
reader - a Reader object
Exception - if conversion fails
public Object fromXML(Reader reader,
boolean validating)
throws Exception
Reader.
reader - an object Readervalidating - a flag indicating whether or not a validating parser should be used
Exception - if conversion fails
protected Object getObject()
throws SAXException
Stack.
Stack
SAXException - if nothing is on the stackprotected void clearObject()
public void startElement(String namespace_uri,
String simple_name,
String qualified_name,
Attributes attrs)
throws SAXException
startElement in interface ContentHandlerstartElement in class DefaultHandlernamespace_uri - The namespace URIsimple_name - the simple name of the elementqualified_name - the fully qualified name of the allementattrs - The element attributes
SAXException - if anything goes wrong
public void characters(char[] chars,
int start,
int length)
DefaultHandler API.
characters in interface ContentHandlercharacters in class DefaultHandlerchars - characters from within an XML tagstart - start indexlength - number of chars in this segment
public void endElement(String namespace_uri,
String simple_name,
String qualified_name)
throws SAXException
DefaultHandler API.
endElement in interface ContentHandlerendElement in class DefaultHandlernamespace_uri - the namespace URIsimple_name - the simple namequalified_name - the qualified name
SAXException - if failed to parse object
public Object forceNewInstance(Class c)
throws Exception
c - An object Class to convert to XML.
Object representation of converted document.
Exception - if conversion fails.public static void main(String[] argv)
argv - An array of argument.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||