Class XmlSchema

All Implemented Interfaces:
NamespaceContextOwner, XmlSchemaObjectBase

public class XmlSchema extends XmlSchemaAnnotated implements NamespaceContextOwner
Contains the definition of a schema. All XML Schema definition language (XSD) elements are children of the schema element.
  • Field Details

  • Constructor Details

    • XmlSchema

      public XmlSchema()
      Create a schema that is not a member of a collection and has no target namespace or system ID.
    • XmlSchema

      public XmlSchema(String namespace, String systemId, XmlSchemaCollection parent)
      Create a new schema with a target namespace and system ID, and record it as a member of a schema collection.
      Parameters:
      namespace - the target namespace.
      systemId - the system ID for the schema. This is used to resolve references to other schemas.
      parent - the parent collection.
    • XmlSchema

      public XmlSchema(String namespace, XmlSchemaCollection parent)
      Create a new schema in a collection with a target namespace.
      Parameters:
      namespace - the target namespace.
      parent - the containing collection.
  • Method Details

    • getAllSchemas

      public Document[] getAllSchemas()
      Return an array of DOM documents consisting of this schema and any schemas that it references. Referenced schemas are only returned if the XmlSchemaExternal objects corresponding to them have their 'schema' fields filled in.
      Returns:
      DOM documents.
    • getAttributeByName

      public XmlSchemaAttribute getAttributeByName(QName name)
      Retrieve a global attribute by its QName.
      Parameters:
      name -
      Returns:
      the attribute.
    • getAttributeByName

      public XmlSchemaAttribute getAttributeByName(String name)
      Look for an attribute by its local name.
      Parameters:
      name -
      Returns:
      the attribute
    • getAttributeFormDefault

      public XmlSchemaForm getAttributeFormDefault()
      Returns:
      the default attribute form for this schema.
    • getAttributeGroupByName

      public XmlSchemaAttributeGroup getAttributeGroupByName(QName name)
      Retrieve an attribute group by QName.
      Parameters:
      name -
      Returns:
    • getAttributeGroups

      public Map<QName,XmlSchemaAttributeGroup> getAttributeGroups()
      Return a map containing all the defined attribute groups of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
      If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.
      Returns:
      the map of attribute groups.
    • getAttributes

      public Map<QName,XmlSchemaAttribute> getAttributes()
      Return a map containing all the defined attributes of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
      If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.
      Returns:
      the map of attributes.
    • getBlockDefault

      public XmlSchemaDerivationMethod getBlockDefault()
      Return the default block value for this schema.
      Returns:
      the default block value.
    • getElementByName

      public XmlSchemaElement getElementByName(QName name)
      Look for a element by its QName.
      Parameters:
      name -
      Returns:
      the element.
    • getElementByName

      public XmlSchemaElement getElementByName(String name)
      get an element by its local name.
      Parameters:
      name -
      Returns:
      the element.
    • getElementFormDefault

      public XmlSchemaForm getElementFormDefault()
      Returns:
      the default element form for this schema.
    • getElements

      public Map<QName,XmlSchemaElement> getElements()
      Return a map containing all the defined elements of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
      If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime
      Returns:
      the map of elements.
    • getExternals

      public List<XmlSchemaExternal> getExternals()
      Return all of the includes, imports, and redefines for this schema.
      If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a list that checks at runtime
      Returns:
      a list of the objects representing includes, imports, and redefines.
    • getFinalDefault

      public XmlSchemaDerivationMethod getFinalDefault()
      Returns:
      the default 'final' value for this schema.
    • getGroupByName

      public XmlSchemaGroup getGroupByName(QName name)
      Retrieve a group by QName.
      Parameters:
      name -
      Returns:
    • getGroups

      public Map<QName,XmlSchemaGroup> getGroups()
      Return a map containing all the defined groups of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
      If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime
      Returns:
      the map of groups.
    • getInputEncoding

      public String getInputEncoding()
      Return the character encoding for this schema. This will only be present if either the schema was read from an XML document or there was a call to setInputEncoding(String).
      Returns:
    • getItems

      public List<XmlSchemaObject> getItems()
      Return all of the global items in this schema.
      If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.
      Returns:
      all of the global items from this schema.
    • getLogicalTargetNamespace

      public String getLogicalTargetNamespace()
      Return the logical target namespace. If a schema document has no target namespace, but it is referenced via an xs:include or xs:redefine, its logical target namespace is the target namespace of the including schema.
      Returns:
      the logical target namespace.
    • getNamespaceContext

      public NamespacePrefixList getNamespaceContext()
      Returns the objects namespace context.
      Specified by:
      getNamespaceContext in interface NamespaceContextOwner
    • getNotationByName

      public XmlSchemaNotation getNotationByName(QName name)
      Retrieve a notation by QName.
      Parameters:
      name -
      Returns:
      the notation
    • getNotations

      public Map<QName,XmlSchemaNotation> getNotations()
      Return a map containing all the defined notations of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
      If org.apache.ws.commons.schema.protectReadOnlyCollections is 'true', this will return a map that checks at runtime.
      Returns:
      the map of notations.
    • getParent

      public XmlSchemaCollection getParent()
      Return the parent XmlSchemaCollection. If this schema was not initialized in a collection the return value will be null.
      Returns:
      the parent collection.
    • getSchemaDocument

      Retrieve a DOM tree for this one schema, independent of any included or related schemas.
      Returns:
      The DOM document.
      Throws:
      XmlSchemaSerializer.XmlSchemaSerializerException
    • getSchemaNamespacePrefix

      public String getSchemaNamespacePrefix()
      Returns:
      the namespace prefix for the target namespace.
    • getSchemaTypes

      public Map<QName,XmlSchemaType> getSchemaTypes()
      Return a map containing all the defined types of this schema. The keys are QNames, where the namespace will always be the target namespace of this schema. This makes it easier to look up items for cross-schema references.
      Returns:
      the map of types.
    • getTargetNamespace

      public String getTargetNamespace()
      Return the declared target namespace of this schema.
      Returns:
      the namespace URI.
      See Also:
    • getTypeByName

      public XmlSchemaType getTypeByName(QName name)
      Search this schema, and its peers in its parent collection, for a schema type specified by QName.
      Parameters:
      name - the type name.
      Returns:
      the type.
    • getTypeByName

      public XmlSchemaType getTypeByName(String name)
      Retrieve a named type from this schema.
      Parameters:
      name -
      Returns:
      the type.
    • getVersion

      public String getVersion()
      Return the declared XML Schema version of this schema. XmlSchema supports only version 1.0.
      Returns:
    • setVersion

      public void setVersion(String version)
      Set the declared XML Schema version of this schema
      Parameters:
      version - the new version.
    • setAttributeFormDefault

      public void setAttributeFormDefault(XmlSchemaForm value)
      Set the default attribute form for this schema.
      Parameters:
      value - the form. This may not be null.
    • setBlockDefault

      public void setBlockDefault(XmlSchemaDerivationMethod blockDefault)
      Set the default block value for this schema.
      Parameters:
      blockDefault - the new block value.
    • setElementFormDefault

      public void setElementFormDefault(XmlSchemaForm elementFormDefault)
      Set the default element form for this schema.
      Parameters:
      elementFormDefault - the element form. This may not be null.
    • setFinalDefault

      public void setFinalDefault(XmlSchemaDerivationMethod finalDefault)
      Set the default 'final' value for this schema. The value may not be null.
      Parameters:
      finalDefault - the new final value.
    • setInputEncoding

      public void setInputEncoding(String encoding)
      Set the character encoding name for the schema. This is typically set when reading a schema from an XML file, so that it can be written back out in the same encoding.
      Parameters:
      encoding - Character encoding name.
    • setNamespaceContext

      public void setNamespaceContext(NamespacePrefixList namespaceContext)
      Sets the schema elements namespace context. This may be used for schema serialization, until a better mechanism was found.
    • setSchemaNamespacePrefix

      public void setSchemaNamespacePrefix(String schemaNamespacePrefix)
      Set the namespace prefix corresponding to the target namespace.
      Parameters:
      schemaNamespacePrefix -
    • setTargetNamespace

      public void setTargetNamespace(String targetNamespace)
      Set the target namespace for this schema.
      Parameters:
      targetNamespace - the new target namespace URI. A value of "" is ignored.
    • toString

      public String toString()
      Overrides:
      toString in class XmlSchemaAnnotated
    • write

      public void write(OutputStream out) throws UnsupportedEncodingException
      Serialize the schema as XML to the specified stream using the encoding established with setInputEncoding(String).
      Parameters:
      out - - the output stream to write to
      Throws:
      UnsupportedEncodingException - for an invalid encoding.
    • write

      public void write(OutputStream out, Map<String,String> options) throws UnsupportedEncodingException
      Serialize the schema as XML to the specified stream using the encoding established with setInputEncoding(String).
      Parameters:
      out - - the output stream to write to
      options - - a map of options
      Throws:
      UnsupportedEncodingException
    • write

      public void write(Writer writer)
      Serialize the schema to a Writer.
      Parameters:
      writer - - the writer to write this
    • write

      public void write(Writer writer, Map<String,String> options)
      Serialize the schema to a Writer.
      Parameters:
      writer - - the writer to write this
    • getAttributeByName

      protected XmlSchemaAttribute getAttributeByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
    • getAttributeGroupByName

      protected XmlSchemaAttributeGroup getAttributeGroupByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
    • getElementByName

      protected XmlSchemaElement getElementByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
    • getGroupByName

      protected XmlSchemaGroup getGroupByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
    • getNotationByName

      protected XmlSchemaNotation getNotationByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
    • getTypeByName

      protected XmlSchemaType getTypeByName(QName name, boolean deep, Stack<XmlSchema> schemaStack)
      Protected method that allows safe (non-recursive schema loading). It looks for a type with constraints.
      Parameters:
      name -
      deep -
      schemaStack -
      Returns:
      the type.
    • getSyntacticalTargetNamespace

      String getSyntacticalTargetNamespace()
    • setLogicalTargetNamespace

      void setLogicalTargetNamespace(String logicalTargetNamespace)
    • setParent

      void setParent(XmlSchemaCollection parent)
    • setSyntacticalTargetNamespace

      void setSyntacticalTargetNamespace(String syntacticalTargetNamespace)
    • getSchema

      private XmlSchema getSchema(Object includeOrImport)
      Get a schema from an import
      Parameters:
      includeOrImport -
      Returns:
      return the schema object.
    • loadDefaultOptions

      private void loadDefaultOptions(Map<String,String> options)
      Load the default options
      Parameters:
      options - - the map of
    • serializeInternal

      private void serializeInternal(Writer out, Map<String,String> options)
      serialize the schema - this is the method tht does to work
      Parameters:
      out -
      options -