ca.uhn.hl7v2.model
Class AbstractGroup

java.lang.Object
  extended by ca.uhn.hl7v2.model.AbstractGroup
All Implemented Interfaces:
Group, Structure, java.io.Serializable
Direct Known Subclasses:
AbstractMessage, GenericGroup

public abstract class AbstractGroup
extends java.lang.Object
implements Group

A partial implementation of Group. Subclasses correspond to specific groups of segments (and/or other sub-groups) that are implicitly defined by message structures in the HL7 specification. A subclass should define it's group structure by putting repeated calls to the add(...) method in it's constructor. Each call to add(...) adds a specific component to the Group.

Author:
Bryan Tripp (bryan_tripp@sourceforge.net)
See Also:
Serialized Form

Constructor Summary
protected AbstractGroup(Group parent, ModelClassFactory factory)
          This constructor should be used by implementing classes that do not also implement Message.
protected AbstractGroup(ModelClassFactory factory)
          This constructor should only be used by classes that implement Message directly.
 
Method Summary
protected  java.lang.String add(java.lang.Class<? extends Structure> c, boolean required, boolean repeating)
          Adds a new Structure (group or segment) to this Group.
protected  java.lang.String add(java.lang.Class<? extends Structure> c, boolean required, boolean repeating, int index)
          Adds a new Structure (group or segment) to this Group.
 java.lang.String addNonstandardSegment(java.lang.String name)
          Expands the group definition to include a segment that is not defined by HL7 to be part of this group (eg an unregistered Z segment).
 java.lang.String addNonstandardSegment(java.lang.String theName, int theIndex)
          Expands the group definition to include a segment that is not defined by HL7 to be part of this group (eg an unregistered Z segment).
 void clear()
          Clears all data from this structure.
 int currentReps(java.lang.String name)
          Returns the number of existing repetitions of the named structure.
 Structure get(java.lang.String name)
          Returns the named structure.
 Structure get(java.lang.String name, int rep)
          Returns a particular repetition of the named Structure.
 Structure[] getAll(java.lang.String name)
          Returns an array of Structure objects by name.
 java.lang.Class<? extends Structure> getClass(java.lang.String name)
          Returns the Class of the Structure at the given name index.
 Message getMessage()
          Returns the Message to which this segment belongs.
 ModelClassFactory getModelClassFactory()
           
 java.lang.String getName()
          Returns the class name (excluding package).
 java.lang.String[] getNames()
          Returns an ordered array of the names of the Structures in this Group.
 Group getParent()
          Returns the parent group within which this structure exists (may be root message group).
 Structure insertRepetition(java.lang.String name, int index)
          Inserts a repetition of a given Structure into repetitions of that structure by name.
protected  void insertRepetition(Structure structure, int index)
          Inserts a repetition of a given Structure into repetitions of that structure by name.
 boolean isRepeating(java.lang.String name)
          Returns true if the named structure is required.
 boolean isRequired(java.lang.String name)
          Returns true if the named structure is required.
 Structure removeRepetition(java.lang.String name, int index)
          Removes a repetition of a given Structure objects by name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractGroup

protected AbstractGroup(Group parent,
                        ModelClassFactory factory)
This constructor should be used by implementing classes that do not also implement Message.

Parameters:
parent - the group to which this Group belongs.
factory - the factory for classes of segments, groups, and datatypes under this group

AbstractGroup

protected AbstractGroup(ModelClassFactory factory)
This constructor should only be used by classes that implement Message directly.

Parameters:
factory - the factory for classes of segments, groups, and datatypes under this group
Method Detail

get

public Structure get(java.lang.String name)
              throws HL7Exception
Returns the named structure. If this Structure is repeating then the first repetition is returned. Creates the Structure if necessary.

Specified by:
get in interface Group
Throws:
HL7Exception - if the named Structure is not part of this Group.

get

public Structure get(java.lang.String name,
                     int rep)
              throws HL7Exception
Returns a particular repetition of the named Structure. If the given repetition number is one greater than the existing number of repetitions then a new Structure is created.

Specified by:
get in interface Group
Throws:
HL7Exception - if the named Structure is not part of this group, if the structure is not repeatable and the given rep is > 0, or if the given repetition number is more than one greater than the existing number of repetitions.

addNonstandardSegment

public java.lang.String addNonstandardSegment(java.lang.String name)
                                       throws HL7Exception
Expands the group definition to include a segment that is not defined by HL7 to be part of this group (eg an unregistered Z segment). The new segment is slotted at the end of the group. Thenceforward if such a segment is encountered it will be parsed into this location. If the segment name is unrecognized a GenericSegment is used. The segment is defined as repeating and not required.

Specified by:
addNonstandardSegment in interface Group
Throws:
HL7Exception

addNonstandardSegment

public java.lang.String addNonstandardSegment(java.lang.String theName,
                                              int theIndex)
                                       throws HL7Exception
Description copied from interface: Group
Expands the group definition to include a segment that is not defined by HL7 to be part of this group (eg an unregistered Z segment).

Specified by:
addNonstandardSegment in interface Group
Throws:
HL7Exception

getNames

public java.lang.String[] getNames()
Returns an ordered array of the names of the Structures in this Group. These names can be used to iterate through the group using repeated calls to get(name).

Specified by:
getNames in interface Group

add

protected java.lang.String add(java.lang.Class<? extends Structure> c,
                               boolean required,
                               boolean repeating)
                        throws HL7Exception
Adds a new Structure (group or segment) to this Group. A place for the Structure is added to the group but there are initially zero repetitions. This method should be used by the constructors of implementing classes to specify which Structures the Group contains - Structures should be added in the order in which they appear. Note that the class is supplied instead of an instance because we want there initially to be zero instances of each structure but we want the AbstractGroup code to be able to create instances as necessary to support get(...) calls.

Returns:
the actual name used to store this structure (may be appended with an integer if there are duplicates in the same Group).
Throws:
HL7Exception

add

protected java.lang.String add(java.lang.Class<? extends Structure> c,
                               boolean required,
                               boolean repeating,
                               int index)
                        throws HL7Exception
Adds a new Structure (group or segment) to this Group. A place for the Structure is added to the group but there are initially zero repetitions. This method should be used by the constructors of implementing classes to specify which Structures the Group contains - Structures should be added in the order in which they appear. Note that the class is supplied instead of an instance because we want there initially to be zero instances of each structure but we want the AbstractGroup code to be able to create instances as necessary to support get(...) calls.

Returns:
the actual name used to store this structure (may be appended with an integer if there are duplicates in the same Group).
Throws:
HL7Exception

getMessage

public Message getMessage()
Returns the Message to which this segment belongs.

Specified by:
getMessage in interface Structure

getParent

public Group getParent()
Returns the parent group within which this structure exists (may be root message group).

Specified by:
getParent in interface Structure

isRequired

public boolean isRequired(java.lang.String name)
                   throws HL7Exception
Returns true if the named structure is required.

Specified by:
isRequired in interface Group
Throws:
HL7Exception

isRepeating

public boolean isRepeating(java.lang.String name)
                    throws HL7Exception
Returns true if the named structure is required.

Specified by:
isRepeating in interface Group
Throws:
HL7Exception

currentReps

public int currentReps(java.lang.String name)
                throws HL7Exception
Returns the number of existing repetitions of the named structure.

Throws:
HL7Exception

getAll

public Structure[] getAll(java.lang.String name)
                   throws HL7Exception
Returns an array of Structure objects by name. For example, if the Group contains an MSH segment and "MSH" is supplied then this call would return a 1-element array containing the MSH segment. Multiple elements are returned when the segment or group repeats. The array may be empty if no repetitions have been accessed yet using the get(...) methods.

Specified by:
getAll in interface Group
Throws:
HL7Exception - if the named Structure is not part of this Group.

removeRepetition

public Structure removeRepetition(java.lang.String name,
                                  int index)
                           throws HL7Exception
Removes a repetition of a given Structure objects by name. For example, if the Group contains 10 repititions an OBX segment and "OBX" is supplied with an index of 2, then this call would remove the 3rd repetition. Note that in this case, the Set ID field in the OBX segments would also need to be renumbered manually.

Returns:
The removed structure
Throws:
HL7Exception - if the named Structure is not part of this Group.

insertRepetition

protected void insertRepetition(Structure structure,
                                int index)
                         throws HL7Exception
Inserts a repetition of a given Structure into repetitions of that structure by name. For example, if the Group contains 10 repititions an OBX segment and an OBX is supplied with an index of 2, then this call would insert the new repetition at index 2. Note that in this case, the Set ID field in the OBX segments would also need to be renumbered manually.

Throws:
HL7Exception - if the named Structure is not part of this Group.

insertRepetition

public Structure insertRepetition(java.lang.String name,
                                  int index)
                           throws HL7Exception
Inserts a repetition of a given Structure into repetitions of that structure by name. For example, if the Group contains 10 repititions an OBX segment and an OBX is supplied with an index of 2, then this call would insert the new repetition at index 2. Note that in this case, the Set ID field in the OBX segments would also need to be renumbered manually.

Returns:
The removed structure
Throws:
HL7Exception - if the named Structure is not part of this Group.

getClass

public java.lang.Class<? extends Structure> getClass(java.lang.String name)
Returns the Class of the Structure at the given name index.

Specified by:
getClass in interface Group

getName

public java.lang.String getName()
Returns the class name (excluding package).

Specified by:
getName in interface Structure
See Also:
Structure.getName()

clear

public void clear()
Clears all data from this structure.


getModelClassFactory

public final ModelClassFactory getModelClassFactory()


Copyright © 2001-2011 University Health Network. All Rights Reserved.