Communities
|
Social Applications
Networks
Support
|
|
C-Level Executives
Other Roles
|
|
Support
Education
Partner
Other Tasks
|
| By Ayub Khan and Marina Sum, Updated: November 9, 2006 |
| |
XML schemas contain numerous design patterns, the most common of which are Russian Doll, Salami Slice, Venetian Blind, and Garden of Eden. The patterns vary according to the number of their global elements or types. A global element or type, which is a child of the schema, contains a target namespace.
You can conveniently classify the four most common patterns according to two criteria, namely:
Choosing the appropriate pattern is a critical step in the design phase of schemas. Once you have made a choice, switching the pattern to another one without GUI tools is tedious and error-prone. By using the intuitive XML tools in NetBeans Enterprise 5.5 (henceforth, NetBeans Enterprise Pack), however, you can seamlessly transform one design pattern to another with only a few GUI steps.
This article defines the four most common pattern types and their characteristics for reuse. It also explains how NetBeans Enterprise Pack displays, detects, and maintains those patterns, which greatly simplifies the design phase of the schema development cycle.
Near the end of the article is a link to a Flash demo that illustrates the procedures described in this article.
| - | Definitions, Rules, and Examples |
| - | Management of Design Patterns With NetBeans Enterprise Pack |
| - | Summary |
| - | References |
| |
This section describes the four most common pattern types and shows you how to define them in XML schemas. Most real-world schemas adopt Venetian Blind or Garden of Eden as their pattern of choice because they are the most reusable.
The following table summarizes the four patterns' characteristics and their advantages and disadvantages.
|
Design Pattern
|
Characteristics
|
Advantages
|
Disadvantages
|
|---|---|---|---|
| |
|||
|
Russian Doll
|
Contains only one global element. All other elements are local.
|
|
|
|
Salami Slice
|
Contains all global elements, hence many potential root elements.
|
|
|
|
Venetian Blind
|
Is an extension of Russian Doll and contains only one global element. All other elements are local.
|
|
Limits encapsulation by exposing types.
|
|
Garden of Eden
|
Is a combination of Venetian Blind and Salami Slice. All elements and types are global, hence many potential root elements.
|
|
|
| |
|||
The Russian Doll design contains only one single global element. All the other elements are local. You nest element declarations within a single global declaration, which you can use once only. You must define only the root element within the global namespace.
See the following example.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.sun.com/point/russiandoll"
xmlns:tns="http://schemas.sun.com/point/russiandoll"
elementFormDefault="qualified">
<xsd:element name="Line">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="PointA">
<xsd:complexType>
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="PointB">
<xsd:complexType>
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
|
Since it contains only one single global element, Russian Doll is the simplest and easiest pattern to use by instance developers. However, if its elements or types are intended for reuse, Russian Doll is not suitable for schema developers.
All the elements in the Salami Slice design are global. No nesting of element declarations is required and you can reuse the declarations throughout the schema. You must define all the elements within the global namespace.
See the following example.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.sun.com/point/salami"
xmlns:tns="http://schemas.sun.com/point/salami"
xmlns="http://schemas.sun.com/point/salami"
elementFormDefault="qualified">
<xsd:element name="PointA">
<xsd:complexType>
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="PointB">
<xsd:complexType>
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="Line">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="PointA"/>
<xsd:element ref="PointB"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
|
The fact that all the elements in Salami Slice are global means a greater degree of reusability than Russian Doll and Venetian Blind. However, this design pattern contains many potential root elements.
The Venetian Blind design contains only one global element. All the other elements are local. You nest element declarations within a single global declaration by means of named complex types and element groups. You can reuse those types and groups throughout the schema and must define only the root element within the global namespace.
See the following example.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.sun.com/point/venetianblind"
xmlns:tns="http://schemas.sun.com/point/venetianblind"
xmlns="http://schemas.sun.com/point/venetianblind"
elementFormDefault="qualified">
<xsd:complexType name="PointType">
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
<xsd:element name="Line">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="PointA" type="PointType"/>
<xsd:element name="PointB" type="PointType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
|
Venetian Blind is an extension of Russian Doll, in which all the types are defined globally. Because it has only one single root element and all its types are reusable, Venetian Blind is suitable for use by both instance developers and schema developers.
The Garden of Eden design is a combination of Venetian Blind and Salami Slice. You define all the elements and types in the global namespace and refer to the elements as required.
See the following example.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.sun.com/point/gardenofeden"
xmlns="http://schemas.sun.com/point/gardenofeden"
elementFormDefault="qualified">
<xsd:complexType name="PointType">
<xsd:attribute name="x" type="xsd:integer"/>
<xsd:attribute name="y" type="xsd:integer"/>
</xsd:complexType>
<xsd:complexType name="LineType">
<xsd:sequence>
<xsd:element ref="PointA"/>
<xsd:element ref="PointB"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="PointA" type="PointType"/>
<xsd:element name="PointB" type="PointType"/>
<xsd:element name="Line" type="LineType"/>
</xsd:schema>
|
Because it exposes all its elements and types globally, Garden of Eden, like Salami Slice, is completely reusable. However, because Garden of Eden exposes multiple elements as global ones, there are many potential root elements.
| |
As mentioned earlier, the XML tools in NetBeans Enterprise Pack smooth the way for switching from one design pattern to another and for maintaining design patterns. This section explains the details.
Figure 1 shows the XML tools in NetBeans Enterprise Pack.
Figure 1: XML Tools in NetBeans Enterprise Pack
|
The UI works as follows:
po.xsd schema file.
The Design view of the XML tools follows the Russian Doll design pattern. Figure 2 is an example, in which a modified
comment global element contains three child elements,
author,
date, and
description. All those child elements were dragged and dropped into position from the Palette.
Figure 2: Instance View of the
po.xsd Schema File
|
Now look at the Source view of the generated schema for the Design view of the
po.xsd schema file. See Figure 3.
Figure 3: Source View of Generated Schema for Instance View of
po.xsd
|
The generated code follows the Russian Doll design pattern. That is, an element dragged and dropped into the schema is created as a global element. All its child elements and attributes are local.
Note: Adding elements, attributes, and complex types from the Palette to Design view can result in a mixed schema. Such schemas do not follow any of the four design patterns described in this article.
The XML tools in NetBeans Enterprise Pack can also transform one design pattern to another. Follow these steps:
Figure 4: Application of a Design Pattern to an XML Schema
|
Figure 5: Apply Design Pattern Wizard
|
Figure 6: Source View of Transformed Schema
|
| |
Choosing the appropriate pattern for your XML schema is crucial in the design phase. Be sure to take advantage of XML tools, such as those in NetBeans Enterprise Pack, to detect and maintain your patterns so that they are readily usable and reusable.
| |

