|
WebLogic Integration | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
An IDocument represents an XML document. An IDocument can provide its document type name (which may be used to refer to a description of its structure and usage). In addition, IDocuments are mutable, and provide methods for retrieving, modifying, adding and removing data elements. All IDocument objects are queryable and updatable using XPath strings. Also, all IDocument instances are serializable to XML and unserializable from XML. IDocument objects should implement the java.io.Serializable interface.
An example of the usage of an IDocument follows. In this example, we are attempting to create an XML document that looks like this...
<?xml version="1.0"?> <!DOCTYPE Person> <Person name="Bob"> <Home squareFeet="2000"/> <Goal>My goal is to elliminate war and poverty</Goal> <Family> <Child name="Jimmy"> <Stats sex="male" hair="brown" eyes="blue"/> </Child> <Child name="Susie"> <Stats sex="female" hair="blonde" eyes="brown"/> </Child> </Family> </Person>To construct this document, we would use the following code...
// Create a blank IDocument (you will get xml header and DOCTYPE for free) IDocument person = DocumentFactory.createDocument(); // Add <Person> person.addElement("", "Person"); // Add <Person name="Bob"> person.addAttribute("/Person", "name", "Bob"); // Add <House/> under <Person> person.addElement("/Person", "House"); // Add squareFeet="2000" to <House> person.addAttribute("/Person/House", "squareFeet", "2000"); // Add <Goal>My goal is to elliminate war and poverty</Goal> // under <Person> person.addElement("/Person", "Goal", "My goal is to elliminate war and poverty"); // Now add family person.addElement("/Person", "Family"); // Add first child Element firstChild = person.addElement("/Person/Family", "Child"); // Focus on first child person.setContextNode(firstChild); // Fill in statistics about first child. This add occurs relative to // the context node which we just set to firstChild. person.addElement("", "Stats"); person.addAttribute("Stats", "sex", "male"); person.addAttribute("Stats", "hair", "brown"); person.addAttribute("Stats", "eyes", "blue"); // Stop focusing on first child person.resetContextNode(); // And second child Element secondChild = person.addElement("/Person/Family", "Child"); // Focus on second child person.setContextNode(secondChild); // Fill in statistics about second child. This add occurs relative to // the context node which we just set to secondChild. person.addElement("", "Stats"); person.addAttribute("Stats", "sex", "female"); person.addAttribute("Stats", "hair", "blonde"); person.addAttribute("Stats", "eyes", "brown"); // Stop focusing on second child person.resetContextNode();Note that if we already had the XML to represent this person, we could have used this code to create the IDocument...
String personXML = ...get the XML from somewhere... IDocument person = DocumentFactory.createDocument(personXML);To see the XML for this document, we use this code...
System.out.println("The XML for person is: " + person.toXML());To query the person's name and goal and number of kids, we use this code...
System.out.println("The person's name: " + person.getStringFrom("/Person/@name"); System.out.println("The person's goal: " + person.getStringFrom("/Person/Goal"); System.out.println("Number of kids: " + person.getIntegerFrom("count(/Person/Family/Child)");To change the person's name and goal and second child's hair color, we use this code...
person.setStringIn("/Person/@name", "BillyBob"); person.setStringIn("/Person/Goal", "To ski 50 times this season"); person.setStringIn("/Person/Family/Child[2]/@hair", "pink"); System.out.println("The person's name: " + person.getStringFrom("/Person/@name"); System.out.println("The person's goal: " + person.getStringFrom("/Person/Goal"); System.out.println("Second childs hair:" + person.getStringFrom("/Person/Family/Child[2]/@hair");To remove the person's goal, we use this code...
person.removeDocumentData("/Person/Goal");To get back the XML content from the document, we use this code...
// Print the XML as a string System.out.println("Person XML: " + person.toXML()); // Print the XML to a Writer (file) java.io.FileWriter fw = new java.io.FileWriter("myFile.xml"); person.toXML(fw);
The default representation of the document represented by IDocument is a org.w3c.dom.Document (i.e. DOM). The IDocument may at times be in an unparsed state. This can happen if the IDocument was explicitly constructed this way (using DocumentFactory.createDocument(String, boolean) where the second arg is true. You can determine the internal state of an IDocument using the isParsed() method. If this returns true, then the content of the document has been parsed into a DOM, otherwise, the IDocument contains just the raw XML text.
In cases where an IDocument is in an unparsed state, you may want to parse the content using a SAX parsing scheme that allows you to build your own in-memory representation of the document (not DOM). The fromXML(ContentHandler) method is provided for this purpose, and allows you to parse the document's content manually using an implementation of the ContentHandler interface. Note that you could accomplish the same thing by getting the raw content from the IDocument, and creating/invoking your own SAX parser.
For more information see the W3C web site for XPath, XML, and DOM.
Method Summary | |
org.w3c.dom.Attr |
addAttribute(java.lang.String parentPath,
java.lang.String attrName)
Add a new attribute to the parent data element referred to by parentPath. |
org.w3c.dom.Attr |
addAttribute(java.lang.String parentPath,
java.lang.String attrName,
java.lang.String value)
Add a new attribute to the parent data element referred to by parentPath. |
void |
addDocumentData(java.lang.String parentPath,
DocumentData value)
Add the given value to the parent data element referred to by parentPath. |
org.w3c.dom.Element |
addElement(java.lang.String parentPath,
java.lang.String elementName)
Add a new element to the parent data element referred to by parentPath. |
org.w3c.dom.Element |
addElement(java.lang.String parentPath,
java.lang.String elementName,
java.lang.String value)
Add a new element to the parent data element referred to by parentPath. |
void |
addNode(java.lang.String parentPath,
org.w3c.dom.Node node)
Add a new node to the parent data element referred to by parentPath. |
java.lang.Object |
clone()
Clone this document. |
void |
forceParsed()
Force this document into the parsed state by using a DOM parser with the document's internal content. |
void |
fromXML(org.xml.sax.ContentHandler contentHandler)
Parse the (unparsed) internal content of this document using a SAX parser and the given ContentHandler. |
void |
fromXML(java.io.File file)
Retrieves an XML document previously saved to a file. |
void |
fromXML(java.io.File file,
java.lang.String encoding)
Retrieves an XML document previously saved to a file. |
void |
fromXML(org.xml.sax.InputSource inputSource)
Use the given SAX InputSource to import XML into this document (thus replacing any previous data elements in this document). |
void |
fromXML(java.io.Reader reader)
Given an XML stream read from reader, import this representation into this document (thus replacing any previous data elements in this document). |
void |
fromXML(java.lang.String xmlText)
Given an XML string, import this representation into this document (thus replacing any previous data elements in this document). |
boolean |
getBooleanFrom(java.lang.String nodeName)
Return a boolean representing the given xpath. |
boolean |
getBooleanFromFirst(java.lang.String nodeName)
Return a boolean representing the value of the first element found with the given name. |
java.util.Calendar |
getDateFrom(java.lang.String nodeName)
Return a Calendar representing the value of the given xpath. |
java.util.Calendar |
getDateFromFirst(java.lang.String nodeName)
Return a Calendar representing the value of the first element found with the given name. |
java.util.Calendar |
getDateTimeFrom(java.lang.String nodeName)
Return a Calendar representing the value of the given xpath. |
java.util.Calendar |
getDateTimeFromFirst(java.lang.String nodeName)
Return a Calendar representing the value of the first element found with the given name. |
org.w3c.dom.Document |
getDocument()
Get the org.w3c.Document contained in this document. |
DocumentData |
getDocumentData(java.lang.String path)
Return an object which encapsulates the data that corresponds to the given path (XPath syntax). |
IDocumentDefinition |
getDocumentDefinition()
Get the IDocumentDefinition for this document which describes the structure and usage of this type of document. |
org.w3c.dom.Element |
getDocumentElement()
Get the element that acts as the document root element for this document. |
java.lang.String |
getDocumentTypeName()
Get the document type name for this document. |
double |
getDoubleFrom(java.lang.String nodeName)
Return a double representing the value of the given xpath. |
double |
getDoubleFromFirst(java.lang.String nodeName)
Return a double representing the value of the first element found with the given name. |
java.lang.String |
getEncoding()
Returns the Java encoding value for this document. |
org.xml.sax.EntityResolver |
getEntityResolver()
Get the EntityResolver used when unserializing. |
int |
getIntegerFrom(java.lang.String nodeName)
Return an int representing the value of the given xpath. |
int |
getIntegerFromFirst(java.lang.String nodeName)
Return an int representing the value of the first element found with the given name. |
java.lang.String |
getPublicID()
Get the public id for this document. |
java.lang.String |
getRawXML()
Get the raw XML for this document. |
java.lang.String |
getRootElementName()
Get the root element tag name for this document. |
java.lang.String |
getStringFrom(java.lang.String nodeName)
Return a string representing the value of the nodes found with the given xpath. |
java.lang.String |
getStringFromFirst(java.lang.String nodeName)
Return a string representing the value of the first element found with the given name. |
IDocument[] |
getSubDocuments(java.lang.String path)
Get an array of sub-documents representing the nodes that are referred to by the path argument. |
java.lang.String |
getSystemID()
Get the system id for this document. |
java.util.Calendar |
getTimeFrom(java.lang.String nodeName)
Return a Calendar representing the value of the given xpath. |
java.util.Calendar |
getTimeFromFirst(java.lang.String nodeName)
Return a Calendar representing the value of the first element found with the given name. |
boolean |
getValidating()
Is this IDocument validating content in calls to fromXML()? |
boolean |
isParsed()
Is this document's XML parsed? If so, the getDocument() method may be used to retrieve the document's parsed XML as a DOM. |
void |
removeDocumentData(java.lang.String path)
Remove the data element referred to by path. |
void |
resetContextNode()
Resets the context node to the document root element. |
void |
setBooleanIn(java.lang.String nodeName,
boolean newValue)
Set the node value of all data nodes found for the given xpath to the string representation of the given newValue. |
void |
setBooleanInFirst(java.lang.String nodeName,
boolean newValue)
Set the first data element found with the given name to the string representation of the given newValue. |
void |
setContextNode(DocumentData data)
Sets the context node for use in all queries to data. |
void |
setContextNode(org.w3c.dom.Node node)
Sets the context node for use in all queries to node. From this point on, until resetContextNode() is called, all calls to getDocumentData (direct or indirect) will be relative to the new context node. |
void |
setContextNode(java.lang.String path)
Sets the context node for use in all queries to path. |
void |
setDateIn(java.lang.String nodeName,
java.util.Calendar newValue)
Set the node value of all data nodes found for the given xpath to the string representation of the given newValue. |
void |
setDateInFirst(java.lang.String nodeName,
java.util.Calendar newValue)
Set the first data element found with the given name to the string representation of the given newValue. |
void |
setDateTimeIn(java.lang.String nodeName,
java.util.Calendar newValue)
Set the node value of all data nodes found for the given xpath to the string representation of the given newValue. |
void |
setDateTimeInFirst(java.lang.String nodeName,
java.util.Calendar newValue)
Set the first data element found with the given name to the string representation of the given newValue. |
void |
setDocumentData(java.lang.String path,
DocumentData value)
Set the data element referred to by path to be value. |
void |
setDocumentDefinition(IDocumentDefinition docDef)
Set the IDocumentDefinition for this document. |
void |
setDocumentElement(org.w3c.dom.Element documentElement)
Set the element that will act as the document root element for this document. |
void |
setDocumentTypeName(java.lang.String typeName)
Set the document type name for this document. |
void |
setDoubleIn(java.lang.String nodeName,
double newValue)
Set the node value of all data nodes found for the given xpath to the string representation of the given newValue. |
void |
setDoubleInFirst(java.lang.String nodeName,
double newValue)
Set the first data element found with the given name to the string representation of the given newValue. |
void |
setEntityResolver(org.xml.sax.EntityResolver entityResolver)
Set the EntityResolver to use when unserializing. |
void |
setIntegerIn(java.lang.String nodeName,
int newValue)
Set the node value of all data nodes found for the given xpath to the string representation of the given newValue. |
void |
setIntegerInFirst(java.lang.String nodeName,
int newValue)
Set the first data element found with the given name to the string representation of the given newValue. |
void |
setPublicID(java.lang.String id)
Get the system id for this document. |
void |
setStringIn(java.lang.String nodeName,
java.lang.String newValue)
Set the node value of all data nodes found for the given xpath to the string representation of the given newValue. |
void |
setStringInFirst(java.lang.String nodeName,
java.lang.String newValue)
Set the first data element found with the given name to the string given by newValue. |
void |
setSystemID(java.lang.String id)
Set the system id for this document. |
void |
setTimeIn(java.lang.String nodeName,
java.util.Calendar newValue)
Set the node value of all data nodes found for the given xpath to the string representation of the given newValue. |
void |
setTimeInFirst(java.lang.String nodeName,
java.util.Calendar newValue)
Set the first data element found with the given name to the string representation of the given newValue. |
void |
setValidating(boolean validating)
Set this IDocument to validate/not-validate during calls to fromXML. |
java.lang.String |
toXML()
Get the XML represented by this document as a String. |
void |
toXML(java.io.Writer writer)
Get the XML represented by this document, and write it to the given Writer. |
void |
toXML(java.io.Writer writer,
int indentSize,
java.lang.String encoding)
Get the XML represented by this document, and write it to the given Writer, using the given indent size and character encoding. |
Method Detail |
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
public java.lang.String getRootElementName()
public boolean isParsed()
public void forceParsed() throws DocumentParseException, DocumentException
public org.w3c.dom.Document getDocument()
public java.lang.String getRawXML()
public org.w3c.dom.Element getDocumentElement()
public java.lang.String getSystemID()
public void setSystemID(java.lang.String id)
public java.lang.String getPublicID()
public void setPublicID(java.lang.String id)
public org.xml.sax.EntityResolver getEntityResolver()
public void setDocumentElement(org.w3c.dom.Element documentElement)
public void setEntityResolver(org.xml.sax.EntityResolver entityResolver)
public IDocumentDefinition getDocumentDefinition()
public void setDocumentDefinition(IDocumentDefinition docDef)
public java.lang.String getDocumentTypeName()
public void setDocumentTypeName(java.lang.String typeName)
public java.lang.String getEncoding()
public void setContextNode(java.lang.String path) throws DocumentException
public void setContextNode(DocumentData data) throws DocumentException
public void setContextNode(org.w3c.dom.Node node)
public void resetContextNode()
public java.lang.String getStringFromFirst(java.lang.String nodeName) throws DocumentException
public int getIntegerFromFirst(java.lang.String nodeName) throws DocumentException
public boolean getBooleanFromFirst(java.lang.String nodeName) throws DocumentException
public double getDoubleFromFirst(java.lang.String nodeName) throws DocumentException
public java.util.Calendar getDateFromFirst(java.lang.String nodeName) throws DocumentException
public java.util.Calendar getDateTimeFromFirst(java.lang.String nodeName) throws DocumentException
public java.util.Calendar getTimeFromFirst(java.lang.String nodeName) throws DocumentException
public boolean getValidating()
public java.lang.String getStringFrom(java.lang.String nodeName) throws DocumentException
public int getIntegerFrom(java.lang.String nodeName) throws DocumentException
public boolean getBooleanFrom(java.lang.String nodeName) throws DocumentException
public double getDoubleFrom(java.lang.String nodeName) throws DocumentException
public java.util.Calendar getDateFrom(java.lang.String nodeName) throws DocumentException
public java.util.Calendar getDateTimeFrom(java.lang.String nodeName) throws DocumentException
public java.util.Calendar getTimeFrom(java.lang.String nodeName) throws DocumentException
public IDocument[] getSubDocuments(java.lang.String path) throws DocumentException
public DocumentData getDocumentData(java.lang.String path) throws DocumentException
public void setStringInFirst(java.lang.String nodeName, java.lang.String newValue) throws DocumentException
public void setIntegerInFirst(java.lang.String nodeName, int newValue) throws DocumentException
public void setBooleanInFirst(java.lang.String nodeName, boolean newValue) throws DocumentException
public void setDoubleInFirst(java.lang.String nodeName, double newValue) throws DocumentException
public void setDateInFirst(java.lang.String nodeName, java.util.Calendar newValue) throws DocumentException
public void setDateTimeInFirst(java.lang.String nodeName, java.util.Calendar newValue) throws DocumentException
public void setTimeInFirst(java.lang.String nodeName, java.util.Calendar newValue) throws DocumentException
public void setValidating(boolean validating)
public void setStringIn(java.lang.String nodeName, java.lang.String newValue) throws DocumentException
public void setIntegerIn(java.lang.String nodeName, int newValue) throws DocumentException
public void setBooleanIn(java.lang.String nodeName, boolean newValue) throws DocumentException
public void setDoubleIn(java.lang.String nodeName, double newValue) throws DocumentException
public void setDateIn(java.lang.String nodeName, java.util.Calendar newValue) throws DocumentException
public void setDateTimeIn(java.lang.String nodeName, java.util.Calendar newValue) throws DocumentException
public void setTimeIn(java.lang.String nodeName, java.util.Calendar newValue) throws DocumentException
public void setDocumentData(java.lang.String path, DocumentData value) throws DocumentException
public org.w3c.dom.Attr addAttribute(java.lang.String parentPath, java.lang.String attrName) throws DocumentException
public org.w3c.dom.Attr addAttribute(java.lang.String parentPath, java.lang.String attrName, java.lang.String value) throws DocumentException
public org.w3c.dom.Element addElement(java.lang.String parentPath, java.lang.String elementName) throws DocumentException
public org.w3c.dom.Element addElement(java.lang.String parentPath, java.lang.String elementName, java.lang.String value) throws DocumentException
public void addNode(java.lang.String parentPath, org.w3c.dom.Node node) throws DocumentException
public void addDocumentData(java.lang.String parentPath, DocumentData value) throws DocumentException
public void removeDocumentData(java.lang.String path) throws DocumentException
public java.lang.String toXML() throws DocumentException
toXML(java.io.Writer, int, String)
public void toXML(java.io.Writer writer) throws java.io.IOException, DocumentException
public void toXML(java.io.Writer writer, int indentSize, java.lang.String encoding) throws java.io.IOException, DocumentException
public void fromXML(java.lang.String xmlText) throws DocumentParseException, DocumentException
public void fromXML(java.io.File file) throws DocumentParseException, DocumentException
file
- public void fromXML(java.io.File file, java.lang.String encoding) throws DocumentParseException, DocumentException
file
- encoding
- The Java encoding style for the content in the given file.public void fromXML(java.io.Reader reader) throws java.io.IOException, DocumentParseException, DocumentException
public void fromXML(org.xml.sax.InputSource inputSource) throws DocumentParseException, DocumentException
public void fromXML(org.xml.sax.ContentHandler contentHandler) throws DocumentParseException, DocumentException
|
WebLogic Integration | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |