Package org.apache.ws.commons.schema
Class SchemaBuilder
java.lang.Object
org.apache.ws.commons.schema.SchemaBuilder
Object used to build a schema from a schema document. This object includes a cache of previously resolved
schema documents. This cache might be useful when an application has multiple webservices that each have
WSDL documents that import the same schema, for example. On app startup, we may wish to cache XmlSchema
objects so we don't build up the schema graph multiple times. key - use a combination of thread id and all
three parameters passed to resolveXmlSchema to give minimal thread safety value - XmlSchema object wrapped
in a SoftReference to encourage GC in low memory situations. CAUTION: XmlSchema objects are not likely to
be thread-safe. This cache should only be used, then cleared, by callers aware of its existence. It is VERY
important that users of this cache call clearCache() after they are done. Usage of the cache is controlled
by calling initCache() which will initialize resolvedSchemas to non-null. Clearing of cache is done by
calling clearCache() which will clear and nullify resolvedSchemas
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) XmlSchemaCollection(package private) Document(package private) XmlSchemaprivate final TargetNamespaceValidator(package private) DocumentBuilderFactoryprivate ExtensionRegistryThe extension registry to be used while building the schema modelprivate static final String[](package private) static ThreadLocal<Map<String, SoftReference<XmlSchema>>> -
Constructor Summary
ConstructorsConstructorDescriptionSchemaBuilder(XmlSchemaCollection collection, TargetNamespaceValidator validator) Schema builder constructor -
Method Summary
Modifier and TypeMethodDescription(package private) XmlSchemabuild method taking in a document and a uristatic voidRemove any entries from the cache for the current thread.private StringgetAttribute(Element content, String attrName) private XmlSchemagetCachedSchema(String targetNamespace, String schemaLocation, String baseUri) Return a cached schema if one exists for this thread.getChildren(Element content) (package private) XmlSchemaDerivationMethodgetDerivation(Element el, String attrName) (package private) StringgetEnumString(Element el, String attrName) (package private) XmlSchemaFormgetFormDefault(Element el, String attrName) (package private) longgetMaxOccurs(Element el) (package private) longgetMinOccurs(Element el) private QNamegetRefQName(String pName, NamespaceContext pContext) private QNamegetRefQName(String pName, Node pNode) private XmlSchemaAll(package private) XmlSchemaAnnotationhandleAnnotation(Element annotEl) Handles the annotation Traversing if encounter appinfo or documentation add it to annotation collectionprivate XmlSchemaAnyprivate XmlSchemaAnyAttributehandleAnyAttribute(XmlSchema schema, Element anyAttrEl, Element schemaEl) (package private) XmlSchemaAppInfohandleAppInfo(Element content) create new XmlSchemaAppinfo and add value gotten from element to this objprivate XmlSchemaAttributehandleAttribute(XmlSchema schema, Element attrEl, Element schemaEl) Process non-toplevel attributesprivate XmlSchemaAttributehandleAttribute(XmlSchema schema, Element attrEl, Element schemaEl, boolean topLevel) Process attributesprivate XmlSchemaAttributeGrouphandleAttributeGroup(XmlSchema schema, Element groupEl, Element schemaEl) private XmlSchemaAttributeGroupRefhandleAttributeGroupRef(XmlSchema schema, Element attrGroupEl) private XmlSchemaChoicehandleChoice(XmlSchema schema, Element choiceEl, Element schemaEl) private XmlSchemaComplexContenthandleComplexContent(XmlSchema schema, Element complexEl, Element schemaEl) private XmlSchemaComplexContentExtensionhandleComplexContentExtension(XmlSchema schema, Element extEl, Element schemaEl) handleComplexContentRestriction(XmlSchema schema, Element restrictionEl, Element schemaEl) (package private) XmlSchemaComplexTypehandleComplexType(XmlSchema schema, Element complexEl, Element schemaEl, boolean topLevel) Handle complex typesprivate XmlSchemaIdentityConstrainthandleConstraint(Element constraintEl, Class<? extends XmlSchemaIdentityConstraint> typeClass) (package private) XmlSchemaDocumentationhandleDocumentation(Element content) (package private) XmlSchemaElementhandleElement(XmlSchema schema, Element el, Element schemaEl, boolean isGlobal) handle elementsprivate voidhandleElementAnnotation(Element el, XmlSchemaElement element) private booleanhandleElementForm(Element el, XmlSchemaElement element, boolean isQualified) private voidhandleElementGlobalType(Element el, XmlSchemaElement element) private voidhandleElementName(boolean isGlobal, XmlSchemaElement element, boolean isQualified) private XmlSchemaGrouphandleGroup(XmlSchema schema, Element groupEl, Element schemaEl) private XmlSchemaGroupRefhandleGroupRef(XmlSchema schema, Element groupEl, Element schemaEl) (package private) XmlSchemaImporthandleImport(XmlSchema schema, Element importEl, Element schemaEl) Handle the import(package private) XmlSchemaIncludehandleInclude(XmlSchema schema, Element includeEl, Element schemaEl) Handles the includeprivate XmlSchemaNotationhandleNotation(XmlSchema schema, Element notationEl) private XmlSchemaRedefinehandleRedefine(XmlSchema schema, Element redefineEl, Element schemaEl) Handle redefineprivate voidhandleSchemaElementBasics(Element schemaEl, String systemId, XmlSchemaCollection.SchemaKey schemaKey) private voidhandleSchemaElementChild(Element schemaEl, Element el) private XmlSchemaSequencehandleSequence(XmlSchema schema, Element sequenceEl, Element schemaEl) private XmlSchemaSimpleContenthandleSimpleContent(XmlSchema schema, Element simpleEl, Element schemaEl) private XmlSchemaSimpleContentExtensionhandleSimpleContentExtension(XmlSchema schema, Element extEl, Element schemaEl) handleSimpleContentRestriction(XmlSchema schema, Element restrictionEl, Element schemaEl) (package private) XmlSchemaSimpleTypehandleSimpleType(XmlSchema schema, Element simpleEl, Element schemaEl, boolean topLevel) Handles simple typesprivate voidhandleSimpleTypeFinal(Element simpleEl, XmlSchemaSimpleType simpleType) private voidhandleSimpleTypeList(XmlSchema schema, Element schemaEl, XmlSchemaSimpleType simpleType, Element listEl) private voidhandleSimpleTypeRestriction(XmlSchema schema, Element schemaEl, XmlSchemaSimpleType simpleType, Element restrictionEl) private voidhandleSimpleTypeUnion(XmlSchema schema, Element schemaEl, XmlSchemaSimpleType simpleType, Element unionEl) (package private) XmlSchemahandleXmlSchemaElement(Element schemaEl, String systemId) handles the schema elementstatic voidSetup the cache to be used by the current thread of execution.private TargetNamespaceValidatornewIncludeValidator(XmlSchema schema) private voidprocessExtensibilityComponents(XmlSchemaObject schemaObject, Element parentElement, boolean namespaces) A generic method to process the extra attributes and the the extra elements present within the schema.private voidputCachedSchema(String targetNamespace, String schemaLocation, String baseUri, XmlSchema readSchema) Add an XmlSchema to the cache if the current thread has the cache enabled.(package private) XmlSchemaresolveXmlSchema(String targetNamespace, String schemaLocation, String baseUri, TargetNamespaceValidator validator) Resolve the schemas(package private) XmlSchemaresolveXmlSchema(String targetNamespace, String schemaLocation, TargetNamespaceValidator validator) Resolve the schemasvoidsetExtReg(ExtensionRegistry extReg) (package private) voidsetNamespaceAttributes(XmlSchema schema, Element schemaEl)
-
Field Details
-
resolvedSchemas
-
RESERVED_ATTRIBUTES
-
RESERVED_ATTRIBUTES_LIST
-
collection
XmlSchemaCollection collection -
currentDocument
Document currentDocument -
currentSchema
XmlSchema currentSchema -
docFac
DocumentBuilderFactory docFac -
currentValidator
-
extReg
The extension registry to be used while building the schema model
-
-
Constructor Details
-
SchemaBuilder
SchemaBuilder(XmlSchemaCollection collection, TargetNamespaceValidator validator) Schema builder constructor- Parameters:
collection-validator-
-
-
Method Details
-
clearCache
public static void clearCache()Remove any entries from the cache for the current thread. Entries for other threads are not altered. -
initCache
public static void initCache()Setup the cache to be used by the current thread of execution. Multiple threads can use the cache, and each one must call this method at some point prior to attempting to resolve the first schema, or the cache will not be used on that thread. IMPORTANT: The thread MUST call clearCache() when it is done with the schemas or a large amount of memory may remain in-use. -
getExtReg
-
setExtReg
-
build
build method taking in a document and a uri- Parameters:
doc-uri-
-
getDerivation
-
getEnumString
-
getFormDefault
-
getMaxOccurs
-
getMinOccurs
-
handleAnnotation
Handles the annotation Traversing if encounter appinfo or documentation add it to annotation collection -
handleAppInfo
create new XmlSchemaAppinfo and add value gotten from element to this obj- Parameters:
content-
-
handleComplexType
XmlSchemaComplexType handleComplexType(XmlSchema schema, Element complexEl, Element schemaEl, boolean topLevel) Handle complex types- Parameters:
schema-complexEl-schemaEl-topLevel-
-
handleDocumentation
-
handleElement
handle elements- Parameters:
schema-el-schemaEl-isGlobal-
-
handleImport
Handle the import- Parameters:
schema-importEl-schemaEl-- Returns:
- XmlSchemaObject
-
handleInclude
Handles the include- Parameters:
schema-includeEl-schemaEl-
-
handleSimpleType
XmlSchemaSimpleType handleSimpleType(XmlSchema schema, Element simpleEl, Element schemaEl, boolean topLevel) Handles simple types- Parameters:
schema-simpleEl-schemaEl-
-
handleXmlSchemaElement
handles the schema element- Parameters:
schemaEl-systemId-
-
resolveXmlSchema
XmlSchema resolveXmlSchema(String targetNamespace, String schemaLocation, String baseUri, TargetNamespaceValidator validator) Resolve the schemas- Parameters:
targetNamespace-schemaLocation-
-
resolveXmlSchema
XmlSchema resolveXmlSchema(String targetNamespace, String schemaLocation, TargetNamespaceValidator validator) Resolve the schemas- Parameters:
targetNamespace-schemaLocation-
-
setNamespaceAttributes
-
getAttribute
-
getCachedSchema
Return a cached schema if one exists for this thread. In order for schemas to be cached the thread must have done an initCache() previously. The parameters are used to construct a key used to lookup the schema- Parameters:
targetNamespace-schemaLocation-baseUri-- Returns:
- The cached schema if one exists for this thread or null.
-
getChildren
-
getRefQName
-
getRefQName
-
handleAll
-
handleAny
-
handleAnyAttribute
private XmlSchemaAnyAttribute handleAnyAttribute(XmlSchema schema, Element anyAttrEl, Element schemaEl) -
handleAttribute
Process non-toplevel attributes- Parameters:
schema-attrEl-schemaEl-- Returns:
-
handleAttribute
private XmlSchemaAttribute handleAttribute(XmlSchema schema, Element attrEl, Element schemaEl, boolean topLevel) Process attributes- Parameters:
schema-attrEl-schemaEl-topLevel-- Returns:
-
handleAttributeGroup
private XmlSchemaAttributeGroup handleAttributeGroup(XmlSchema schema, Element groupEl, Element schemaEl) -
handleAttributeGroupRef
-
handleChoice
-
handleComplexContent
private XmlSchemaComplexContent handleComplexContent(XmlSchema schema, Element complexEl, Element schemaEl) -
handleComplexContentExtension
private XmlSchemaComplexContentExtension handleComplexContentExtension(XmlSchema schema, Element extEl, Element schemaEl) -
handleComplexContentRestriction
private XmlSchemaComplexContentRestriction handleComplexContentRestriction(XmlSchema schema, Element restrictionEl, Element schemaEl) -
handleConstraint
private XmlSchemaIdentityConstraint handleConstraint(Element constraintEl, Class<? extends XmlSchemaIdentityConstraint> typeClass) -
handleElementAnnotation
-
handleElementForm
-
handleElementGlobalType
-
handleElementName
-
handleGroup
-
handleGroupRef
-
handleNotation
-
handleRedefine
Handle redefine- Parameters:
schema-redefineEl-schemaEl-- Returns:
-
handleSchemaElementBasics
private void handleSchemaElementBasics(Element schemaEl, String systemId, XmlSchemaCollection.SchemaKey schemaKey) -
handleSchemaElementChild
-
handleSequence
-
handleSimpleContent
private XmlSchemaSimpleContent handleSimpleContent(XmlSchema schema, Element simpleEl, Element schemaEl) -
handleSimpleContentExtension
private XmlSchemaSimpleContentExtension handleSimpleContentExtension(XmlSchema schema, Element extEl, Element schemaEl) -
handleSimpleContentRestriction
private XmlSchemaSimpleContentRestriction handleSimpleContentRestriction(XmlSchema schema, Element restrictionEl, Element schemaEl) -
handleSimpleTypeFinal
-
handleSimpleTypeList
private void handleSimpleTypeList(XmlSchema schema, Element schemaEl, XmlSchemaSimpleType simpleType, Element listEl) -
handleSimpleTypeRestriction
private void handleSimpleTypeRestriction(XmlSchema schema, Element schemaEl, XmlSchemaSimpleType simpleType, Element restrictionEl) -
handleSimpleTypeUnion
private void handleSimpleTypeUnion(XmlSchema schema, Element schemaEl, XmlSchemaSimpleType simpleType, Element unionEl) -
newIncludeValidator
-
processExtensibilityComponents
private void processExtensibilityComponents(XmlSchemaObject schemaObject, Element parentElement, boolean namespaces) A generic method to process the extra attributes and the the extra elements present within the schema. What are considered extensions are child elements with non schema namespace and child attributes with any namespace- Parameters:
schemaObject-parentElement-
-
putCachedSchema
private void putCachedSchema(String targetNamespace, String schemaLocation, String baseUri, XmlSchema readSchema) Add an XmlSchema to the cache if the current thread has the cache enabled. The first three parameters are used to construct a key- Parameters:
targetNamespace-schemaLocation-baseUri- This parameter is the value put under the key (if the cache is enabled)readSchema-
-