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
-
public class BindingElement extends NestingElementBase
Model component for binding element.- Author:
- Dennis M. Sosnoski
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBindingElement.UnmarshalWrapperInner class as wrapper for binding element on unmarshalling.
-
Field Summary
Fields Modifier and Type Field Description static intBOTH_BINDINGstatic intIN_BINDINGstatic intOUT_BINDINGstatic StringArrays_allowedAttributesEnumeration of allowed attribute names-
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 Constructor Description BindingElement()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIdClass(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.URLgetBaseUrl()Get base URL for relative include paths.intgetDefaultStyle()Get default style value for child components.BindingElementgetExistingIncludeBinding(URL url)Get existing included binding.BindingElementgetIncludeBinding(URL url, BindingElement root, ValidationContext vctx)Get included binding.intgetMajorVersion()Get major version number.intgetMinorVersion()Get minor version number.StringgetName()Get binding name.StringgetTargetPackage()Get package for generated context factory class.booleanhasAttribute()booleanhasContent()booleanisAddConstructors()Check if default constructor generation is enabled.booleanisForceClasses()Check if marshaller/unmarshaller class creation for top-level non-base abstract mappings is forced.booleanisForward()Check if forward references to IDs must be supported in XML.booleanisIdClass(String name)Check if a class can be referenced by ID.booleanisInBinding()Check if this binding component applies for unmarshalling XML.booleanisOptional()booleanisOutBinding()Check if this binding component applies for marshalling XML.booleanisPrecompiled()Check if a precompiled binding.booleanisTrackSource()Check if source position tracking enabled for unmarshalling.booleanisTrimWhitespace()Check if whitespace should be trimmed from simple values.static ValidationContextnewValidationContext()Create a default validation context.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.voidrunValidation(ValidationContext vctx)Run the actual validation of a binding model.voidsetAddConstructors(boolean add)Set default constructor generation.voidsetBaseUrl(URL base)Set base URL for relative include paths.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.voidsetName(String name)Set 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.IteratortopChildIterator()Get iterator for top-level child elements.ArrayListtopChildren()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, setStyleName, validate
-
Methods inherited from class org.jibx.binding.model.ElementBase
getComment, name, setComment, toString, type, validateAttributes
-
-
-
-
Field Detail
-
s_allowedAttributes
public static final StringArray s_allowedAttributes
Enumeration of allowed attribute names
-
IN_BINDING
public static final int IN_BINDING
- See Also:
- Constant Field Values
-
OUT_BINDING
public static final int OUT_BINDING
- See Also:
- Constant Field Values
-
BOTH_BINDING
public static final int BOTH_BINDING
- See Also:
- Constant Field Values
-
-
Method Detail
-
setName
public void setName(String name)
Set binding name.- Parameters:
name- binding definition name
-
getName
public String 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
public void setTargetPackage(String pack)
Set package for generated context factory class.- Parameters:
pack- generated context factory package (nullif unspecified)
-
getTargetPackage
public String getTargetPackage()
Get package for generated context factory class.- Returns:
- package for generated context factory (
nullif unspecified)
-
setBaseUrl
public void setBaseUrl(URL base)
Set base URL for relative include paths.- Parameters:
base- URL
-
getBaseUrl
public URL getBaseUrl()
Get base URL for relative include paths.- Returns:
- base URL
-
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- Precompiled flag
-
addIncludePath
public boolean addIncludePath(String path, boolean precomp)
Add include path to set processed.- Parameters:
path- Pathprecomp- precompiled binding flag- Returns:
trueif new path,falseif duplicate
-
getIncludeBinding
public BindingElement getIncludeBinding(URL url, BindingElement root, ValidationContext vctx) throws IOException, org.jibx.runtime.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 element
- Throws:
IOException- I/O errororg.jibx.runtime.JiBXException- Jibx error
-
getExistingIncludeBinding
public BindingElement getExistingIncludeBinding(URL url)
Get existing included binding.- Parameters:
url- binding path- Returns:
- binding if it exists, otherwise
null
-
addIncludeBinding
public void addIncludeBinding(String path, BindingElement bind)
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- Binding Element
-
addIdClass
public void addIdClass(IClass clas)
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
public boolean isIdClass(String name)
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
public void addTopChild(Object child)
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
public ArrayList topChildren()
Get list of top-level child elements.- Returns:
- list of child elements, or
nullif none
-
topChildIterator
public Iterator topChildIterator()
Get iterator for top-level child elements.- Returns:
- iterator for child elements
-
addNamespaceDecl
public void addNamespaceDecl(String prefix, String uri)
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
-
prevalidate
public void prevalidate(ValidationContext vctx)
Prevalidate all attributes of element in isolation.- Overrides:
prevalidatein classNestingElementBase- Parameters:
vctx- validation context
-
runValidation
public void runValidation(boolean full, ValidationContext vctx)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
public void runValidation(ValidationContext vctx)
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 org.jibx.runtime.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:
org.jibx.runtime.JiBXException- on error in reading binding
-
readBinding
public static BindingElement readBinding(InputStream is, String fname, ValidationContext vctx) throws org.jibx.runtime.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:
org.jibx.runtime.JiBXException- on error in reading binding
-
validateBinding
public static BindingElement validateBinding(String name, URL path, InputStream is, ValidationContext vctx) throws org.jibx.runtime.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:
org.jibx.runtime.JiBXException- on error in binding XML structure
-
newValidationContext
public static ValidationContext newValidationContext()
Create a default validation context.- Returns:
- new validation context
-
-