com.legstar.coxb.util
Class BindingUtil

java.lang.Object
  extended by com.legstar.coxb.util.BindingUtil

public final class BindingUtil
extends Object

Helper methods useful when manipulating bindings and transformers directly.


Field Summary
static String BIND_SUFFIX
          Suffix for binding class name.
static String COXB_PACKAGENAME_SUFFIX
          Binding classes go to a package which name ends with this.
static String JAXB_OBJECTFACTORY_NAME
          The JAXB object factory name.
static String WRAPPER_SUFFIX
          Suffix for array wrappers class names.
 
Method Summary
static String getCoxbTypeName(ICobolBinding binding)
          Builds a binding type name using the associated jaxb type name.
static String getFieldName(ICobolBinding binding)
          Returns a name that can be used as a field name.
static Class<?> getJavaClass(Field hostField)
          This method determines the relevant java type to be stored in a binding element.
static String getJavaClassName(String jaxbPackage, String jaxbTypeName)
          Since JAXB classes may hide a POJO, this method gets a special javaClassName annotation from the JAXB class.
static String getJaxbTypeName(ICobolBinding binding)
          Returns the binding associated jaxb type name.
static String getXmlNamespace(String jaxbPackageName, String jaxbTypeName)
          Retrieves the XML namespace associated with a JAXB element.
static ICobolBinding lookupBinding(ICobolBinding rootBinding, String bindingName)
          Search for a binding with a specific name.
static Object newJaxbObject(Object jaxbObjectFactory, String jaxbClassName)
          Loads a JAXB object using a JAXB Object factory.
static Object newJaxbObjectFactory(String packageName)
          Loads a JAXB object factory class using a combination of current and thread class loader.
static IHostTransformers newTransformers(String jaxbQualifiedClassName)
          Create an instance of Transformers for a given JAXB root class name.
static IHostTransformers newTransformers(String jaxbPackageName, String jaxbClassName)
          Create an instance of Transformers for a given JAXB root class name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BIND_SUFFIX

public static final String BIND_SUFFIX
Suffix for binding class name.

See Also:
Constant Field Values

WRAPPER_SUFFIX

public static final String WRAPPER_SUFFIX
Suffix for array wrappers class names.

See Also:
Constant Field Values

JAXB_OBJECTFACTORY_NAME

public static final String JAXB_OBJECTFACTORY_NAME
The JAXB object factory name.

See Also:
Constant Field Values

COXB_PACKAGENAME_SUFFIX

public static final String COXB_PACKAGENAME_SUFFIX
Binding classes go to a package which name ends with this.

See Also:
Constant Field Values
Method Detail

lookupBinding

public static ICobolBinding lookupBinding(ICobolBinding rootBinding,
                                          String bindingName)
                                   throws HostException
Search for a binding with a specific name.

This will descend the tree represented by bindings and their children until it finds a binding with the requested name.

Parameters:
rootBinding - the starting point for the search
bindingName - the
Returns:
the binding with the requested name or null if none is found
Throws:
HostException - if no binding exist

newJaxbObjectFactory

public static Object newJaxbObjectFactory(String packageName)
                                   throws CobolBindingException
Loads a JAXB object factory class using a combination of current and thread class loader. This assumes the JAXB classes are available on the classpath and returns a new instance of of the object factory.

Parameters:
packageName - the package containing a JAXB Object Factory
Returns:
a JAXB Object factory
Throws:
CobolBindingException - if JAXB classes are not found

newJaxbObject

public static Object newJaxbObject(Object jaxbObjectFactory,
                                   String jaxbClassName)
                            throws CobolBindingException
Loads a JAXB object using a JAXB Object factory.

Parameters:
jaxbObjectFactory - the JAXB Object factory
jaxbClassName - the JAXB class name
Returns:
a new instance of the JAXB object
Throws:
CobolBindingException - if instantiation failed

newTransformers

public static IHostTransformers newTransformers(String jaxbPackageName,
                                                String jaxbClassName)
                                         throws CobolBindingException
Create an instance of Transformers for a given JAXB root class name. Assumes binding classes were generated for this JAXB class.

Parameters:
jaxbPackageName - the JAXB package name
jaxbClassName - the JAXB root class name
Returns:
a new instance of Transformers
Throws:
CobolBindingException - if transformers cannot be created

newTransformers

public static IHostTransformers newTransformers(String jaxbQualifiedClassName)
                                         throws CobolBindingException
Create an instance of Transformers for a given JAXB root class name. Assumes binding classes were generated for this JAXB class.

Parameters:
jaxbQualifiedClassName - the JAXB class name
Returns:
a new instance of Transformers
Throws:
CobolBindingException - if transformers cannot be created

getJavaClassName

public static String getJavaClassName(String jaxbPackage,
                                      String jaxbTypeName)
                               throws CobolBindingException
Since JAXB classes may hide a POJO, this method gets a special javaClassName annotation from the JAXB class. Such an annotation is planted by schema generators and propagated by jaxbgen. If no such annotation is present, then the JAXB class itself is returned as it is considered it is not hiding a POJO.

Parameters:
jaxbPackage - the JAXB package name
jaxbTypeName - the JAXB type name
Returns:
a class name (including package name) that the JAXB class is hiding or the JAXB class itself if it is not hiding a POJO.
Throws:
CobolBindingException - if getting annotation fails

getJavaClass

public static Class<?> getJavaClass(Field hostField)
                             throws CobolBindingException
This method determines the relevant java type to be stored in a binding element. In case of list items, we seek the items types rather than the generic java.util.List type.

Parameters:
hostField - field from which java type is extracted
Returns:
the java type class
Throws:
CobolBindingException - if class cannot be determined

getJaxbTypeName

public static String getJaxbTypeName(ICobolBinding binding)
Returns the binding associated jaxb type name. Since certain bindings are not associated with a jaxb property, this might return null.

Parameters:
binding - the binding for which the jaxb type is to be returned
Returns:
the binding associated jaxb type name

getCoxbTypeName

public static String getCoxbTypeName(ICobolBinding binding)
Builds a binding type name using the associated jaxb type name.

Parameters:
binding - the binding for which the binding type is to be returned
Returns:
the binding type name

getFieldName

public static String getFieldName(ICobolBinding binding)
Returns a name that can be used as a field name.

Parameters:
binding - the binding for which the field name is to be returned
Returns:
the binding proposed field name

getXmlNamespace

public static String getXmlNamespace(String jaxbPackageName,
                                     String jaxbTypeName)
                              throws HostException
Retrieves the XML namespace associated with a JAXB element.

Parameters:
jaxbPackageName - a JAXB element package name
jaxbTypeName - a JAXB element type name
Returns:
the XML namespace
Throws:
HostException - if retrieving XML element name fails


Copyright © 2015 LegSem. All Rights Reserved.