Class XmlBeans
- java.lang.Object
-
- org.apache.xmlbeans.XmlBeans
-
public final class XmlBeans extends java.lang.ObjectProvides an assortment of utilities for managing XML Bean types, type systems, QNames, paths, and queries.
-
-
Field Summary
Fields Modifier and Type Field Description static SchemaTypeNO_TYPEThe SchemaType object given to an XmlObject instance when no type can be determined.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclearThreadLocals()static java.lang.StringcompilePath(java.lang.String pathExpr)Compiles an XPath, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached.static java.lang.StringcompilePath(java.lang.String pathExpr, XmlOptions options)Compiles an XPath, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached; takes an option for specifying text that indicates the name of context node.static java.lang.StringcompileQuery(java.lang.String queryExpr)Compiles an XQuery, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached.static java.lang.StringcompileQuery(java.lang.String queryExpr, XmlOptions options)Compiles an XQuery, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached; takes an option for specifying text that indicates the context node.static SchemaTypeSystemcompileXmlBeans(java.lang.String name, SchemaTypeSystem system, XmlObject[] schemas, BindingConfig config, SchemaTypeLoader typepath, Filer filer, XmlOptions options)Returns the SchemaTypeSystem that results from augumenting the SchemaTypeSystem passed in by incrementally adding the given XML schema definitions.static SchemaTypeSystemcompileXsd(SchemaTypeSystem system, XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options)Returns the SchemaTypeSystem that results from augumenting the SchemaTypeSystem passed in by incrementally adding the given XML schema definitions.static SchemaTypeSystemcompileXsd(XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options)Returns the SchemaTypeSystem that results from compiling the XML schema definitions passed.static SchemaTypeSystemgetBuiltinTypeSystem()Returns the builtin type system.static SchemaTypeLoadergetContextTypeLoader()Gets the SchemaTypeLoader based on the current thread's context ClassLoader.static javax.xml.namespace.QNamegetQName(java.lang.String localPart)Obtains a name from the thread local QNameCachestatic javax.xml.namespace.QNamegetQName(java.lang.String namespaceUri, java.lang.String localPart)Obtains a name from the thread local QNameCachestatic QNameCachegetQNameCache()Returns a thread local QNameCachestatic java.lang.StringgetTitle()Returns the XmlBeans Package title, "org.apache.xmlbeans", the value ofXmlBeans.class.getPackage().getImplementationTitle().static java.lang.StringgetVendor()Returns the XmlBeans vendor, "Apache Software Foundation", the value ofXmlBeans.class.getPackage().getImplementationVendor().static java.lang.StringgetVersion()Returns the XmlBeans version, the value ofXmlBeans.class.getPackage().getImplementationVersion().static SchemaTypeLoaderloadXsd(XmlObject[] schemas)Returns the SchemaTypeSystem that results from compiling the XML schema definitions passed.static SchemaTypeLoaderloadXsd(XmlObject[] schemas, XmlOptions options)Returns the SchemaTypeSystem that results from compiling the XML schema definitions passed in schemas.static XmlCursornodeToCursor(org.w3c.dom.Node n)Creates an XmlCursor for a DOM node which is implemented by XmlBwansstatic XmlObjectnodeToXmlObject(org.w3c.dom.Node n)Creates an XmlObject for a DOM node which is implemented by XmlBwansstatic javax.xml.stream.XMLStreamReadernodeToXmlStreamReader(org.w3c.dom.Node n)Creates an XmlObject for a DOM node which is implemented by XmlBwansstatic ResourceLoaderresourceLoaderForPath(java.io.File[] path)Returns a new ResourceLoader for a search path where each component of the path is either a directory or a compiled xbean jar.static org.w3c.dom.NodestreamToNode(javax.xml.stream.XMLStreamReader xs)Returns the XmlObject for a DOM node which is implemented by XmlBwansstatic SchemaTypetypeForClass(java.lang.Class c)Returns the SchemaType from a corresponding XmlObject subclass, or null if none.static SchemaTypeLoadertypeLoaderForClassLoader(java.lang.ClassLoader loader)Returns a SchemaTypeLoader that searches for compiled schema types in the given ClassLoader.static SchemaTypeLoadertypeLoaderForResource(ResourceLoader resourceLoader)Returns a SchemaTypeLoader that searches for compiled schema types in the given ResourceLoader.static SchemaTypeLoadertypeLoaderUnion(SchemaTypeLoader[] typeLoaders)Returns the union of a list of typeLoaders.static SchemaTypeSystemtypeSystemForClassLoader(java.lang.ClassLoader loader, java.lang.String stsName)Returns the SchemaTypeSystem of the given name (as returned bySchemaTypeSystem.getName()) for the given ClassLoader.
-
-
-
Field Detail
-
NO_TYPE
public static SchemaType NO_TYPE
The SchemaType object given to an XmlObject instance when no type can be determined.The NO_TYPE is the universal derived type. That is, it is derived from all other schema types, and no instances of the NO_TYPE are valid. (It is not to be confused with the anyType, which is the universal base type from which all other types can be derived, and of which all instances are valid.)
-
-
Method Detail
-
getTitle
public static final java.lang.String getTitle()
Returns the XmlBeans Package title, "org.apache.xmlbeans", the value ofXmlBeans.class.getPackage().getImplementationTitle().
-
getVendor
public static final java.lang.String getVendor()
Returns the XmlBeans vendor, "Apache Software Foundation", the value ofXmlBeans.class.getPackage().getImplementationVendor().
-
getVersion
public static final java.lang.String getVersion()
Returns the XmlBeans version, the value ofXmlBeans.class.getPackage().getImplementationVersion().
-
clearThreadLocals
public static void clearThreadLocals()
-
getQNameCache
public static QNameCache getQNameCache()
Returns a thread local QNameCache
-
getQName
public static javax.xml.namespace.QName getQName(java.lang.String localPart)
Obtains a name from the thread local QNameCache
-
getQName
public static javax.xml.namespace.QName getQName(java.lang.String namespaceUri, java.lang.String localPart)Obtains a name from the thread local QNameCache
-
compilePath
public static java.lang.String compilePath(java.lang.String pathExpr) throws XmlExceptionCompiles an XPath, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached.- Throws:
XmlException
-
compilePath
public static java.lang.String compilePath(java.lang.String pathExpr, XmlOptions options) throws XmlExceptionCompiles an XPath, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached; takes an option for specifying text that indicates the name of context node. The default is "this", as in "$this".- Parameters:
options- Options for the path. For example, you can call theXmlOptions.setXqueryCurrentNodeVar(String)method to specify a particular name for the expression variable that indicates the context node.- Throws:
XmlException
-
compileQuery
public static java.lang.String compileQuery(java.lang.String queryExpr) throws XmlExceptionCompiles an XQuery, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached.- Throws:
XmlException
-
compileQuery
public static java.lang.String compileQuery(java.lang.String queryExpr, XmlOptions options) throws XmlExceptionCompiles an XQuery, returning a String equal to that which was passed, but whose identity is that of one which has been precompiled and cached; takes an option for specifying text that indicates the context node.- Parameters:
options- Options for the query. For example, you can call theXmlOptions.setXqueryCurrentNodeVar(String)method to specify a particular name for the expression variable that indicates the context node and theXmlOptions.setXqueryVariables(Map)method to map external variable names to values.- Throws:
XmlException
-
getContextTypeLoader
public static SchemaTypeLoader getContextTypeLoader()
Gets the SchemaTypeLoader based on the current thread's context ClassLoader. This is the SchemaTypeLoader that is used to assign schema types to XML documents by default. The SchemaTypeLoader is also consulted to resolve wildcards and xsi:type attributes.The "parse" methods of XmlBeans all delegate to the "parseInstance" methods of the context type loader.
-
getBuiltinTypeSystem
public static SchemaTypeSystem getBuiltinTypeSystem()
Returns the builtin type system. This SchemaTypeSystem contains only the 46 builtin types defined by the XML Schema specification.
-
nodeToCursor
public static XmlCursor nodeToCursor(org.w3c.dom.Node n)
Creates an XmlCursor for a DOM node which is implemented by XmlBwans
-
nodeToXmlObject
public static XmlObject nodeToXmlObject(org.w3c.dom.Node n)
Creates an XmlObject for a DOM node which is implemented by XmlBwans
-
nodeToXmlStreamReader
public static javax.xml.stream.XMLStreamReader nodeToXmlStreamReader(org.w3c.dom.Node n)
Creates an XmlObject for a DOM node which is implemented by XmlBwans
-
streamToNode
public static org.w3c.dom.Node streamToNode(javax.xml.stream.XMLStreamReader xs)
Returns the XmlObject for a DOM node which is implemented by XmlBwans
-
loadXsd
public static SchemaTypeLoader loadXsd(XmlObject[] schemas) throws XmlException
Returns the SchemaTypeSystem that results from compiling the XML schema definitions passed.Just like compileXsd, but uses the context type loader for linking, and returns a unioned typeloader that is suitable for creating instances.
- Throws:
XmlException
-
loadXsd
public static SchemaTypeLoader loadXsd(XmlObject[] schemas, XmlOptions options) throws XmlException
Returns the SchemaTypeSystem that results from compiling the XML schema definitions passed in schemas.
This is just like compileXsd, but uses the context type loader for linking, and returns a unioned typeloader that is suitable for creating instances.
Use the options parameter to specify one or both of the following:
- A collection instance that should be used as an error listener during
compilation, as described in
XmlOptions.setErrorListener(java.util.Collection). - Whether validation should not be done when building the SchemaTypeSystem,
as described in
XmlOptions.setCompileNoValidation().
- Parameters:
schemas- The schema definitions from which to build the schema type system.options- Options specifying an error listener and/or validation behavior.- Throws:
XmlException
- A collection instance that should be used as an error listener during
compilation, as described in
-
compileXsd
public static SchemaTypeSystem compileXsd(XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options) throws XmlException
Returns the SchemaTypeSystem that results from compiling the XML schema definitions passed.
The XmlObjects passed in should be w3c <schema> elements whose type is org.w3c.x2001.xmlSchema.Schema. (That is, schema elements in the XML namespace http://www.w3c.org/2001/XMLSchema.) Also org.w3c.x2001.xmlSchema.SchemaDocument is permitted.
The optional second argument is a SchemaTypeLoader which will be consulted for already-compiled schema types which may be linked while processing the given schemas.
The SchemaTypeSystem that is returned should be combined (via
typeLoaderUnion(org.apache.xmlbeans.SchemaTypeLoader[])) with the typepath typeloader in order to create a typeloader that can be used for creating and validating instances.Use the options parameter to specify the following:
- A collection instance that should be used as an error listener during
compilation, as described in
XmlOptions.setErrorListener(java.util.Collection). - Whether validation should not be done when building the SchemaTypeSystem,
as described in
XmlOptions.setCompileNoValidation().
- Parameters:
schemas- The schema definitions from which to build the schema type system.typepath- The path to already-compiled schema types for linking while processing.options- Options specifying an error listener and/or validation behavior.- Throws:
XmlException
- A collection instance that should be used as an error listener during
compilation, as described in
-
compileXsd
public static SchemaTypeSystem compileXsd(SchemaTypeSystem system, XmlObject[] schemas, SchemaTypeLoader typepath, XmlOptions options) throws XmlException
Returns the SchemaTypeSystem that results from augumenting the SchemaTypeSystem passed in by incrementally adding the given XML schema definitions.
These could be new definitions (if the Schema document is not recorded into the existing SchemaTypeSystem), modifications to the already existing definitions (if the Schema document is already recorded in the existing SchemaTypeSystem), or deletions (if the Schema document is already recorded in the existing SchemaTypeSystem and the new definitions are empty). The identity of documents is established using
XmlDocumentProperties.getSourceName(), so if the caller choses to construct the Schema definitions using other methods than parsing an XML document, they should make sure that the names returned by that method are consistent with the caller's intent (add/modify).The XmlObjects passed in should be w3c <schema> elements whose type is org.w3c.x2001.xmlSchema.Schema. (That is, schema elements in the XML namespace http://www.w3c.org/2001/XMLSchema.) Also org.w3c.x2001.xmlSchema.SchemaDocument is permitted.
The optional second argument is a SchemaTypeLoader which will be consulted for already-compiled schema types which may be linked while processing the given schemas.
The SchemaTypeSystem that is returned should be combined (via
typeLoaderUnion(org.apache.xmlbeans.SchemaTypeLoader[])) with the typepath typeloader in order to create a typeloader that can be used for creating and validating instances.Use the options parameter to specify the following:
- A collection instance that should be used as an error listener during
compilation, as described in
XmlOptions.setErrorListener(java.util.Collection). - Whether validation should not be done when building the SchemaTypeSystem,
as described in
XmlOptions.setCompileNoValidation().
- Parameters:
schemas- The schema definitions from which to build the schema type system.typepath- The path to already-compiled schema types for linking while processing.options- Options specifying an error listener and/or validation behavior.- Throws:
XmlException
- A collection instance that should be used as an error listener during
compilation, as described in
-
compileXmlBeans
public static SchemaTypeSystem compileXmlBeans(java.lang.String name, SchemaTypeSystem system, XmlObject[] schemas, BindingConfig config, SchemaTypeLoader typepath, Filer filer, XmlOptions options) throws XmlException
Returns the SchemaTypeSystem that results from augumenting the SchemaTypeSystem passed in by incrementally adding the given XML schema definitions.
These could be new definitions (if the Schema document is not recorded into the existing SchemaTypeSystem), modifications to the already existing definitions (if the Schema document is already recorded in the existing SchemaTypeSystem), or deletions (if the Schema document is already recorded in the existing SchemaTypeSystem and the new definitions are empty). The identity of documents is established using
XmlDocumentProperties.getSourceName(), so if the caller choses to construct the Schema definitions using other methods than parsing an XML document, they should make sure that the names returned by that method are consistent with the caller's intent (add/modify).The XmlObjects passed in should be w3c <schema> elements whose type is org.w3c.x2001.xmlSchema.Schema. (That is, schema elements in the XML namespace http://www.w3c.org/2001/XMLSchema.) Also org.w3c.x2001.xmlSchema.SchemaDocument is permitted.
The optional name argument is used to name the compiled schema type system. A randomly generated name will be used if the name is null.
The optional
BindingConfigargument is used to control the shape of the generated code. ABindingConfigisn't used ifFileris null.The optional SchemaTypeLoader argument will be consulted for already-compiled schema types which may be linked while processing the given schemas. If not specified, the context typeloader (as returned by
getContextTypeLoader()) will be used.The optional
Filerargument is used to create new binary or source files which are the product of the compilation. If the Filer is null, the schema binaries (.xsb) files and source files won't be generated.The SchemaTypeSystem that is returned should be combined (via
typeLoaderUnion(org.apache.xmlbeans.SchemaTypeLoader[])) with the typepath typeloader in order to create a typeloader that can be used for creating and validating instances.Use the options parameter to specify the following:
- A collection instance that should be used as an error listener during
compilation, as described in
XmlOptions.setErrorListener(java.util.Collection). - Whether validation should not be done when building the SchemaTypeSystem,
as described in
XmlOptions.setCompileNoValidation().
- Parameters:
name- The type system name or null to use a randomly generated name.system- A pre-existing SchemaTypeSystem used in incremental compilation.schemas- The schema definitions from which to build the schema type system.config- The configuration controls the code generation shape.typepath- The path to already-compiled schema types for linking while processing.filer- The Filer instance used to create binary binding files and source text files.options- Options specifying an error listener and/or validation behavior.- Throws:
XmlException
- A collection instance that should be used as an error listener during
compilation, as described in
-
typeLoaderUnion
public static SchemaTypeLoader typeLoaderUnion(SchemaTypeLoader[] typeLoaders)
Returns the union of a list of typeLoaders. The returned SchemaTypeLoader searches the given list of SchemaTypeLoaders in order from first to last.
-
typeLoaderForClassLoader
public static SchemaTypeLoader typeLoaderForClassLoader(java.lang.ClassLoader loader)
Returns a SchemaTypeLoader that searches for compiled schema types in the given ClassLoader.
-
typeLoaderForResource
public static SchemaTypeLoader typeLoaderForResource(ResourceLoader resourceLoader)
Returns a SchemaTypeLoader that searches for compiled schema types in the given ResourceLoader.- See Also:
resourceLoaderForPath(File[])
-
typeSystemForClassLoader
public static SchemaTypeSystem typeSystemForClassLoader(java.lang.ClassLoader loader, java.lang.String stsName)
Returns the SchemaTypeSystem of the given name (as returned bySchemaTypeSystem.getName()) for the given ClassLoader.Note: you will almost always need typeLoaderForClassLoader() instead (see
typeLoaderForClassLoader(java.lang.ClassLoader)).
-
resourceLoaderForPath
public static ResourceLoader resourceLoaderForPath(java.io.File[] path)
Returns a new ResourceLoader for a search path where each component of the path is either a directory or a compiled xbean jar.
-
typeForClass
public static SchemaType typeForClass(java.lang.Class c)
Returns the SchemaType from a corresponding XmlObject subclass, or null if none.
-
-