|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ix.util.xml.XMLTranslator
public class XMLTranslator
A class for translating between objects and XML. Note that a single XMLTranslator maps in both directions to make it easier to create mappings that are consistent.
Field Summary | |
---|---|
protected ClassSyntax |
classSyntax
|
protected java.lang.Class |
defaultListClass
|
protected java.lang.Class |
defaultMapClass
|
protected java.lang.Class |
defaultSetClass
|
protected org.jdom.Namespace |
homeNamespace
The namespace used in elements that represent object classes and fields. |
protected java.lang.String |
homeNamespaceURI
The URI for the home namespace. |
protected java.lang.String |
implAttributeName
|
protected org.jdom.Element |
lastExaminedElement
|
protected LispPrinter |
lispPrinter
|
protected java.lang.Class |
listTextClass
|
protected java.lang.String |
mapEntryName
|
protected org.jdom.Namespace |
mostRecentHomeNamespace
Size 1 cache for fast comparisons. |
protected boolean |
omitImplAttributes
|
protected org.jdom.output.XMLOutputter |
outputter
|
protected Function1 |
postfilter
|
protected Function1 |
prefilter
|
protected boolean |
requireNamespace
Is an I-X namespace required in input XML? |
protected boolean |
writePrintableListsAsText
|
Constructor Summary | |
---|---|
XMLTranslator()
|
|
XMLTranslator(ClassSyntax syntax)
|
Method Summary | |
---|---|
protected java.util.Collection |
collectionFromElement(java.lang.Class implClass,
org.jdom.Element elt)
|
protected org.jdom.Element |
collectionToElement(java.lang.Class iface,
java.util.Collection obj)
|
java.lang.String |
documentToXMLString(org.jdom.Document doc)
Converts a JDOM Document to a string of XML. |
protected LiteralDocument |
embeddedXMLFromElement(java.lang.Class c,
org.jdom.Element elt)
|
protected org.jdom.Element |
embeddedXMLToElement(java.lang.Object obj)
|
ClassSyntax |
getClassSyntax()
|
protected java.lang.Object |
getFieldValue(org.jdom.Element fieldElt,
FieldDescr fd)
|
java.lang.Object |
getFieldValue(java.lang.Object obj,
FieldDescr fd)
|
org.jdom.Namespace |
getHomeNamespace()
Returns the home namespace used by this XMLTranslator. |
protected java.lang.String |
getImplAttributeValue(org.jdom.Element elt)
|
protected java.lang.Class |
getImplClass(org.jdom.Element elt,
java.lang.Class c,
java.lang.Class implDefault)
|
org.jdom.Element |
getLastExaminedElement()
Returns the JDOM Element most recently examined by the methods that convert XML to objects. |
org.jdom.output.XMLOutputter |
getOutputter()
|
(package private) void |
handleUnknownFieldFromElement(java.lang.Object obj,
java.lang.String fieldName,
org.jdom.Element fieldElt)
|
boolean |
isAttributeClass(java.lang.Class c)
|
protected boolean |
isHomeNamespace(org.jdom.Namespace namespace)
|
protected boolean |
isHomeNamespaceURI(java.lang.String uri)
|
protected java.util.List |
listFromElement(java.lang.Class c,
org.jdom.Element elt)
|
protected java.util.List |
listFromElementText(java.lang.Class c,
org.jdom.Element elt)
|
protected org.jdom.Element |
listToElement(java.lang.Object obj)
|
boolean |
looksLikeAnObjectDocument(org.jdom.Document doc)
|
protected java.lang.Object |
makeInstance(java.lang.Class c)
Makes an instance of a class using the 0-argument constructor. |
protected LList |
makeLListFromElement(org.jdom.Element elt)
|
protected java.util.Map |
mapFromElement(java.lang.Class c,
org.jdom.Element elt)
|
protected org.jdom.Element |
mapToElement(java.lang.Object obj)
|
protected org.jdom.Element |
nsElement(java.lang.String name)
Utility that creates an element in the home namespace. |
java.lang.Object |
objectFromDocument(org.jdom.Document doc)
Converts a JDOM Document to an object. |
protected java.lang.Object |
objectFromElement(java.lang.Class c,
org.jdom.Element elt)
|
java.lang.Object |
objectFromElement(org.jdom.Element elt)
Converts a JDOM Element to an object. |
java.lang.Object |
objectFromXML(java.lang.String text)
Converts a string of XML to an object. |
org.jdom.Document |
objectToDocument(java.lang.Object obj)
Converts an object to a JDOM Document. |
protected org.jdom.Element |
objectToElement(java.lang.Object obj)
Converts an object to a JDOM Element. |
java.lang.String |
objectToXMLString(java.lang.Object obj)
Converts an object to a string of XML. |
protected java.lang.Object |
primitiveObjectFromElement(java.lang.Class c,
org.jdom.Element elt)
|
protected java.lang.Object |
primitiveObjectFromString(java.lang.Class c,
java.lang.String s)
|
protected org.jdom.Element |
primitiveObjectToElement(java.lang.Object obj)
|
protected void |
processStructAttributes(java.lang.Object obj,
ClassDescr cd,
org.jdom.Element elt)
|
protected void |
processStructSubelements(java.lang.Object obj,
ClassDescr cd,
org.jdom.Element elt)
|
java.lang.Object |
readObject(java.net.URL url)
|
protected void |
requireEltSize(int size,
org.jdom.Element elt)
|
protected void |
requireEltType(java.lang.String name,
org.jdom.Element elt)
|
void |
setFieldValue(java.lang.Object obj,
FieldDescr fd,
java.lang.Object fieldVal)
|
protected java.util.Set |
setFromElement(java.lang.Class c,
org.jdom.Element elt)
|
protected void |
setImplAttribute(org.jdom.Element elt,
java.lang.String className)
|
void |
setOmitImplAttributes(boolean v)
Controlls whether or not implClass attributes
are added to List, Set, and Map elements when converting to XML. |
void |
setPostfilter(Function1 f)
|
void |
setPrefilter(Function1 f)
|
void |
setRequireNamespace(boolean v)
Controls whether element names must be in the home namespace for the elements to be translatable to objects. |
protected org.jdom.Element |
setToElement(java.lang.Object obj)
|
protected java.lang.String |
stringFromElement(java.lang.Class c,
org.jdom.Element elt)
|
protected org.jdom.Element |
stringToElement(java.lang.Object obj)
|
protected java.lang.Object |
structFromElement(java.lang.Class c,
org.jdom.Element elt)
|
protected org.jdom.Element |
structToElement(java.lang.Object obj)
|
protected void |
visitField(java.lang.Object obj,
FieldDescr fd,
org.jdom.Element objElt)
|
static java.lang.Class |
wrapperClass(java.lang.Class pc)
Returns the wrapper class for a primitive class, such as Long.class for long.class . |
void |
writeObject(java.lang.Object obj,
java.io.File file)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected ClassSyntax classSyntax
protected org.jdom.output.XMLOutputter outputter
protected LispPrinter lispPrinter
protected Function1 prefilter
protected Function1 postfilter
protected java.lang.String implAttributeName
protected java.lang.String mapEntryName
protected boolean omitImplAttributes
protected boolean writePrintableListsAsText
protected org.jdom.Element lastExaminedElement
protected java.lang.Class defaultListClass
protected java.lang.Class defaultSetClass
protected java.lang.Class defaultMapClass
protected java.lang.Class listTextClass
protected boolean requireNamespace
protected org.jdom.Namespace homeNamespace
protected java.lang.String homeNamespaceURI
protected org.jdom.Namespace mostRecentHomeNamespace
isHomeNamespace(Namespace)
Constructor Detail |
---|
public XMLTranslator()
public XMLTranslator(ClassSyntax syntax)
Method Detail |
---|
public ClassSyntax getClassSyntax()
public org.jdom.output.XMLOutputter getOutputter()
public void setPrefilter(Function1 f)
public void setPostfilter(Function1 f)
public void setOmitImplAttributes(boolean v)
implClass
attributes
are added to List, Set, and Map elements when converting to XML.
Note that if it's set to true, the XML will not contain enough
information to determine the original implementation classes
and the translator will have to do its best to make reasonable
choices based on field classes and the defaults.
public org.jdom.Namespace getHomeNamespace()
protected org.jdom.Element nsElement(java.lang.String name)
public void setRequireNamespace(boolean v)
looksLikeAnObjectDocument(Document)
protected boolean isHomeNamespace(org.jdom.Namespace namespace)
protected boolean isHomeNamespaceURI(java.lang.String uri)
public void writeObject(java.lang.Object obj, java.io.File file) throws java.io.IOException
writeObject
in interface Saver
java.io.IOException
public java.lang.String objectToXMLString(java.lang.Object obj)
objectToDocument(Object)
and then
to a string by documentToXMLString(org.jdom.Document)
.
public java.lang.String documentToXMLString(org.jdom.Document doc)
public org.jdom.Document objectToDocument(java.lang.Object obj)
protected org.jdom.Element objectToElement(java.lang.Object obj)
typeToElement(Object)
methods to call.
If the prefilter is not null, it is called on the object before translation begins, and the result is used instead the original object. (Of course, the prefilter could just return the original object, but this enables it to supply a substitute.)
setPrefilter(Function1)
protected org.jdom.Element primitiveObjectToElement(java.lang.Object obj)
protected org.jdom.Element stringToElement(java.lang.Object obj)
protected org.jdom.Element embeddedXMLToElement(java.lang.Object obj)
protected org.jdom.Element listToElement(java.lang.Object obj)
protected org.jdom.Element setToElement(java.lang.Object obj)
protected org.jdom.Element collectionToElement(java.lang.Class iface, java.util.Collection obj)
protected org.jdom.Element mapToElement(java.lang.Object obj)
protected void setImplAttribute(org.jdom.Element elt, java.lang.String className)
protected org.jdom.Element structToElement(java.lang.Object obj)
protected void visitField(java.lang.Object obj, FieldDescr fd, org.jdom.Element objElt)
public java.lang.Object getFieldValue(java.lang.Object obj, FieldDescr fd)
public boolean isAttributeClass(java.lang.Class c)
public java.lang.Object readObject(java.net.URL url) throws java.io.IOException
readObject
in interface Loader
java.io.IOException
public java.lang.Object objectFromXML(java.lang.String text)
public java.lang.Object objectFromDocument(org.jdom.Document doc)
public boolean looksLikeAnObjectDocument(org.jdom.Document doc)
public org.jdom.Element getLastExaminedElement()
public java.lang.Object objectFromElement(org.jdom.Element elt)
typeFromElement
methods
to call.
If the postfilter is not null, it is called on the object before it is returned, and the result of that call is returned instead.
Note that most of the work, and the calling of the postfiler, are actually done in the 2-argument version of this method and that some recursions may go directly to that method.
objectFromElement(Class, Element)
,
setPostfilter(Function1)
protected java.lang.Object objectFromElement(java.lang.Class c, org.jdom.Element elt)
protected java.lang.Object primitiveObjectFromElement(java.lang.Class c, org.jdom.Element elt)
protected java.lang.Object primitiveObjectFromString(java.lang.Class c, java.lang.String s)
protected java.lang.String stringFromElement(java.lang.Class c, org.jdom.Element elt)
protected LiteralDocument embeddedXMLFromElement(java.lang.Class c, org.jdom.Element elt)
protected java.util.List listFromElementText(java.lang.Class c, org.jdom.Element elt)
protected java.util.List listFromElement(java.lang.Class c, org.jdom.Element elt)
protected java.util.Set setFromElement(java.lang.Class c, org.jdom.Element elt)
protected java.util.Collection collectionFromElement(java.lang.Class implClass, org.jdom.Element elt)
protected LList makeLListFromElement(org.jdom.Element elt)
protected java.lang.String getImplAttributeValue(org.jdom.Element elt)
protected java.lang.Class getImplClass(org.jdom.Element elt, java.lang.Class c, java.lang.Class implDefault)
protected java.util.Map mapFromElement(java.lang.Class c, org.jdom.Element elt)
protected void requireEltType(java.lang.String name, org.jdom.Element elt)
protected void requireEltSize(int size, org.jdom.Element elt)
protected java.lang.Object structFromElement(java.lang.Class c, org.jdom.Element elt)
protected void processStructAttributes(java.lang.Object obj, ClassDescr cd, org.jdom.Element elt)
protected void processStructSubelements(java.lang.Object obj, ClassDescr cd, org.jdom.Element elt)
public void setFieldValue(java.lang.Object obj, FieldDescr fd, java.lang.Object fieldVal)
protected java.lang.Object getFieldValue(org.jdom.Element fieldElt, FieldDescr fd)
void handleUnknownFieldFromElement(java.lang.Object obj, java.lang.String fieldName, org.jdom.Element fieldElt)
public static final java.lang.Class wrapperClass(java.lang.Class pc)
Long.class
for long.class
.
protected java.lang.Object makeInstance(java.lang.Class c)
XMLException
- if the attempt fails.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |