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 classInner class as wrapper for binding element on unmarshalling. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intprivate booleanAdd default constructors where needed flag.private URLBase URL for use with relative include paths.private final ArrayListList of child elements.private StringBinding direction.private booleanGenerate souce tracking interface flag.private booleanSupport forward references to IDs flag.private SetSet of class names which can be referenced by ID.private final MapMap from include path to actual binding.private final SetSet of paths for includes.private booleanInput binding flag.private intMajor version of binding.private intMinor version of binding.private StringBinding name.private ArrayListList of namespace declarations to be added on output (lazy create,nullif none).private booleanOutput binding flag.private booleanPrecompiled binding flag.private final SetSet of paths for precompiled includes.private StringPackage for generated context factory.private booleanGenerate souce tracking interface flag.private booleanTrim whitespace for simple values (schema compatibility) flag.static final intstatic final StringArrayEnumeration of allowed attribute names(package private) static final EnumSetFields 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 TypeMethodDescriptionvoidaddIdClass(IClass clas) Add a class defined with a ID value.voidaddIncludeBinding(String path, BindingElement bind) Add binding accessible to includes.booleanaddIncludePath(String path, boolean precomp) Add include path to set processed.voidaddNamespaceDecl(String prefix, String uri) Add namespace declaration for output when marshalling.voidaddTopChild(Object child) Add top-level child element.private static FormatElementprivate voiddefineBaseFormat(FormatElement format, DefinitionContext dctx, ValidationContext vctx) Define a built-in format.Get base URL for relative include paths.intGet default style value for child components.Get existing included binding.getIncludeBinding(URL url, BindingElement root, ValidationContext vctx) Get included binding.intGet major version number.intGet minor version number.getName()Get binding name.Get package for generated context factory class.booleanbooleanbooleanCheck if default constructor generation is enabled.booleanCheck if marshaller/unmarshaller class creation for top-level non-base abstract mappings is forced.booleanCheck if forward references to IDs must be supported in XML.booleanCheck if a class can be referenced by ID.booleanCheck if this binding component applies for unmarshalling XML.booleanbooleanCheck if this binding component applies for marshalling XML.booleanCheck if a precompiled binding.booleanCheck if source position tracking enabled for unmarshalling.booleanCheck if whitespace should be trimmed from simple values.static ValidationContextCreate a default validation context.private voidpreGet(IMarshallingContext ictx) Marshalling hook method to add namespace declarations to <binding> element.private voidpreSet(IUnmarshallingContext ictx) Make sure all attributes are defined.voidprevalidate(ValidationContext vctx) Prevalidate all attributes of element in isolation.static BindingElementreadBinding(InputStream is, String fname, BindingElement contain, boolean precomp, ValidationContext vctx) Read a binding definition (possibly as an include) to construct binding model.static BindingElementreadBinding(InputStream is, String fname, ValidationContext vctx) Read a binding definition to construct binding model.voidrunValidation(boolean full, ValidationContext vctx) Run the actual validation of a binding model.voidRun the actual validation of a binding model.voidsetAddConstructors(boolean add) Set default constructor generation.voidsetBaseUrl(URL base) Set base URL for relative include paths.private voidSet the correct direction text.voidsetForceClasses(boolean force) Set force marshaller/unmarshaller class creation for top-level non-base abstract mappings.voidsetForward(boolean forward) Set forward references to IDs be supported in XML.voidsetInBinding(boolean in) Set binding component applies for unmarshalling XML.voidsetMajorVersion(int ver) Set major version number.voidsetMinorVersion(int ver) Set minor version number.voidSet binding name.voidsetOutBinding(boolean out) Set binding component applies for marshalling XML.voidsetPrecompiled(boolean precomp) Set precompiled binding flag.voidsetTargetPackage(String pack) Set package for generated context factory class.voidsetTrackSource(boolean track) Set source position tracking for unmarshalling.voidsetTrimWhitespace(boolean trim) Set trim whitespace flag.Get iterator for top-level child elements.Get list of top-level child elements.static BindingElementvalidateBinding(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, validateMethods 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,nullif 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-trueif forward references supported,falseif not
-
isForward
public boolean isForward()Check if forward references to IDs must be supported in XML.- Returns:
trueif forward references required,falseif not
-
setTrackSource
public void setTrackSource(boolean track) Set source position tracking for unmarshalling.- Parameters:
track-trueif source position tracking enabled,falseif not
-
isTrackSource
public boolean isTrackSource()Check if source position tracking enabled for unmarshalling.- Returns:
trueif source position tracking enabled,falseif not
-
setForceClasses
public void setForceClasses(boolean force) Set force marshaller/unmarshaller class creation for top-level non-base abstract mappings.- Parameters:
force-trueif class generation forced,falseif not
-
isForceClasses
public boolean isForceClasses()Check if marshaller/unmarshaller class creation for top-level non-base abstract mappings is forced.- Returns:
trueif class generation forced,falseif not
-
setAddConstructors
public void setAddConstructors(boolean add) Set default constructor generation.- Parameters:
add-trueif constructors should be added,falseif not
-
isAddConstructors
public boolean isAddConstructors()Check if default constructor generation is enabled.- Returns:
trueif default constructor generation enabled,falseif not
-
setTrimWhitespace
public void setTrimWhitespace(boolean trim) Set trim whitespace flag.- Parameters:
trim-trueif whitespace should be trimmed from simple values,falseif 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 (nullif unspecified)
-
getTargetPackage
Get package for generated context factory class.- Returns:
- package for generated context factory (
nullif 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-trueif binding supports output,falseif not
-
isOutBinding
public boolean isOutBinding()Check if this binding component applies for marshalling XML.- Returns:
trueif binding supports output,falseif not
-
setInBinding
public void setInBinding(boolean in) Set binding component applies for unmarshalling XML.- Parameters:
in-trueif binding supports input,falseif not
-
isInBinding
public boolean isInBinding()Check if this binding component applies for unmarshalling XML.- Returns:
trueif binding supports input,falseif not
-
isPrecompiled
public boolean isPrecompiled()Check if a precompiled binding.- Returns:
trueif precompiled,falseif 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:
trueif new path,falseif 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:
IOExceptionJiBXException
-
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:
trueif class is bound with an ID,falseif 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
nullif 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 (nullif 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:
getDefaultStylein 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:
prevalidatein 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 (nullif unknown)contain- containing binding (nullif 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 (nullif 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
nullif error in unmarshalling - Throws:
JiBXException- on error in binding XML structure
-
newValidationContext
Create a default validation context.- Returns:
- new validation context
-