|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ls.util.xml.JavaXMLConverter
This class is for the creating of XML String from Java Object or Java Object from XML String.
Java objects can contains the follwoing data types
primitve Attributes
structured Attributes
the only collection class is Vector (to store the other objects class)
e.g
public class Instrument {
public String name;
public Date created;
public int nomAmt;
public Vector instrStructure;
}
public class InstrStructure {
public int componentAmt;
public Instrument inst;
}
Creating the Objects
Instrument instrument = new Instrument();
instrument.name = "Tom";
instrument.created = new Date();
instrument.nomAmt = 10;
instrument.instrStructure = new Vector();
InstrStructure instrStruct = new InstrStructure();
instrStruct.componentAmt = 50;
instrStruct.inst = instrument;
instrument.instrStructure.add(instrStruct);
Hashtable objectHash = new Hashtable();
objectHash.put("instrument",instrument);
call the function javaToXML like
JavaXMLConverter javaXMLConverter = new JavaXMLConverter();
javaXMLConverter.javaToXML(objectHash);
Output of the object
<FIDM>
<instrument id="2" class="Instrument">
<name>Tom</name>
<created>02.02.2001 13:44:43</created>
<nomAmt>10</nomAmt>
<instrStructure id="3" class="InstrStructure">
<componentAmt>50</componentAmt>
<inst ref="2"/>
</instrStructure>
</instrument>
</FIDM>
It is also possible to convert multiple objects at the same time
for that need to insert in the objectHash
like
objectHash.put("instrument",instrument);
objectHash.put("student",student);
To convert the xml String to java object
first need to set up the class package
for details setClassPackageMapping(java.lang.String[][])
and then call the javaXMLConverter.xmlToJava(xmlString)
Constructor Summary | |
JavaXMLConverter()
|
Method Summary | |
void |
addStaticDataObject(Object object)
Allows to specify the object which contain the static data. |
String |
javaToXML(Object object)
Conversion of XML string form Object |
String |
javaToXML(Object object,
String outermostTag)
Conversion of XML string form Object |
void |
setClassPackageMapping(String[][] classPackageMapping)
Defines the mapping from class names to package names. |
void |
setStaticDataObjects(Iterator staicObjectIterator)
Allows to specify the objects which contain the static data. |
void |
setTab(boolean tab)
Setting the tab for the XML output |
void |
setTransientSemantic(boolean writeTransient,
String transientIDName)
Allow to set transient semantic. |
Object |
xmlToJava(String xmlString)
Converts an XML String to java objects. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public JavaXMLConverter()
Method Detail |
public void setTab(boolean tab)
tab
- The tab is true to set the tab in the XML string else falsepublic void setTransientSemantic(boolean writeTransient, String transientIDName) throws XMLConversionException
writeTransient
- true to write the transinet attribute in the XML string else falsetransientIDName
- name of the attribute which is used as attribute name to
refer transient object, if writeTransient is true.XMLConversionException
- If writeTransient is true and transientIDName is nullpublic void setClassPackageMapping(String[][] classPackageMapping)
Example: String classPackage[][] = { {"Liability", "com.ls.three60t.fidm.instrument_Package"}, {"InstrStructure", "com.ls.three60t.fidm.instrument_Package"}, {"InstrInGroup", "com.ls.three60t.fidm.instrument_Package"}, {"InstrIdent", "com.ls.three60t.fidm.instrument_Package"}, {"InstrGroup", "com.ls.three60t.fidm.instrument_Package"}, };
classPackageMapping
- a two dimensional array containing the mapping from classes to package namespublic void addStaticDataObject(Object object) throws XMLConversionException
object
- the static data objectXMLConversionException
- If any problem occurs while storingt the transient objectspublic void setStaticDataObjects(Iterator staicObjectIterator) throws XMLConversionException
staicObjectIterator
- an Iterator of static objectsXMLConversionException
- If any problem occurs while storingt the transient objectspublic Object xmlToJava(String xmlString) throws XMLToJavaConversionException
xmlString
- The String which contains the XML formatted tags and need to convert as Java ObjectXMLToJavaConversionException
- If any problem occurs while converting the xml string to java objectspublic String javaToXML(Object object) throws JavaToXMLConversionException
Object
object
- either a single object to be converted or a hashtable containing the names of
the objects as keys and the objects to be converted as values.JavaToXMLConversionException
- If any problem occurs while convertingpublic String javaToXML(Object object, String outermostTag) throws JavaToXMLConversionException
Object
object
- either a single object to be converted or a hashtable containing the names of
the objects as keys and the objects to be converted as values.outermostTag
- tag which is used as outter most tagJavaToXMLConversionException
- If any problem occurs while converting
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |