org.jibx.binding.model
Class BindingOrganizer

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

public class BindingOrganizer
extends Object

Organizer for a set of bindings under construction. This tracks the individual bindings by default namespace or by associated object (to allow multiple bindings using a single namespace), and manages the relationships between the different bindings.

Author:
Dennis M. Sosnoski

Constructor Summary
BindingOrganizer(boolean force, boolean track, boolean addcon, boolean in, boolean out, boolean trim)
          Constructor taking flags used with constructed bindings.
 
Method Summary
 BindingHolder addBinding(Object obj, String uri, String prefix, boolean dflt)
          Add a binding to the set in use.
 void addBindingObject(Object obj, BindingHolder holder)
          Associate a control object with an existing binding.
 void addDefaultPrefix(String uri, String pref)
          Set the default prefix for a namespace, if none already set.
 void addFormat(FormatElement format)
          Add a format definition to the binding.
 void addRootUris(Collection uris)
          Adds a collection of namespace URIs to be referenced at root binding level.
 void addTypeNameReference(BindingHolder hold, String uri, Object obj)
          Add reference from binding to a type name defined in the same or another binding.
 BindingHolder configureFiles(String rootname, String trgtpack, List pregens)
          Configure the names to be used for writing bindings to files.
 void forceBindingPrefix(String prefix, BindingHolder holder)
          Force specified prefix to be used for binding.
 BindingHolder getBinding(Object obj)
          Get the binding associated with a particular control object and namespace, if defined.
 List getKeys()
          Get the list of binding key objects.
 BindingHolder getRequiredBinding(Object obj)
          Get the binding associated with a particular control object.
static boolean isEqual(Object a, Object b)
          General object comparison method.
 Iterator iterateBindings()
          Iterate the collection of bindings.
 boolean validateBindings(BindingHolder root, File dir, ValidationContext vctx)
          Validate the constructed bindings.
 void writeBindings(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
 

Constructor Detail

BindingOrganizer

public BindingOrganizer(boolean force,
                        boolean track,
                        boolean addcon,
                        boolean in,
                        boolean out,
                        boolean trim)
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
trim - trim whitespace flag
Method Detail

addBinding

public BindingHolder addBinding(Object obj,
                                String uri,
                                String prefix,
                                boolean dflt)
Add a binding to the set in use.

Parameters:
obj - object associated with binding (can be namespace URI, if only one binding per namespace)
uri - namespace URI (null if no namespace)
prefix - namespace prefix (null if not specified, empty string if unprefixed default namespace)
dflt - namespace is default for elements in binding flag
Returns:
created binding holder

getBinding

public BindingHolder getBinding(Object obj)
Get the binding associated with a particular control object and namespace, if defined.

Parameters:
obj - object associated with binding
Returns:
binding holder, or null if not yet defined

getRequiredBinding

public BindingHolder getRequiredBinding(Object obj)
Get the binding associated with a particular control object.

Parameters:
obj - object associated with binding (can be namespace URI, if only one binding per namespace)
Returns:
binding holder

addBindingObject

public void addBindingObject(Object obj,
                             BindingHolder holder)
Associate a control object with an existing binding. The control object is added in addition to any other control objects for that binding, so that the binding will be returned when any of the control objects is used for look up.

Parameters:
obj - object associated with binding (can be namespace URI, if only one binding per namespace)
holder - binding holder

addDefaultPrefix

public void addDefaultPrefix(String uri,
                             String pref)
Set the default prefix for a namespace, if none already set.

Parameters:
uri - namespace URI
pref - prefix to be used (empty string if to be default namespace)

forceBindingPrefix

public void forceBindingPrefix(String prefix,
                               BindingHolder holder)
Force specified prefix to be used for binding.

Parameters:
prefix -
holder -

isEqual

public static boolean isEqual(Object a,
                              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

addTypeNameReference

public void addTypeNameReference(BindingHolder hold,
                                 String uri,
                                 Object obj)
Add reference from binding to a type name defined in the same or another binding.

Parameters:
hold - binding containing reference
uri - namespace URI for type name
obj - object associated with referenced binding

addFormat

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

Parameters:
format -

iterateBindings

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

Returns:
iterator

addRootUris

public void addRootUris(Collection uris)
Adds a collection of namespace URIs to be referenced at root binding level.

Parameters:
uris -

getKeys

public List getKeys()
Get the list of binding key objects.

Returns:
keys

configureFiles

public BindingHolder configureFiles(String rootname,
                                    String trgtpack,
                                    List pregens)
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:
rootname - file name for root or singleton binding definition
trgtpack - target package for binding (null if unspecified)
pregens - pregenerated bindings to be included in root binding
Returns:
root or singleton binding holder

validateBindings

public boolean validateBindings(BindingHolder root,
                                File dir,
                                ValidationContext vctx)
                         throws IOException
Validate the constructed bindings. The configureFiles(String, String, List) must be called before this method is called, in order to complete the root binding definition.

Parameters:
root - root binding holder (returned by configureFiles(String, String, List))
dir - target directory for writing binding definitions
vctx - validation context to use
Returns:
true if valid, false if error
Throws:
IOException

writeBindings

public void writeBindings(File dir)
                   throws JiBXException,
                          IOException
Write the bindings to supplied destination path. The configureFiles(String, String, List) must be called before this method is called, in order to configure the file names and complete the root binding definition.

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


Copyright © 2005-2011 jibx.org. All Rights Reserved.