public class SchemaHelper
extends java.lang.Object
Aggregates tools and data structures for working with XML Schemas, and is in
turn encapsulated in the MetaDataFramework
object. Major components include
XSDatatypeManager
for performing
iterative validation of xml documents using datatypes defined in the
Schema.DefinitionMiner
which traverses an
XML Schema and builds a dictionary of GlobalElement
objects, one for each element defined in the Schema.SchemaNodeMap
that represents the
structure defined by the Schema as a tree of SchemaNode
objects.NOTE: The SchemaHelper assumes that XML Schemas are represented using the "Venetian Blind" technique.
Modifier and Type | Field and Description |
---|---|
static int |
MAXOCCURS_DEFAULT
NOT YET DOCUMENTED
|
static int |
MINOCCURS_DEFAULT
NOT YET DOCUMENTED
|
static java.lang.String |
NILLABLE_DEFAULT
NOT YET DOCUMENTED
|
static int |
UNBOUNDED
NOT YET DOCUMENTED
|
Constructor and Description |
---|
SchemaHelper(java.io.File schemaFile)
Constructor for the SchemaHelper object
|
SchemaHelper(java.io.File schemaFile,
java.lang.String rootElementName)
Constructor for the SchemaHelper object for disk-based schema
|
SchemaHelper(java.net.URL schemaURL)
Constructor for the SchemaHelper object
|
SchemaHelper(java.net.URL schemaURL,
java.lang.String rootElementName)
Constructor for the SchemaHelper object using web-based schema.
|
Modifier and Type | Method and Description |
---|---|
static void |
box(java.lang.String s,
java.lang.String prefix)
NOT YET DOCUMENTED
|
boolean |
checkValidValue(java.lang.String typeName,
java.lang.String value)
Checks to see if a value is valid against a specified datatype.
|
java.lang.String |
decodeAnyTypeXpath(java.lang.String xpath)
Replaces xpath used to access an "anyType" node in the XML Document with a version
that is known to the schema.
|
void |
destroy()
Description of the Method
|
java.lang.String |
encodeAnyTypeXpath(java.lang.String xpath)
Replaces xpath having node name of "any" with a wild-card version that
can actually access the any element (which is anonymous) in the XML Document.
|
java.lang.String |
encodePathIfAnyType(java.lang.String xpath) |
java.util.List |
getChildrenOrder(java.lang.String xpath)
Returns a list of element names for the given path from the instanceDoc.
|
Compositor |
getCompositor(SchemaNode schemaNode)
Gets the compositor attribute of the SchemaHelper object
|
Compositor |
getCompositor(java.lang.String xpath)
Gets the compositor attribute of the SchemaHelper object
|
DefinitionMiner |
getDefinitionMiner()
Gets the definitionMiner attribute of the SchemaHelper object
|
java.util.List |
getEnumerationValues(GlobalDef globalDef,
boolean getLeafValues)
Gets the enumerationValues that are specified by the typeName.
|
java.util.List |
getEnumerationValues(java.lang.String typeName,
boolean getLeafValues)
Gets the enumerationValues attribute of the SchemaHelper object
|
GlobalDef |
getGlobalDef(SchemaNode schemaNode)
Gets a globalDef from the globalDefMap.
|
GlobalDef |
getGlobalDef(java.lang.String typeName)
Gets a globalDef from the default namespace of the globalDefMap.
|
GlobalDef |
getGlobalDefFromXPath(java.lang.String xpath)
Finds a globalDef object for a given xpath.
|
GlobalDefMap |
getGlobalDefMap()
Gets the globalDefMap attribute of the SchemaHelper object.
|
org.dom4j.Node |
getInstanceDocNode(java.lang.String xpath)
Gets a
Node from the instanceDocument |
java.util.List |
getInstanceDocNodes(java.lang.String xpath)
Gets the instanceDocNodes attribute of the SchemaHelper object
|
org.dom4j.Document |
getInstanceDocument()
Gets the instanceDocument attribute of the SchemaHelper object
|
static int |
getMaxOccurs(org.dom4j.Element e)
Utility to extract the maxOccurs attribute of the given element and returns
an int equivalent.
|
org.dom4j.Document |
getMinimalDocument()
Create a miminal instance document that is used as the starting point for a
new document.
|
static int |
getMinOccurs(org.dom4j.Element e)
Extract the minOccurs attribute of the given element and returns an int
equivalent.
|
boolean |
getNamespaceEnabled()
Gets the namespaceEnabled attribute of the SchemaHelper object
|
org.dom4j.Element |
getNewElement(java.lang.String encodedPath)
Creates a "miminalElement" (one that contains only required elements) from
the instanceDocument.
|
SchemaNode |
getParentSchemaNode(SchemaNode schemaNode)
Gets the parent of a SchemaNode
|
SchemaNode |
getParentSchemaNode(java.lang.String xpath)
Gets the parent of the SchemaNode associated with a given xpath
|
java.lang.String |
getRepeatingComplexSingletonChildName(java.lang.String xpath)
Gets the qualified element name of the repeatingComplexSingleton child of
the node specified by the provided path, or an empty string if such a child
does not exist.
|
java.lang.String |
getRootElementName()
Gets the rootElementName attribute of the SchemaHelper object
|
java.lang.String |
getSchemaLocation()
Gets the rootURI attribute of the SchemaHelper object
|
org.dom4j.Namespace |
getSchemaNamespace() |
SchemaNode |
getSchemaNode(java.lang.String xpath)
Gets a schemaNode from the schemaNodeMap.
|
SchemaNodeMap |
getSchemaNodeMap()
Gets the schemaNodeMap attribute of the SchemaHelper object
|
SchemaProps |
getSchemaProps()
Gets the schemaProps attribute of the SchemaHelper object
|
java.lang.String |
getTargetNamespace()
Gets the targetNamespace attribute of the SchemaHelper object
|
java.lang.String |
getVersion()
Gets the version attribute of the SchemaHelper object
|
com.sun.msv.datatype.xsd.XSDatatype |
getXSDataType(java.lang.String dataTypeName)
Get a named
XSDatatype object used to validate input. |
XSDatatypeManager |
getXSDatatypeManager()
Gets the xsdDatatypeManager attribute of the SchemaHelper object.
|
boolean |
hasChoiceCompositor(SchemaNode schemaNode)
Returns true if the Node's type definition specifies a choice compositor
|
boolean |
hasChoiceCompositor(java.lang.String encodedXPath)
NOT YET DOCUMENTED
|
boolean |
hasCompositor(java.lang.String encodedXPath)
Returns true if the schemaNode for the specified path has a compositor.
|
boolean |
hasMultiSelect(SchemaNode schemaNode)
multiselect iff
isComplex
hasSequenceCompositor
containing a single multiSelect element
|
boolean |
hasOptionalMultiSelect(SchemaNode schemaNode)
Returns true if this element is optional and contains only a single
multiSelect element.
|
boolean |
hasOptionalMultiSelect(java.lang.String pathArg)
Test a JSP-encoded pathArg for whether it refers to an element that
satisfies the
hasOptionalMultiSelect(SchemaNode) predicate. |
boolean |
hasRepeatingComplexSingleton(java.lang.String xpath)
Returns true if the node at the provided path contains a Single, Complex
element with maxOccurs of more than 1.
|
boolean |
hasRequiredMultiSelect(SchemaNode schemaNode)
NOT YET DOCUMENTED
|
boolean |
hasSequenceCompositor(SchemaNode schemaNode)
Returns true if the Node's type definition specifies a sequence compositor
|
boolean |
hasSequenceCompositor(java.lang.String encodedXPath)
NOT YET DOCUMENTED
|
boolean |
isAnyTypeElement(java.lang.String xpath) |
boolean |
isChoiceElement(SchemaNode schemaNode)
Return true if this element is a member of a choice compositor.
|
boolean |
isChoiceElement(java.lang.String encodedXPath)
Gets the choiceElement attribute of the SchemaHelper object
|
boolean |
isComboUnionType(GlobalDef typeDef)
Gets the comboUnionType attribute of the SchemaHelper object
|
boolean |
isEnumerationType(GlobalDef typeDef)
Returns true if the given typeDef represents an eumeration datatype
|
boolean |
isEnumerationType(java.lang.String typeName)
Returns true if the typeName corresponds to datatype that represents an
enumeration.
|
boolean |
isMultiChoiceElement(SchemaNode schemaNode)
Returns true if the given schemaNode allows for multiple choice children
elements.
|
boolean |
isMultiChoiceElement(java.lang.String encodedXPath)
Returns true if the given path corresponds to a schemaNode that allows for
multiple choice children elements.
|
boolean |
isMultiSelect(SchemaNode schemaNode)
Determines if the SchemaNode should rendered as a MultiSelect Element
(e.g., checkboxes).
|
boolean |
isMultiSelect(java.lang.String encodedXPath)
Gets the multiSelect attribute of the SchemaHelper object
|
boolean |
isRecursiveElement(java.lang.String encodedXPath) |
boolean |
isRepeatingComplexSingleton(java.lang.String xpath)
Returns true if the provided path meets the requirememts for a repeating
complex singleton element.
|
boolean |
isRepeatingElement(SchemaNode schemaNode)
Gets the repeatingElement attribute of the SchemaHelper object
|
boolean |
isRepeatingElement(SchemaNode schemaNode,
GlobalDef typeDef)
Determines whether an instanceDocumentNode is a repeating element (i.e., it
has maxOccurs > 1 and is NOT an enumerationType).
|
boolean |
isRepeatingElement(java.lang.String encodedXPath)
Gets the repeatingElement attribute of the SchemaHelper object
|
boolean |
isRequiredAttribute(SchemaNode schemaNode)
Returns true if a
SchemaNode defines a
required attribute. |
boolean |
isRequiredBranch(SchemaNode schemaNode)
Returns true if the schemaNode is an element, a complexType (a branch) and
is required.
|
boolean |
isRequiredContentElement(SchemaNode schemaNode)
Returns true if the given schemaNode must have a text value (in addition to
possibly having subelements).
|
boolean |
isSingleton(SchemaNode schemaNode)
Returns true if this schemaNode is the only child of it's parent.
|
boolean |
isSingleton(java.lang.String xpath)
Gets the singleton attribute of the SchemaHelper object
|
static void |
main(java.lang.String[] args)
The main program for the SchemaHelper class
|
static void |
setDebug(boolean d)
Sets the debug attribute of the SchemaHelper class
|
void |
setSchemaNodeReadOnly(java.lang.String xpath)
set the isReadOnly attribute of the schemaNode specified by the given xpath
to true
|
static void |
setVerbose(boolean v)
Sets the verbose attribute of the SchemaHelper class
|
static java.lang.String |
toSchemaPath(java.lang.String encodedXPath)
convert a jsp-encoded path into a normalized form for accessing schemaNodes
|
public static final int MINOCCURS_DEFAULT
public static final int MAXOCCURS_DEFAULT
public static final java.lang.String NILLABLE_DEFAULT
public static final int UNBOUNDED
public SchemaHelper(java.io.File schemaFile) throws SchemaHelperException
schemaFile
- NOT YET DOCUMENTEDSchemaHelperException
- NOT YET DOCUMENTEDpublic SchemaHelper(java.io.File schemaFile, java.lang.String rootElementName) throws SchemaHelperException
schemaFile
- path to root file of schemarootElementName
- NOT YET DOCUMENTEDSchemaHelperException
- Description of the Exceptionpublic SchemaHelper(java.net.URL schemaURL) throws SchemaHelperException
schemaURL
- NOT YET DOCUMENTEDSchemaHelperException
- NOT YET DOCUMENTEDpublic SchemaHelper(java.net.URL schemaURL, java.lang.String rootElementName) throws SchemaHelperException
schemaURL
- URL to root file of schemarootElementName
- NOT YET DOCUMENTEDSchemaHelperException
- Description of the Exceptionpublic boolean getNamespaceEnabled()
public SchemaProps getSchemaProps()
public java.lang.String getSchemaLocation()
public org.dom4j.Namespace getSchemaNamespace()
public java.lang.String getVersion()
public java.lang.String getRootElementName()
public java.lang.String getTargetNamespace()
public GlobalDef getGlobalDef(java.lang.String typeName)
typeName
- the name of the globalDef objectGlobalDef
object, or null if not found.public GlobalDef getGlobalDef(SchemaNode schemaNode)
schemaNode
- a SchemaNode
objectGlobalDef
object, or
null if not found.public Compositor getCompositor(java.lang.String xpath)
xpath
- NOT YET DOCUMENTEDpublic Compositor getCompositor(SchemaNode schemaNode)
schemaNode
- NOT YET DOCUMENTEDpublic org.dom4j.Node getInstanceDocNode(java.lang.String xpath)
Node
from the instanceDocumentxpath
- xpath specifying the desired nodepublic java.util.List getInstanceDocNodes(java.lang.String xpath)
xpath
- NOT YET DOCUMENTEDpublic SchemaNode getSchemaNode(java.lang.String xpath)
xpath
- A string representation of an XPathSchemaNode
object , or null if not foundpublic void setSchemaNodeReadOnly(java.lang.String xpath)
xpath
- The new schemaNodeReadOnly valuepublic SchemaNode getParentSchemaNode(java.lang.String xpath)
xpath
- A string representation of an XPathpublic SchemaNode getParentSchemaNode(SchemaNode schemaNode)
schemaNode
- a SchemaNode
public static void main(java.lang.String[] args)
args
- The command line argumentspublic com.sun.msv.datatype.xsd.XSDatatype getXSDataType(java.lang.String dataTypeName)
XSDatatype
object used to validate input. Used only by
EditorAction in the "suggest" package org.dlese.dpc.to validate the email
field. this is necessary because the email field is not really specified as
being of this type and therefore another way is necessary for finding a
validating type.dataTypeName
- The name of a XSDatatype
objectpublic XSDatatypeManager getXSDatatypeManager()
public GlobalDefMap getGlobalDefMap()
public org.dom4j.Document getInstanceDocument()
public DefinitionMiner getDefinitionMiner()
public boolean checkValidValue(java.lang.String typeName, java.lang.String value) throws java.lang.Exception
value
- Value to be validatedtypeName
- Name of the DataType to be validated againstjava.lang.Exception
- If the value is not valid. The exception usually
contains helpful informationpublic SchemaNodeMap getSchemaNodeMap()
public static java.lang.String toSchemaPath(java.lang.String encodedXPath)
encodedXPath
- Description of the Parameterpublic boolean isRepeatingElement(java.lang.String encodedXPath)
encodedXPath
- Description of the Parameterpublic boolean isRepeatingElement(SchemaNode schemaNode)
schemaNode
- Description of the Parameterpublic boolean isRepeatingElement(SchemaNode schemaNode, GlobalDef typeDef)
schemaNode
- a wrapper to a Node in the instanceDocumenttypeDef
- a DataType to be tested for isEumerationpublic boolean isRecursiveElement(java.lang.String encodedXPath)
public boolean isSingleton(java.lang.String xpath)
xpath
- NOT YET DOCUMENTEDpublic boolean isSingleton(SchemaNode schemaNode)
schemaNode
- NOT YET DOCUMENTEDpublic boolean isRepeatingComplexSingleton(java.lang.String xpath)
xpath
- NOT YET DOCUMENTEDpublic boolean hasRepeatingComplexSingleton(java.lang.String xpath)
xpath
- NOT YET DOCUMENTEDpublic java.lang.String getRepeatingComplexSingletonChildName(java.lang.String xpath)
xpath
- NOT YET DOCUMENTEDpublic boolean isAnyTypeElement(java.lang.String xpath)
public boolean isMultiChoiceElement(java.lang.String encodedXPath)
encodedXPath
- xpath corresponding to a schemaNode to be testedpublic boolean isMultiChoiceElement(SchemaNode schemaNode)
schemaNode
- schemaNode to be testedpublic boolean isChoiceElement(java.lang.String encodedXPath)
encodedXPath
- NOT YET DOCUMENTEDpublic boolean isChoiceElement(SchemaNode schemaNode)
This is determined by the typeDefinition of the element's parent.
schemaNode
- Description of the Parameterpublic boolean hasChoiceCompositor(java.lang.String encodedXPath)
encodedXPath
- NOT YET DOCUMENTEDpublic boolean hasCompositor(java.lang.String encodedXPath)
encodedXPath
- NOT YET DOCUMENTEDpublic boolean hasChoiceCompositor(SchemaNode schemaNode)
schemaNode
- Description of the Parameterpublic boolean hasSequenceCompositor(java.lang.String encodedXPath)
encodedXPath
- NOT YET DOCUMENTEDpublic boolean hasSequenceCompositor(SchemaNode schemaNode)
schemaNode
- Description of the Parameterpublic boolean isMultiSelect(java.lang.String encodedXPath)
encodedXPath
- Description of the Parameterpublic boolean isMultiSelect(SchemaNode schemaNode)
schemaNode
- Description of the Parameterpublic boolean hasMultiSelect(SchemaNode schemaNode)
schemaNode
- NOT YET DOCUMENTEDpublic boolean hasOptionalMultiSelect(java.lang.String pathArg)
hasOptionalMultiSelect(SchemaNode)
predicate.NOTE: NEVER REFERENCED
pathArg
- an JSP-encoded XPathpublic boolean hasOptionalMultiSelect(SchemaNode schemaNode)
schemaNode
- Description of the Parameterpublic boolean hasRequiredMultiSelect(SchemaNode schemaNode)
schemaNode
- NOT YET DOCUMENTEDpublic boolean isRequiredBranch(SchemaNode schemaNode)
schemaNode
- Description of the Parameterpublic boolean isRequiredContentElement(SchemaNode schemaNode)
NOTE: currently we are calling ANY extended element (besides stringTextType) optional. I don't even know how you would define it as required in the schema, but I'm not worrying about it for now ...
schemaNode
- Description of the Parameterpublic boolean isRequiredAttribute(SchemaNode schemaNode)
SchemaNode
defines a
required attribute.schemaNode
- Description of the Parameterpublic boolean isComboUnionType(GlobalDef typeDef)
typeDef
- NOT YET DOCUMENTEDpublic boolean isEnumerationType(GlobalDef typeDef)
typeDef
- Description of the Parameterpublic boolean isEnumerationType(java.lang.String typeName)
typeName
- the name of a datatype defined by a schemapublic java.util.List getChildrenOrder(java.lang.String xpath)
xpath
- NOT YET DOCUMENTEDpublic java.util.List getEnumerationValues(GlobalDef globalDef, boolean getLeafValues)
getLeafValues
- specifies whether human-readable values are returnedglobalDef
- NOT YET DOCUMENTEDpublic java.util.List getEnumerationValues(java.lang.String typeName, boolean getLeafValues)
typeName
- NOT YET DOCUMENTEDgetLeafValues
- NOT YET DOCUMENTEDpublic GlobalDef getGlobalDefFromXPath(java.lang.String xpath)
SchemaNodeMap
and then using the name as an index into the GlobalDefMap
.xpath
- an xpath to a specific nodeGlobalDef
objectpublic org.dom4j.Document getMinimalDocument()
Document
public org.dom4j.Element getNewElement(java.lang.String encodedPath)
encodedPath
- JSP-encoded xpath that specifies the element to createpublic static int getMaxOccurs(org.dom4j.Element e)
e
- element from a xml schemapublic static int getMinOccurs(org.dom4j.Element e)
e
- element from a xml schemapublic java.lang.String encodePathIfAnyType(java.lang.String xpath)
public java.lang.String encodeAnyTypeXpath(java.lang.String xpath)
public java.lang.String decodeAnyTypeXpath(java.lang.String xpath)
public void destroy()
public static void setDebug(boolean d)
d
- The new debug valuepublic static void setVerbose(boolean v)
v
- The new verbose valuepublic static void box(java.lang.String s, java.lang.String prefix)
s
- NOT YET DOCUMENTEDprefix
- NOT YET DOCUMENTED