Class BindingOrganizer
- Author:
- Dennis M. Sosnoski
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
Base prefix used when no prefix set for namespace.private final boolean
private boolean
Bindings finalized flag.private final boolean
private final List
List of format definitions in bindings.private final boolean
private final List
List of unique key objects for bindings.private boolean
Flag for no-namespace namespace used from namespaced binding.private final Set
Set of namespace URIs needing to be defined in root binding.private final Map
Map from object to binding holder for that namespace.private final boolean
private final Map
Map from namespace URIs referenced in bindings not using that namespace to first referencing binding.private final boolean
private final boolean
private final Map
Map from namespace URI to default prefix for that namespace.private final Map
Map from namespace URI to prefix, for bindings with prefix specified.private static final Logger
Logger for class. -
Constructor Summary
ConstructorsConstructorDescriptionBindingOrganizer
(boolean force, boolean track, boolean addcon, boolean in, boolean out, boolean trim) Constructor taking flags used with constructed bindings. -
Method Summary
Modifier and TypeMethodDescriptionaddBinding
(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.(package private) void
addNamespaceUsage
(BindingHolder hold, String uri) Add usage of namespace for an element or attribute name in binding, assuring that the namespace definition will be in-scope for that 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.private Map
buildDefaultPrefixes
(UniqueNameSet prefset, Map nsdfltpref) Set the default prefixes to be used for namespaces.private void
Internal check method to verify that the collection of bindings is still modifiable.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.private void
generatePrefix
(String uri, UniqueNameSet prefset, Map uridfltprefs) Generate prefix if not already set for namespace.getBinding
(Object obj) Get the binding associated with a particular control object and namespace, if defined.getKeys()
Get the list of binding key objects.getRequiredBinding
(Object obj) Get the binding associated with a particular control object.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
General object comparison method.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.
-
Field Details
-
s_logger
private static final Logger s_loggerLogger for class. -
BASE_PREFIX
Base prefix used when no prefix set for namespace.- See Also:
-
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_trimWhitespace
private final boolean m_trimWhitespace -
m_uriPrefixFixed
Map from namespace URI to prefix, for bindings with prefix specified. -
m_uriPrefixDefaults
Map from namespace URI to default prefix for that namespace. -
m_keyObjects
List of unique key objects for bindings. Multiple key objects may be supplied for each binding, so this just tracks the one used when initially creating the binding. -
m_objectBindings
Map from object to binding holder for that namespace. -
m_referenceUriBinding
Map from namespace URIs referenced in bindings not using that namespace to first referencing binding. -
m_nsRootUris
Set of namespace URIs needing to be defined in root binding. -
m_formats
List of format definitions in bindings. -
m_nonamespaceUsed
private boolean m_nonamespaceUsedFlag for no-namespace namespace used from namespaced binding. -
m_finished
private boolean m_finishedBindings finalized flag.
-
-
Constructor Details
-
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 flagtrack
- track source flagaddcon
- add constructors flagin
- input binding flagout
- output binding flagtrim
- trim whitespace flag
-
-
Method Details
-
addBinding
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
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
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
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
Set the default prefix for a namespace, if none already set.- Parameters:
uri
- namespace URIpref
- prefix to be used (empty string if to be default namespace)
-
forceBindingPrefix
Force specified prefix to be used for binding.- Parameters:
prefix
-holder
-
-
isEqual
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 comparedb
- second object to be compared- Returns:
true
if both objects arenull
, or ifa.equals(b)
;false
otherwise
-
checkModifiable
private void checkModifiable()Internal check method to verify that the collection of bindings is still modifiable. -
addNamespaceUsage
Add usage of namespace for an element or attribute name in binding, assuring that the namespace definition will be in-scope for that binding. If a namespace is defined by one binding and referenced by another, or if it's referenced by more than one binding, it will be defined at the root binding level. This method is used as a callback from the binding holder code, in order to track usage of namespaces across all bindings.- Parameters:
hold
- binding containing usageuri
- referenced namespace URI (null
if no-namespace)
-
addTypeNameReference
Add reference from binding to a type name defined in the same or another binding.- Parameters:
hold
- binding containing referenceuri
- namespace URI for type nameobj
- object associated with referenced binding
-
addFormat
Add a format definition to the binding.- Parameters:
format
-
-
iterateBindings
Iterate the collection of bindings.null
values may be present in the collection, due to bindings which have been eliminated.- Returns:
- iterator
-
addRootUris
Adds a collection of namespace URIs to be referenced at root binding level.- Parameters:
uris
-
-
getKeys
Get the list of binding key objects.- Returns:
- keys
-
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
-
generatePrefix
Generate prefix if not already set for namespace.- Parameters:
uri
-prefset
-uridfltprefs
-
-
buildDefaultPrefixes
Set the default prefixes to be used for namespaces. As part of constructing the map it also checks for conflicts on specified prefixes for namespaces used at the root binding level. This is a complex process, due to the way namespaces work across bindings with abstract mapping references. Since an abstract mapping doesn't define a wrapper element, all namespaces used by the abstract mapping need to be declared on the containing element. In practice, this means that any namespaces in the binding defining the abstract mapping need to be merged into the set of namespaces in the binding making the reference, and these namespaces all must use distinct prefixes. Furthermore, a static analysis of the namespace usage may not be enough to detect conflicts in usage, since even if there are no conflicts in a set of binding definitions conflicts may be created when these bindings are referenced from other bindings (either through direct includes, or as precompiled bindings).
This code checks for any direct conflicts on namespaces with specified prefixes which are being defined in the root binding and throws an exception if such a conflict is found, and creates guaranteed-unique prefixes in cases where no prefixes are provided (either as specified values or as defaults). It does not prevent the user from either specifying prefixes or using default prefixes which may result in conflicts when the bindings are used by other bindings.
- Parameters:
prefset
- prefixes in usensdfltpref
- map from namespace URI to default prefix (null
value for namespace used as the default allowed)- Returns:
- map from namespace URI to non-
null
and non-empty prefix (used for namespace declarations)
-
configureFiles
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 definitiontrgtpack
- 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. TheconfigureFiles(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 byconfigureFiles(String, String, List)
)dir
- target directory for writing binding definitionsvctx
- validation context to use- Returns:
true
if valid,false
if error- Throws:
IOException
-
writeBindings
Write the bindings to supplied destination path. TheconfigureFiles(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
-