Java Reference
In-Depth Information
<xsd:element name="product">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="sku" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- Pull from Chameleon -->
<xsd:element name="customer" type="CustomerType"
minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
The master schema here defines an Invoice type that includes the Product defined in the
Chameleon schema. This is a powerful leveraging of the ways that namespaces work in XML
schema, and makes it seem very attractive initially. It appears that you may be able to get
around some of the dependency problems introduced in the last recipe on schema design. If
you declare no namespace and use Chameleons for common types wherever possible, clients
are not broken if you later substitute types.
But you should know that the use of the Chameleon design pattern is heavily debated.
Chameleon depends on certain areas of the schema specification whose interpretation is not
strictly agreed upon by vendors. As a primary purpose of SOA is to achieve interoperable gen-
eric services, be careful signing yourself up for something that is only sometimes supported.
Also, Chameleon will generally degrade performance during validation, even from vendors
who do support it. That's because the delay in namespace resolution prevents parsers from
caching components of the schema based on their namespaces.
Chameleons also limit the ability to use XPath identity constraints. XPaths do not use the de-
fault namespace, so their use must be prefixed, which undermines the point of Chameleon in
the first place.
Chameleons increase the likelihood of component name collisions because types are not
bound by their namespaces.
Ultimately, namespaces, like packages, are there for a reason, which is to logically group a set
of types and set them off as being constituent of a given general idea. If you can't put your
types in a namespace, you may need to reconsider your design. If you could put your types in
Search WWH ::




Custom Search