org.jibx.schema.codegen.custom
Class ComponentExtension

java.lang.Object
  extended by org.jibx.schema.codegen.custom.BaseExtension
      extended by org.jibx.schema.codegen.custom.ComponentExtension
Direct Known Subclasses:
GlobalExtension

public class ComponentExtension
extends BaseExtension

Extension information for all schema components other than the schema element itself. This is the basic extension which associates schema components with values or classes for code generation.

Author:
Dennis M. Sosnoski

Field Summary
private  ComponentCustom m_custom
          Customization information for this component.
private  GlobalExtension m_global
          Containing global definition extension.
private  boolean m_optional
          Optional component flag.
private  QName m_overrideType
          Override for type specified in schema (null if none).
private  boolean m_removed
          Component dropped from schema definition.
private  boolean m_repeated
          Repeated component flag.
private  boolean m_separateClass
          Class to be generated for component flag.
private  int m_useCount
          Number of times a component is used in code generation.
private static org.apache.log4j.Logger s_logger
          Logger for class.
 
Fields inherited from class org.jibx.schema.codegen.custom.BaseExtension
ARITY_OPTIONAL_COLLECTION, ARITY_OPTIONAL_SINGLETON, ARITY_REQUIRED_COLLECTION, ARITY_REQUIRED_SINGLETON
 
Constructor Summary
ComponentExtension(OpenAttrBase comp, GlobalExtension global)
          Constructor.
 
Method Summary
 void applyAndCountUsage(ValidationContext vctx)
          Apply extensions to schema definition component, deleting components flagged for skipping and substituting types as configured.
private  boolean checkReference(OpenAttrBase comp)
          Check a reference to a component.
 int getAnyType()
          Get the xs:any handling type code to be applied for this component.
 java.lang.String getBaseName()
          Get base name for corresponding property.
 int getChoiceType()
          Get the xs:choice handling type code to be applied for this component.
 java.lang.String getClassName()
          Get name to be used for generated class.
private  NestingCustomBase getContainingCustom()
          Get the innermost customization which applies to this component.
(package private)  ComponentCustom getCustom()
          Get customization information for this component.
 GlobalExtension getGlobal()
          Get the containing global extension.
 QName getOverrideType()
          Get override type.
 int getUnionType()
          Get the xs:union handling type code to be applied for this component.
 int getUseCount()
          Get the use count for the component.
 int incrementUseCount()
          Increment the use count for the component.
 boolean isChoiceExposed()
          Check if xs:choice selection state should be exposed for this component.
 boolean isIgnored()
          Check if component is to be ignored.
 boolean isOptional()
          Check if optional component.
 boolean isRemoved()
          Check if component to be removed from schema.
 boolean isRepeated()
          Check if repeated component.
 boolean isSeparateClass()
          Check if class to be generated for component.
 boolean isUnionExposed()
          Check if xs:union selection state should be exposed for this component.
protected  boolean normalize(int depth)
          Normalize the child schema definition.
private  void removeChild(int index)
          Remove a child element.
private  QName replaceAndReference(QName type, ValidationContext vctx)
          Check for type substitution on a type reference, then record the reference.
(package private)  void setCustom(ComponentCustom custom)
          Set customization information for this component.
 void setOptional(boolean optional)
          Set optional component.
 void setOverrideType(QName qname)
          Set override type.
 void setRemoved(boolean removed)
          Set flag for component to be removed from schema.
 void setRepeated(boolean repeated)
          Set repeated component.
 void setSeparateClass(boolean generate)
          Set class to be generated for component.
private  boolean substituteTypeDerivation(java.lang.String lead, OpenAttrBase topcomp, OpenAttrBase childcomp, CommonTypeDerivation derive)
          Try to replace type definition with substitute type from derivation.
 
Methods inherited from class org.jibx.schema.codegen.custom.BaseExtension
getComponent, getReplacementType, setTypeReplacer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_logger

private static final org.apache.log4j.Logger s_logger
Logger for class.


m_removed

private boolean m_removed
Component dropped from schema definition.


m_separateClass

private boolean m_separateClass
Class to be generated for component flag.


m_optional

private boolean m_optional
Optional component flag.


m_repeated

private boolean m_repeated
Repeated component flag.


m_global

private final GlobalExtension m_global
Containing global definition extension.


m_custom

private ComponentCustom m_custom
Customization information for this component.


m_overrideType

private QName m_overrideType
Override for type specified in schema (null if none).


m_useCount

private int m_useCount
Number of times a component is used in code generation.

Constructor Detail

ComponentExtension

public ComponentExtension(OpenAttrBase comp,
                          GlobalExtension global)
Constructor.

Parameters:
comp -
global - containing global definition extension (null allowed only as special case when calling this constructor from the global extension subclass constructor)
Method Detail

isRemoved

public boolean isRemoved()
Check if component to be removed from schema.

Returns:
removed flag

setRemoved

public void setRemoved(boolean removed)
Set flag for component to be removed from schema.

Parameters:
removed -

isIgnored

public boolean isIgnored()
Check if component is to be ignored.

Returns:
ignored flag

isOptional

public boolean isOptional()
Check if optional component.

Returns:
optional

setOptional

public void setOptional(boolean optional)
Set optional component.

Parameters:
optional -

isRepeated

public boolean isRepeated()
Check if repeated component.

Returns:
repeated

setRepeated

public void setRepeated(boolean repeated)
Set repeated component.

Parameters:
repeated -

isSeparateClass

public boolean isSeparateClass()
Check if class to be generated for component.

Returns:
generate

setSeparateClass

public void setSeparateClass(boolean generate)
Set class to be generated for component.

Parameters:
generate - true if class generated, false if not

getGlobal

public GlobalExtension getGlobal()
Get the containing global extension.

Returns:
global

getOverrideType

public QName getOverrideType()
Get override type.

Returns:
type name (null if none)

setOverrideType

public void setOverrideType(QName qname)
Set override type.

Parameters:
qname - type name (null if none)

incrementUseCount

public int incrementUseCount()
Increment the use count for the component.

Returns:
incremented use count

getUseCount

public int getUseCount()
Get the use count for the component.

Returns:
use count

getClassName

public java.lang.String getClassName()
Get name to be used for generated class.

Returns:
class name (null if not set)

getBaseName

public java.lang.String getBaseName()
Get base name for corresponding property.

Returns:
property name (null if not set)

getCustom

ComponentCustom getCustom()
Get customization information for this component.

Returns:
custom

setCustom

void setCustom(ComponentCustom custom)
Set customization information for this component.

Parameters:
custom -

getContainingCustom

private NestingCustomBase getContainingCustom()
Get the innermost customization which applies to this component.

Returns:
customization

getAnyType

public int getAnyType()
Get the xs:any handling type code to be applied for this component. The default value is NestingCustomBase.ANY_DOM if not overridden at any level.

Returns:
code

getChoiceType

public int getChoiceType()
Get the xs:choice handling type code to be applied for this component. The default value is NestingCustomBase.SELECTION_CHECKEDSET if not overridden at any level.

Returns:
code

isChoiceExposed

public boolean isChoiceExposed()
Check if xs:choice selection state should be exposed for this component.

Returns:
exposed flag

getUnionType

public int getUnionType()
Get the xs:union handling type code to be applied for this component. The default value is NestingCustomBase.SELECTION_CHECKEDSET if not overridden at any level.

Returns:
code

isUnionExposed

public boolean isUnionExposed()
Check if xs:union selection state should be exposed for this component.

Returns:
exposed flag

replaceAndReference

private QName replaceAndReference(QName type,
                                  ValidationContext vctx)
Check for type substitution on a type reference, then record the reference. TODO: how to handle substitutions across namespaces? the problem here is that the returned name needs to be correct in the use context, which may be using a different namespace for the same definition (due to includes of no-namespace schemas into a namespaced schema). the current code is only an interim fix that will not always work

Parameters:
type - original type
vctx - validation context
Returns:
replacement type (may be the same as the original type; null if to be deleted)

checkReference

private boolean checkReference(OpenAttrBase comp)
Check a reference to a component. If the reference component has been deleted this just returns false. If the component has not been deleted it counts the reference on that component, and records the dependency from this component before returning true. For convenience, this may be called with a null argument, which just returns true.

Parameters:
comp - component (call ignored if null)
Returns:
true if reference to be kept, false if deleted

removeChild

private void removeChild(int index)
Remove a child element. This checks to make sure the removal is valid, and also handles logging of the change.

Parameters:
index -

applyAndCountUsage

public void applyAndCountUsage(ValidationContext vctx)
Apply extensions to schema definition component, deleting components flagged for skipping and substituting types as configured. This code is not intended to handle the deletion of global definition components, which should be removed separately.

Parameters:
vctx - validation context

substituteTypeDerivation

private boolean substituteTypeDerivation(java.lang.String lead,
                                         OpenAttrBase topcomp,
                                         OpenAttrBase childcomp,
                                         CommonTypeDerivation derive)
Try to replace type definition with substitute type from derivation. If

Parameters:
lead - prefix text for indentation of logging messages
topcomp - schema component being normalized
childcomp - current child of schema component being normalized
derive - type derivation supplying substitute type
Returns:
true if type modified, false if not

normalize

protected boolean normalize(int depth)
Normalize the child schema definition. This recursively traverses the schema model tree rooted in the component associated with this extension, normalizing each child component. TODO: handle revalidation for changed subtrees

Parameters:
depth - nesting depth for validation
Returns:
true if any part of tree under this component modified, false if not


Project Web Site