schema2template.model
Class PuzzlePieceSet

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

public class PuzzlePieceSet
extends Object
implements QNamedPuzzleComponent, Collection<PuzzlePiece>

Collection Class for RelaxNG definitions of an Element, Attribute, Value or Datatype.

Conventions:


Constructor Summary
PuzzlePieceSet()
           
PuzzlePieceSet(Collection<PuzzlePiece> c)
           
 
Method Summary
 boolean add(PuzzlePiece e)
           
 boolean addAll(Collection<? extends PuzzlePiece> c)
           
 PuzzlePieceSet byParent(QNamedPuzzleComponent parents)
          Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but only those which have at least one element from the QNamedPuzzleComponent parameter as one of their parent Definitions.
 boolean canHaveText()
          Determines whether the Definitions can have text - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name.
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection<?> c)
           
 boolean containsName(QNamed aNamed)
          Check whether this List contains an Element by this Name
 boolean containsName(String aDefinitionName)
          Check whether this List contains an Element by this Name
 boolean equals(Object o)
           
 PuzzlePieceSet getAttributes()
          ELEMENT PuzzlePiece only: Get all attribute Definitions
 PuzzlePieceSet getChildElements()
          ELEMENT PuzzlePiece only: Get all child element Definitions
 Collection<PuzzlePiece> getCollection()
          Method to treat NamedDefined as a Collection of PuzzlePiece
 PuzzlePieceSet getDatatypes()
          ATTRIBUTE PuzzlePiece only: Get all datatype Definitions
 String getLocalName()
          Get only localname
 String getNamespace()
          Get only namespace
 PuzzlePieceSet getParents()
          Get all parent Definitions
 String getQName()
          Gets the ns:local tag name of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions share the same tag name.
 MSVExpressionType getType()
          Gets the type of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name.
 PuzzlePieceSet getValues()
          ATTRIBUTE PuzzlePiece only: Get all value Definitions
 int hashCode()
           
 boolean isEmpty()
           
 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.
 Iterator<PuzzlePiece> iterator()
           
 void makeImmutable()
          Make PuzzlePieceSet immutable.
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 boolean retainAll(Collection<?> c)
           
 int size()
           
 Object[] toArray()
           
<T> T[]
toArray(T[] a)
           
 String toString()
          Returns String representation (convenient method for getQName())
 PuzzlePieceSet without(QNamedPuzzleComponent removeAll)
          Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but without the elements of the parameter removeAll
 PuzzlePieceSet withoutMultiples()
          Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but restricted to one PuzzlePiece per Name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PuzzlePieceSet

public PuzzlePieceSet()

PuzzlePieceSet

public PuzzlePieceSet(Collection<PuzzlePiece> c)
Method Detail

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<PuzzlePiece>
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<PuzzlePiece>
Overrides:
hashCode in class Object

makeImmutable

public void makeImmutable()
Make PuzzlePieceSet immutable. Cannot be undone. Template Usage: Not for use in templates as all PuzzlePieceSet already have been made immutable.


withoutMultiples

public PuzzlePieceSet withoutMultiples()

Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but restricted to one PuzzlePiece per Name.

Template Usage: #foreach ($element in $elements.withoutMultiples())

Returns:
new PuzzlePieceSet

without

public PuzzlePieceSet without(QNamedPuzzleComponent removeAll)

Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but without the elements of the parameter removeAll

Template Usage: #set ($non_base_attributes = $element.getAttributes().without($baseclass.getAttributes())

Parameters:
removeAll - QNamedPuzzleComponent which (or which elements) should be removed from the new PuzzlePieceSet
Returns:
new PuzzlePieceSet

byParent

public PuzzlePieceSet byParent(QNamedPuzzleComponent parents)
Returns new PuzzlePieceSet containing the elements of this PuzzlePieceSet, but only those which have at least one element from the QNamedPuzzleComponent parameter as one of their parent Definitions.

Template Usage: Imagine we have one attribute name and we're not interested in the differences between Definitions sharing the same name. We're now printing the resulting allowed attribute values for each parent element name:


#set ( $oneOrMoreAttributes = $model.getAttribute($atttributename) )
## we want to write information about only _one_ parent per Name...
#foreach ($parent in $oneOrMoreAttributes.getParents().withoutMultiples())
- Allowed Values for Parent Element $parent :
## but we want the attribute values displayed which are allowed in _all_ parents with the same Name...
#foreach ($value in $oneOrMoreAttributes.byParent($parent.withMultiples()).getValues())
-- "$value"
#end
#end

Parameters:
parents -
Returns:
new PuzzlePieceSet

containsName

public boolean containsName(String aDefinitionName)
Check whether this List contains an Element by this Name

Parameters:
aDefinitionName -
Returns:
True if an element by this name exists

containsName

public boolean containsName(QNamed aNamed)
Check whether this List contains an Element by this Name

Parameters:
aNamed -
Returns:
True if an element by this name exists

getQName

public String getQName()
Gets the ns:local tag name of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions share the same tag name. Throws Exception otherwise.

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

getType

public MSVExpressionType getType()
Gets the type of the Definitions - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name. Throws Exception otherwise.

Specified by:
getType in interface PuzzleComponent
Returns:
The type of this PuzzleComponent

canHaveText

public boolean canHaveText()
Determines whether the Definitions can have text - provided that this PuzzlePieceSet is not empty and all Definitions have the same type and name. Throws Exception otherwise.

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.

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 $aDefinitionSet as you would use a string variable

Overrides:
toString in class Object

add

public boolean add(PuzzlePiece e)
Specified by:
add in interface Collection<PuzzlePiece>

addAll

public boolean addAll(Collection<? extends PuzzlePiece> c)
Specified by:
addAll in interface Collection<PuzzlePiece>

clear

public void clear()
Specified by:
clear in interface Collection<PuzzlePiece>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<PuzzlePiece>

containsAll

public boolean containsAll(Collection<?> c)
Specified by:
containsAll in interface Collection<PuzzlePiece>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<PuzzlePiece>

iterator

public Iterator<PuzzlePiece> iterator()
Specified by:
iterator in interface Iterable<PuzzlePiece>
Specified by:
iterator in interface Collection<PuzzlePiece>

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<PuzzlePiece>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<PuzzlePiece>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<PuzzlePiece>

size

public int size()
Specified by:
size in interface Collection<PuzzlePiece>

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection<PuzzlePiece>

toArray

public <T> T[] toArray(T[] a)
Specified by:
toArray in interface Collection<PuzzlePiece>

getChildElements

public PuzzlePieceSet getChildElements()
Description copied from interface: PuzzleComponent
ELEMENT PuzzlePiece only: Get all child element Definitions

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

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.

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

getAttributes

public PuzzlePieceSet getAttributes()
Description copied from interface: PuzzleComponent
ELEMENT PuzzlePiece only: Get all attribute Definitions

Specified by:
getAttributes in interface PuzzleComponent
Returns:
The attribute Definitions of this PuzzleComponent

getDatatypes

public PuzzlePieceSet getDatatypes()
Description copied from interface: PuzzleComponent
ATTRIBUTE PuzzlePiece only: Get all datatype Definitions

Specified by:
getDatatypes in interface PuzzleComponent
Returns:
The datatype Definitions of this PuzzleComponent

getParents

public PuzzlePieceSet getParents()
Description copied from interface: PuzzleComponent
Get all parent Definitions

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

getValues

public PuzzlePieceSet getValues()
Description copied from interface: PuzzleComponent
ATTRIBUTE PuzzlePiece only: Get all value Definitions

Specified by:
getValues in interface PuzzleComponent
Returns:
The constant value Definitions of this PuzzleComponent


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