schema2template.model
public class PuzzlePiece extends Object implements Comparable<PuzzlePiece>, QNamedPuzzleComponent
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:
Modifier and Type | Method and Description |
---|---|
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.
|
public boolean equals(Object b)
public int hashCode()
public int compareTo(PuzzlePiece o)
compareTo
in interface Comparable<PuzzlePiece>
o
- Other Objectprotected boolean contentEquals(PuzzlePiece other)
public String getQName()
public String getLocalName()
QNamed
getLocalName
in interface QNamed
public String getNamespace()
QNamed
getNamespace
in interface QNamed
public String toString()
Returns String representation (convenient method for getQName())
Template Usage: Just use $aDefinition as you would use a string variable.
public MSVExpressionType getType()
getType
in interface PuzzleComponent
public com.sun.msv.grammar.Expression getExpression()
public boolean canHaveText()
canHaveText
in interface PuzzleComponent
public boolean isSingleton(PuzzleComponent child)
PuzzleComponent
isSingleton
in interface PuzzleComponent
child
- PuzzleComponent childpublic Collection<PuzzlePiece> getCollection()
PuzzleComponent
getCollection
in interface PuzzleComponent
public PuzzlePieceSet withMultiples()
public int getMultipleNumber()
public PuzzlePieceSet getParents()
getParents
in interface PuzzleComponent
public PuzzlePieceSet getChildElements()
getChildElements
in interface PuzzleComponent
public boolean isMandatory(QNamedPuzzleComponent child)
QNamedPuzzleComponent
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'.
isMandatory
in interface QNamedPuzzleComponent
child
- The child Definition(s) of type ELEMENT or ATTRIBUTEpublic PuzzlePieceSet getAttributes()
getAttributes
in interface PuzzleComponent
public PuzzlePieceSet getValues()
getValues
in interface PuzzleComponent
public PuzzlePieceSet getDatatypes()
getDatatypes
in interface PuzzleComponent
public static void extractPuzzlePieces(com.sun.msv.grammar.Expression root, PuzzlePieceSet newElementSet, PuzzlePieceSet newAttributeSet)
root
- MSV root ExpressionnewElementSet
- empty Set. Will be filled with Definitions of Type.ELEMENTnewAttributeSet
- empty Set. Will be filled with Definitions of Type.ATTRIBUTECopyright © 2010-2014 The Apache Software Foundation. All Rights Reserved.