|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.xsd.util.XSDSchemaBuildingTools
public abstract class XSDSchemaBuildingTools
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 |
---|
protected static XSDPackage m_xsdPackage
getXSDFactory()
protected static XSDFactory m_xsdFactory
getXSDFactory()
Constructor Detail |
---|
public XSDSchemaBuildingTools()
Method Detail |
---|
public static XSDSimpleTypeDefinition addSimpleTypeDefinition(XSDSchema schema, java.lang.String localName, java.lang.String type, java.lang.String userInfo)
This method shows the simplest way to add a global named XSDSimpleTypeDefinition to an existing schema object.
schema
- to add the simpleTypeDeclaration tolocalName
- for the typetype
- localName of base of type within this schemauserInfo
- if non-null, will be added as a documentation
element in an annotation element
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)
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.
schema
- to add the complexTypeDefinition tolocalName
- localName for the typetype
- localName of base of type; in this method must be
resolveable within this schemaattrs
- HashMap of attributes to add; keys are names
and values are the type of each one; if null, none addeduserInfo
- if non-null, will be added as a documentation
element in an annotation element
public static XSDAttributeDeclaration addAttributeDeclaration(XSDConcreteComponent component, java.lang.String localName, java.lang.Object type)
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.
component
- to add annotation to; must be a XSDSchema or
a XSDComplexTypeDefinition objectlocalName
- of the attributeDeclarationtype
- either an XSDAttributeDeclaration, in which case
we set a ref= to it, or a String localName of the base type
public static XSDAnnotation addUserInformation(XSDConcreteComponent component, java.lang.String sourceURI, java.lang.String text)
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.
component
- to add annotation to; may be any kind of
XSDConcreteComponent object including an XSDSchemasourceURI
- to set for the userInformationtext
- text to add as the userInformation
(xsd:documentation) node to the annotation
public static XSDModelGroup addModelGroupDefinition(XSDConcreteComponent component, java.lang.String localName, XSDCompositor compositor, java.util.List<? extends XSDTerm> groupTerms)
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.
component
- to add the modelGroupDefinition tolocalName
- for the groupcompositor
- to use for the groupgroupTerms
- 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
public static boolean removeTypeDefinition(XSDSchema schema, java.lang.String namespace, java.lang.String localName)
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.
schema
- to remove the *TypeDefinition fromnamespace
- for the typelocalName
- for the type
public static XSDSchema getBlankSchema(XSDFactory factory, java.lang.String targetPrefix, java.lang.String targetNS, java.lang.String annotationText, java.lang.String annotationSource)
This creates a simple schema with just some namespace information attached. More detailed programs may also wish to set other schema attributes.
factory
- to create objects from; if null we will use
our own sample getXSDFactory
methodtargetPrefix
- to usetargetNS
- to useannotationText
- to set as a documentation element
on an annotation (if null is not set)annotationSource
- to use if annotationText is not null
public static XSDFactory getXSDFactory()
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.
|
Copyright 2001-2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |