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 booleancanHaveText()Determines whether this Element can have a text node as childintcompareTo(PuzzlePiece o)Uses the ns:local name of the wrapped MSV Expression as first key and the hashCode as second key.protected booleancontentEquals(PuzzlePiece other)booleanequals(Object b)Uses the name and the wrapped MSV Expression to test for equality.static voidextractPuzzlePieces(com.sun.msv.grammar.Expression root, PuzzlePieceSet newElementSet, PuzzlePieceSet newAttributeSet, String schemaFileName)Creates all PuzzlePiece objects from MSV root tree.PuzzlePieceSetgetAttributes()Gets the Attributes of this PuzzlePiece.PuzzlePieceSetgetChildElements()Gets the child elements of this PuzzlePiece.Collection<PuzzlePiece>getCollection()Method to treat NamedDefined as a Collection of PuzzlePiecePuzzlePieceSetgetDatatypes()Gets the defined datatypes.com.sun.msv.grammar.ExpressiongetExpression()Gets the wrapped ExpressionStringgetLocalName()Get only localnameintgetMultipleNumber()Gets the index of 'this' in the List of Definitions returned by withMultiples()StringgetNamespace()Get only namespacePuzzlePieceSetgetParents()Gets the Parents which can contain this PuzzlePiece as a childStringgetQName()Gets the ns:local tag name of this PuzzlePieceMSVExpressionTypegetType()Gets the type of this (ELEMENT, ATTRIBUTE, DATA, VALUE)PuzzlePieceSetgetValues()Gets the defined constant values.inthashCode()Uses the wrapped MSV Expression for the hashCode.booleanisMandatory(QNamedPuzzleComponent child)ELEMENT Definition only: Determine solely by child type and name whether child is mandatory.booleanisSingleton(PuzzleComponent child)Determines whether the child PuzzlePiece(s) is/are singleton(s)StringtoString()Returns String representation (convenient method for getQName())PuzzlePieceSetwithMultiples()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:
compareToin 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:QNamedGet only localname- Specified by:
getLocalNamein interfaceQNamed- Returns:
- localname
-
getNamespace
public String getNamespace()
Description copied from interface:QNamedGet only namespace- Specified by:
getNamespacein 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:
getTypein 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:
canHaveTextin interfacePuzzleComponent- Returns:
- True if a text node is allowed, false otherwise
-
isSingleton
public boolean isSingleton(PuzzleComponent child)
Description copied from interface:PuzzleComponentDetermines 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:
isSingletonin interfacePuzzleComponent- Parameters:
child- PuzzleComponent child- Returns:
- True if child is defined as Singleton, falso otherwise.
-
getCollection
public Collection<PuzzlePiece> getCollection()
Description copied from interface:PuzzleComponentMethod to treat NamedDefined as a Collection of PuzzlePiece- Specified by:
getCollectionin 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:
getParentsin 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:
getChildElementsin interfacePuzzleComponent- Returns:
- The child Definitions of type ELEMENT
-
isMandatory
public boolean isMandatory(QNamedPuzzleComponent child)
Description copied from interface:QNamedPuzzleComponentELEMENT 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:
isMandatoryin 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:
getAttributesin 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:
getValuesin 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:
getDatatypesin 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
-
-