|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectecologylab.generic.Debug
ecologylab.xml.ElementState
public class ElementState
This class is the heart of the ecologylab.xml
translation framework.
| Nested Class Summary | |
|---|---|
protected class |
ElementState.ClassToCollectionMap
Convenience for specifying what collection to put objects of a given type into, where there is a clear mapping based on type (class). |
static class |
ElementState.DeclarationStyle
These are the styles for declaring fields as translated to XML. |
static interface |
ElementState.xml_attribute
Metalanguage declaration that tells ecologylab.xml translators that each Field it is applied to as an annotation is a scalar-value, which should be represented in XML as an attribute. |
static interface |
ElementState.xml_class
Supplementary metalanguage declaration that can be applied only to a field. |
static interface |
ElementState.xml_classes
Supplementary metalanguage declaration that can be applied only to a field. |
static interface |
ElementState.xml_collection
Metalanguage declaration that tells ecologylab.xml translators that each Field it is applied to as an annotation is of type Collection. |
static interface |
ElementState.xml_leaf
Metalanguage declaration that tells ecologylab.xml translators that each Field it is applied to as an annotation is a scalar-value, which should be represented in XML as a leaf node: an XML element with a single text node child, which represents the value. |
static interface |
ElementState.xml_map
Metalanguage declaration that tells ecologylab.xml translators that each Field it is applied to as an annotation is of type Map. |
static interface |
ElementState.xml_nested
Metalanguage declaration that tells ecologylab.xml translators that each Field it is applied to as an annotation is represented in XML by a (non-leaf) nested child element. |
static interface |
ElementState.xml_tag
Metalanguage declaration that can be applied either to field or to class declarations. |
| Field Summary | |
|---|---|
static int |
CDATA
Value for the leaf annotation that specifies translation to XML as CDATA. |
protected static int |
ESTIMATE_CHARS_PER_FIELD
|
static short |
FLOATING_PRECISION_OFF
Constant indicating that floating precision cutoff is disabled. |
protected static java.lang.Class[] |
MARSHALLING_PARAMS
Used for argument marshalling with reflection to access a set method that takes a String as an argument. |
static int |
NORMAL
Value for the leaf annotation that specifies translation to XML without CDATA. |
static int |
UTF16
|
static int |
UTF16_LE
|
static int |
UTF8
|
protected static java.lang.String |
XML_FILE_HEADER
xml header |
| Fields inherited from interface ecologylab.xml.XMLTranslationExceptionTypes |
|---|
FILE_NOT_FOUND, IO_EXCEPTION, NULL_PURL, UNKNOWN |
| Constructor Summary | |
|---|---|
ElementState()
Construct. |
|
| Method Summary | |
|---|---|
protected void |
addNestedElement(ElementState elementState)
This is the hook that enables programmers to do something special when handling a nested XML element and its associate ElementState (subclass), by overriding this method and providing a custom implementation. |
protected void |
addNestedElement(ecologylab.xml.NodeToJavaOptimizations pte,
org.w3c.dom.Node childNode)
Old-school DOM approach. |
protected void |
appendTextNodeString(java.lang.String newText)
Called during translateFromXML(). |
static org.w3c.dom.Document |
buildDOM(java.io.File file)
This method creates a DOM Document from the local XML file. |
static org.w3c.dom.Document |
buildDOM(java.io.InputStream inStream)
This method creates a DOM Document from the XML file at a given URI, which could be a local file or a URL. |
static org.w3c.dom.Document |
buildDOM(ParsedURL purl)
|
static org.w3c.dom.Document |
buildDOM(java.lang.String xmlFileOrURLName)
This method creates a DOM Document from the XML file at a given URI, which could be a local file or a URL. |
static org.w3c.dom.Document |
buildDOM(java.net.URL url)
This method creates a DOM Document from the XML file at a given URL. |
static org.w3c.dom.Document |
buildDOMFromXMLCharSequence(java.lang.CharSequence charSequence,
int charsetType)
This method creates a DOM Document from an XML-formatted String. |
static org.w3c.dom.Document |
buildDOMFromXMLString(java.lang.CharSequence charSequence)
This method creates a DOM Document from an XML-formatted String, encoded as UTF8. |
void |
checkAnnotation()
|
protected boolean |
convertNameStyles()
Specifies automatic conversion from XML style names (e.g. |
protected void |
createChildHook(ElementState child)
Perform custom processing on the newly created child node, just before it is added to this. |
protected ecologylab.xml.FieldToXMLOptimizations |
fieldToXMLOptimizations(java.lang.reflect.Field field,
java.lang.Class<? extends ElementState> thatClass)
Get a tag translation object that corresponds to the fieldName, with this class. |
protected short |
floatingPrecision()
Returns the precision of floating point numbers associated with this instance of ElementState. |
protected java.util.Collection<? extends ElementState> |
getCollection(java.lang.Class thatClass)
When translating from XML, if a tag is encountered with no matching field, perhaps it belongs in a Collection. |
ElementState |
getElementStateById(java.lang.String id)
The DOM classic accessor method. |
protected java.util.Map |
getMap(java.lang.Class thatClass)
When translating from XML, if a tag is encountered with no matching field, perhaps it belongs in a Collection. |
ElementState |
getNestedNameSpace(java.lang.String id)
Either lookup an existing Nested Namespace object, or form a new one, map it, and return it. |
java.lang.String |
getTextNodeString()
|
protected java.lang.String[] |
leafElementFieldNames()
An array of Strings with the names of the leaf elements. |
ElementState |
lookupNestedNameSpace(java.lang.String id)
Lookup an ElementState subclass representing the scope of the nested XML Namespace in this. |
protected Optimizations |
optimizations()
|
ElementState |
parent()
|
protected void |
postTranslationProcessingHook()
Perform custom processing immediately after all translation from XML is completed. |
protected void |
preTranslationProcessingHook()
Perform custom processing immediately before translating this to XML. |
void |
recycle()
Clear data structures and references to enable garbage collecting of resources associated with this. |
static void |
setDeclarationStyle(ElementState.DeclarationStyle ds)
|
protected boolean |
setFieldUsingTypeRegistry(java.lang.reflect.Field field,
java.lang.String fieldValue)
Set a field that is an extended primitive -- a non ElementState -- using the type registry. |
void |
setFloatingPrecision(short floatingPrecision)
|
void |
setParent(ElementState parent)
Set the parent of this, to create the tree structure. |
static void |
setUseDOMForTranslateTo(boolean value)
Set to true to use the DOM parser by default for translateToXML(). |
static ElementState |
translateFromXML(java.io.File xmlFile,
TranslationSpace translationSpace)
Translate a file from XML to a strongly typed tree of XML objects. |
static ElementState |
translateFromXML(java.io.InputStream xmlStream,
TranslationSpace translationSpace)
Translate an InputStream from XML to a strongly typed tree of XML objects. |
static ElementState |
translateFromXML(ParsedURL purl,
TranslationSpace translationSpace)
Translate data from a ParseURL from XML to a strongly typed tree of XML objects. |
static ElementState |
translateFromXML(java.lang.String fileName,
TranslationSpace translationSpace)
Translate a file XML to a strongly typed tree of XML objects. |
static ElementState |
translateFromXML(java.net.URL url,
TranslationSpace translationSpace)
|
static ElementState |
translateFromXMLCharSequence(java.lang.CharSequence xmlString,
TranslationSpace translationSpace)
Translate a String of XML to a strongly typed tree of XML objects. |
static ElementState |
translateFromXMLDOM(org.w3c.dom.Document doc,
TranslationSpace translationSpace)
Given the Document object for an XML DOM, builds a tree of equivalent ElementState objects. |
static ElementState |
translateFromXMLDOM(java.io.File xmlFile,
TranslationSpace translationSpace)
Translate a file from XML to a strongly typed tree of XML objects. |
static ElementState |
translateFromXMLDOM(java.io.InputStream xmlStream,
TranslationSpace nameSpace)
Given an XML-formatted String, builds a tree of equivalent ElementState objects. |
static ElementState |
translateFromXMLDOM(ParsedURL purl,
TranslationSpace translationSpace)
Given the URL of a valid XML document, reads the document and builds a tree of equivalent ElementState objects. |
static ElementState |
translateFromXMLDOM(java.lang.String fileName,
TranslationSpace translationSpace)
Given the name of a valid XML file, reads the file and builds a tree of equivalent ElementState objects. |
static ElementState |
translateFromXMLDOM(java.net.URL xmlDocumentURL,
TranslationSpace translationSpace)
Given the URL of a valid XML document, reads the document and builds a tree of equivalent ElementState objects. |
static ElementState |
translateFromXMLDOMCharSequence(java.lang.CharSequence charSequence,
int charsetType,
TranslationSpace translationSpace)
Given an XML-formatted String, builds a tree of equivalent ElementState objects. |
static ElementState |
translateFromXMLDOMCharSequence(java.lang.CharSequence charSequence,
TranslationSpace translationSpace)
Given an XML-formatted String, uses charset type UTF-8 to create a stream, and build a tree of equivalent ElementState objects. |
static ElementState |
translateFromXMLRootNode(org.w3c.dom.Node xmlRootNode,
TranslationSpace translationSpace)
A recursive DOM-based translation translateFromXML(...). |
static ElementState |
translateFromXMLSAX(java.lang.CharSequence charSequence,
TranslationSpace translationSpace)
Use the (faster!) SAX parser to form a strongly typed tree of ElementState objects from XML. |
static ElementState |
translateFromXMLSAX(java.io.File file,
TranslationSpace translationSpace)
Use the (faster!) SAX parser to form a strongly typed tree of ElementState objects from XML. |
static ElementState |
translateFromXMLSAX(java.io.InputStream inputStream,
TranslationSpace translationSpace)
Use the (faster!) SAX parser to form a strongly typed tree of ElementState objects from XML. |
static ElementState |
translateFromXMLSAX(ParsedURL purl,
TranslationSpace translationSpace)
Use the (faster!) SAX parser to form a strongly typed tree of ElementState objects from XML. |
static ElementState |
translateFromXMLSAX(java.net.URL url,
TranslationSpace translationSpace)
Use the (faster!) SAX parser to form a strongly typed tree of ElementState objects from XML. |
org.w3c.dom.Document |
translateToDOM()
Create a W3C Document object from this. |
java.lang.StringBuilder |
translateToXML()
Translates a tree of ElementState objects into an equivalent XML string. |
void |
translateToXML(java.lang.Appendable appendable)
Translates a tree of ElementState objects, and writes the output to the Appendable passed in. |
void |
translateToXML(java.io.File outputFile)
Translates a tree of ElementState objects, and writes the output to the File passed in. |
java.lang.StringBuilder |
translateToXML(java.lang.StringBuilder buffy)
Translates a tree of ElementState objects into equivalent XML in a StringBuilder. |
void |
writePrettyXML(java.io.File xmlFile)
Translate to XML, then write the result to a file. |
void |
writePrettyXML(java.io.OutputStream outputStream)
Translate to XML, then write the result to a file. |
void |
writePrettyXML(java.lang.String xmlFileName)
Translate to XML, then write the result to a file, while formatting nicely. |
| Methods inherited from class ecologylab.generic.Debug |
|---|
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int UTF16_LE
public static final int UTF16
public static final int UTF8
protected static final java.lang.String XML_FILE_HEADER
protected static final int ESTIMATE_CHARS_PER_FIELD
protected static java.lang.Class[] MARSHALLING_PARAMS
public static final short FLOATING_PRECISION_OFF
public static final int CDATA
public static final int NORMAL
| Constructor Detail |
|---|
public ElementState()
| Method Detail |
|---|
public java.lang.StringBuilder translateToXML()
throws XMLTranslationException
this, all nested elements
must be after all attributes.
The result is a hierarchichal XML structure.
Note: to keep XML files from growing unduly large, there is a default
value for each type.
Attributes which are set to the default value (for that type),
are not emitted.
XMLTranslationException - if there is a problem with the
structure. Specifically, in each ElementState object, fields for
attributes must be declared
before all fields for nested elements (those derived from ElementState).
If there is any public field which is not derived from ElementState
declared after the declaration for 1 or more ElementState instance
variables, this exception will be thrown.
public java.lang.StringBuilder translateToXML(java.lang.StringBuilder buffy)
throws XMLTranslationException
this, all nested elements
must be after all attributes.
The result is a hierarchichal XML structure.
Note: to keep XML files from growing unduly large, there is a default
value for each type.
Attributes which are set to the default value (for that type),
are not emitted.
buffy - StringBuilder to translate into, or null if you want one created for you.
XMLTranslationException - if a problem arises during translation.
Problems with Field access are possible, but very unlikely.
public void translateToXML(java.io.File outputFile)
throws XMLTranslationException,
java.io.IOException
outputFile - File to write the XML to.
XMLTranslationException - if a problem arises during translation.
Problems with Field access are possible, but very unlikely.
java.io.IOException - If there are problems with the file.
public void translateToXML(java.lang.Appendable appendable)
throws XMLTranslationException
appendable - Appendable to translate into. Must be non-null. Can be a Writer, OutputStream, ...
XMLTranslationException - if a problem arises during translation.
The most likely cause is an IOException.
Problems with Field access are possible, but very unlikely.
public org.w3c.dom.Document translateToDOM()
throws XMLTranslationException
XMLTranslationExceptionprotected short floatingPrecision()
public static ElementState translateFromXMLDOM(ParsedURL purl,
TranslationSpace translationSpace)
throws XMLTranslationException
purl - ParsedURL for the XML document that needs to be translated.translationSpace - NameSpace that provides basis for translation.
XMLTranslationException
public static ElementState translateFromXML(ParsedURL purl,
TranslationSpace translationSpace)
throws XMLTranslationException
xmlStream - An InputStream to the XML that needs to be translated.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXMLDOM(java.net.URL xmlDocumentURL,
TranslationSpace translationSpace)
throws XMLTranslationException
xmlDocumentURL - URL for the XML document that needs to be translated.translationSpace - NameSpace that provides basis for translation.
XMLTranslationException
public static ElementState translateFromXML(java.net.URL url,
TranslationSpace translationSpace)
throws XMLTranslationException
XMLTranslationException
public static ElementState translateFromXMLDOM(java.io.File xmlFile,
TranslationSpace translationSpace)
throws XMLTranslationException
xmlFile - XML source material.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXML(java.io.File xmlFile,
TranslationSpace translationSpace)
throws XMLTranslationException
xmlFile - XML source material.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXMLDOM(java.lang.String fileName,
TranslationSpace translationSpace)
throws XMLTranslationException
fileName - the name of the XML file that needs to be translated.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXML(java.lang.String fileName,
TranslationSpace translationSpace)
throws XMLTranslationException
fileName - the name of the XML file that needs to be translated.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXMLDOM(java.io.InputStream xmlStream,
TranslationSpace nameSpace)
throws XMLTranslationException
xmlStream - An InputStream to the XML that needs to be translated.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXML(java.io.InputStream xmlStream,
TranslationSpace translationSpace)
throws XMLTranslationException
xmlStream - An InputStream to the XML that needs to be translated.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXMLDOMCharSequence(java.lang.CharSequence charSequence,
int charsetType,
TranslationSpace translationSpace)
throws XMLTranslationException
charSequence - the actual XML that needs to be translated.charsetType - A constant from ecologylab.generic.StringInputStream.
0 for UTF16_LE. 1 for UTF16. 2 for UTF8.
XMLTranslationException
public static ElementState translateFromXMLDOMCharSequence(java.lang.CharSequence charSequence,
TranslationSpace translationSpace)
throws XMLTranslationException
charSequence - the actual XML that needs to be translated.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXMLCharSequence(java.lang.CharSequence xmlString,
TranslationSpace translationSpace)
throws XMLTranslationException
xmlString - the actual XML that needs to be translated.translationSpace - Specifies mapping from XML nodes (elements and attributes) to Java types.
XMLTranslationException
public static ElementState translateFromXMLDOM(org.w3c.dom.Document doc,
TranslationSpace translationSpace)
throws XMLTranslationException
doc - Document object for DOM tree that needs to be translated.translationSpace - NameSpace that provides basis for translation.
XMLTranslationException
public static ElementState translateFromXMLRootNode(org.w3c.dom.Node xmlRootNode,
TranslationSpace translationSpace)
throws XMLTranslationException
xmlRootNode - Root node of the DOM tree that needs to be translated.translationSpace - NameSpace that provides basis for translation.
XMLTranslationException
public static ElementState translateFromXMLSAX(java.lang.CharSequence charSequence,
TranslationSpace translationSpace)
throws XMLTranslationException
charSequence - translationSpace -
XMLTranslationException
public static ElementState translateFromXMLSAX(ParsedURL purl,
TranslationSpace translationSpace)
throws XMLTranslationException
purl - translationSpace -
XMLTranslationException
public static ElementState translateFromXMLSAX(java.net.URL url,
TranslationSpace translationSpace)
throws XMLTranslationException
url - translationSpace -
XMLTranslationException
public static ElementState translateFromXMLSAX(java.io.File file,
TranslationSpace translationSpace)
throws XMLTranslationException
file - translationSpace -
XMLTranslationException
public static ElementState translateFromXMLSAX(java.io.InputStream inputStream,
TranslationSpace translationSpace)
throws XMLTranslationException
inputStream - translationSpace -
XMLTranslationExceptionpublic static org.w3c.dom.Document buildDOM(java.net.URL url)
url - the URL to the XML from which the DOM is to be created
public static org.w3c.dom.Document buildDOM(ParsedURL purl)
public static org.w3c.dom.Document buildDOM(java.io.File file)
file - the XML file from which the DOM is to be created
public static org.w3c.dom.Document buildDOM(java.lang.String xmlFileOrURLName)
xmlFileOrURLName - the path to the XML from which the DOM is to be created
public static org.w3c.dom.Document buildDOM(java.io.InputStream inStream)
inStream - InputStream from which the DOM is to be created
public static org.w3c.dom.Document buildDOMFromXMLCharSequence(java.lang.CharSequence charSequence,
int charsetType)
charSequence - the XML-formatted String from which the DOM is to be createdcharsetType - A constant from ecologylab.generic.StringInputStream.
0 for UTF16_LE. 1 for UTF16. 2 for UTF8.
public static org.w3c.dom.Document buildDOMFromXMLString(java.lang.CharSequence charSequence)
charSequence - the XML-formatted String from which the DOM is to be created
public void writePrettyXML(java.lang.String xmlFileName)
throws XMLTranslationException
XMLTranslationException
public void writePrettyXML(java.io.File xmlFile)
throws XMLTranslationException
xmlFile - the file in which the xml needs to be saved
XMLTranslationException
public void writePrettyXML(java.io.OutputStream outputStream)
throws XMLTranslationException
xmlFile - the file in which the xml needs to be saved
XMLTranslationException
protected ecologylab.xml.FieldToXMLOptimizations fieldToXMLOptimizations(java.lang.reflect.Field field,
java.lang.Class<? extends ElementState> thatClass)
protected boolean setFieldUsingTypeRegistry(java.lang.reflect.Field field,
java.lang.String fieldValue)
field - fieldValue -
protected void addNestedElement(ecologylab.xml.NodeToJavaOptimizations pte,
org.w3c.dom.Node childNode)
throws XMLTranslationException
pte - childNode -
XMLTranslationExceptionprotected void addNestedElement(ElementState elementState)
elementState -
XMLTranslationExceptionprotected void appendTextNodeString(java.lang.String newText)
newText - Text Node value just found parsing the XML.public java.lang.String getTextNodeString()
public ElementState getElementStateById(java.lang.String id)
protected java.util.Collection<? extends ElementState> getCollection(java.lang.Class thatClass)
thatClass - The class of the ElementState superclass that could be stored in a Collection.
protected java.util.Map getMap(java.lang.Class thatClass)
thatClass - The class of the ElementState superclass that could be stored in a Collection.
protected java.lang.String[] leafElementFieldNames()
protected boolean convertNameStyles()
public ElementState parent()
public void setParent(ElementState parent)
parent - public void setFloatingPrecision(short floatingPrecision)
public static void setDeclarationStyle(ElementState.DeclarationStyle ds)
public void checkAnnotation()
throws java.lang.NoSuchFieldException
java.lang.NoSuchFieldExceptionprotected Optimizations optimizations()
protected void createChildHook(ElementState child)
child - protected void preTranslationProcessingHook()
protected void postTranslationProcessingHook()
public void recycle()
public ElementState getNestedNameSpace(java.lang.String id)
id - esClass -
public ElementState lookupNestedNameSpace(java.lang.String id)
id -
public static void setUseDOMForTranslateTo(boolean value)
value -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||