Apache CXF API

org.apache.cxf.common.xmlschema
Class XmlSchemaUtils

java.lang.Object
  extended by org.apache.cxf.common.xmlschema.XmlSchemaUtils

public final class XmlSchemaUtils
extends Object

Some functions that avoid problems with Commons XML Schema.


Field Summary
static String XSI_NIL
           
static String XSI_NIL_WITH_PREFIX
           
static String XSI_NS_ATTR
           
 
Method Summary
static void addImportIfNeeded(org.apache.ws.commons.schema.XmlSchema schema, QName qname)
          For convenience, start from a qname, and add the import if it is non-null and has a namespace.
static void addImportIfNeeded(org.apache.ws.commons.schema.XmlSchema schema, String namespaceUri)
          Assist in managing the required for imports of peer schemas.
static String cleanedUpSchemaSource(org.apache.ws.commons.schema.XmlSchemaObject subject)
           
static List<String> enumeratorValues(org.apache.ws.commons.schema.XmlSchemaSimpleType type)
          Retrieve the string values for an enumeration.
static org.apache.ws.commons.schema.XmlSchemaElement findElementByRefName(SchemaCollection xmlSchemaCollection, QName name, String referencingURI)
          This copes with an observed phenomenon in the schema built by the ReflectionServiceFactoryBean.
static org.apache.ws.commons.schema.XmlSchemaAll getAll(org.apache.ws.commons.schema.XmlSchemaComplexType type)
           
static QName getBaseType(org.apache.ws.commons.schema.XmlSchemaComplexType type)
           
static org.apache.ws.commons.schema.XmlSchemaChoice getChoice(org.apache.ws.commons.schema.XmlSchemaComplexType type)
           
static List<org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef> getContentAttributes(org.apache.ws.commons.schema.XmlSchemaComplexType type)
           
static List<org.apache.ws.commons.schema.XmlSchemaAnnotated> getContentAttributes(org.apache.ws.commons.schema.XmlSchemaComplexType type, SchemaCollection collection)
           
static List<org.apache.ws.commons.schema.XmlSchemaObject> getContentElements(org.apache.ws.commons.schema.XmlSchemaComplexType type, SchemaCollection collection)
           
static org.apache.ws.commons.schema.XmlSchemaSequence getContentSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)
           
static QName getElementQualifiedName(org.apache.ws.commons.schema.XmlSchemaElement element, org.apache.ws.commons.schema.XmlSchema schema)
          By convention, an element that is named in its schema's TNS can have a 'name' but no QName.
static org.apache.ws.commons.schema.XmlSchemaType getElementType(SchemaCollection xmlSchemaCollection, String referencingURI, org.apache.ws.commons.schema.XmlSchemaElement element, org.apache.ws.commons.schema.XmlSchemaType containingType)
          Follow a chain of references from element to element until we can obtain a type.
static org.apache.ws.commons.schema.XmlSchemaAnnotated getObjectAnnotated(org.apache.ws.commons.schema.XmlSchemaObject object, QName contextName)
          If the object is an attribute or an anyAttribute, return the 'Annotated'.
static org.apache.ws.commons.schema.XmlSchemaParticle getObjectParticle(org.apache.ws.commons.schema.XmlSchemaObject object, QName contextName)
          If the object is an element or an any, return the particle.
static org.apache.ws.commons.schema.XmlSchemaElement getReferredElement(org.apache.ws.commons.schema.XmlSchemaElement element, SchemaCollection xmlSchemaCollection)
           
static org.apache.ws.commons.schema.XmlSchemaSequence getSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)
           
static boolean isAttributeNameQualified(org.apache.ws.commons.schema.XmlSchemaAttribute attribute, org.apache.ws.commons.schema.XmlSchema schema)
           
static boolean isAttributeQualified(org.apache.ws.commons.schema.XmlSchemaAttribute attribute, boolean global, org.apache.ws.commons.schema.XmlSchema localSchema, org.apache.ws.commons.schema.XmlSchema attributeSchema)
          due to a bug, feature, or just plain oddity of JAXB, it isn't good enough to just check the form of an element and of its schema.
static boolean isComplexType(org.apache.ws.commons.schema.XmlSchemaType type)
           
static boolean isElementNameQualified(org.apache.ws.commons.schema.XmlSchemaElement element, org.apache.ws.commons.schema.XmlSchema schema)
           
static boolean isElementQualified(org.apache.ws.commons.schema.XmlSchemaElement element, boolean global, org.apache.ws.commons.schema.XmlSchema localSchema, org.apache.ws.commons.schema.XmlSchema elementSchema)
          due to a bug, feature, or just plain oddity of JAXB, it isn't good enough to just check the form of an element and of its schema.
static boolean isEumeration(org.apache.ws.commons.schema.XmlSchemaSimpleType type)
          Return true if a simple type is a straightforward XML Schema representation of an enumeration.
static boolean isParticleArray(org.apache.ws.commons.schema.XmlSchemaParticle particle)
           
static boolean isParticleOptional(org.apache.ws.commons.schema.XmlSchemaParticle particle)
           
static boolean schemaImportsNamespace(org.apache.ws.commons.schema.XmlSchema schema, String namespaceUri)
          Is there an import for a particular namespace in a schema?
static void setElementName(org.apache.ws.commons.schema.XmlSchemaElement element, String name)
          Wrapper around XmlSchemaElement.setName that checks for inconsistency with refName.
static void setElementRefName(org.apache.ws.commons.schema.XmlSchemaElement element, QName name)
          Wrapper around XmlSchemaElement.setRefName that checks for inconsistency with name and QName.
static void unsupportedConstruct(String messageKey, String what, QName subjectName, org.apache.ws.commons.schema.XmlSchemaObject subject)
           
static void unsupportedConstruct(String messageKey, org.apache.ws.commons.schema.XmlSchemaType subject)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XSI_NIL

public static final String XSI_NIL
See Also:
Constant Field Values

XSI_NS_ATTR

public static final String XSI_NS_ATTR
See Also:
Constant Field Values

XSI_NIL_WITH_PREFIX

public static final String XSI_NIL_WITH_PREFIX
See Also:
Constant Field Values
Method Detail

setElementName

public static void setElementName(org.apache.ws.commons.schema.XmlSchemaElement element,
                                  String name)
Wrapper around XmlSchemaElement.setName that checks for inconsistency with refName.

Parameters:
element -
name -

setElementRefName

public static void setElementRefName(org.apache.ws.commons.schema.XmlSchemaElement element,
                                     QName name)
Wrapper around XmlSchemaElement.setRefName that checks for inconsistency with name and QName.

Parameters:
element -
name -

isEumeration

public static boolean isEumeration(org.apache.ws.commons.schema.XmlSchemaSimpleType type)
Return true if a simple type is a straightforward XML Schema representation of an enumeration. If we discover schemas that are 'enum-like' with more complex structures, we might make this deal with them.

Parameters:
type - Simple type, possible an enumeration.
Returns:
true for an enumeration.

enumeratorValues

public static List<String> enumeratorValues(org.apache.ws.commons.schema.XmlSchemaSimpleType type)
Retrieve the string values for an enumeration.

Parameters:
type -
Returns:

schemaImportsNamespace

public static boolean schemaImportsNamespace(org.apache.ws.commons.schema.XmlSchema schema,
                                             String namespaceUri)
Is there an import for a particular namespace in a schema?

Parameters:
schema -
namespaceUri -
Returns:

addImportIfNeeded

public static void addImportIfNeeded(org.apache.ws.commons.schema.XmlSchema schema,
                                     String namespaceUri)
Assist in managing the required for imports of peer schemas.

Parameters:
schema -
namespaceUri -

addImportIfNeeded

public static void addImportIfNeeded(org.apache.ws.commons.schema.XmlSchema schema,
                                     QName qname)
For convenience, start from a qname, and add the import if it is non-null and has a namespace.

Parameters:
schema -
qname -
See Also:
addImportIfNeeded(XmlSchema, String)

findElementByRefName

public static org.apache.ws.commons.schema.XmlSchemaElement findElementByRefName(SchemaCollection xmlSchemaCollection,
                                                                                 QName name,
                                                                                 String referencingURI)
This copes with an observed phenomenon in the schema built by the ReflectionServiceFactoryBean. It is creating element such that: (a) the type is not set. (b) the refName is set. (c) the namespaceURI in the refName is set empty. This apparently indicates 'same Schema' to everyone else, so thus function implements that convention here. It is unclear if that is a correct structure, and it if changes, we can simplify or eliminate this function.

Parameters:
name -
referencingURI -
Returns:

getBaseType

public static QName getBaseType(org.apache.ws.commons.schema.XmlSchemaComplexType type)

getContentAttributes

public static List<org.apache.ws.commons.schema.XmlSchemaAttributeOrGroupRef> getContentAttributes(org.apache.ws.commons.schema.XmlSchemaComplexType type)

getContentAttributes

public static List<org.apache.ws.commons.schema.XmlSchemaAnnotated> getContentAttributes(org.apache.ws.commons.schema.XmlSchemaComplexType type,
                                                                                         SchemaCollection collection)

getContentElements

public static List<org.apache.ws.commons.schema.XmlSchemaObject> getContentElements(org.apache.ws.commons.schema.XmlSchemaComplexType type,
                                                                                    SchemaCollection collection)

getContentSequence

public static org.apache.ws.commons.schema.XmlSchemaSequence getContentSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)

getElementQualifiedName

public static QName getElementQualifiedName(org.apache.ws.commons.schema.XmlSchemaElement element,
                                            org.apache.ws.commons.schema.XmlSchema schema)
By convention, an element that is named in its schema's TNS can have a 'name' but no QName. This can get inconvenient for consumers who want to think about qualified names. Unfortunately, XmlSchema elements, unlike types, don't store a reference to their containing schema.

Parameters:
element -
schema -
Returns:

getElementType

public static org.apache.ws.commons.schema.XmlSchemaType getElementType(SchemaCollection xmlSchemaCollection,
                                                                        String referencingURI,
                                                                        org.apache.ws.commons.schema.XmlSchemaElement element,
                                                                        org.apache.ws.commons.schema.XmlSchemaType containingType)
Follow a chain of references from element to element until we can obtain a type.

Parameters:
element -
Returns:

getObjectAnnotated

public static org.apache.ws.commons.schema.XmlSchemaAnnotated getObjectAnnotated(org.apache.ws.commons.schema.XmlSchemaObject object,
                                                                                 QName contextName)
If the object is an attribute or an anyAttribute, return the 'Annotated'. If it's not one of those, or it's a group, throw. We're not ready for groups yet.

Parameters:
object -
Returns:

getObjectParticle

public static org.apache.ws.commons.schema.XmlSchemaParticle getObjectParticle(org.apache.ws.commons.schema.XmlSchemaObject object,
                                                                               QName contextName)
If the object is an element or an any, return the particle. If it's not a particle, or it's a group, throw. We're not ready for groups yet.

Parameters:
object -
Returns:

getReferredElement

public static org.apache.ws.commons.schema.XmlSchemaElement getReferredElement(org.apache.ws.commons.schema.XmlSchemaElement element,
                                                                               SchemaCollection xmlSchemaCollection)

getSequence

public static org.apache.ws.commons.schema.XmlSchemaSequence getSequence(org.apache.ws.commons.schema.XmlSchemaComplexType type)

getChoice

public static org.apache.ws.commons.schema.XmlSchemaChoice getChoice(org.apache.ws.commons.schema.XmlSchemaComplexType type)

getAll

public static org.apache.ws.commons.schema.XmlSchemaAll getAll(org.apache.ws.commons.schema.XmlSchemaComplexType type)

isAttributeNameQualified

public static boolean isAttributeNameQualified(org.apache.ws.commons.schema.XmlSchemaAttribute attribute,
                                               org.apache.ws.commons.schema.XmlSchema schema)

isAttributeQualified

public static boolean isAttributeQualified(org.apache.ws.commons.schema.XmlSchemaAttribute attribute,
                                           boolean global,
                                           org.apache.ws.commons.schema.XmlSchema localSchema,
                                           org.apache.ws.commons.schema.XmlSchema attributeSchema)
due to a bug, feature, or just plain oddity of JAXB, it isn't good enough to just check the form of an element and of its schema. If schema 'a' (default unqualified) has a complex type with an element with a ref= to schema (b) (default unqualified), JAXB seems to expect to see a qualifier, anyway.
So, if the element is local to a complex type, all we care about is the default element form of the schema and the local form of the element.
If, on the other hand, the element is global, we might need to compare namespaces.

Parameters:
attribute - the attribute
global - if this element is a global element (complex type ref= to it, or in a part)
localSchema - the schema of the complex type containing the reference, only used for the 'odd case'.
elementSchema - the schema for the element.
Returns:
if the element needs to be qualified.

isComplexType

public static boolean isComplexType(org.apache.ws.commons.schema.XmlSchemaType type)

isElementNameQualified

public static boolean isElementNameQualified(org.apache.ws.commons.schema.XmlSchemaElement element,
                                             org.apache.ws.commons.schema.XmlSchema schema)

isElementQualified

public static boolean isElementQualified(org.apache.ws.commons.schema.XmlSchemaElement element,
                                         boolean global,
                                         org.apache.ws.commons.schema.XmlSchema localSchema,
                                         org.apache.ws.commons.schema.XmlSchema elementSchema)
due to a bug, feature, or just plain oddity of JAXB, it isn't good enough to just check the form of an element and of its schema. If schema 'a' (default unqualified) has a complex type with an element with a ref= to schema (b) (default unqualified), JAXB seems to expect to see a qualifier, anyway.
So, if the element is local to a complex type, all we care about is the default element form of the schema and the local form of the element.
If, on the other hand, the element is global, we might need to compare namespaces.

Parameters:
element - the element.
global - if this element is a global element (complex type ref= to it, or in a part)
localSchema - the schema of the complex type containing the reference, only used for the 'odd case'.
elementSchema - the schema for the element.
Returns:
if the element needs to be qualified.

isParticleArray

public static boolean isParticleArray(org.apache.ws.commons.schema.XmlSchemaParticle particle)

isParticleOptional

public static boolean isParticleOptional(org.apache.ws.commons.schema.XmlSchemaParticle particle)

unsupportedConstruct

public static void unsupportedConstruct(String messageKey,
                                        String what,
                                        QName subjectName,
                                        org.apache.ws.commons.schema.XmlSchemaObject subject)

unsupportedConstruct

public static void unsupportedConstruct(String messageKey,
                                        org.apache.ws.commons.schema.XmlSchemaType subject)

cleanedUpSchemaSource

public static String cleanedUpSchemaSource(org.apache.ws.commons.schema.XmlSchemaObject subject)

Apache CXF API

Apache CXF