com.legstar.coxb
Class CobolElementVisitor

java.lang.Object
  extended by com.legstar.coxb.CobolElementVisitor

public abstract class CobolElementVisitor
extends Object

This class is a super-class of all visitors (visitor pattern) involved in converting java object trees instances to host data buffers.

Author:
Fady Moussallam

Constructor Summary
CobolElementVisitor()
          No-arg constructor.
CobolElementVisitor(byte[] hostBytes, int offset, ICobolConverters cobolConverters)
          Constructor for a given host buffer and converters set.
 
Method Summary
 ICobolBinding chooseDefaultAlternative(ICobolChoiceBinding ce)
          Default alternative selection logic.
 boolean exists(ICobolBinding ce)
          This deals with a special case of elements which have a dependingOn clause but their maxOccurs is 1.
 ICobolConverters getCobolConverters()
           
 byte[] getHostBytes()
           
 int getMaxAlternaliveLength(ICobolChoiceBinding ce)
          Given a choice, evaluate the largest alternative size.
 int getOffset()
           
 int getStartOffset()
          COBOL items are usually expected at a certain offset (fixed position).
 Hashtable<String,Object> getVariablesMap()
           
 boolean isCandidateAlternative(ICobolBinding alt)
          Should an alternative be considered for visiting.
 void setChosenAlternative(ICobolChoiceBinding ce, ICobolBinding chosenAlternative)
          If chosen alternative is shorter than the max, keep record of the difference because next item (if any) is not variably located.
 void setCobolConverters(ICobolConverters cobolConverters)
           
 void setHostBytes(byte[] hostBytes)
           
 void setOffset(int offset)
           
 void setVariablesMap(Hashtable<String,Object> variablesMap)
           
 void storeCustomVariable(ICobolBinding binding)
          Store the value of a binding in the custom variables map for later referral by custom code.
abstract  void visit(ICobolArrayBinaryBinding ce)
          Visit method of visitor pattern for Binary arrays.
abstract  void visit(ICobolArrayComplexBinding ce)
          Visit method of visitor pattern for arrays of complex elements.
abstract  void visit(ICobolArrayDbcsBinding ce)
          Visit method of visitor pattern for Dbcs arrays.
abstract  void visit(ICobolArrayDoubleBinding ce)
          Visit method of visitor pattern for Double arrays.
abstract  void visit(ICobolArrayFloatBinding ce)
          Visit method of visitor pattern for Float arrays.
abstract  void visit(ICobolArrayNationalBinding ce)
          Visit method of visitor pattern for National arrays.
abstract  void visit(ICobolArrayOctetStreamBinding ce)
          Visit method of visitor pattern for Octet stream arrays.
abstract  void visit(ICobolArrayPackedDecimalBinding ce)
          Visit method of visitor pattern for packed decimal arrays.
abstract  void visit(ICobolArrayStringBinding ce)
          Visit method of visitor pattern for String arrays.
abstract  void visit(ICobolArrayZonedDecimalBinding ce)
          Visit method of visitor pattern for zoned decimal arrays.
abstract  void visit(ICobolBinaryBinding ce)
          Visit method of visitor pattern for single Binary elements.
abstract  void visit(ICobolChoiceBinding ce)
          Visit method of visitor pattern for choice elements.
abstract  void visit(ICobolComplexBinding ce)
          Visit method of visitor pattern for complex elements.
abstract  void visit(ICobolDbcsBinding ce)
          Visit method of visitor pattern for single Dbcs.
abstract  void visit(ICobolDoubleBinding ce)
          Visit method of visitor pattern for single Double elements.
abstract  void visit(ICobolFloatBinding ce)
          Visit method of visitor pattern for single Float elements.
abstract  void visit(ICobolNationalBinding ce)
          Visit method of visitor pattern for single Nationals.
abstract  void visit(ICobolOctetStreamBinding ce)
          Visit method of visitor pattern for single Octet streams.
abstract  void visit(ICobolPackedDecimalBinding ce)
          Visit method of visitor pattern for single packed decimals.
abstract  void visit(ICobolStringBinding ce)
          Visit method of visitor pattern for single Strings.
abstract  void visit(ICobolZonedDecimalBinding ce)
          Visit method of visitor pattern for single zoned decimals.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CobolElementVisitor

public CobolElementVisitor()
No-arg constructor.


CobolElementVisitor

public CobolElementVisitor(byte[] hostBytes,
                           int offset,
                           ICobolConverters cobolConverters)
Constructor for a given host buffer and converters set.

Parameters:
hostBytes - host buffer used by visitor
offset - offset in host buffer
cobolConverters - set of converters to use for cobol elements
Method Detail

visit

public abstract void visit(ICobolComplexBinding ce)
                    throws HostException
Visit method of visitor pattern for complex elements.

Parameters:
ce - complex element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolChoiceBinding ce)
                    throws HostException
Visit method of visitor pattern for choice elements.

Parameters:
ce - choice element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayComplexBinding ce)
                    throws HostException
Visit method of visitor pattern for arrays of complex elements.

Parameters:
ce - complex array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolStringBinding ce)
                    throws HostException
Visit method of visitor pattern for single Strings.

Parameters:
ce - String element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayStringBinding ce)
                    throws HostException
Visit method of visitor pattern for String arrays.

Parameters:
ce - String array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolNationalBinding ce)
                    throws HostException
Visit method of visitor pattern for single Nationals.

Parameters:
ce - National element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayNationalBinding ce)
                    throws HostException
Visit method of visitor pattern for National arrays.

Parameters:
ce - National array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolDbcsBinding ce)
                    throws HostException
Visit method of visitor pattern for single Dbcs.

Parameters:
ce - Dbcs element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayDbcsBinding ce)
                    throws HostException
Visit method of visitor pattern for Dbcs arrays.

Parameters:
ce - Dbcs array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolZonedDecimalBinding ce)
                    throws HostException
Visit method of visitor pattern for single zoned decimals.

Parameters:
ce - Zoned decimal element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayZonedDecimalBinding ce)
                    throws HostException
Visit method of visitor pattern for zoned decimal arrays.

Parameters:
ce - Zoned decimal array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolPackedDecimalBinding ce)
                    throws HostException
Visit method of visitor pattern for single packed decimals.

Parameters:
ce - Packed decimal element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayPackedDecimalBinding ce)
                    throws HostException
Visit method of visitor pattern for packed decimal arrays.

Parameters:
ce - Packed dcimal array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolBinaryBinding ce)
                    throws HostException
Visit method of visitor pattern for single Binary elements.

Parameters:
ce - Binary element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayBinaryBinding ce)
                    throws HostException
Visit method of visitor pattern for Binary arrays.

Parameters:
ce - Binary array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolFloatBinding ce)
                    throws HostException
Visit method of visitor pattern for single Float elements.

Parameters:
ce - Float element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayFloatBinding ce)
                    throws HostException
Visit method of visitor pattern for Float arrays.

Parameters:
ce - Float array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolDoubleBinding ce)
                    throws HostException
Visit method of visitor pattern for single Double elements.

Parameters:
ce - Double element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayDoubleBinding ce)
                    throws HostException
Visit method of visitor pattern for Double arrays.

Parameters:
ce - Double array element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolOctetStreamBinding ce)
                    throws HostException
Visit method of visitor pattern for single Octet streams.

Parameters:
ce - Octet stream element descriptor
Throws:
HostException - error while visiting

visit

public abstract void visit(ICobolArrayOctetStreamBinding ce)
                    throws HostException
Visit method of visitor pattern for Octet stream arrays.

Parameters:
ce - Octet stream element descriptor
Throws:
HostException - error while visiting

getCobolConverters

public ICobolConverters getCobolConverters()
Returns:
Returns the CobolConverters.

setCobolConverters

public void setCobolConverters(ICobolConverters cobolConverters)
Parameters:
cobolConverters - The CobolConverters to set.

getHostBytes

public byte[] getHostBytes()
Returns:
Returns the mHostBytes.

setHostBytes

public void setHostBytes(byte[] hostBytes)
Parameters:
hostBytes - The mHostBytes to set.

getOffset

public int getOffset()
Returns:
Returns the mOffset.

setOffset

public void setOffset(int offset)
Parameters:
offset - The mOffset to set.

getVariablesMap

public Hashtable<String,Object> getVariablesMap()
Returns:
the current variables map.

setVariablesMap

public void setVariablesMap(Hashtable<String,Object> variablesMap)
Parameters:
variablesMap - the variables map to set

storeCustomVariable

public void storeCustomVariable(ICobolBinding binding)
                         throws HostException
Store the value of a binding in the custom variables map for later referral by custom code.

Parameters:
binding - the current binding
Throws:
HostException - if value cannot be stored

exists

public boolean exists(ICobolBinding ce)
               throws HostException
This deals with a special case of elements which have a dependingOn clause but their maxOccurs is 1. As such, they are not arrays but the associated dependingOn counter determines if the element exist or not (optional items).

If existence depends on a a counter, check counter value first. If the associated counter is zero, then the object does not exist (should not be visited as it has no bytes in the host payload or no java value object).

Parameters:
ce - the binding object
Returns:
true if object exists (has associated bytes in the incoming host payload or a non-null outbound java object value).
Throws:
HostException - if existence test fails

getStartOffset

public int getStartOffset()
COBOL items are usually expected at a certain offset (fixed position). Most of the time, this offset is where the previous item left but sometimes, a virtual filler must be accounted for.

Note that the virtual offset contributes to the offset only if there is a following, fixed position, item. It must not be added to the last item in a structure.

This is a destructive method that resets the virtual filler length to zero.

Returns:
returns the offset where unmarshaling should start for the next item.

getMaxAlternaliveLength

public int getMaxAlternaliveLength(ICobolChoiceBinding ce)
                            throws HostException
Given a choice, evaluate the largest alternative size.

Parameters:
ce - the choice binding
Returns:
the size of the largest alternative
Throws:
HostException - if size cannot be evaluated

chooseDefaultAlternative

public ICobolBinding chooseDefaultAlternative(ICobolChoiceBinding ce)
                                       throws HostException
Default alternative selection logic.

Every alternative is given a chance. If it throws an exception, the next alternative is tried. If it does not increment the offset, the next alternative is tried.

If none of the alternatives worked, an exception is raised.

Parameters:
ce - the choice binding
Returns:
an alternative that was successfully visited
Throws:
HostException - if no alternative could be chosen

isCandidateAlternative

public boolean isCandidateAlternative(ICobolBinding alt)
Should an alternative be considered for visiting.

Used with the default choice selection.

By default all alternatives are candidate.

Parameters:
alt - the proposed candidate alternative
Returns:
true if this alternative should be considered for visiting

setChosenAlternative

public void setChosenAlternative(ICobolChoiceBinding ce,
                                 ICobolBinding chosenAlternative)
                          throws HostException
If chosen alternative is shorter than the max, keep record of the difference because next item (if any) is not variably located. We might already have a virtual offset, left over from an inner choice.

Parameters:
ce - the choice binding
chosenAlternative - the chosen alternative
Throws:
HostException - if size cannot be evaluated


Copyright © 2015 LegSem. All Rights Reserved.