Open Business Objects for EDI
v3.6.0

com.americancoders.edi
Class Segment

java.lang.Object
  |
  +--com.americancoders.edi.Segment
All Implemented Interfaces:
ICompositeDEContainer, IContainedObject, IDataElementContainer, IIdentifier

public class Segment
extends java.lang.Object
implements IDataElementContainer, ICompositeDEContainer, IContainedObject

class for Segments OBOE - Open Business Objects for EDI

An EDI and XML Translator Written In Java

Copyright 1998-2009 - American Coders, LTD - Raleigh NC USA

All rights reserved

American Coders, Ltd
P. O. Box 97462
Raleigh, NC 27624 USA
1-919-846-2014
http://www.americancoders.com

Version:
3.6.0
Author:
Joe McVerry - American Coders, Ltd.

Field Summary
protected  int byteOffsetPositionInIncomingDocument
           
protected  java.lang.Object[] deArray
          array of owned datalements
protected  com.americancoders.edi.TemplateSegment myTemplate
          TemplateSegment that can build this segment
protected  com.americancoders.edi.IContainedObject parent
           
protected  int positionInIncomingDocument
          position within the X12 or EDIFACT document
 
Constructor Summary
Segment(com.americancoders.edi.TemplateSegment inTemplateSegment, com.americancoders.edi.IContainedObject inParent)
          create a Segment based on its template
 
Method Summary
 java.lang.Object buildDE(int pos)
          defines a dataelement by the predefined templateDE array
 java.lang.Object buildDE(java.lang.String ID)
          defines a dataelement by the predefined templateDE array
 int doIUseThisXMLElement(java.lang.String inTag, int startAt)
          routine to ask if it uses a dataelement
 java.lang.String get()
          returns all the data associated with the Segment
dataelements separated by '*'
composites separated by '<', note data elements within composites are seperated by ':'
 int getByteOffsetPositionInIncomingDocument()
           
 com.americancoders.edi.CompositeDE getCompositeDE(int inSequence)
          returns a compositeDE by its position
 com.americancoders.edi.CompositeDE getCompositeDE(java.lang.String inID)
          returns a compositeDE by its id
 com.americancoders.edi.DataElement getDataElement(int inSequence)
          returns a data element by its sequence number, not location within vector
 com.americancoders.edi.DataElement getDataElement(java.lang.String inID)
          returns a data element by its id
 com.americancoders.edi.DataElement getDataElement(java.lang.String inID, int inoffset)
          returns a data element by its id, from an offset
 com.americancoders.edi.DataElement getDataElementByName(java.lang.String inName, int inoffset)
          returns a data element by its id off of an offset
 int getDataElementLength()
          returns the length of the data in the data elements
 int getDataElementSize()
          returns the number of defined data element
 java.lang.String getDataElementValue(int pos)
          returns the value set in the data element if the data element is not built it will return a zero-length string.
 java.lang.String getDataElementValue(java.lang.String ID)
          returns the value set in the data element if the data element is not built it will return a zero-length string.
 java.lang.String getDescription()
          returns the Short Description for the Segment
 java.lang.String getFixedLengthFormattedText()
          returns fixed length formatted text
 java.lang.String getFormattedText(int formatType)
          returns the formatted text
 java.lang.String getID()
          gets the segment id
 java.lang.String getName()
          gets the segment Name
 int getObjectPosition(java.lang.Object inObject)
          returns an objects position in array
 int getOccurs()
          returns the occurs value
 com.americancoders.edi.IContainedObject getParent()
          gets parent attribute
 int getPositionInIncomingDocument()
          gets the x12 or edifact position for incoming documnents
 com.americancoders.edi.DataElement getPrimaryIDDE()
          returns the data element associated with being known as making this segment unique
 char getRequired()
          returns the required flag
 int getSequence()
          gets the segment sequence
 com.americancoders.edi.TemplateSegment getTemplate()
          returns the TemplateSegment used to build the Segment
 java.lang.String getXMLTag()
          returns the xml tag field
 void initializeToPrevalidateFields()
          sets the default value for the data elements
Part of Extended Edition Package
will create mandatory subsegments.
 boolean isCompositeDE(int inSequence)
          returns a boolean if vector position held by a composite
 boolean isDataElement(int inSequence)
          returns a boolean if vector position held by a data element
 boolean isUsed()
          returns the used indicator
 boolean parse(com.americancoders.edi.ITokenizer TransactionSetTokenizer)
          parses an EDI Document adds to datalement vector and adds to secondary segment vector
 int parse(org.w3c.dom.Node node)
          parses a XML EDI Document adds to datalement vector or compositeDE and adds to secondary segment vector
 boolean parse(java.io.PushbackInputStream pis)
          parses a Fixed Length EDI Document adds to datalement vector or compositeDE and adds to secondary segment vector
 void setByteOffsetPositionInIncomingDocument(int byteOffsetPositionInIncomingDocument)
           
 com.americancoders.edi.DataElement setDataElementValue(int pos, java.lang.String inValue)
          sets the value set in the data element without needing to build the data element object if the data element is not built it will be built.
 com.americancoders.edi.DataElement setDataElementValue(java.lang.String ID, java.lang.String inValue)
          returns the value set in the data element if the data element is not built it will return a zero-length string.
 void setParent(com.americancoders.edi.IContainedObject inParent)
          sets parent attribute
 void setPosition(int inPos)
          sets the x12 or edifact position for incoming documnents
 java.lang.String toString()
          the toString method
 int trim()
          removes empty trailing data elements and returns the number of used dataelements
 void useDefault()
          sets the default value for the data elements
Part of Extended Edition Package
will create mandatory subsegments.
 boolean validate()
          used to verify if the segment is built correctly.
 boolean validate(com.americancoders.edi.DocumentErrors inDErr)
          used to verify if the segment is built correctly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

deArray

protected java.lang.Object[] deArray
array of owned datalements


myTemplate

protected com.americancoders.edi.TemplateSegment myTemplate
TemplateSegment that can build this segment


positionInIncomingDocument

protected int positionInIncomingDocument
position within the X12 or EDIFACT document


byteOffsetPositionInIncomingDocument

protected int byteOffsetPositionInIncomingDocument

parent

protected com.americancoders.edi.IContainedObject parent
Constructor Detail

Segment

public Segment(com.americancoders.edi.TemplateSegment inTemplateSegment,
               com.americancoders.edi.IContainedObject inParent)
create a Segment based on its template

Parameters:
inTemplateSegment - predefined TemplateSegment
inParent - owning Object
Method Detail

getTemplate

public com.americancoders.edi.TemplateSegment getTemplate()
returns the TemplateSegment used to build the Segment

Returns:
TemplateSegment

getID

public java.lang.String getID()
gets the segment id

Specified by:
getID in interface IIdentifier
Returns:
String id

getName

public java.lang.String getName()
gets the segment Name

Returns:
String Name

getOccurs

public int getOccurs()
returns the occurs value

Returns:
int occurs value

getRequired

public char getRequired()
returns the required flag

Returns:
char required

getXMLTag

public java.lang.String getXMLTag()
returns the xml tag field

Specified by:
getXMLTag in interface IIdentifier
Returns:
String tag value

isUsed

public boolean isUsed()
returns the used indicator

Returns:
boolean

getSequence

public int getSequence()
gets the segment sequence

Returns:
int sequence number

getDescription

public java.lang.String getDescription()
returns the Short Description for the Segment

Returns:
String

parse

public boolean parse(com.americancoders.edi.ITokenizer TransactionSetTokenizer)
              throws OBOEException
parses an EDI Document adds to datalement vector and adds to secondary segment vector

Parameters:
TransactionSetTokenizer - tokenizer hold string data
Throws:
OBOEException - as thrown, can't process subsegment maybe

parse

public int parse(org.w3c.dom.Node node)
          throws OBOEException
parses a XML EDI Document adds to datalement vector or compositeDE and adds to secondary segment vector

Parameters:
node - Incoming DOM node
Throws:
OBOEException - as thrown

parse

public boolean parse(java.io.PushbackInputStream pis)
              throws OBOEException,
                     java.io.IOException
parses a Fixed Length EDI Document adds to datalement vector or compositeDE and adds to secondary segment vector

Parameters:
pis - PushbackInputStream
Throws:
OBOEException - as thrown
java.io.IOException

buildDE

public java.lang.Object buildDE(int pos)
defines a dataelement by the predefined templateDE array

Specified by:
buildDE in interface IDataElementContainer
Parameters:
pos - int
position is relative to 1.
Returns:
DataElement or Composite

validate

public boolean validate()
used to verify if the segment is built correctly.

Returns:
boolean true if segment built correctly
Basic Edition always returns true

validate

public boolean validate(com.americancoders.edi.DocumentErrors inDErr)
used to verify if the segment is built correctly

Parameters:
inDErr - DocumentErrorsObject
Returns:
boolean true if segment built correctly

getFormattedText

public java.lang.String getFormattedText(int formatType)
returns the formatted text

Parameters:
formatType - int indicating x12, edificact...
Returns:
String

getFixedLengthFormattedText

public java.lang.String getFixedLengthFormattedText()
returns fixed length formatted text

Returns:
String

getDataElementSize

public int getDataElementSize()
returns the number of defined data element

Specified by:
getDataElementSize in interface IDataElementContainer
Returns:
int DataElement count

get

public java.lang.String get()
returns all the data associated with the Segment
dataelements separated by '*'
composites separated by '<', note data elements within composites are seperated by ':'

Specified by:
get in interface ICompositeDEContainer
Returns:
String for all segments and deArray within the Segment

getDataElementLength

public int getDataElementLength()
returns the length of the data in the data elements

Specified by:
getDataElementLength in interface ICompositeDEContainer
Returns:
int

getDataElement

public com.americancoders.edi.DataElement getDataElement(java.lang.String inID)
returns a data element by its id

Specified by:
getDataElement in interface IDataElementContainer
Parameters:
inID - ID of dataelement to find
Returns:
DataElement

getDataElement

public com.americancoders.edi.DataElement getDataElement(java.lang.String inID,
                                                         int inoffset)
returns a data element by its id, from an offset

Parameters:
inID - ID of dataelement to find
inoffset - int
Returns:
DataElement

getDataElementByName

public com.americancoders.edi.DataElement getDataElementByName(java.lang.String inName,
                                                               int inoffset)
returns a data element by its id off of an offset

Parameters:
inName - name of dataelement to find
inoffset - int
Returns:
DataElement

getDataElement

public com.americancoders.edi.DataElement getDataElement(int inSequence)
returns a data element by its sequence number, not location within vector

Specified by:
getDataElement in interface IDataElementContainer
Parameters:
inSequence - int position of dataelement
position is relative to 1.
Returns:
DataElement

getCompositeDE

public com.americancoders.edi.CompositeDE getCompositeDE(java.lang.String inID)
returns a compositeDE by its id

Specified by:
getCompositeDE in interface ICompositeDEContainer
Parameters:
inID - String id of composite
Returns:
CompositeDataElement

getCompositeDE

public com.americancoders.edi.CompositeDE getCompositeDE(int inSequence)
returns a compositeDE by its position

Specified by:
getCompositeDE in interface ICompositeDEContainer
Parameters:
inSequence - int position of CompositeDE
position is relative to 1.
Returns:
CompositeDataElement

getObjectPosition

public int getObjectPosition(java.lang.Object inObject)
returns an objects position in array

Parameters:
inObject - object that may be in the array
Returns:
int

isDataElement

public boolean isDataElement(int inSequence)
returns a boolean if vector position held by a data element

Parameters:
inSequence - is object in the array a dataelement
position is relative to 1.
Returns:
boolean

isCompositeDE

public boolean isCompositeDE(int inSequence)
returns a boolean if vector position held by a composite

Parameters:
inSequence - int is object in array at this position a composite
position is relative to 1.
Returns:
boolean

trim

public int trim()
removes empty trailing data elements and returns the number of used dataelements

Returns:
int

doIUseThisXMLElement

public int doIUseThisXMLElement(java.lang.String inTag,
                                int startAt)
routine to ask if it uses a dataelement

Parameters:
inTag - String id
startAt - prepositioning
Returns:
int position of data element

useDefault

public void useDefault()
sets the default value for the data elements
Part of Extended Edition Package
will create mandatory subsegments.
if mandatory subsegment is part of vector (collection) will create the first one


initializeToPrevalidateFields

public void initializeToPrevalidateFields()
sets the default value for the data elements
Part of Extended Edition Package
will create mandatory subsegments.
if mandatory subsegment is part of vector (collection) will create the first one


setParent

public void setParent(com.americancoders.edi.IContainedObject inParent)
sets parent attribute

Specified by:
setParent in interface IContainedObject
Parameters:
inParent - TemplateSegmentContainer

getParent

public com.americancoders.edi.IContainedObject getParent()
gets parent attribute

Specified by:
getParent in interface IContainedObject
Returns:
TemplateSegmentContainer

getPrimaryIDDE

public com.americancoders.edi.DataElement getPrimaryIDDE()
returns the data element associated with being known as making this segment unique

Returns:
DataElement

setPosition

public void setPosition(int inPos)
sets the x12 or edifact position for incoming documnents

Parameters:
inPos -

getByteOffsetPositionInIncomingDocument

public int getByteOffsetPositionInIncomingDocument()

setByteOffsetPositionInIncomingDocument

public void setByteOffsetPositionInIncomingDocument(int byteOffsetPositionInIncomingDocument)

getPositionInIncomingDocument

public int getPositionInIncomingDocument()
gets the x12 or edifact position for incoming documnents

Returns:
int

toString

public java.lang.String toString()
the toString method

Overrides:
toString in class java.lang.Object

buildDE

public java.lang.Object buildDE(java.lang.String ID)
Description copied from interface: IDataElementContainer
defines a dataelement by the predefined templateDE array

Specified by:
buildDE in interface IDataElementContainer
Parameters:
ID - field to build is identified by its templates id value
Returns:
Object always a DataElement, I used Object to keep it consistent with what Segments buildDE returns.

getDataElementValue

public java.lang.String getDataElementValue(java.lang.String ID)
                                     throws OBOEException
Description copied from interface: IDataElementContainer
returns the value set in the data element if the data element is not built it will return a zero-length string. if the position is out of range the OBOEException will be thrown.

Specified by:
getDataElementValue in interface IDataElementContainer
Parameters:
ID - String ID of datalement to look for
Returns:
String contents of data lement
Throws:
OBOEException - ID is unknown, or position is for a composite de

getDataElementValue

public java.lang.String getDataElementValue(int pos)
                                     throws OBOEException
Description copied from interface: IDataElementContainer
returns the value set in the data element if the data element is not built it will return a zero-length string. if the position is out of range the OBOEException will be thrown.

Specified by:
getDataElementValue in interface IDataElementContainer
Parameters:
pos - int position within the segement
Returns:
String contents of data lement
Throws:
OBOEException - ID is unknown

setDataElementValue

public com.americancoders.edi.DataElement setDataElementValue(java.lang.String ID,
                                                              java.lang.String inValue)
                                                       throws OBOEException
Description copied from interface: IDataElementContainer
returns the value set in the data element if the data element is not built it will return a zero-length string. if the position is out of range the OBOEException will be thrown.

Specified by:
setDataElementValue in interface IDataElementContainer
Parameters:
ID - String ID of datalement to look for
Returns:
DataElement DataElement object
Throws:
OBOEException - ID is unknown, or position is for a composite de

setDataElementValue

public com.americancoders.edi.DataElement setDataElementValue(int pos,
                                                              java.lang.String inValue)
                                                       throws OBOEException
Description copied from interface: IDataElementContainer
sets the value set in the data element without needing to build the data element object if the data element is not built it will be built. if the position is out of range the OBOEException will be thrown.

Specified by:
setDataElementValue in interface IDataElementContainer
Parameters:
pos - int position within the segement
Returns:
DataElement DataElement object
Throws:
OBOEException - ID is unknown

Open Business Objects for EDI
v3.6.0


OBOE is a trademark or registered trademark of American Coders, Ltd. in the US and other countries.
Copyright 1999-2004 American Coders, Ltd.
POB 97462
Raleigh NC 27624 USA
All Rights Reserved.