Package org.jibx.binding.model
Class BindingElement
java.lang.Object
org.jibx.binding.model.ElementBase
org.jibx.binding.model.NestingElementBase
org.jibx.binding.model.BindingElement
Model component for binding element.
- Author:
- Dennis M. Sosnoski
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Inner class as wrapper for binding element on unmarshalling. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
private boolean
Add default constructors where needed flag.private URL
Base URL for use with relative include paths.private final ArrayList
List of child elements.private String
Binding direction.private boolean
Generate souce tracking interface flag.private boolean
Support forward references to IDs flag.private Set
Set of class names which can be referenced by ID.private final Map
Map from include path to actual binding.private final Set
Set of paths for includes.private boolean
Input binding flag.private int
Major version of binding.private int
Minor version of binding.private String
Binding name.private ArrayList
List of namespace declarations to be added on output (lazy create,null
if none).private boolean
Output binding flag.private boolean
Precompiled binding flag.private final Set
Set of paths for precompiled includes.private String
Package for generated context factory.private boolean
Generate souce tracking interface flag.private boolean
Trim whitespace for simple values (schema compatibility) flag.static final int
static final StringArray
Enumeration of allowed attribute names(package private) static final EnumSet
Fields inherited from class org.jibx.binding.model.ElementBase
BINDING_ELEMENT, COLLECTION_ELEMENT, ELEMENT_NAMES, FORMAT_ELEMENT, INCLUDE_ELEMENT, INPUT_ELEMENT, MAPPING_ELEMENT, NAMESPACE_ELEMENT, OUTPUT_ELEMENT, SPLIT_ELEMENT, STRUCTURE_ELEMENT, TEMPLATE_ELEMENT, VALUE_ELEMENT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIdClass
(IClass clas) Add a class defined with a ID value.void
addIncludeBinding
(String path, BindingElement bind) Add binding accessible to includes.boolean
addIncludePath
(String path, boolean precomp) Add include path to set processed.void
addNamespaceDecl
(String prefix, String uri) Add namespace declaration for output when marshalling.void
addTopChild
(Object child) Add top-level child element.private static FormatElement
private void
defineBaseFormat
(FormatElement format, DefinitionContext dctx, ValidationContext vctx) Define a built-in format.Get base URL for relative include paths.int
Get default style value for child components.Get existing included binding.getIncludeBinding
(URL url, BindingElement root, ValidationContext vctx) Get included binding.int
Get major version number.int
Get minor version number.getName()
Get binding name.Get package for generated context factory class.boolean
boolean
boolean
Check if default constructor generation is enabled.boolean
Check if marshaller/unmarshaller class creation for top-level non-base abstract mappings is forced.boolean
Check if forward references to IDs must be supported in XML.boolean
Check if a class can be referenced by ID.boolean
Check if this binding component applies for unmarshalling XML.boolean
boolean
Check if this binding component applies for marshalling XML.boolean
Check if a precompiled binding.boolean
Check if source position tracking enabled for unmarshalling.boolean
Check if whitespace should be trimmed from simple values.static ValidationContext
Create a default validation context.private void
preGet
(IMarshallingContext ictx) Marshalling hook method to add namespace declarations to <binding> element.private void
preSet
(IUnmarshallingContext ictx) Make sure all attributes are defined.void
prevalidate
(ValidationContext vctx) Prevalidate all attributes of element in isolation.static BindingElement
readBinding
(InputStream is, String fname, BindingElement contain, boolean precomp, ValidationContext vctx) Read a binding definition (possibly as an include) to construct binding model.static BindingElement
readBinding
(InputStream is, String fname, ValidationContext vctx) Read a binding definition to construct binding model.void
runValidation
(boolean full, ValidationContext vctx) Run the actual validation of a binding model.void
Run the actual validation of a binding model.void
setAddConstructors
(boolean add) Set default constructor generation.void
setBaseUrl
(URL base) Set base URL for relative include paths.private void
Set the correct direction text.void
setForceClasses
(boolean force) Set force marshaller/unmarshaller class creation for top-level non-base abstract mappings.void
setForward
(boolean forward) Set forward references to IDs be supported in XML.void
setInBinding
(boolean in) Set binding component applies for unmarshalling XML.void
setMajorVersion
(int ver) Set major version number.void
setMinorVersion
(int ver) Set minor version number.void
Set binding name.void
setOutBinding
(boolean out) Set binding component applies for marshalling XML.void
setPrecompiled
(boolean precomp) Set precompiled binding flag.void
setTargetPackage
(String pack) Set package for generated context factory class.void
setTrackSource
(boolean track) Set source position tracking for unmarshalling.void
setTrimWhitespace
(boolean trim) Set trim whitespace flag.Get iterator for top-level child elements.Get list of top-level child elements.static BindingElement
validateBinding
(String name, URL path, InputStream is, ValidationContext vctx) Validate a binding definition.Methods inherited from class org.jibx.binding.model.NestingElementBase
addChild, childIterator, children, getDefinitions, getStyle, getStyleName, setDefinitions, setStyleName, validate
Methods inherited from class org.jibx.binding.model.ElementBase
getComment, name, setComment, toString, type, validateAttributes
-
Field Details
-
s_allowedAttributes
Enumeration of allowed attribute names -
IN_BINDING
public static final int IN_BINDING- See Also:
-
OUT_BINDING
public static final int OUT_BINDING- See Also:
-
BOTH_BINDING
public static final int BOTH_BINDING- See Also:
-
s_directionEnum
-
m_name
Binding name. -
m_direction
Binding direction. -
m_inputBinding
private boolean m_inputBindingInput binding flag. -
m_outputBinding
private boolean m_outputBindingOutput binding flag. -
m_forwardReferences
private boolean m_forwardReferencesSupport forward references to IDs flag. -
m_trackSource
private boolean m_trackSourceGenerate souce tracking interface flag. -
m_forceClasses
private boolean m_forceClassesGenerate souce tracking interface flag. -
m_addConstructors
private boolean m_addConstructorsAdd default constructors where needed flag. -
m_trimWhitespace
private boolean m_trimWhitespaceTrim whitespace for simple values (schema compatibility) flag. -
m_majorVersion
private int m_majorVersionMajor version of binding. -
m_minorVersion
private int m_minorVersionMinor version of binding. -
m_targetPackage
Package for generated context factory. -
m_precompiled
private boolean m_precompiledPrecompiled binding flag. -
m_baseUrl
Base URL for use with relative include paths. -
m_includePaths
Set of paths for includes. -
m_precompiledPaths
Set of paths for precompiled includes. -
m_includeBindings
Map from include path to actual binding. -
m_children
List of child elements. -
m_idClassSet
Set of class names which can be referenced by ID. -
m_namespaceDeclares
List of namespace declarations to be added on output (lazy create,null
if none).
-
-
Constructor Details
-
BindingElement
public BindingElement()Default constructor.
-
-
Method Details
-
setName
Set binding name.- Parameters:
name
- binding definition name
-
getName
Get binding name.- Returns:
- binding definition name
-
setForward
public void setForward(boolean forward) Set forward references to IDs be supported in XML.- Parameters:
forward
-true
if forward references supported,false
if not
-
isForward
public boolean isForward()Check if forward references to IDs must be supported in XML.- Returns:
true
if forward references required,false
if not
-
setTrackSource
public void setTrackSource(boolean track) Set source position tracking for unmarshalling.- Parameters:
track
-true
if source position tracking enabled,false
if not
-
isTrackSource
public boolean isTrackSource()Check if source position tracking enabled for unmarshalling.- Returns:
true
if source position tracking enabled,false
if not
-
setForceClasses
public void setForceClasses(boolean force) Set force marshaller/unmarshaller class creation for top-level non-base abstract mappings.- Parameters:
force
-true
if class generation forced,false
if not
-
isForceClasses
public boolean isForceClasses()Check if marshaller/unmarshaller class creation for top-level non-base abstract mappings is forced.- Returns:
true
if class generation forced,false
if not
-
setAddConstructors
public void setAddConstructors(boolean add) Set default constructor generation.- Parameters:
add
-true
if constructors should be added,false
if not
-
isAddConstructors
public boolean isAddConstructors()Check if default constructor generation is enabled.- Returns:
true
if default constructor generation enabled,false
if not
-
setTrimWhitespace
public void setTrimWhitespace(boolean trim) Set trim whitespace flag.- Parameters:
trim
-true
if whitespace should be trimmed from simple values,false
if not
-
isTrimWhitespace
public boolean isTrimWhitespace()Check if whitespace should be trimmed from simple values.- Returns:
- trim whitespace flag
-
getMajorVersion
public int getMajorVersion()Get major version number.- Returns:
- major version
-
setMajorVersion
public void setMajorVersion(int ver) Set major version number.- Parameters:
ver
- major version
-
getMinorVersion
public int getMinorVersion()Get minor version number.- Returns:
- minor version
-
setMinorVersion
public void setMinorVersion(int ver) Set minor version number.- Parameters:
ver
- minor version
-
setTargetPackage
Set package for generated context factory class.- Parameters:
pack
- generated context factory package (null
if unspecified)
-
getTargetPackage
Get package for generated context factory class.- Returns:
- package for generated context factory (
null
if unspecified)
-
setBaseUrl
Set base URL for relative include paths.- Parameters:
base
-
-
getBaseUrl
Get base URL for relative include paths.- Returns:
- base URL
-
setDirection
private void setDirection()Set the correct direction text. This should be used whenever the individual in and out flags are set, so that modifications are output correctly when a binding is marshalled. -
setOutBinding
public void setOutBinding(boolean out) Set binding component applies for marshalling XML.- Parameters:
out
-true
if binding supports output,false
if not
-
isOutBinding
public boolean isOutBinding()Check if this binding component applies for marshalling XML.- Returns:
true
if binding supports output,false
if not
-
setInBinding
public void setInBinding(boolean in) Set binding component applies for unmarshalling XML.- Parameters:
in
-true
if binding supports input,false
if not
-
isInBinding
public boolean isInBinding()Check if this binding component applies for unmarshalling XML.- Returns:
true
if binding supports input,false
if not
-
isPrecompiled
public boolean isPrecompiled()Check if a precompiled binding.- Returns:
true
if precompiled,false
if not
-
setPrecompiled
public void setPrecompiled(boolean precomp) Set precompiled binding flag.- Parameters:
precomp
-
-
addIncludePath
Add include path to set processed.- Parameters:
path
-precomp
- precompiled binding flag- Returns:
true
if new path,false
if duplicate
-
getIncludeBinding
public BindingElement getIncludeBinding(URL url, BindingElement root, ValidationContext vctx) throws IOException, JiBXException Get included binding. If the binding was supplied directly it's just returned; otherwise, it's read from the URL. This method should only be called ifaddIncludePath(String, boolean)
returnstrue
, so that each unique included binding is only processed once.- Parameters:
url
- binding pathroot
- binding containing the includevctx
- validation context- Returns:
- binding
- Throws:
IOException
JiBXException
-
getExistingIncludeBinding
Get existing included binding.- Parameters:
url
- binding path- Returns:
- binding if it exists, otherwise
null
-
addIncludeBinding
Add binding accessible to includes. This allows bindings to be supplied directly, without needing to be parsed from an input document.- Parameters:
path
- URL string identifying the binding (virtual path)bind
-
-
addIdClass
Add a class defined with a ID value. This is used to track the classes with ID values for validating ID references in the binding. If the binding uses global IDs, the actual ID class is added to the table along with all interfaces implemented by the class and all superclasses, since instances of the ID class can be referenced in any of those forms. If the binding does not use global IDs, only the actual ID class is added, since references must be type-specific.- Parameters:
clas
- information for class with ID value
-
isIdClass
Check if a class can be referenced by ID. This just checks if any classes compatible with the reference type are bound with ID values.- Parameters:
name
- fully qualified name of class- Returns:
true
if class is bound with an ID,false
if not
-
addTopChild
Add top-level child element. TODO: should be ElementBase argument, but JiBX doesn't allow yet- Parameters:
child
- element to be added as child of this element
-
topChildren
Get list of top-level child elements.- Returns:
- list of child elements, or
null
if none
-
topChildIterator
Get iterator for top-level child elements.- Returns:
- iterator for child elements
-
addNamespaceDecl
Add namespace declaration for output when marshalling.- Parameters:
prefix
- namespace prefix (null
if none)uri
- namespace URI (non-null
)
-
hasAttribute
public boolean hasAttribute() -
hasContent
public boolean hasContent() -
isOptional
public boolean isOptional() -
getDefaultStyle
public int getDefaultStyle()Get default style value for child components. This call is only meaningful after validation.- Overrides:
getDefaultStyle
in classNestingElementBase
- Returns:
- default style value for child components
-
preGet
Marshalling hook method to add namespace declarations to <binding> element.- Parameters:
ictx
-- Throws:
IOException
-
preSet
Make sure all attributes are defined.- Parameters:
ictx
- unmarshalling context- Throws:
JiBXException
- on unmarshalling error
-
prevalidate
Prevalidate all attributes of element in isolation.- Overrides:
prevalidate
in classNestingElementBase
- Parameters:
vctx
- validation context
-
buildFormat
-
defineBaseFormat
Define a built-in format. This checks to make sure the type referenced by the format is present in the classpath, since some of the build-in formats apply to classes which are not part of the required runtime.- Parameters:
format
-dctx
-vctx
-
-
runValidation
Run the actual validation of a binding model. This allows either partial or full validation, with partial validation not requiring access to class files.- Parameters:
full
- run full validation flag (requires access to class files)vctx
- context for controlling validation
-
runValidation
Run the actual validation of a binding model. This form of call always does a full validation.- Parameters:
vctx
- context for controlling validation
-
readBinding
public static BindingElement readBinding(InputStream is, String fname, BindingElement contain, boolean precomp, ValidationContext vctx) throws JiBXException Read a binding definition (possibly as an include) to construct binding model.- Parameters:
is
- input stream for reading bindingfname
- name of input file (null
if unknown)contain
- containing binding (null
if none)precomp
- precompiled binding flagvctx
- validation context used during unmarshalling- Returns:
- root of binding definition model
- Throws:
JiBXException
- on error in reading binding
-
readBinding
public static BindingElement readBinding(InputStream is, String fname, ValidationContext vctx) throws JiBXException Read a binding definition to construct binding model. This method cannot be used for precompiled bindings.- Parameters:
is
- input stream for reading bindingfname
- name of input file (null
if unknown)vctx
- validation context used during unmarshalling- Returns:
- root of binding definition model
- Throws:
JiBXException
- on error in reading binding
-
validateBinding
public static BindingElement validateBinding(String name, URL path, InputStream is, ValidationContext vctx) throws JiBXException Validate a binding definition. This method cannot be used for precompiled bindings.- Parameters:
name
- binding definition namepath
- binding definition URLis
- input stream for reading bindingvctx
- validation context to record problems- Returns:
- root of binding definition model, or
null
if error in unmarshalling - Throws:
JiBXException
- on error in binding XML structure
-
newValidationContext
Create a default validation context.- Returns:
- new validation context
-