org.jibx.binding.model
Class BindingOrganizer

java.lang.Object
  extended by org.jibx.binding.model.BindingOrganizer

public class BindingOrganizer
extends java.lang.Object

Organizer for a set of bindings under construction. This tracks the individual bindings by default namespace, and manages the relationships between the different bindings.

Author:
Dennis M. Sosnoski

Field Summary
private  boolean m_addConstructors
           
private  java.lang.String m_defaultUri
          Default namespace used with this set of bindings.
private  boolean m_elementDefault
          Make each binding namespace the default for elements in that binding flag.
private  boolean m_finished
          Bindings finalized flag.
private  boolean m_forceClasses
           
private  LazyList m_formats
          List of format definitions in binding.
private  boolean m_inBinding
           
private  InsertionOrderedMap m_nsPrefixMap
          Map from namespace URI to prefix used for that namespace.
private  boolean m_outBinding
           
private  InsertionOrderedSet m_referencedNamespaces
          Set of namespaces referenced across bindings.
private  boolean m_trackSource
           
private  InsertionOrderedMap m_uriBindingMap
          Map from namespace URI to binding holder.
private  boolean m_useDefault
          Use first binding namespace as default for documents flag.
 
Constructor Summary
BindingOrganizer(boolean force, boolean track, boolean addcon, boolean in, boolean out, boolean dfltns, boolean elmtdflt)
          Constructor taking flags used with constructed bindings.
 
Method Summary
 void addFormat(FormatElement format)
          Add a format definition to the binding.
(package private)  void addNamespaceReference(java.lang.String uri)
          Add namespace to set used outside defining binding.
private  void checkModifiable()
          Internal check method to verify that the collection of bindings is still modifiable.
 BindingHolder configureFiles(java.lang.String name, java.lang.String[] adduris, java.lang.String pack)
          Configure the names to be used for writing bindings to files.
 BindingHolder findBinding(java.lang.String uri)
          Find the binding to be used for a particular namespace.
 BindingHolder getBinding(java.lang.String uri)
          Get the existing binding definition for a namespace.
 java.util.ArrayList getNamespaces()
          Get the list of binding namespace URIs.
private static boolean isAsciiAlpha(char chr)
          Check if a character is an ASCII alpha character.
private static boolean isAsciiAlphaNum(char chr)
          Check if a character is an ASCII alpha or numeric character.
private static boolean isAsciiNum(char chr)
          Check if a character is an ASCII numeric character.
static boolean isEqual(java.lang.Object a, java.lang.Object b)
          General object comparison method.
 java.util.Iterator iterateBindings()
          Iterate the collection of bindings.
 void writeBindings(java.io.File dir)
          Write the bindings to supplied destination path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_forceClasses

private final boolean m_forceClasses

m_trackSource

private final boolean m_trackSource

m_addConstructors

private final boolean m_addConstructors

m_inBinding

private final boolean m_inBinding

m_outBinding

private final boolean m_outBinding

m_useDefault

private final boolean m_useDefault
Use first binding namespace as default for documents flag.


m_elementDefault

private final boolean m_elementDefault
Make each binding namespace the default for elements in that binding flag.


m_referencedNamespaces

private final InsertionOrderedSet m_referencedNamespaces
Set of namespaces referenced across bindings.


m_nsPrefixMap

private final InsertionOrderedMap m_nsPrefixMap
Map from namespace URI to prefix used for that namespace.


m_uriBindingMap

private final InsertionOrderedMap m_uriBindingMap
Map from namespace URI to binding holder.


m_formats

private final LazyList m_formats
List of format definitions in binding.


m_defaultUri

private java.lang.String m_defaultUri
Default namespace used with this set of bindings.


m_finished

private boolean m_finished
Bindings finalized flag.

Constructor Detail

BindingOrganizer

public BindingOrganizer(boolean force,
                        boolean track,
                        boolean addcon,
                        boolean in,
                        boolean out,
                        boolean dfltns,
                        boolean elmtdflt)
Constructor taking flags used with constructed bindings.

Parameters:
force - force classes flag
track - track source flag
addcon - add constructors flag
in - input binding flag
out - output binding flag
dfltns - use first binding namespace as default for documents flag
elmtdflt - make each binding namespace the default for elements in that binding flag
Method Detail

findBinding

public BindingHolder findBinding(java.lang.String uri)
Find the binding to be used for a particular namespace. If this is the first time a particular namespace was requested, a new binding will be created for that namespace and returned.

Parameters:
uri - namespace URI (null if no namespace)
Returns:
binding holder

isEqual

public static boolean isEqual(java.lang.Object a,
                              java.lang.Object b)
General object comparison method. Don't know why Sun hasn't seen fit to include this somewhere, but at least it's easy to write (over and over again).

Parameters:
a - first object to be compared
b - second object to be compared
Returns:
true if both objects are null, or if a.equals(b); false otherwise

checkModifiable

private void checkModifiable()
Internal check method to verify that the collection of bindings is still modifiable.


addNamespaceReference

void addNamespaceReference(java.lang.String uri)
Add namespace to set used outside defining binding.

Parameters:
uri - namespace for binding of referenced component

addFormat

public void addFormat(FormatElement format)
Add a format definition to the binding.

Parameters:
format -

iterateBindings

public java.util.Iterator iterateBindings()
Iterate the collection of bindings. null values may be present in the collection, due to bindings which have been eliminated.

Returns:
iterator

getBinding

public BindingHolder getBinding(java.lang.String uri)
Get the existing binding definition for a namespace.

Parameters:
uri -
Returns:
binding holder, or null if none

getNamespaces

public java.util.ArrayList getNamespaces()
Get the list of binding namespace URIs.

Returns:
namespaces

isAsciiAlpha

private static boolean isAsciiAlpha(char chr)
Check if a character is an ASCII alpha character.

Parameters:
chr -
Returns:
alpha character flag

isAsciiNum

private static boolean isAsciiNum(char chr)
Check if a character is an ASCII numeric character.

Parameters:
chr -
Returns:
numeric character flag

isAsciiAlphaNum

private static boolean isAsciiAlphaNum(char chr)
Check if a character is an ASCII alpha or numeric character.

Parameters:
chr -
Returns:
alpha or numeric character flag

configureFiles

public BindingHolder configureFiles(java.lang.String name,
                                    java.lang.String[] adduris,
                                    java.lang.String pack)
Configure the names to be used for writing bindings to files. If only one binding has been defined, it just gets the supplied name. If multiple bindings have been defined, a single root binding is constructed which includes all the other bindings and defines namespaces for those bindings, all <format> definitions are moved to that root binding, and is is given the supplied name while the other bindings are given unique names within the same directory.

Parameters:
name - file name for root or singleton binding definition
adduris - list of namespaces to be added to bindings, if not already defined
pack - target package for binding
Returns:
root or singleton binding holder

writeBindings

public void writeBindings(java.io.File dir)
                   throws JiBXException,
                          java.io.IOException
Write the bindings to supplied destination path. The binding file names must be set before calling this method, generally by a call to configureFiles(String, String[], String).

Parameters:
dir - target directory for writing binding definitions
Throws:
JiBXException
java.io.IOException


Project Web Site