org.quattor.pan.type
Class Type

java.lang.Object
  extended by org.quattor.pan.type.Type
Direct Known Subclasses:
BaseType, FullType

public abstract class Type
extends java.lang.Object

Common superclass for all pan language types defining the required methods.

Author:
loomis

Field Summary
protected  java.lang.String source
           
protected  java.lang.String sourceRange
           
 
Constructor Summary
Type(java.lang.String source, SourceRange sourceRange)
           
 
Method Summary
abstract  Element findDefault(Context context)
          This method returns the default value for the type or null if no default value exists.
 java.lang.String getSource()
          Return a string representation of the source containing this type.
 java.lang.String getSourceRange()
          Retrieve the SourceRange for this type definition.
abstract  Element setDefaults(Context context, Element self)
          This method will recursively set the default values on the given element.
 java.lang.String toString()
           
abstract  void validate(Context context, Element self)
          This method will run this type's validation against the given element.
 void validateAsIncludedType(Context context, Element self)
          This method will run this type's validation (as an included type) against the given element.
abstract  void verifySubtypesDefined(TypeMap types)
          This method verifies that all of the types referenced from this type are already defined within the given context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

source

protected final java.lang.String source

sourceRange

protected final java.lang.String sourceRange
Constructor Detail

Type

public Type(java.lang.String source,
            SourceRange sourceRange)
Method Detail

verifySubtypesDefined

public abstract void verifySubtypesDefined(TypeMap types)
                                    throws EvaluationException
This method verifies that all of the types referenced from this type are already defined within the given context. If not, an EvaluationException will be thrown.

Parameters:
types - TypeMap to use for looking up referenced types
Throws:
EvaluationException

validate

public abstract void validate(Context context,
                              Element self)
                       throws ValidationException
This method will run this type's validation against the given element. The method may not modify either argument.

Parameters:
context - ObjectContext for running the validation
self - Element to validate
Throws:
ValidationException

validateAsIncludedType

public void validateAsIncludedType(Context context,
                                   Element self)
                            throws ValidationException
This method will run this type's validation (as an included type) against the given element. This is separated from the usual validate() method because the validation may be different when the type is included rather than referenced directly. This is the case for the RecordType. The default implementation of this method simply throws a ValidationException indicating that it cannot be the target of the type include statement.

Parameters:
context - ObjectContext for running the validation
self - Element to validate
Throws:
ValidationException

setDefaults

public abstract Element setDefaults(Context context,
                                    Element self)
                             throws EvaluationException
This method will recursively set the default values on the given element. Note that self cannot be null. If the current element is null, then use the findDefault() method to retrieve the default value, set it, and then call this method to descend into referenced type definitions. This method will return a replacement element if necessary. This may be the case self was protected and default values had to be added. This method will return null if no replacement was necessary. It is the caller's responsibility to make the appropriate update to the parent element.

Parameters:
context -
self -
Returns:
replacement element or null if no replacement is necessary
Throws:
EvaluationException

findDefault

public abstract Element findDefault(Context context)
This method returns the default value for the type or null if no default value exists. While only FullType objects can directly have a default value, these can be referenced by other types like AliasType and RecordType.

Parameters:
context - the context may be needed by a complex type to look up other type definitions
Returns:
default value or null if one doesn't exist

getSource

public java.lang.String getSource()
Return a string representation of the source containing this type. If the source wasn't set at creation this returns the string "".

Returns:
String source containing this type

getSourceRange

public java.lang.String getSourceRange()
Retrieve the SourceRange for this type definition. If the location was not defined at creation this returns the string "".

Returns:
String location of this type definition

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2011 Quattor. All Rights Reserved.