Class PuzzlePiece
- java.lang.Object
-
- 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:
- hashCode uses the hashCode from the encapsulated Expressions. So two Definitions (rarely) can have the same hashCode. Equals uses Name _and_ hashCode.
- Sorting is done by ns:local tag names as first key and hashCode as second key.
- All returned PuzzlePieceSet objects are immutable to protect them against naive usage in velocity templates
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canHaveText()
Determines whether this Element can have a text node as childint
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, String schemaFileName)
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 PuzzlePiecePuzzlePieceSet
getDatatypes()
Gets the defined datatypes.com.sun.msv.grammar.Expression
getExpression()
Gets the wrapped ExpressionString
getLocalName()
Get only localnameint
getMultipleNumber()
Gets the index of 'this' in the List of Definitions returned by withMultiples()String
getNamespace()
Get only namespacePuzzlePieceSet
getParents()
Gets the Parents which can contain this PuzzlePiece as a childString
getQName()
Gets the ns:local tag name of this PuzzlePieceMSVExpressionType
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)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.
-
-
-
Method Detail
-
equals
public boolean equals(Object b)
Uses the name and the wrapped MSV Expression to test for equality.
-
hashCode
public int hashCode()
Uses the wrapped MSV Expression for the hashCode. MSV Expressions are numbered consecutively by a distinct Hash Code.
-
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 interfaceComparable<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
-
getLocalName
public String getLocalName()
Description copied from interface:QNamed
Get only localname- Specified by:
getLocalName
in interfaceQNamed
- Returns:
- localname
-
getNamespace
public String getNamespace()
Description copied from interface:QNamed
Get only namespace- Specified by:
getNamespace
in interfaceQNamed
- 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.
-
getType
public MSVExpressionType getType()
Gets the type of this (ELEMENT, ATTRIBUTE, DATA, VALUE)- Specified by:
getType
in interfacePuzzleComponent
- 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 interfacePuzzleComponent
- 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 interfacePuzzleComponent
- 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 interfacePuzzleComponent
- 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 interfacePuzzleComponent
- 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 interfacePuzzleComponent
- 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 interfaceQNamedPuzzleComponent
- 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 interfacePuzzleComponent
- 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 interfacePuzzleComponent
- 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 interfacePuzzleComponent
- Returns:
- The datatypes
-
extractPuzzlePieces
public static void extractPuzzlePieces(com.sun.msv.grammar.Expression root, PuzzlePieceSet newElementSet, PuzzlePieceSet newAttributeSet, String schemaFileName)
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 ExpressionnewElementSet
- empty Set. Will be filled with Definitions of Type.ELEMENTnewAttributeSet
- empty Set. Will be filled with Definitions of Type.ATTRIBUTE
-
-