Class CompositorGuard

java.lang.Object
org.dlese.dpc.xml.schema.compositor.CompositorGuard
Direct Known Subclasses:
AllGuard, ChoiceGuard, SequenceGuard

public abstract class CompositorGuard extends Object
The CompositorGuard classes is responsible for enforcing the min and max occurrance schema constraints defined for a Compositor (e.g., All, Choice, or Sequence). CompositorGuards determine whether there is "room" in a given instanceElement for any new members, and what members can be added.
Author:
ostwald
  • Field Details

    • instanceMembers

      protected List instanceMembers
      Description of the Field
  • Constructor Details

    • CompositorGuard

      public CompositorGuard(Compositor compositor, org.dom4j.Element instanceElement)
      Constructor for the CompositorGuard object

      Parameters:
      compositor - NOT YET DOCUMENTED
      instanceElement - NOT YET DOCUMENTED
    • CompositorGuard

      public CompositorGuard(Compositor compositor, List instanceMembers)
      Constructor for the CompositorGuard object
      Parameters:
      compositor - Description of the Parameter
      instanceMembers - Description of the Parameter
  • Method Details

    • toString

      public String toString()
      NOT YET DOCUMENTED
      Overrides:
      toString in class Object
      Returns:
      NOT YET DOCUMENTED
    • acceptsNewMember

      public boolean acceptsNewMember()
      Will the CompositorGuard allow another member element to be added?

      A hook to force validation is provided but not used because we most often are dealing with instanceElements that are not valid (e.g., user has just added a element in the metadata editor). Absent the validity constraint, this method returns if the number of occurrences are less then the number of occurrances allowed by the schema.

      Returns:
      true if the instance element can accept a new member.
    • acceptsNewMember

      public boolean acceptsNewMember(String memberName, int memberIndex)
      Tests whether the instance element can accept a new member of "memberName" at the specified memberIndex.
      Parameters:
      memberName - NOT YET DOCUMENTED
      memberIndex - NOT YET DOCUMENTED
      Returns:
      true if the instance element will accept the specified member.
    • checkValid

      public boolean checkValid() throws Exception
      NOT YET DOCUMENTED
      Returns:
      NOT YET DOCUMENTED
      Throws:
      Exception - NOT YET DOCUMENTED
    • getCompositor

      public Compositor getCompositor()
      Gets the compositor attribute of the CompositorGuard object
      Returns:
      The compositor value
    • getOccurrences

      protected abstract List getOccurrences() throws Exception
      Returns a list of occurrence instances that can be used to determine whether an instance document element satisfies the occurrence constraints of the schema.
      Returns:
      The occurrences value
      Throws:
      Exception - NOT YET DOCUMENTED
    • getSubOccurrenceCount

      protected final int getSubOccurrenceCount(CompositorMember cm, org.dom4j.Element instanceElement) throws Exception
      Gets the subOccurrenceCount attribute of the CompositorGuard object
      Parameters:
      cm - Description of the Parameter
      instanceElement - Description of the Parameter
      Returns:
      The subOccurrenceCount value
      Throws:
      Exception - Description of the Exception
    • getInstance

      public static CompositorGuard getInstance(Compositor compositor, org.dom4j.Element instanceElement)
      Gets the instance attribute of the CompositorGuard class
      Parameters:
      compositor - Description of the Parameter
      instanceElement - Description of the Parameter
      Returns:
      The instance value
    • getOccurrencesCount

      public final int getOccurrencesCount()
      Gets the occurrencesCount attribute of the CompositorGuard object
      Returns:
      The occurrencesCount value
    • getOccurrencesCount

      public final int getOccurrencesCount(String name)
      Gets the occurrencesCount attribute of the ChoiceGuard object
      Parameters:
      name - NOT YET DOCUMENTED
      Returns:
      The occurrencesCount value
    • resolveLeafNameToCMName

      public String resolveLeafNameToCMName(String leafName) throws Exception
      Uses resolveLeafNameToCM to return the instanceQualifiedName of the CompositorMember that controls the leafElement of leafName.
      Parameters:
      leafName - NOT YET DOCUMENTED
      Returns:
      NOT YET DOCUMENTED
      Throws:
      Exception - NOT YET DOCUMENTED
    • resolveLeafNameToCM

      public CompositorMember resolveLeafNameToCM(String leafName) throws Exception
      Given a leaf element name, find the CompositorMember that ultimately controls it
      Parameters:
      leafName - NOT YET DOCUMENTED
      Returns:
      NOT YET DOCUMENTED
      Throws:
      Exception - NOT YET DOCUMENTED
    • printInstanceMembers

      public void printInstanceMembers()
      Description of the Method
    • findOccurence

      public org.dlese.dpc.xml.schema.compositor.CompositorGuard.Occurrence findOccurence(CompositorMember cm, int memberIndex)
      NOT YET DOCUMENTED
      Parameters:
      cm - NOT YET DOCUMENTED
      memberIndex - NOT YET DOCUMENTED
      Returns:
      NOT YET DOCUMENTED
    • findOccurrence

      public org.dlese.dpc.xml.schema.compositor.CompositorGuard.Occurrence findOccurrence(String leafName, int memberIndex)
      Find the occurrence containing the nth element of memberName. This is used to determine which occurence can take a new member of memberName. SequenceGuard.acceptsNewMember calls this method to determine whether a member can be added at a certain place (one it determines which occurrence, then it checks to see if the member can be added to that occurrence legally.

      Caluclated by traversing the elements in each occurrence, keeping track of how many elements have memberName. When

      Parameters:
      leafName - NOT YET DOCUMENTED
      memberIndex - NOT YET DOCUMENTED
      Returns:
      NOT YET DOCUMENTED
    • printOccurrences

      public void printOccurrences()
      debugging