schema2template.model
Class PuzzlePiece

java.lang.Object
  extended by schema2template.model.PuzzlePiece
All Implemented Interfaces:
Comparable<PuzzlePiece>, PuzzleComponent, QNamed, QNamedPuzzleComponent

public class PuzzlePiece
extends Object
implements Comparable<PuzzlePiece>, QNamedPuzzleComponent

One of the following RelaxNG definitions of an Element, Attribute, Value or Datatype.

Each PuzzlePiece encapsulates one MSV Expression. Two PuzzlePiece can share the same MSV Expression (RelaxNG pattern: <element><choice><name>aName</name><name>anotherName</name></choice></element>)

Conventions:


Method Summary
 boolean canHaveText()
          Determines whether this Element can have a text node as child
 int compareTo(PuzzlePiece o)
          Uses the ns:local name of the wrapped MSV Expression as first key and the hashCode as second key.
protected  boolean contentEquals(PuzzlePiece other)
           
 boolean equals(Object b)
          Uses the name and the wrapped MSV Expression to test for equality.
static void extractPuzzlePieces(com.sun.msv.grammar.Expression root, PuzzlePieceSet newElementSet, PuzzlePieceSet newAttributeSet)
          Creates all PuzzlePiece objects from MSV root tree.
 PuzzlePieceSet getAttributes()
          Gets the Attributes of this PuzzlePiece.
 PuzzlePieceSet getChildElements()
          Gets the child elements of this PuzzlePiece.
 Collection<PuzzlePiece> getCollection()
          Method to treat NamedDefined as a Collection of PuzzlePiece
 PuzzlePieceSet getDatatypes()
          Gets the defined datatypes.
 com.sun.msv.grammar.Expression getExpression()
          Gets the wrapped Expression
 String getLocalName()
          Get only localname
 int getMultipleNumber()
          Gets the index of 'this' in the List of Definitions returned by withMultiples()
 String getNamespace()
          Get only namespace
 PuzzlePieceSet getParents()
          Gets the Parents which can contain this PuzzlePiece as a child
 String getQName()
          Gets the ns:local tag name of this PuzzlePiece
 MSVExpressionType getType()
          Gets the type of this (ELEMENT, ATTRIBUTE, DATA, VALUE)
 PuzzlePieceSet getValues()
          Gets the defined constant values.
 int hashCode()
          Uses the wrapped MSV Expression for the hashCode.
 boolean isMandatory(QNamedPuzzleComponent child)
          ELEMENT Definition only: Determine solely by child type and name whether child is mandatory.
 boolean isSingleton(PuzzleComponent child)
          Determines whether the child PuzzlePiece(s) is/are singleton(s) Convention: If child is a collection this method returns false if one child element is no singleton.
 String toString()
          Returns String representation (convenient method for getQName())
 PuzzlePieceSet withMultiples()
          Gets the List of Definitions which share the same tag name, but are defined multiple times in the schema.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

equals

public boolean equals(Object b)
Uses the name and the wrapped MSV Expression to test for equality.

Overrides:
equals in class Object
Parameters:
b - Another object
Returns:
Whether both objects equal

hashCode

public int hashCode()
Uses the wrapped MSV Expression for the hashCode. MSV Expressions are numbered consecutively by a distinct Hash Code.

Overrides:
hashCode in class Object

compareTo

public int compareTo(PuzzlePiece o)
Uses the ns:local name of the wrapped MSV Expression as first key and the hashCode as second key. If o1.equals(o2) this method will return 0 (since both must share the same Expression and name).

Specified by:
compareTo in interface Comparable<PuzzlePiece>
Parameters:
o - Other Object
Returns:
Comparison

contentEquals

protected boolean contentEquals(PuzzlePiece other)

getQName

public String getQName()
Gets the ns:local tag name of this PuzzlePiece

Specified by:
getQName in interface QNamed
Returns:
The tag name

getLocalName

public String getLocalName()
Description copied from interface: QNamed
Get only localname

Specified by:
getLocalName in interface QNamed
Returns:
localname

getNamespace

public String getNamespace()
Description copied from interface: QNamed
Get only namespace

Specified by:
getNamespace in interface QNamed
Returns:
namespace

toString

public String toString()

Returns String representation (convenient method for getQName())

Template Usage: Just use $aDefinition as you would use a string variable.

Overrides:
toString in class Object

getType

public MSVExpressionType getType()
Gets the type of this (ELEMENT, ATTRIBUTE, DATA, VALUE)

Specified by:
getType in interface PuzzleComponent
Returns:
The ExpressionType of this PuzzlePiece

getExpression

public com.sun.msv.grammar.Expression getExpression()
Gets the wrapped Expression

Returns:
The Expression wrapped by this.

canHaveText

public boolean canHaveText()
Determines whether this Element can have a text node as child

Specified by:
canHaveText in interface PuzzleComponent
Returns:
True if a text node is allowed, false otherwise

isSingleton

public boolean isSingleton(PuzzleComponent child)
Description copied from interface: PuzzleComponent
Determines whether the child PuzzlePiece(s) is/are singleton(s) Convention: If child is a collection this method returns false if one child element is no singleton. If this is a collection this method returns false if child is no singleton for one element of this.

Specified by:
isSingleton in interface PuzzleComponent
Parameters:
child - PuzzleComponent child
Returns:
True if child is defined as Singleton, falso otherwise.

getCollection

public Collection<PuzzlePiece> getCollection()
Description copied from interface: PuzzleComponent
Method to treat NamedDefined as a Collection of PuzzlePiece

Specified by:
getCollection in interface PuzzleComponent
Returns:
Collection of PuzzlePiece objects

withMultiples

public PuzzlePieceSet withMultiples()
Gets the List of Definitions which share the same tag name, but are defined multiple times in the schema. The list is type specific, i.e. an ATTRIBUTE can never be a multiple of an ELEMENT.

Returns:
The list of Definitions which share the same tag name.

getMultipleNumber

public int getMultipleNumber()
Gets the index of 'this' in the List of Definitions returned by withMultiples()

Returns:
Index of this PuzzlePiece object in the PuzzlePieceSet returned by withMultiples()

getParents

public PuzzlePieceSet getParents()
Gets the Parents which can contain this PuzzlePiece as a child

Specified by:
getParents in interface PuzzleComponent
Returns:
The parent Definitions

getChildElements

public PuzzlePieceSet getChildElements()
Gets the child elements of this PuzzlePiece. Please note that only Definitions of type ELEMENT can have child elements.

Specified by:
getChildElements in interface PuzzleComponent
Returns:
The child Definitions of type ELEMENT

isMandatory

public boolean isMandatory(QNamedPuzzleComponent child)
Description copied from interface: QNamedPuzzleComponent
ELEMENT Definition only: Determine solely by child type and name whether child is mandatory.

Here's why we're not using the child Definition object(s) for this: An element often has a mandatory attribute, but two (or more) different content definitions for this attribute. This is done by defining this attribute twice and creating a CHOICE between both Definitions. If you'd ask whether one of these definitions is mandatory, you'd always get false as answer as you have the choice between the two definitions. Mostly this is not the answer you're looking for.

Contract: If 'this' is a Collection, mandatory means mandatory for one member of 'this'.

Specified by:
isMandatory in interface QNamedPuzzleComponent
Parameters:
child - The child Definition(s) of type ELEMENT or ATTRIBUTE
Returns:
true if child is a defined child of this and if it's mandatory. False otherwise.

getAttributes

public PuzzlePieceSet getAttributes()
Gets the Attributes of this PuzzlePiece. Please note that only Definitions of type ELEMENT can have attributes.

Specified by:
getAttributes in interface PuzzleComponent
Returns:
The child Definitions of type ATTRIBUTE

getValues

public PuzzlePieceSet getValues()
Gets the defined constant values. Please note that only Definitions of type ATTRIBUTE can have values.

Specified by:
getValues in interface PuzzleComponent
Returns:
The constant values

getDatatypes

public PuzzlePieceSet getDatatypes()
Gets the defined datatypes. Please note that only Definitions of type ATTRIBUTE can have datatypes.

Specified by:
getDatatypes in interface PuzzleComponent
Returns:
The datatypes

extractPuzzlePieces

public static void extractPuzzlePieces(com.sun.msv.grammar.Expression root,
                                       PuzzlePieceSet newElementSet,
                                       PuzzlePieceSet newAttributeSet)
Creates all PuzzlePiece objects from MSV root tree. The PuzzlePiece objects are all made immutable to protect them against changes by naive template usage. Note that the Sets of all elements/attributes can only be made immutable by the caller after this method run.

Parameters:
root - MSV root Expression
newElementSet - empty Set. Will be filled with Definitions of Type.ELEMENT
newAttributeSet - empty Set. Will be filled with Definitions of Type.ATTRIBUTE


Copyright © 2010-2011 The Apache Software Foundation. All Rights Reserved.