com.legstar.jaxb.gen
Class CobolJAXBCustomizer

java.lang.Object
  extended by com.legstar.jaxb.gen.CobolJAXBCustomizer

public class CobolJAXBCustomizer
extends Object

This class implements the methods needed to inject custom JAXB bindings into an XML Schema.

The bindings are necessary so that XJC generates the correct JAXB Classes.

This will not replace any customization that the user might have added manually in the XML Schema.


Constructor Summary
CobolJAXBCustomizer(JaxbGenModel xjbModel)
          Construct the customizer.
 
Method Summary
 void customize(File sourceXsdFile, File targetXsdFile)
          Adds JAXB custom bindings to an XML Schema.
 void customize(File sourceXsdFile, String sourceXsdCharset, File targetXsdFile, String targetXsdCharset)
          Adds JAXB custom bindings to an XML Schema.
protected  Element getElement(DocumentFragment markupParent, String namespace, String namespacePrefix, String elementLocalName)
          Lookup a DOM element in the parent markup.
 JaxbGenModel getJaxbGenModel()
           
protected  DocumentFragment getMarkupParent(org.apache.ws.commons.schema.XmlSchemaAppInfo appInfo)
          The content of appinfo is a raw W3C nodelist.
protected  org.apache.ws.commons.schema.XmlSchemaAppInfo getXmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAnnotated element)
          Try to recover application info from an XML schema element and create new ones if none is found.
 void injectJaxbElementNameXmlTransformAnnotation(Element xmltransformEl, String jaxbNamespace, String jaxbNamespacePrefix)
          Inject a ElementNameXmlTransform element in the JAXB XmlTransform annotation.
 void injectJaxbEnumerationsAnnotation(org.apache.ws.commons.schema.XmlSchema schema, String jaxbNamespace, String jaxbNamespacePrefix)
          Enumerations in anonymous simple types are not mapped to type safe Enum classes by JAXB unless they are annotated.
 void injectJaxbExtensionAttributes(org.apache.ws.commons.schema.XmlSchema xsd, String jaxbPrefix)
          JAXB needs to know the LegStar extension prefix used.
 void injectJaxbGlobalBindingsAnnotations(DocumentFragment markupParent, String jaxbNamespace, String jaxbNamespacePrefix)
          Inject a global bindings element in the parent annotation node.
 String injectJaxbNamespace(org.apache.ws.commons.schema.XmlSchema xsd)
          Searches the schema element for the JAXB namespace.
 void injectJaxbSchemaAnnotations(org.apache.ws.commons.schema.XmlSchema schema, String jaxbNamespace, String jaxbNamespacePrefix)
          Given an XML Schema, this will inject or replace custom JAXB bindings annotations at the schema level.
 void injectJaxbSchemaBindingsAnnotations(DocumentFragment markupParent, String jaxbNamespace, String jaxbNamespacePrefix)
          Inject a schema bindings element in the parent annotation node.
 void injectJaxbSerializableAnnotation(Element globalbindingsEl, String jaxbNamespace, String jaxbNamespacePrefix)
          Inject a serializable element in the JAXB global bindings annotation.
 void injectJaxbTypeNameXmlTransformAnnotation(Element xmltransformEl, String jaxbNamespace, String jaxbNamespacePrefix)
          Inject a TypeNameXmlTransform element in the JAXB XmlTransform annotation.
protected  void injectJaxbTypeSafeEnumClassAnnotation(String jaxbNamespace, String jaxbNamespacePrefix, org.apache.ws.commons.schema.XmlSchemaSimpleType xsdSimpleType, String elementName)
          Create a typesafeEnumClass markup.
protected  void injectJaxbTypeSafeEnumMemberAnnotation(String jaxbNamespace, String jaxbNamespacePrefix, org.apache.ws.commons.schema.XmlSchemaEnumerationFacet enumerationFacet, String value)
          Create a typesafeEnumMember markup.
 void injectJaxbXmlTransformAnnotation(Element schemabindingsEl, String jaxbNamespace, String jaxbNamespacePrefix)
          Inject a XmlTransform element in the JAXB schema bindings annotation.
protected  void processCollectionElements(org.apache.ws.commons.schema.XmlSchema schema, String jaxbNamespace, String jaxbNamespacePrefix, org.apache.ws.commons.schema.XmlSchemaObjectCollection items)
          Take all elements from a collection and process them.
protected  void processComplexType(org.apache.ws.commons.schema.XmlSchema schema, String jaxbNamespace, String jaxbNamespacePrefix, org.apache.ws.commons.schema.XmlSchemaComplexType xsdComplexType)
          Process an XML schema complex type.
protected  void processElement(org.apache.ws.commons.schema.XmlSchema schema, String jaxbNamespace, String jaxbNamespacePrefix, org.apache.ws.commons.schema.XmlSchemaElement xsdElement)
          Process an XML schema element.
protected  void processParticle(org.apache.ws.commons.schema.XmlSchema schema, String jaxbNamespace, String jaxbNamespacePrefix, QName parentName, org.apache.ws.commons.schema.XmlSchemaParticle particle)
          A particle is usually all or sequence.
protected  void processSimpleType(org.apache.ws.commons.schema.XmlSchema schema, String jaxbNamespace, String jaxbNamespacePrefix, org.apache.ws.commons.schema.XmlSchemaElement xsdElement, org.apache.ws.commons.schema.XmlSchemaSimpleType xsdSimpleType)
          Process an XML schema simple type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CobolJAXBCustomizer

public CobolJAXBCustomizer(JaxbGenModel xjbModel)
                    throws ParserConfigurationException
Construct the customizer.

Parameters:
xjbModel - the bindings parameters
Throws:
ParserConfigurationException - if can't configure a DOM parser
Method Detail

customize

public void customize(File sourceXsdFile,
                      File targetXsdFile)
               throws IOException
Adds JAXB custom bindings to an XML Schema.

Parameters:
sourceXsdFile - the source XML Schema file
targetXsdFile - the target, customized, XML Schema file
Throws:
IOException - if output file cannot be written

customize

public void customize(File sourceXsdFile,
                      String sourceXsdCharset,
                      File targetXsdFile,
                      String targetXsdCharset)
               throws IOException
Adds JAXB custom bindings to an XML Schema.

Parameters:
sourceXsdFile - the source XML Schema file
sourceXsdCharset - the source character set
targetXsdFile - the target, customized, XML Schema file
targetXsdCharset - the target character set
Throws:
IOException - if output file cannot be written

injectJaxbNamespace

public String injectJaxbNamespace(org.apache.ws.commons.schema.XmlSchema xsd)
Searches the schema element for the JAXB namespace. If the namespace is found, the associated prefix is returned otherwise, the JAXB namespace is added to the schema.

Parameters:
xsd - the XML Schema
Returns:
the JAXB namespace prefix

injectJaxbExtensionAttributes

public void injectJaxbExtensionAttributes(org.apache.ws.commons.schema.XmlSchema xsd,
                                          String jaxbPrefix)
JAXB needs to know the LegStar extension prefix used. Here we lookup the extension attribute and version if they are found, we add to them otherwise we create new attributes.

Parameters:
xsd - the XML Schema
jaxbPrefix - the JAXB namespace prefix

injectJaxbSchemaAnnotations

public void injectJaxbSchemaAnnotations(org.apache.ws.commons.schema.XmlSchema schema,
                                        String jaxbNamespace,
                                        String jaxbNamespacePrefix)
Given an XML Schema, this will inject or replace custom JAXB bindings annotations at the schema level.

The generated schema holds JAXB annotations needed when, later on, the schema is used to generate JAXB classes. The markup produced looks like this:

 <xsd:appinfo>
    <jaxb:globalBindings generateIsSetMethod="true">
       <jxb:serializable uid="1"/>
    </jaxb:globalBindings>
    <jaxb:schemaBindings>
       <jaxb:nameXmlTransform>
          <jaxb:typeName prefix="Type" suffix="Type" />
          <jaxb:elementName prefix="Type" suffix="Type" />
        </jaxb:nameXmlTransform>
    </jaxb:schemaBindings>
 </xsd:appinfo>
 

Parameters:
schema - the XML Schema
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

getXmlSchemaAppInfo

protected org.apache.ws.commons.schema.XmlSchemaAppInfo getXmlSchemaAppInfo(org.apache.ws.commons.schema.XmlSchemaAnnotated element)
Try to recover application info from an XML schema element and create new ones if none is found.

Parameters:
element - an XML schema element that might hold annotations
Returns:
an existing or new XML schema application info

getMarkupParent

protected DocumentFragment getMarkupParent(org.apache.ws.commons.schema.XmlSchemaAppInfo appInfo)
The content of appinfo is a raw W3C nodelist. It is convenient to put this nodelist inside a DOM fragment called parent markup that we create or recover here.

Parameters:
appInfo - the application info element
Returns:
a parent DOM fragment for the annotation nodes list

injectJaxbGlobalBindingsAnnotations

public void injectJaxbGlobalBindingsAnnotations(DocumentFragment markupParent,
                                                String jaxbNamespace,
                                                String jaxbNamespacePrefix)
Inject a global bindings element in the parent annotation node.

If the element is already present we update its attributes.

Parameters:
markupParent - the parent annotation node (its a document fragment)
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

getElement

protected Element getElement(DocumentFragment markupParent,
                             String namespace,
                             String namespacePrefix,
                             String elementLocalName)
Lookup a DOM element in the parent markup. If not found, an new DOM element is created and added to the parent markup.

Parameters:
markupParent - the parent markup
namespace - the DOM namespace
namespacePrefix - the DOM namespace prefix
elementLocalName - the element local name
Returns:
an existing or new DOM element

injectJaxbSerializableAnnotation

public void injectJaxbSerializableAnnotation(Element globalbindingsEl,
                                             String jaxbNamespace,
                                             String jaxbNamespacePrefix)
Inject a serializable element in the JAXB global bindings annotation.

If the element is already present we update its attributes.

Parameters:
globalbindingsEl - the global bindings node
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

injectJaxbSchemaBindingsAnnotations

public void injectJaxbSchemaBindingsAnnotations(DocumentFragment markupParent,
                                                String jaxbNamespace,
                                                String jaxbNamespacePrefix)
Inject a schema bindings element in the parent annotation node.

If the element is already present we update its attributes.

Parameters:
markupParent - the parent annotation node (its a document fragment)
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

injectJaxbXmlTransformAnnotation

public void injectJaxbXmlTransformAnnotation(Element schemabindingsEl,
                                             String jaxbNamespace,
                                             String jaxbNamespacePrefix)
Inject a XmlTransform element in the JAXB schema bindings annotation.

If the element is already present we update its attributes.

Parameters:
schemabindingsEl - the schema bindings node
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

injectJaxbTypeNameXmlTransformAnnotation

public void injectJaxbTypeNameXmlTransformAnnotation(Element xmltransformEl,
                                                     String jaxbNamespace,
                                                     String jaxbNamespacePrefix)
Inject a TypeNameXmlTransform element in the JAXB XmlTransform annotation.

If the element is already present we update its attributes.

Parameters:
xmltransformEl - the XmlTransform node
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

injectJaxbElementNameXmlTransformAnnotation

public void injectJaxbElementNameXmlTransformAnnotation(Element xmltransformEl,
                                                        String jaxbNamespace,
                                                        String jaxbNamespacePrefix)
Inject a ElementNameXmlTransform element in the JAXB XmlTransform annotation.

If the element is already present we update its attributes.

Parameters:
xmltransformEl - the XmlTransform node
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

injectJaxbEnumerationsAnnotation

public void injectJaxbEnumerationsAnnotation(org.apache.ws.commons.schema.XmlSchema schema,
                                             String jaxbNamespace,
                                             String jaxbNamespacePrefix)
Enumerations in anonymous simple types are not mapped to type safe Enum classes by JAXB unless they are annotated.

Since this is how cob2xsd handles COBOL level 88, we need these extra annotations.

Parameters:
schema - the XML Schema
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix

processCollectionElements

protected void processCollectionElements(org.apache.ws.commons.schema.XmlSchema schema,
                                         String jaxbNamespace,
                                         String jaxbNamespacePrefix,
                                         org.apache.ws.commons.schema.XmlSchemaObjectCollection items)
Take all elements from a collection and process them.

Parameters:
schema - the XML Schema
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix
items - the parent collection

processElement

protected void processElement(org.apache.ws.commons.schema.XmlSchema schema,
                              String jaxbNamespace,
                              String jaxbNamespacePrefix,
                              org.apache.ws.commons.schema.XmlSchemaElement xsdElement)
Process an XML schema element.

Parameters:
schema - the XML Schema
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix
xsdElement - the XML Schema element to process

processSimpleType

protected void processSimpleType(org.apache.ws.commons.schema.XmlSchema schema,
                                 String jaxbNamespace,
                                 String jaxbNamespacePrefix,
                                 org.apache.ws.commons.schema.XmlSchemaElement xsdElement,
                                 org.apache.ws.commons.schema.XmlSchemaSimpleType xsdSimpleType)
Process an XML schema simple type.

Only anonymous simple types get annotated. The reason for this is that named simple types do not originate from cob2xsd and are probably more complex than what we anticipate here.

Anonymous simple types might contain enumeration facets. If that's the case then we inject annotations.

Parameters:
schema - the XML Schema
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix
xsdElement - the XML Schema element which type we are processing
xsdSimpleType - the XML Schema type to process

processComplexType

protected void processComplexType(org.apache.ws.commons.schema.XmlSchema schema,
                                  String jaxbNamespace,
                                  String jaxbNamespacePrefix,
                                  org.apache.ws.commons.schema.XmlSchemaComplexType xsdComplexType)
Process an XML schema complex type.

Parameters:
schema - the XML Schema
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix
xsdComplexType - the XML Schema type to process

processParticle

protected void processParticle(org.apache.ws.commons.schema.XmlSchema schema,
                               String jaxbNamespace,
                               String jaxbNamespacePrefix,
                               QName parentName,
                               org.apache.ws.commons.schema.XmlSchemaParticle particle)
A particle is usually all or sequence. It contains a collection of other schema objects that need to be processed.

Parameters:
schema - the XML Schema
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix
parentName - the name of the parent schema object for logging
particle - the particle schema object

injectJaxbTypeSafeEnumClassAnnotation

protected void injectJaxbTypeSafeEnumClassAnnotation(String jaxbNamespace,
                                                     String jaxbNamespacePrefix,
                                                     org.apache.ws.commons.schema.XmlSchemaSimpleType xsdSimpleType,
                                                     String elementName)
Create a typesafeEnumClass markup. This marks the simple Type as eligible to become a separate Enum class.

Parameters:
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix
xsdSimpleType - the simple type to annotate
elementName - the name of the element whose simple type we are dealing with.

injectJaxbTypeSafeEnumMemberAnnotation

protected void injectJaxbTypeSafeEnumMemberAnnotation(String jaxbNamespace,
                                                      String jaxbNamespacePrefix,
                                                      org.apache.ws.commons.schema.XmlSchemaEnumerationFacet enumerationFacet,
                                                      String value)
Create a typesafeEnumMember markup. This provides a legal java identifier for an enumeration value. Since these are constant values, we follow the naming convention for static fields (all uppercase).

Parameters:
jaxbNamespace - the JAXB namespace
jaxbNamespacePrefix - the JAXB namespace prefix
enumerationFacet - the enumeration facet to annotate
value - the enumeration value.

getJaxbGenModel

public JaxbGenModel getJaxbGenModel()
Returns:
the bindings parameters


Copyright © 2014 LegSem. All Rights Reserved.