org.inria.ns.reflex.processor.asl.types
Class TypeAction

java.lang.Object
  extended by org.inria.ns.reflex.processor.core.AbstractAction
      extended by org.inria.ns.reflex.processor.asl.AbstractStepAction
          extended by org.inria.ns.reflex.processor.asl.types.TypeAction
All Implemented Interfaces:
NamedType, Type, Executable, Identifiable, Presentable, NamespaceContextFactory

public class TypeAction
extends AbstractStepAction
implements Type

TypeAction defines a data type exposed with the <asl:type> element.

A type definition may be named or anonymous.

A type definition may be based on another type.

At runtime, a type matcher backed by this type is feeding the context.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from class org.inria.ns.reflex.processor.asl.AbstractStepAction
AbstractStepAction.ItemsLists
 
Nested classes/interfaces inherited from class org.inria.ns.reflex.processor.core.AbstractAction
AbstractAction.ParameterAdapter, AbstractAction.UselessAction
 
Field Summary
 
Fields inherited from class org.inria.ns.reflex.processor.asl.AbstractStepAction
STEP_USED_BUBBLE_MESSAGE
 
Fields inherited from class org.inria.ns.reflex.processor.core.AbstractAction
actions, parent, processorInstance
 
Constructor Summary
TypeAction(QName name, QName base, Expression init, int ws, QName compareWith, QName parseWith, Element element, AbstractAction parent)
          Creates a new instance of TypeAction.
 
Method Summary
 CompositeData addToDataModel(TypedData typedData, QName name, Object value)
           
 TypedData cast(Object o, XPathContext ctxt)
          Cast an object to a typed data of this type.
 TypedData cast(Object o, XPathContext ctxt, boolean useParseWith)
          Cast an object to a typed data of this type.
 Comparator getComparator()
          Return the comparator.
 Schema getOwnerSchema()
          The schema instance that owns this definition.
 QName getParentType()
          Return either the base type if defined or xs:anySimpleType
 QName getTypeName()
          Return the name of this type.
 TypedData parse(TextCandidate tc, XPathContext ctxt)
          Parses a string to a data of this type.
 void runAction(DataSet dataSet)
          Feeds the context with this type.
static AbstractAction unmarshal(AbstractAction parent, Element element)
          XML unmarshaller for TypeAction.
 
Methods inherited from class org.inria.ns.reflex.processor.asl.AbstractStepAction
computeOccurs, getId, getMaxOccurs, getMinOccurs, invokeHandler, stableRun, unstableRun
 
Methods inherited from class org.inria.ns.reflex.processor.core.AbstractAction
addAction, addFallbackAction, createContext, getCanonicalPath, getFallbackAction, getLocalFallbackAction, getLogger, getNamespaceContext, getNode, getParent, recover, recover, removeFallbackAction, reorganize, run, runActions, toPrettyString, toPrettyString, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TypeAction

public TypeAction(QName name,
                  QName base,
                  Expression init,
                  int ws,
                  QName compareWith,
                  QName parseWith,
                  Element element,
                  AbstractAction parent)
Creates a new instance of TypeAction.

Parameters:
name - The name of the type, that can be null if the type is anonymous.
base - The type on which this type is based.
init - Used to initialize the typed data.
ws - Indicates how to process whitespace : -1=unspecified, 0=preserve (default), 1=replace, 2=collapse
compareWith - The XPath function used for comparison.
parseWith - The XPath function used for casting.
element - The element from which the action has been unmarshalled. Used for namespace prefix resolution when performing XPath expressions.
parent - The action depending from.
Method Detail

unmarshal

public static AbstractAction unmarshal(AbstractAction parent,
                                       Element element)
                                throws XMLException
XML unmarshaller for TypeAction.

Parameters:
parent - The action depending from.
element - The XML element to unmarshall.
Returns:
The TypeAction created.
Throws:
UnmarshalException - When the element and its content is not those expected.
XMLException

runAction

public void runAction(DataSet dataSet)
               throws ExecutionException,
                      XPathException
Feeds the context with this type.

Overrides:
runAction in class AbstractStepAction
Parameters:
dataSet - The set of datas used when the action is running.
Throws:
ExecutionException - If the action can't be performed.
XPathException

parse

public TypedData parse(TextCandidate tc,
                       XPathContext ctxt)
                throws TypeFormatException
Parses a string to a data of this type.

Specified by:
parse in interface Type
Parameters:
tc - The string to parse, as a text candidate.
ctxt - The context uses a variable resolver that can supply the data set and the schema client handler, and used to store the $asl:data property while parsing.
Returns:
The typed data.
Throws:
TypeFormatException - If the string is not of this type.
See Also:
org.inria.ns.reflex.processor.asl.types.Type#parse(String, XPathContext)

addToDataModel

public CompositeData addToDataModel(TypedData typedData,
                                    QName name,
                                    Object value)

cast

public TypedData cast(Object o,
                      XPathContext ctxt)
               throws TypeFormatException
Cast an object to a typed data of this type.

Specified by:
cast in interface Type
Parameters:
o - The object to cast.
ctxt - The XPath context used to perform the cast.
Returns:
A typed data of this type.
Throws:
TypeFormatException - When the input object is not of the type expected.
See Also:
Type.cast(Object, XPathContext)

cast

public TypedData cast(Object o,
                      XPathContext ctxt,
                      boolean useParseWith)
               throws TypeFormatException
Cast an object to a typed data of this type.

Parameters:
o - The object to cast.
ctxt - The XPath context used to perform the cast.
useParseWith - true indicates to use the XPath function given by the @parse-with attribute, false otherwise.
Returns:
A typed data of this type.
Throws:
TypeFormatException
See Also:
Type.cast(Object, XPathContext)

getTypeName

public QName getTypeName()
Return the name of this type.

Specified by:
getTypeName in interface NamedType
Returns:
The name of this type, that can be null is this type is anonymous.
See Also:
NamedType.getTypeName()

getOwnerSchema

public Schema getOwnerSchema()
The schema instance that owns this definition.

Specified by:
getOwnerSchema in interface Type
Returns:
The schema instance that owns this definition.

getComparator

public Comparator getComparator()
Return the comparator.

Specified by:
getComparator in interface Type
Returns:
A non-null comparator that may comparate datas of this type.
See Also:
Type.getComparator()

getParentType

public QName getParentType()
Return either the base type if defined or xs:anySimpleType

Specified by:
getParentType in interface Type
Parameters:
The - parent type.
Returns:
The non-null type name.