|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.iapi.types.SqlXmlUtil
public class SqlXmlUtil
This class contains "utility" methods that work with XML-specific objects that are only available if JAXP and/or Xalan are in the classpath. NOTE: This class is only compiled with JDK 1.4 and higher since the XML-related classes that it uses (JAXP and Xalan) are not part of earlier JDKs. Having a separate class for this functionality is beneficial for two reasons: 1. Allows us to allocate XML objects and compile an XML query expression a single time per statement, instead of having to do it for every row against which the query is evaluated. An instance of this class is created at compile time and then passed (using "saved objects") to the appropriate operator implementation method in XML.java; see SqlXmlExecutor.java for more about the role this class plays in "saved object" processing. 2. By keeping all XML-specific references in this one class, we have a single "point of entry" to the XML objects--namely, the constructor for this class. Thus, if we always make sure to check for the required XML classes _before_ calling this class's constructor, we can detect early on whether some classes (ex. Xalan) are missing, and can throw a friendly error up front, instead of a ClassNotFoundException somewhere deeper in the execution codepath. The initial check for the required XML classes can be found in XML.checkXMLRequirements(). Note that we don't want to put references to XML-specific objects directly into XML.java because that class (XML.java) is instantiated anytime a table with an XML column is referenced. That would mean that if a user tried to select a non-XML column (ex. integer) from a table that had at least one XML column in it, the user would have to have JAXP and Xalan classes in his/her classpath--which we don't want. Instead, by keeping all XML-specific objects in this one class, and then only instantiating this class when an XML operator is used (either implicitly or explicitly), we make it so that the user is only required to have XML-specific classes in his/her classpath _if_ s/he is trying to access or operate on XML values.
Nested Class Summary | |
---|---|
private class |
SqlXmlUtil.XMLErrorHandler
|
Field Summary | |
---|---|
private javax.xml.parsers.DocumentBuilder |
dBuilder
|
private java.lang.String |
opName
|
private XPath |
query
|
private java.lang.String |
queryExpr
|
private boolean |
recompileQuery
|
private Serializer |
serializer
|
private XPathContext |
xpContext
|
Constructor Summary | |
---|---|
SqlXmlUtil()
Constructor: Initializes objects required for parsing and serializing XML values. |
Method Summary | |
---|---|
void |
compileXQExpr(java.lang.String queryExpr,
java.lang.String opName)
Take the received string, which is an XML query expression, compile it, and store the compiled query locally. |
protected java.util.ArrayList |
evalXQExpression(XMLDataValue xmlContext,
boolean returnResults,
int[] resultXType)
Evaluate this object's compiled XML query expression against the received xmlContext. |
int |
getTypeFormatId()
Get the formatID which corresponds to this class. |
private XPathContext |
getXPathContext()
Create and return an instance of Xalan's XPathContext that can be used to compile an XPath expression. |
private void |
loadSerializer()
Create an instance of Xalan serializer for the sake of serializing an XML value according the SQL/XML specification for serialization. |
void |
readExternal(java.io.ObjectInput in)
|
protected java.lang.String |
serializeToString(java.util.ArrayList items,
XMLDataValue xmlVal)
Take an array list (sequence) of XML nodes and/or string values and serialize that entire list according to SQL/XML serialization rules, which ultimately point to XML serialization rules as defined by w3c. |
protected java.lang.String |
serializeToString(java.lang.String xmlAsText)
Take a string representing an XML value and serialize it according SQL/XML serialization rules. |
void |
writeExternal(java.io.ObjectOutput out)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private javax.xml.parsers.DocumentBuilder dBuilder
private Serializer serializer
private XPath query
private XPathContext xpContext
private java.lang.String queryExpr
private java.lang.String opName
private boolean recompileQuery
Constructor Detail |
---|
public SqlXmlUtil() throws StandardException
StandardException
Method Detail |
---|
public void compileXQExpr(java.lang.String queryExpr, java.lang.String opName) throws StandardException
queryExpr
- The XPath expression to compile
StandardException
protected java.lang.String serializeToString(java.lang.String xmlAsText) throws java.lang.Exception
xmlAsText
- String version of XML on which to perform
serialization.
java.lang.Exception
protected java.lang.String serializeToString(java.util.ArrayList items, XMLDataValue xmlVal) throws java.io.IOException
items
- List of items to serializexmlVal
- XMLDataValue into which the serialized string
returned by this method is ultimately going to be stored.
This is used for keeping track of XML values that represent
sequences having top-level (parentless) attribute nodes.
java.io.IOException
protected java.util.ArrayList evalXQExpression(XMLDataValue xmlContext, boolean returnResults, int[] resultXType) throws java.lang.Exception
xmlContext
- The XML value against which to evaluate
the stored (compiled) query expressionreturnResults
- Whether or not to return the actual
results of the queryresultXType
- The qualified XML type of the result
of evaluating the expression, if returnResults is true.
If the result is a sequence of exactly one Document node
then this will be XML(DOCUMENT(ANY)); else it will be
XML(SEQUENCE). If returnResults is false, this value
is ignored.
java.lang.Exception
- thrown on error (and turned into a
StandardException by the caller).private XPathContext getXPathContext()
private void loadSerializer() throws java.io.IOException
java.io.IOException
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
java.io.IOException
- on errorExternalizable.writeExternal(java.io.ObjectOutput)
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
java.io.IOException
- on error
java.lang.ClassNotFoundException
- on errorExternalizable.readExternal(java.io.ObjectInput)
public int getTypeFormatId()
getTypeFormatId
in interface TypedFormat
|
Built on Thu 2012-03-29 21:53:33+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |