com.berryworks.edireader
Class Plugin

java.lang.Object
  extended by com.berryworks.edireader.Plugin

public abstract class Plugin
extends java.lang.Object

Parent class for all EDIReader plugins.

Naming plugin classes. The class should extend com.berryworks.edireader.Plugin and must be named precisely according to a specific pattern. If the plugin is for an ANSI X.12 transaction set, the class name must be ANSI_nnn where nnn is the 3-digit number that appears in the ST segment to designate the particular transaction set. For a UN/EDIFACT message type, the class name must be EDIFACT_name where name is the symbolic name for the message type that appears in the UNH segment. For instance, a plugin for an EDIFACT purchase order message would have the class name EDIFACT_ORDERS.

EDIReader uses this class name to make the runtime linkage to the plugin. Once it has parsed the ST segment (or UNH segment for EDIFACT) it forms the classname that the plugin would have if it is available and uses the classloader to locate a class of this name in the CLASSPATH. If no such class exists, then EDIReader continues without a plugin and generates XML that does not reflect the internal looping structure of the document.

For this linkage to work properly, the fully-qualified class name must match. Therefore, your plugin must bear a package name of com.berryworks.edireader.plugin although it can be compiled separately and does not have to be placed inside any particular jar file.

LoopDescriptors. The essence of a Plugin is an array of LoopDescriptors. An EDIReader plugin is expected to subclass Plugin and initialize the loops array with loop descriptors. Each LoopDescriptor expresses a specific situation that corresponds to the entry or exit of a loop instance while parsing. Refer to the documentation for LoopDescriptor for further details.

PluginController. A parser for a particular EDI standard, typically AnsiReader or EdifactReader, uses an instance of a PluginController to interact with the plugin while parsing the segments of an EDI document. For each segment encountered within a document, the parser calls the transition method on the PluginController to determine if the segment corresponds to a loop transaction, either the entry of a new loop or the completion of a loop. The transition() method then in turn calls the query() method on the plugin, which considers the LoopDescriptors associated with the segment type to determine if one applies to the current context. The query() method considers the LoopDescriptors in the order in which they were provided in the loops array. The first one that is determined to "match" the context expressed in the query arguments is returned by the query method. Therefore, the ordering of the LoopDescriptors for a given segment type is very important as described in the documentation for LoopDescriptor.

Plugin Optimization. The description above suggests that the entire array of LoopDescriptors in a plugin is examined serially for each segment within an EDI document. This is logically but not literally true. For performance reasons, an optimized form of a plugin is created when a plugin class is loaded so that the LoopDescriptors associated with a particular segment type can be accessed efficiently. The PluginPreparation class is for this purpose.

See Also:
LoopDescriptor, PluginController, PluginPreparation

Field Summary
static java.lang.String ANY_CONTEXT
           
static java.lang.String CURRENT
           
static java.lang.String INITIAL_CONTEXT
           
 
Constructor Summary
Plugin(java.lang.String documentType, java.lang.String documentName)
           
 
Method Summary
 com.berryworks.edireader.plugin.PluginControllerImpl createController(java.lang.String standard, com.berryworks.edireader.tokenizer.Tokenizer tokenizer)
           
 void debug(boolean d)
           
static int getCount()
           
 java.lang.String getDocumentName()
          Get the readable name for the document (for example, "Health Care Claim")
 java.lang.String getDocumentType()
          Get the document type (for example, "837")
 void init()
          Perform any initialization needed for the plugin before use with a new document.
 boolean isValidating()
           
 void prepare()
           
 com.berryworks.edireader.plugin.LoopDescriptor query(java.lang.String segment, java.lang.String currentLoopStack, int currentLevel)
          Query the plugin about a loop that starts with a designated segment type, given that you are already within a particular loop.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ANY_CONTEXT

public static final java.lang.String ANY_CONTEXT
See Also:
Constant Field Values

INITIAL_CONTEXT

public static final java.lang.String INITIAL_CONTEXT
See Also:
Constant Field Values

CURRENT

public static final java.lang.String CURRENT
See Also:
Constant Field Values
Constructor Detail

Plugin

public Plugin(java.lang.String documentType,
              java.lang.String documentName)
Method Detail

init

public void init()
Perform any initialization needed for the plugin before use with a new document.

The only cases where this is needed is for plugins that have state. Most plugins are stateless and therefore an instance of a plugin can be reused for many documents. However, it is possible to develop a subclass of Plugin that maintains state. For example, a FilteringPlugin might need to make decisions based on what segment types have been seen previously in a given document. In such a case, you may override the init() method in order to reset the state before starting a new document. In developing such a state-bearing plugin, you must carefully consider thread safety issues for multi-threaded environments. The use of ThreadLocal is recommended in such cases.


getDocumentType

public java.lang.String getDocumentType()
Get the document type (for example, "837")

Returns:
The documentType value

getDocumentName

public java.lang.String getDocumentName()
Get the readable name for the document (for example, "Health Care Claim")

Returns:
The documentName value

query

public com.berryworks.edireader.plugin.LoopDescriptor query(java.lang.String segment,
                                                            java.lang.String currentLoopStack,
                                                            int currentLevel)
Query the plugin about a loop that starts with a designated segment type, given that you are already within a particular loop.

Parameters:
segment - type of segment encountered
currentLoopStack - stack representing nested loops in current state
currentLevel - nesting level of current state
Returns:
descriptor matching query parameters, or null if none

debug

public void debug(boolean d)

getCount

public static int getCount()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

prepare

public void prepare()

isValidating

public boolean isValidating()

createController

public com.berryworks.edireader.plugin.PluginControllerImpl createController(java.lang.String standard,
                                                                             com.berryworks.edireader.tokenizer.Tokenizer tokenizer)