Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Clean Up Your Schema for SOAP : Page 2

As your repository of schemas grows, you need tools to manipulate and manage your schemas. The Eclipse XSD Schema Infoset Model has powerful querying and editing capabilities. This article shows you how to update a schema for use with SOAP by automatically converting attribute uses into element declarations.


advertisement
First, we need to find all of the complexTypes in the schema, since those are the only places that attributes can actually be used. We don't need to search for all attribute declarations, because we can always ask each complexType later what attributes it actually uses. Querying our schema document is a very simple process: iterate through the contents and look for complex types. Note that there are a wide variety of querying methods for examining schema contents, this is just one way to do it.

// Find type definitions: for our purposes, the simplest // way to get all complexTypes is to drop down to the // underlying EMF model of a schema to iterate through // all concrete components contained within this schema List complexTypeDefinitions = new ArrayList(); for (Iterator iter = schema.eAllContents(); iter.hasNext(); ) { XSDConcreteComponent concreteComponent = (XSDConcreteComponent)iter.next(); if (concreteComponent instanceof XSDComplexTypeDefinition) { complexTypeDefinitions.add(concreteComponent); } } // An alternate method would be to use the abstract Infoset // relationship of schema.getTypeDefinitions(), which would // get all globally-visible typedefs (simple and complex) // within the whole schema, however that would miss any // types that were nested inside of other components

Now that we've got a list of all the complexTypes we need to update, let's exclude any types that we have decided are incompatible with our sample program. Since we are just querying information about various schema components, we can make effective use of the many abstract Infoset relationships and methods that the Model exposes. These abstract methods automatically take into account things like base types and derivation types; references to declarations elsewhere; and effects of imported, included, or redefined schema documents.

// Detect name collisions between top-level elems and attrs List elementNames = getElementNames(complexType); List attributeNames = getAttributeNames(complexType); attributeNames.retainAll(elementNames); if (!attributeNames.isEmpty()) { // Report the name collision and return... } // Now check for any attribute wildcards, which we // can't really change into elements XSDWildcard attributeWildcard = complexType.getAttributeWildcard(); if (null != attributeWildcard) { // Report an incompatible wildcard and return... } // Check the content for other incompatible conditions like // groups with choice or all or a simpleType XSDComplexTypeContent complexTypeContent = complexType.getContent(); if (complexTypeContent instanceof XSDSimpleTypeDefinition) { // Report a simple type as incompatible and return... } else if (null != complexTypeContent) { XSDTerm particleTerm = ((XSDParticle)complexTypeContent).getTerm(); if (particleTerm instanceof XSDModelGroup) { XSDCompositor compositor = ((XSDModelGroup)particleTerm).getCompositor(); if ((XSDCompositor.ALL_LITERAL == compositor) || (XSDCompositor.CHOICE_LITERAL == compositor)) { // Report an incompatible group type and return... } } // more checks for wildcards, etc. }

Author's Note: Not all code for detecting incompatibilities is shown here. Please download the samples zip file to see the full story! The MakeSoapCompatible.java program is carefully designed and thoroughly commented to showcase how to manipulate schemas with the Model, and should be your next step if you want to learn more.




Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap