org.eclipse.xsd.util
Class XSDSchemaBuildingTools

java.lang.Object
  extended by org.eclipse.xsd.util.XSDSchemaBuildingTools

public abstract class XSDSchemaBuildingTools
extends java.lang.Object

XSDSchemaBuildingTools is a collection of convenience methods for building simple schemas.

These are suitable to show examples of how to build convenience methods to more easily manipulate components in a schema. They also serve as useful examples of usage of the library's functions.

Note that these methods are somewhat simplistic, especially in terms of support for namespaces. To simplify the calling signatures, and to account for the 80% case where you don't have multiple namespaces, most method simply take a localName that's assumed to be correct in the current context. However it should be simple to copy & paste these methods and add namespaceURI's to each method if desired.


Field Summary
protected static XSDFactory m_xsdFactory
          A cached XSDFactory: one per lifetime.
protected static XSDPackage m_xsdPackage
          A cached XSDPackage: one per lifetime.
 
Constructor Summary
XSDSchemaBuildingTools()
           
 
Method Summary
static XSDAttributeDeclaration addAttributeDeclaration(XSDConcreteComponent component, java.lang.String localName, java.lang.Object type)
          Add a an attribute declaration to a component.
static XSDComplexTypeDefinition addComplexTypeDefinition(XSDSchema schema, java.lang.String localName, java.lang.String type, java.util.HashMap<java.lang.String,java.lang.Object> attrs, java.lang.String userInfo)
          Add a named complexTypeDefinition to a schema.
static XSDModelGroup addModelGroupDefinition(XSDConcreteComponent component, java.lang.String localName, XSDCompositor compositor, java.util.List<? extends XSDTerm> groupTerms)
          Add a named modelGroup(Definition) to a container.
static XSDSimpleTypeDefinition addSimpleTypeDefinition(XSDSchema schema, java.lang.String localName, java.lang.String type, java.lang.String userInfo)
          Add named simpleTypeDefinition to the schema.
static XSDAnnotation addUserInformation(XSDConcreteComponent component, java.lang.String sourceURI, java.lang.String text)
          Add a local annotation with userInfo to the given item.
static XSDSchema getBlankSchema(XSDFactory factory, java.lang.String targetPrefix, java.lang.String targetNS, java.lang.String annotationText, java.lang.String annotationSource)
          Worker method to get a simple 'blank' schema.
static XSDFactory getXSDFactory()
          Worker method to initialize various XSD and etools prereqs.
static boolean removeTypeDefinition(XSDSchema schema, java.lang.String namespace, java.lang.String localName)
          Remove a named *TypeDefinition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_xsdPackage

protected static XSDPackage m_xsdPackage
A cached XSDPackage: one per lifetime.

See Also:
getXSDFactory()

m_xsdFactory

protected static XSDFactory m_xsdFactory
A cached XSDFactory: one per lifetime.

See Also:
getXSDFactory()
Constructor Detail

XSDSchemaBuildingTools

public XSDSchemaBuildingTools()
Method Detail

addSimpleTypeDefinition

public static XSDSimpleTypeDefinition addSimpleTypeDefinition(XSDSchema schema,
                                                              java.lang.String localName,
                                                              java.lang.String type,
                                                              java.lang.String userInfo)
Add named simpleTypeDefinition to the schema.

This method shows the simplest way to add a global named XSDSimpleTypeDefinition to an existing schema object.

Parameters:
schema - to add the simpleTypeDeclaration to
localName - for the type
type - localName of base of type within this schema
userInfo - if non-null, will be added as a documentation element in an annotation element
Returns:
the simpleTypeDefinition created, after having been added to the schema; null if any error occoured

addComplexTypeDefinition

public static XSDComplexTypeDefinition addComplexTypeDefinition(XSDSchema schema,
                                                                java.lang.String localName,
                                                                java.lang.String type,
                                                                java.util.HashMap<java.lang.String,java.lang.Object> attrs,
                                                                java.lang.String userInfo)
Add a named complexTypeDefinition to a schema.

This method shows the simplest way to add a global named XSDComplexTypeDefinition to an existing schema object. It also provides basic attribute and type support. Note that this method does not handle namespaces although that support would be simple to add.

Parameters:
schema - to add the complexTypeDefinition to
localName - localName for the type
type - localName of base of type; in this method must be resolveable within this schema
attrs - HashMap of attributes to add; keys are names and values are the type of each one; if null, none added
userInfo - if non-null, will be added as a documentation element in an annotation element
Returns:
the complexTypeDefinition created, after having been added to the schema; null if any error occoured

addAttributeDeclaration

public static XSDAttributeDeclaration addAttributeDeclaration(XSDConcreteComponent component,
                                                              java.lang.String localName,
                                                              java.lang.Object type)
Add a an attribute declaration to a component.

Either adds a global attributeDeclaration to the schema, or a specific one (and a basic useage thereof) to a complex type. Note that users must add any other constraints or the like themselves. This method also does not handle namespaces, although that support would be simple to add.

Parameters:
component - to add annotation to; must be a XSDSchema or a XSDComplexTypeDefinition object
localName - of the attributeDeclaration
type - either an XSDAttributeDeclaration, in which case we set a ref= to it, or a String localName of the base type
Returns:
the attributeDeclaration created, after having been added to the schema; null if any error occoured

addUserInformation

public static XSDAnnotation addUserInformation(XSDConcreteComponent component,
                                               java.lang.String sourceURI,
                                               java.lang.String text)
Add a local annotation with userInfo to the given item.

Note: We take an XSDConcreteComponent, however we must then cast it to one of the types that has a setAnnotation call defined, since it doesn't have a clear 'parent' interface for annotations.

Also note that UserInformation and ApplicationInformation objects can only be added after the parent of the annotation has been added to an XSDSchema object. This is because these objects are modeled in the concrete DOM layer only, and otherwise will throw a DOMException.

Parameters:
component - to add annotation to; may be any kind of XSDConcreteComponent object including an XSDSchema
sourceURI - to set for the userInformation
text - text to add as the userInformation (xsd:documentation) node to the annotation
Returns:
the XSDAnnotation object created, after having been added to the component; null if any error occoured

addModelGroupDefinition

public static XSDModelGroup addModelGroupDefinition(XSDConcreteComponent component,
                                                    java.lang.String localName,
                                                    XSDCompositor compositor,
                                                    java.util.List<? extends XSDTerm> groupTerms)
Add a named modelGroup(Definition) to a container.

This method creates a single XSDModelGroup that contains a list of XSDParticles for each item in the list. It can simplify your code by performing the creation of each particle for each group item. Note that this method does not set any additional items for the particles, like min/maxOccours etc.

If passed an XSDSchema, we then add this as a global XSDModelGroupDefinition. If passed an XSDModelGroup, add this to the contents, If passed an XSDModelGroupDefinition, set this as the model group, Otherwise, if passed an XSDComplexTypeDefinition we set this group to be the single content of the typedef.

Parameters:
component - to add the modelGroupDefinition to
localName - for the group
compositor - to use for the group
groupTerms - List of XSDTerm objects to put in the group, in list.iterator() order; we throw an exception if any of these objects are not valid
Returns:
the modelGroup created, after having been added to the schema; null if any error occoured

removeTypeDefinition

public static boolean removeTypeDefinition(XSDSchema schema,
                                           java.lang.String namespace,
                                           java.lang.String localName)
Remove a named *TypeDefinition.

This method shows the simplest way to remove a named type definition of any type (we automatically search for both simple and complex types). Note that removing or replacing an actual schema component requires working in the concrete model directly.

Parameters:
schema - to remove the *TypeDefinition from
namespace - for the type
localName - for the type
Returns:
true if successful; false otherwise

getBlankSchema

public static XSDSchema getBlankSchema(XSDFactory factory,
                                       java.lang.String targetPrefix,
                                       java.lang.String targetNS,
                                       java.lang.String annotationText,
                                       java.lang.String annotationSource)
Worker method to get a simple 'blank' schema.

This creates a simple schema with just some namespace information attached. More detailed programs may also wish to set other schema attributes.

Parameters:
factory - to create objects from; if null we will use our own sample getXSDFactory method
targetPrefix - to use
targetNS - to use
annotationText - to set as a documentation element on an annotation (if null is not set)
annotationSource - to use if annotationText is not null
Returns:
false if we should abort the test; true otherwise

getXSDFactory

public static XSDFactory getXSDFactory()
Worker method to initialize various XSD and etools prereqs.

This is SAMPLE CODE ONLY, SUBJECT TO CHANGE!

The initialization sequence depends on some specific versions of Eclipse and may depend on how your application is run (as an Eclipse plugin or as a headless program, etc.). Note this caches the package and factory objects, and does not bother to re-call init() unless needed. This actual implementation is meant to be run as a standalone headless program although it may be suitable for other applications.

Returns:
an XSDFactory already initialized; or a cached one if we've been previously called

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.