org.apache.asn1.ber
Class TupleEncodingVisitor

java.lang.Object
  extended byorg.apache.asn1.codec.stateful.AbstractStatefulEncoder
      extended byorg.apache.asn1.ber.TupleEncodingVisitor
All Implemented Interfaces:
org.apache.asn1.codec.stateful.StatefulEncoder, TupleNodeVisitor

public class TupleEncodingVisitor
extends org.apache.asn1.codec.stateful.AbstractStatefulEncoder
implements TupleNodeVisitor

A tuple tree visitor that encodes tuples in prefix order into a buffer, and chunking the buffer via callbacks as it is filled. This encoder will work on both determinate and indeterminate tuples. However all indeterminate tuples must be followed in sequence by an indeterminate terminator tuple.

Author:
Apache Directory Project $Rev: 157644 $
To Do:
might eventually want to make this encoder use a buffer pool to get its chunk buffers rather than having it create its own

Field Summary
private  java.util.ArrayList buffers
          The List storing the ByteBuffers collected during a visitation
private static java.nio.ByteBuffer[] EMPTY_ARRAY
          An empty buffer array so we do not recreate every time on toArray
private  VisitorMonitor visitorMonitor
          The visitor monitor used by this TupleNodeVisitor
 
Fields inherited from class org.apache.asn1.codec.stateful.AbstractStatefulEncoder
 
Constructor Summary
TupleEncodingVisitor()
           
 
Method Summary
 boolean canVisit(TupleNode node)
          Checks to see if a node can be visited.
 void encode(java.lang.Object obj)
           
 void flush()
          Flushes out the array of ByteBuffer's collected during the visitation.
 java.util.ArrayList getOrder(TupleNode node, java.util.ArrayList children)
          Get the array of children to visit sequentially to determine the order of child visitations.
 boolean isPrefix()
          Determines whether the visitation order is prefix or postfix.
 void setMonitor(VisitorMonitor monitor)
          Sets the monitoring which recieves callbacks of notable events from this visitor.
 void visit(TupleNode node)
          Visits a tree of tuple nodes using a specific visitation order.
 
Methods inherited from class org.apache.asn1.codec.stateful.AbstractStatefulEncoder
encodeOccurred, getEncoderMonitor, setCallback, setEncoderMonitor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

private static final java.nio.ByteBuffer[] EMPTY_ARRAY
An empty buffer array so we do not recreate every time on toArray


buffers

private java.util.ArrayList buffers
The List storing the ByteBuffers collected during a visitation


visitorMonitor

private VisitorMonitor visitorMonitor
The visitor monitor used by this TupleNodeVisitor

Constructor Detail

TupleEncodingVisitor

public TupleEncodingVisitor()
Method Detail

encode

public void encode(java.lang.Object obj)
            throws org.apache.asn1.codec.EncoderException
Specified by:
encode in interface org.apache.asn1.codec.stateful.StatefulEncoder
Throws:
org.apache.asn1.codec.EncoderException

visit

public void visit(TupleNode node)
Visits a tree of tuple nodes using a specific visitation order.

Specified by:
visit in interface TupleNodeVisitor
Parameters:
node - the node to visit
To Do:
major kludge in this method please see warnings inline

canVisit

public boolean canVisit(TupleNode node)
Checks to see if a node can be visited.

Specified by:
canVisit in interface TupleNodeVisitor
Parameters:
node - the node to be visited
Returns:
whether or node the node should be visited

isPrefix

public boolean isPrefix()
Determines whether the visitation order is prefix or postfix.

Specified by:
isPrefix in interface TupleNodeVisitor
Returns:
true if the visitation is in prefix order, false otherwise.

getOrder

public java.util.ArrayList getOrder(TupleNode node,
                                    java.util.ArrayList children)
Get the array of children to visit sequentially to determine the order of child visitations. Some children may not be returned at all if canVisit() returns false on them.

Specified by:
getOrder in interface TupleNodeVisitor
Parameters:
node - the parent branch node
children - the child node array
Returns:
the new reordered array of children

flush

public void flush()
Flushes out the array of ByteBuffer's collected during the visitation. This is done by calling encodeOccurred in one shot.


setMonitor

public void setMonitor(VisitorMonitor monitor)
Description copied from interface: TupleNodeVisitor
Sets the monitoring which recieves callbacks of notable events from this visitor.

Specified by:
setMonitor in interface TupleNodeVisitor
Parameters:
monitor - the monitor instance for the visitor


Copyright © 2004-2006 . All Rights Reserved.