|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bowstreet.xml.schema.Schema
public class Schema
The Schema class encapsulates a W3C schema or DTD,providing convenienebet
access to the elements defined within it.A Schema object can be instantiated
either with a URL (file:// or http://) or by passing in the String
holding the actual schema content. Then the elements can be accessed. So a
typical call sequence might be:
Schema schema = new Schema(httpUrlToSchema);
// get the source
String s = schema.getSchemaSource();
System.out.println(s);
// dump the root elements..
java.util.List elements = schema.getRootElements(true);
java.util.Iterator iter = elements.iterator();
while (iter.hasNext())
System.out.println(iter.next());
// get all elements..
elements = schema.getElements(true);
// get non leaf elements..
elements = schema.getNonLeafElements(true);
The Schemas are registered in the WebApp
at regen time using the
WebApp
api (addSchema()).
Here's a sample valid schema. It incorporates a targetNamespace to allow it to be referenced
in WSDL generated via the WebServiceEnable builder.
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://bowstreet.com/02/2002/wsenabled"
targetNamespace="http://bowstreet.com/02/2002/wsenabled">
<element name="books" type="tns:books" />
<complexType name="books">
<sequence>
<element name="book" type="tns:book"/>
</sequence>
</complexType>
<complexType name="book">
<sequence>
<element name="title" type="string"/>
<element name="authors" type="tns:authors"/>
<element name="price" type="string"/>
<element name="salePrice" type="string"/>
<attribute name="copyright" type="string"/>
<attribute name="edition" type="string"/>
</sequence>
</complexType>
<complexType name="authors">
<sequence>
<element name="author" type="string"/>
</sequence>
</complexType>
</schema>
WebApp
Nested Class Summary | |
---|---|
class |
Schema.Eh
|
Field Summary | |
---|---|
static java.lang.String |
BOWSTREET_XML_SCHEMA_HONOUR_ALL_SCHEMA_LOCATIONS
|
static java.lang.String |
BOWSTREET_XML_SCHEMA_LOG_PARSING_ERRORS
|
static java.lang.String |
BOWSTREET_XML_SCHEMA_RECURSIONS
|
static int |
ELEMENT_PATH_DATA_TYPE_ELEMENT
|
static int |
ELEMENT_PATH_DATA_TYPE_TYPE
|
Constructor Summary | |
---|---|
Schema(java.lang.String schemaText)
Constructor taking a schema as a String input. |
|
Schema(java.lang.String schemaText,
java.lang.String importsLocationURL)
Constructor taking a schema and its location as String inputs. |
|
Schema(java.lang.String schemaText,
java.lang.String importsLocationURL,
java.util.List otherSchemas)
Constructor taking a schema and its location as String inputs. |
|
Schema(java.net.URL url)
Constructor taking a URL as input. |
Method Summary | |
---|---|
java.lang.String |
expandSchemaImportLocations(java.lang.String schemaLocation)
|
java.lang.String |
expandSchemaImportLocations(java.lang.String schemaSource,
java.lang.String location,
boolean addToImportURIs,
boolean expandImports,
java.lang.String absolutePath,
java.lang.String schemaURL)
|
java.lang.String |
findName(java.lang.String name)
Given a name, try to find it in the elements or types of the schema and return the full path name. |
java.lang.String |
getAnnotation(java.lang.String itemName)
|
java.util.List |
getAttributes()
Returns a list of the attributes in the schema, as xpaths. |
ElementPathData |
getElementPathData(java.lang.String xPathRef)
Returns an ElementPathData description object for the element or type xpath provided. |
ElementPathData |
getElementPathData(java.lang.String xPathRef,
int type)
Returns an ElementPathData description object for the element or type xpath provided. |
java.util.List |
getElements()
Returns a list of element paths extracted earlier from the schema. |
static java.io.File |
getFileFromURL(java.net.URL url)
Utility function to get a File from a URL which has already been proven to have url.getProtocol().equals("file"). |
java.util.List |
getNonLeafElements()
Extracts just all elements that are not leaf elements (so they are still truly complex elements and not just Strings) returning a List of Xpaths. |
java.lang.Object |
getPreparser()
|
java.util.List |
getRootElements()
Returns a list of element paths extracted earlier from the schema, but only for the "root" element names, not subelements. |
java.lang.String |
getSchemaImportSource(java.lang.String url)
Returns the schema source for the URL supplied. |
java.util.Iterator |
getSchemaImportURIs()
Returns the keyset iterator of locations that we built up by recursively following imports in the Schema. |
java.lang.String |
getSchemaSource()
Returns the source string that was used in the Schema(String) constructor. |
java.util.List |
getSubElements(java.lang.String reqdParentPath,
boolean immediateChildrenOnly)
For a given parent path, returns the list of subelements. |
java.lang.String |
getTargetNamespace()
Returns the targetNamespace defined for this schema. |
java.util.List |
getTypes(boolean getSubElements,
boolean getLeafElements,
java.lang.String typeSuffix)
Extracts the types and optionally subelement trees from the Schema returning a list of XPaths. |
org.apache.xerces.xs.XSModel |
getXSModel()
|
boolean |
isAnElement(java.lang.String path)
Returns true if the passed in XPath maps to an element in the Schema (rather than a type). |
boolean |
isAType(java.lang.String path)
Returns true if the passed in XPath maps to a Type in the Schema (rather than an Element). |
boolean |
isQualified()
|
boolean |
isRootElementWithChildren(java.lang.String path)
Returns TRUE when the given path maps to a root elemment with children. |
static void |
main(java.lang.String[] args)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String BOWSTREET_XML_SCHEMA_HONOUR_ALL_SCHEMA_LOCATIONS
public static final java.lang.String BOWSTREET_XML_SCHEMA_LOG_PARSING_ERRORS
public static final java.lang.String BOWSTREET_XML_SCHEMA_RECURSIONS
public static final int ELEMENT_PATH_DATA_TYPE_ELEMENT
public static final int ELEMENT_PATH_DATA_TYPE_TYPE
Constructor Detail |
---|
public Schema(java.lang.String schemaText) throws java.lang.Exception
schemaText
- the w3c schema or DTD as string. This is not a
filename! It should be the actual schema.
java.lang.Exception
public Schema(java.lang.String schemaText, java.lang.String importsLocationURL) throws java.lang.Exception
schemaText
- the w3c schema or DTD as string. This is not a
filename! It should be the actual schema.importsLocationURL
- if available (maybe null) the location where this
schema source was pulled from so it can be used
as a relative URL for imports
java.lang.Exception
public Schema(java.lang.String schemaText, java.lang.String importsLocationURL, java.util.List otherSchemas) throws java.lang.Exception
schemaText
- the w3c schema or DTD as string. This is not a
filename! It should be the actual schema.importsLocationURL
- if available (maybe null) the location where this
schema source was pulled from so it can be used
as a relative URL for importsotherSchemas
- a list of other schemas that can be "stacked" into this
schemaspace for resolution of references
java.lang.Exception
public Schema(java.net.URL url) throws java.lang.Exception
Schema(String)
constructor should be used, passing in the dereferenced variable's content.
The URI in the schemaPath can be "file://filepath" or "http://url".
The Schema class supports CR XSD schemas (http://www.w3.org/2000/10/XMLSchema) as
well as 'final' rec. (http://www.w3.org/2001/XMLSchema) in
addition to XDR and SOX schemas and DTDs.
url
- URL to schema (file:// or http:// )
java.lang.Exception
SchemaPath
Method Detail |
---|
public java.lang.String expandSchemaImportLocations(java.lang.String schemaLocation)
public java.lang.String expandSchemaImportLocations(java.lang.String schemaSource, java.lang.String location, boolean addToImportURIs, boolean expandImports, java.lang.String absolutePath, java.lang.String schemaURL) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public java.lang.String findName(java.lang.String name)
name
- name of the type or element to be located
public java.lang.String getAnnotation(java.lang.String itemName)
public java.util.List getAttributes() throws java.lang.Exception
java.lang.Exception
public ElementPathData getElementPathData(java.lang.String xPathRef)
xPathRef
- the xpath for the element or type
public ElementPathData getElementPathData(java.lang.String xPathRef, int type)
xPathRef
- the xpath for the element or typetype
- the type of match desired: ELEMENT_PATH_DATA_TYPE_ELEMENT for an element
or ELEMENT_PATH_DATA_TYPE_TYPE for a type.
public java.util.List getElements() throws java.lang.Exception
java.lang.Exception
public static java.io.File getFileFromURL(java.net.URL url)
url
- which is known to return true from url.getProtocol().equals("file")
public java.util.List getNonLeafElements() throws java.lang.Exception
java.lang.Exception
public java.lang.Object getPreparser()
public java.util.List getRootElements() throws java.lang.Exception
java.lang.Exception
public java.lang.String getSchemaImportSource(java.lang.String url)
public java.util.Iterator getSchemaImportURIs()
public java.lang.String getSchemaSource()
public java.util.List getSubElements(java.lang.String reqdParentPath, boolean immediateChildrenOnly)
reqdParentPath
- immediateChildrenOnly
-
public java.lang.String getTargetNamespace()
public java.util.List getTypes(boolean getSubElements, boolean getLeafElements, java.lang.String typeSuffix) throws java.lang.Exception
getSubElements
- indicator of whether subelement tree should be retrievedgetLeafElements
- indicator of whether leafs elements should be retrieved
if subelements are being retrievedtypeSuffix
- can be null, an optional suffix added to the type name to
make it clear in UIs that this is a type, not an element
java.lang.Exception
public org.apache.xerces.xs.XSModel getXSModel()
public boolean isAnElement(java.lang.String path)
path
- XPath to target, eg books/book/book
public boolean isAType(java.lang.String path)
path
- XPath to target, eg books/book/book
public boolean isQualified()
public boolean isRootElementWithChildren(java.lang.String path)
path
- XPath to element that will be tested, eg books/book.
public static void main(java.lang.String[] args)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |