com.wm.app.tn.doc
Class XMLDocType

java.lang.Object
  extended by com.wm.app.tn.util.TNFixedData
      extended by com.wm.app.tn.doc.BizDocType
          extended by com.wm.app.tn.doc.XMLDocType
All Implemented Interfaces:
com.wm.data.IData, com.wm.util.coder.IDataCodable, java.lang.Cloneable

public class XMLDocType
extends BizDocType

This class keeps associated info about XML business document types. XML bizdocs are documents represented in XML. The doc types use XQL queries to identfy specific forms of XML bizdocs (eg, cXML POs, OAG POs, etc) and XQL queries for extracting both system and custom attributes. It is left up the users creating new XML doc types to make sure the identification queries are fine-grained enough to distinguish the different doc types. In addition, methods are provided for converting XMLDocType objects into IData objects and vice versa. This is useful for peristing it in the database. By using the IDataCodable methods in this way, member variables can easily be added without having the change the data model.

Author:
Floyd West

Nested Class Summary
 
Nested classes/interfaces inherited from class com.wm.app.tn.util.TNFixedData
com.wm.app.tn.util.TNFixedData.TreeCursor
 
Constructor Summary
XMLDocType()
          Empty constructor.
XMLDocType(com.wm.data.IData in)
          Creates a XMLDocType object
 
Method Summary
 java.lang.String attributeQueriesToString()
           
 java.lang.String attributesListToString()
           
 java.lang.String attributeTransformToString()
           
static boolean cacheContainsQuery(java.lang.String qry)
           
static void cacheQueryResult(java.lang.String qry, java.lang.String result)
           
static void clearQueryCache()
          Internal use only.
 void compare(BizDocType oldType, BizDocType newType, java.util.Vector<ActivityLogEntry> logs)
           
 BizDocType copy()
          Creates a new XMLDocType and copies the contents of the current XMLDocType object (ie, "this") to the new XMLDocType object.
static com.wm.data.IData create()
          create needed for IDataCodable implementation.
 BizDocEnvelope createEnvelope(com.wm.data.IData in)
          Factory method for creating a new BizDocEnvelope for a document of this type.
 com.wm.data.IData createPipeline(BizDocEnvelope bizdoc)
          Factory method for creating a pipeline from the given BizDoc.
static void createQueryCache(int size)
          Internal use only.
static com.wm.lang.xql.TreeExpression createXqlQuery(java.lang.String query)
           
static com.wm.lang.xql.TreeExpression createXqlQuery(java.lang.String query, java.lang.String[][] nsDecls)
           
 java.lang.String envelopeQueriesToString()
           
 java.lang.String getAttributeQuery(java.lang.String id)
           
 byte[] getContentBytes(BizDocEnvelope bizdoc)
          Get content of a bizdoc The content of an XML doc is stored in a content part named, "xmldata".
 java.lang.String getContentType(BizDocEnvelope bizdoc)
          Determine the content-type of the bizdoc
 java.lang.Object getDeliveryContent(BizDocEnvelope bizdoc)
          Get delivery content for the given envelope
 java.lang.String getDisplayName()
          Returns a name that will be displayed on the TN Console.
 java.lang.String getDocType()
           
static byte[] getDocumentContent(com.wm.lang.xml.Document doc)
           
static byte[] getDocumentContent(com.wm.data.IData in)
          Used to determine if a pipeline contains an XML document and then turns it into a byte array.
static java.lang.String getDocumentEncoding(com.wm.data.IData in)
           
static com.wm.lang.xml.Document getDocumentNode(BizDocEnvelope env)
           
 java.lang.String getDTD()
           
 java.lang.String getEditorName()
          Returns the name of the editor used to by the TN Console to create and modify instances of a doctype.
static java.lang.String getEncodingFromXML(byte[] data)
          Utility method to scan for the encoding in the XML header.
 EnvelopeData getEnvelopeData(java.lang.String attr)
           
 java.lang.String getEnvelopeQuery(java.lang.String attr)
           
 java.lang.String getFtpFileExtension(BizDocEnvelope bizdoc)
          Get file extension for FTP transport
 com.wm.data.IData getIData()
          IDataCodable implementation.
 java.lang.String[] getIdentifyingQueries()
           
 java.lang.String[] getIdentifyingQueryEvaluations()
           
 java.lang.String[][] getNamespaceMap()
           
 java.lang.String[] getQueries()
           
 java.lang.String[] getQueryEvaluations()
           
static java.lang.String getQueryResult(java.lang.String qry)
           
 com.wm.lang.ns.NSName getRecordBlueprint()
           
 java.lang.String[] getSignatureQueries()
           
 java.util.Enumeration<java.lang.String> getSystemAttributeIds()
          This method overrides implementation in BizDocType and Enumerates List of System attribut IDs after checking if system attribute is available in Envelope Data.
 com.wm.lang.ns.NSName getValidationSchema()
           
 boolean isType(com.wm.data.IData in)
          Abstract method for determining if the IData contains data representing a lower level document type (eg, XML, EDI, etc).
 java.lang.String namespaceDeclToString()
           
 com.wm.lang.xql.TreeExpression newXqlQuery(java.lang.String query)
           
 java.lang.String pipelineDataToString()
           
 java.lang.String queriesToString()
           
 boolean recognize(com.wm.data.IData in)
          Determines if the XML document in the pipeline is of this XMLDocType (eg, cXML_Order_Request).
 void removeAllAttributes()
          Remove all associated attributes including envelope attributes and signature queries.
static boolean s_isType(com.wm.data.IData in)
          Searches for "node" in the pipeline and checks to see if it is XML.
 void setAttributeQuery(BizDocAttribute attr, java.lang.String qry)
           
 void setContentBytes(BizDocEnvelope env, byte[] data)
          Set content of a bizdoc The content of an XML doc is stored in a content part named, "xmldata".
 void setContentBytes(BizDocEnvelope env, byte[] data, java.lang.String enc)
          Set content of a bizdoc.
 void setDocType(java.lang.String docType)
          Sets the DOCTYPE
 void setDTD(java.lang.String dtd)
          Sets the DTD
 void setEnvelopeData(EnvelopeData envelopeData, java.lang.String attr)
          Sets envelope data for a particular envelope attribute
 void setEnvelopeQuery(java.lang.String attr, boolean required, java.lang.String qry, int xFn, java.lang.String[] args)
          Sets a query to determine a particular envelope attribute.
 void setEnvelopeQuery(java.lang.String attr, boolean required, java.lang.String qry, int xFn, java.lang.String[] args, int preFn, java.lang.String[] preFnArgs)
          Sets a query to determine a particular envelope attribute.
 void setEnvelopeQuery(java.lang.String attr, java.lang.String qry, int xFn, java.lang.String[] args)
          Sets a query to determine a particular envelope attribute.
 void setIData(com.wm.data.IData idata)
          Sets the attributes of the class based on a IData object.
 void setIdentifyingQueries(java.lang.String[] queries)
          Set queries used to identify docs of this type
 void setIdentifyingQueries(java.lang.String[] queries, java.lang.String[] results)
          Set queries used to identify docs of this type, and the values to which they must evaluate
 void setNamespaceMap(java.lang.String[][] nsDecls)
          Sets the namespace equivalency map.
 void setRecordBlueprint(com.wm.lang.ns.NSName s)
          Set the NSRecord used to turn docs of this type into records
 void setSignatureQueries(java.lang.String q_sig, java.lang.String q_bod)
          Sets the queries for signature and signed body
 void setValidationSchema(com.wm.lang.ns.NSName s)
          Set the NSSchema used to validate docs of this type
 java.lang.String toString()
          Default toString implementation returns class name followed by contents.
static java.lang.Object[][] XMLDocTypeSchema()
           
 
Methods inherited from class com.wm.app.tn.doc.BizDocType
addBAMAttribute, addPipelineMatch, createActivityLog, determineSenderFromSession, getAttribute, getAttributeIds, getAttributeTransform, getBAMAction, getBAMDocTypeDependency, getBAMDocTypeMapping, getBAMEventMap, getBAMEventMapName, getBAMMonitoringAttributes, getDescription, getFormattedContentPart, getId, getLastModifiedTime, getName, getPipelineMatchIData, getPreRoutingFlags, getSigningService, getSubDocTypeID, getType, getValidationService, getVerificationService, getVersion, isAttributeListEventOption, isAttributeRequired, isDeleted, isFormattedContentPart, isHidden, isMonitored, isRoutable, monitor, newEnvelope, pipelineMatch, removeAttribute, removeBAMAttribute, removePipelineMatch, setAttribute, setAttribute, setAttributeRequirement, setAttributeTransform, setAttributeTransform, setAttributeTransform, setBAMAction, setBAMDocTypeDependency, setBAMDocTypeMapping, setBAMEventMap, setBAMEventMapName, setBAMEventOptionForAttrList, setBAMMonitoringAttributes, setDeleted, setDescription, setDetermineSenderFromSession, setHidden, setId, setLastModifiedTime, setName, setPipelineMatchIData, setPreRoutingFlags, setReceiveSvc, setRouting, setSigningService, setSubDocTypeID, setType, setValidationService, setVerificationService, setVersion
 
Methods inherited from class com.wm.app.tn.util.TNFixedData
clone, dataSize, get, get, getCursor, getHashCursor, getIndexCursor, getKey, getSharedCursor, getTreeCursor, indexOf, merge, set, set
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XMLDocType

public XMLDocType()
Empty constructor. Used to revive instances from persistent storage.


XMLDocType

public XMLDocType(com.wm.data.IData in)
Creates a XMLDocType object

Parameters:
in - IData object containing values for each class attribute.
Method Detail

XMLDocTypeSchema

public static java.lang.Object[][] XMLDocTypeSchema()

s_isType

public static boolean s_isType(com.wm.data.IData in)
Searches for "node" in the pipeline and checks to see if it is XML.

Parameters:
in - pipeline containing keyword and data for XML document
Returns:
true if pipeline contains an XML document of any kind

isType

public boolean isType(com.wm.data.IData in)
Description copied from class: BizDocType
Abstract method for determining if the IData contains data representing a lower level document type (eg, XML, EDI, etc). This is really meant to be a class (static) method but you cant override a static. Each subclass must provide it owns way of determing this. For example, if an XML document then "in" will have a "node" keyword.

Specified by:
isType in class BizDocType
Parameters:
in - IData object containing keyword and data for particular document type
Returns:
true if "in" contains a document of this class type

createQueryCache

public static void createQueryCache(int size)
Internal use only. Called at the start of recognition to create a cache to hold query results for the current thread.


clearQueryCache

public static void clearQueryCache()
Internal use only. Called at the end of recognition to remove the cache of query results for the current thread.


cacheContainsQuery

public static boolean cacheContainsQuery(java.lang.String qry)

getQueryResult

public static java.lang.String getQueryResult(java.lang.String qry)

cacheQueryResult

public static void cacheQueryResult(java.lang.String qry,
                                    java.lang.String result)

recognize

public boolean recognize(com.wm.data.IData in)
                  throws BizDocTypeException
Determines if the XML document in the pipeline is of this XMLDocType (eg, cXML_Order_Request).

Specified by:
recognize in class BizDocType
Parameters:
in - pipeline containing keyword and data for XML document
Returns:
true if the XML document is of this XMLDocType
Throws:
BizDocTypeException - may be thrown if there is an exception when trying to apply the queries

createEnvelope

public BizDocEnvelope createEnvelope(com.wm.data.IData in)
                              throws BizDocTypeException
Factory method for creating a new BizDocEnvelope for a document of this type.

Specified by:
createEnvelope in class BizDocType
Parameters:
in - input IData for the document in question
Returns:
a new BizDocEnvelope
Throws:
BizDocTypeException - may be thrown

createPipeline

public com.wm.data.IData createPipeline(BizDocEnvelope bizdoc)
                                 throws BizDocTypeException
Factory method for creating a pipeline from the given BizDoc.

Specified by:
createPipeline in class BizDocType
Parameters:
bizdoc - input BizDocEnvelope
Returns:
the IData representation of the given envelope
Throws:
BizDocTypeException

copy

public BizDocType copy()
Creates a new XMLDocType and copies the contents of the current XMLDocType object (ie, "this") to the new XMLDocType object.

Specified by:
copy in class BizDocType

getContentBytes

public byte[] getContentBytes(BizDocEnvelope bizdoc)
Get content of a bizdoc The content of an XML doc is stored in a content part named, "xmldata". This method returns the content of the part named "xmldata", returns null if no such part.

Specified by:
getContentBytes in class BizDocType
Parameters:
bizdoc - BizDoc to get the contents
Returns:
the bizdoc content as a byte[]

setContentBytes

public void setContentBytes(BizDocEnvelope env,
                            byte[] data)
Set content of a bizdoc The content of an XML doc is stored in a content part named, "xmldata". This method adds a part named 'xmldata' to the given envelope

Specified by:
setContentBytes in class BizDocType
Parameters:
bizdoc - BizDoc to set the contents
data - the content

setContentBytes

public void setContentBytes(BizDocEnvelope env,
                            byte[] data,
                            java.lang.String enc)
Set content of a bizdoc. The content of an XML doc is stored in a content part named "xmldata". This method adds a part named "xmldata" to the given envelope.

Parameters:
bizdoc - BizDoc to set the contents
data - the content
enc - the encoding, defaults to "UTF8"

getDeliveryContent

public java.lang.Object getDeliveryContent(BizDocEnvelope bizdoc)
                                    throws java.io.IOException
Get delivery content for the given envelope

Overrides:
getDeliveryContent in class BizDocType
Parameters:
bizdoc - BizDocEnvelope to get the delivery content from
Returns:
the content of BizDocEnvelope as a java Object for small documents, the return value will be byte[] for large document, the return value will be InputStream
Throws:
java.io.IOException

getFtpFileExtension

public java.lang.String getFtpFileExtension(BizDocEnvelope bizdoc)
Get file extension for FTP transport

Overrides:
getFtpFileExtension in class BizDocType
Parameters:
bizdoc - BizDocEnvelope to get the ftp file extension
Returns:
the file extention

getDisplayName

public java.lang.String getDisplayName()
Description copied from class: BizDocType
Returns a name that will be displayed on the TN Console. Subclasses should override this method.

Overrides:
getDisplayName in class BizDocType
Returns:
the a name to be displayed in the TN Console

getEditorName

public java.lang.String getEditorName()
Description copied from class: BizDocType
Returns the name of the editor used to by the TN Console to create and modify instances of a doctype. You must override this method if your BizDocType sublass is to be editable in the TN Console.

Overrides:
getEditorName in class BizDocType
Returns:
the the class name of the doctype editor

getQueries

public java.lang.String[] getQueries()
Returns:
the determining queries

getIdentifyingQueries

public java.lang.String[] getIdentifyingQueries()
Returns:
the determining queries

getQueryEvaluations

public java.lang.String[] getQueryEvaluations()
Returns:
the evalution strings to compare when applying a query

getIdentifyingQueryEvaluations

public java.lang.String[] getIdentifyingQueryEvaluations()
Returns:
the evalution strings to compare when applying a query

getDocType

public java.lang.String getDocType()
Returns:
the XML DOCTYPE if there is one

getDTD

public java.lang.String getDTD()
Returns:
the DTD if there is one

getEnvelopeQuery

public java.lang.String getEnvelopeQuery(java.lang.String attr)
Returns:
a particular envelope query

getEnvelopeData

public EnvelopeData getEnvelopeData(java.lang.String attr)
Returns:
envelope data for a particular envelope attribute

setEnvelopeData

public void setEnvelopeData(EnvelopeData envelopeData,
                            java.lang.String attr)
Sets envelope data for a particular envelope attribute


getAttributeQuery

public java.lang.String getAttributeQuery(java.lang.String id)
Parameters:
name - name of the interesting attribute
Returns:
query for the interesting attribute

getContentType

public java.lang.String getContentType(BizDocEnvelope bizdoc)
Determine the content-type of the bizdoc

Specified by:
getContentType in class BizDocType
Parameters:
bizdoc - Envelope to test
Returns:
"text/xml" if bizdoc is of this type, null otherwise

getValidationSchema

public com.wm.lang.ns.NSName getValidationSchema()
Returns:
the NSSchema used to validate docs of this type

getRecordBlueprint

public com.wm.lang.ns.NSName getRecordBlueprint()
Returns:
the NSRecord used to turn docs of this type into records

getSignatureQueries

public java.lang.String[] getSignatureQueries()
Returns:
the query for the signature and signed body

getNamespaceMap

public java.lang.String[][] getNamespaceMap()
Returns:
the namespace prefix-to-uri mappings used while querying

removeAllAttributes

public void removeAllAttributes()
Remove all associated attributes including envelope attributes and signature queries.

Overrides:
removeAllAttributes in class BizDocType

setDocType

public void setDocType(java.lang.String docType)
Sets the DOCTYPE

Parameters:
docType - String representing the DOCTYPE

setDTD

public void setDTD(java.lang.String dtd)
Sets the DTD

Parameters:
dtc - string representing the SYSTEM

setNamespaceMap

public void setNamespaceMap(java.lang.String[][] nsDecls)
Sets the namespace equivalency map.

Parameters:
nsDecls - a set of namespace prefix-to-uri mappings.

setIdentifyingQueries

public void setIdentifyingQueries(java.lang.String[] queries)
                           throws BizDocTypeException
Set queries used to identify docs of this type

Throws:
BizDocTypeException

setIdentifyingQueries

public void setIdentifyingQueries(java.lang.String[] queries,
                                  java.lang.String[] results)
                           throws BizDocTypeException
Set queries used to identify docs of this type, and the values to which they must evaluate

Throws:
BizDocTypeException

setEnvelopeQuery

public void setEnvelopeQuery(java.lang.String attr,
                             java.lang.String qry,
                             int xFn,
                             java.lang.String[] args)
                      throws BizDocTypeException
Sets a query to determine a particular envelope attribute.

Parameters:
attr - one of the DocConstants for envelope queries
qry - defining query for the envelope attribute
xFn - number of the transformation function (use BizDocAttributeTransform constants)
args - arguments for the transformation function, if any
Throws:
BizDocTypeException

setEnvelopeQuery

public void setEnvelopeQuery(java.lang.String attr,
                             boolean required,
                             java.lang.String qry,
                             int xFn,
                             java.lang.String[] args)
                      throws BizDocTypeException
Sets a query to determine a particular envelope attribute.

Parameters:
attr - one of the DocConstants for envelope queries
required - whether or not this attribute is required for the document
qry - defining query for the envelope attribute
xFn - number of the transformation function (use BizDocAttributeTransform constants)
args - arguments for the transformation function, if any
Throws:
BizDocTypeException

setEnvelopeQuery

public void setEnvelopeQuery(java.lang.String attr,
                             boolean required,
                             java.lang.String qry,
                             int xFn,
                             java.lang.String[] args,
                             int preFn,
                             java.lang.String[] preFnArgs)
                      throws BizDocTypeException
Sets a query to determine a particular envelope attribute.

Parameters:
attr - one of the DocConstants for envelope queries
required - whether or not this attribute is required for the document
qry - defining query for the envelope attribute
xFn - number of the transformation function (use BizDocAttributeTransform constants)
args - arguments for the transformation function, if any
preFn - number of the pre transformation function (use BizDocAttributeTransform constants)
preFnArgs - arguments for the pre transformation function, if any
Throws:
BizDocTypeException

setAttributeQuery

public void setAttributeQuery(BizDocAttribute attr,
                              java.lang.String qry)
                       throws BizDocTypeException
Parameters:
name - name of the interesting attribute
qry - query to extract interesting attribute value
Throws:
BizDocTypeException

setValidationSchema

public void setValidationSchema(com.wm.lang.ns.NSName s)
Set the NSSchema used to validate docs of this type


setRecordBlueprint

public void setRecordBlueprint(com.wm.lang.ns.NSName s)
Set the NSRecord used to turn docs of this type into records


setSignatureQueries

public void setSignatureQueries(java.lang.String q_sig,
                                java.lang.String q_bod)
                         throws BizDocTypeException
Sets the queries for signature and signed body

Parameters:
q_sig - identifies the signature in the document (must be B64-encoded)
q_bod - identifies the signed body in the doc
Throws:
BizDocTypeException

getIData

public com.wm.data.IData getIData()
Description copied from class: BizDocType
IDataCodable implementation. If subclasses override this to save additional state, they should always start with a call to super.getIData().

Specified by:
getIData in interface com.wm.util.coder.IDataCodable
Overrides:
getIData in class BizDocType
Returns:
the class as a IData object.

create

public static com.wm.data.IData create()
create needed for IDataCodable implementation.


setIData

public void setIData(com.wm.data.IData idata)
Sets the attributes of the class based on a IData object.

Specified by:
setIData in interface com.wm.util.coder.IDataCodable
Overrides:
setIData in class BizDocType
Parameters:
idata - IData object containing values for class attributes

getSystemAttributeIds

public java.util.Enumeration<java.lang.String> getSystemAttributeIds()
This method overrides implementation in BizDocType and Enumerates List of System attribut IDs after checking if system attribute is available in Envelope Data.

Overrides:
getSystemAttributeIds in class BizDocType
Returns:
a list of system attributes associated with docs of this type

pipelineDataToString

public java.lang.String pipelineDataToString()
Returns:
a String representation of the pipeline data

attributesListToString

public java.lang.String attributesListToString()
Returns:
a String representation of the extracted attributes list

queriesToString

public java.lang.String queriesToString()
Returns:
a String representation of the identify queries

envelopeQueriesToString

public java.lang.String envelopeQueriesToString()
Returns:
a String representation of the envelope queries

attributeQueriesToString

public java.lang.String attributeQueriesToString()
Returns:
a String representation of the attribute queries

attributeTransformToString

public java.lang.String attributeTransformToString()
Returns:
a String representation of the attributes transform

namespaceDeclToString

public java.lang.String namespaceDeclToString()
Returns:
a String representation of the namespace declaration

toString

public java.lang.String toString()
Description copied from class: com.wm.app.tn.util.TNFixedData
Default toString implementation returns class name followed by contents.

Overrides:
toString in class com.wm.app.tn.util.TNFixedData
Returns:
a String representation of the class attributes

compare

public void compare(BizDocType oldType,
                    BizDocType newType,
                    java.util.Vector<ActivityLogEntry> logs)
Specified by:
compare in class BizDocType
Parameters:
logs - the new logs will be added.
priorDocType - the previous value before update operation takes place.
newDocType - the new value against which previous value will be compared.

newXqlQuery

public com.wm.lang.xql.TreeExpression newXqlQuery(java.lang.String query)
                                           throws com.wm.lang.widl.WattException
Throws:
com.wm.lang.widl.WattException

createXqlQuery

public static com.wm.lang.xql.TreeExpression createXqlQuery(java.lang.String query)
                                                     throws com.wm.lang.widl.WattException
Throws:
com.wm.lang.widl.WattException

createXqlQuery

public static com.wm.lang.xql.TreeExpression createXqlQuery(java.lang.String query,
                                                            java.lang.String[][] nsDecls)
                                                     throws com.wm.lang.widl.WattException
Throws:
com.wm.lang.widl.WattException

getDocumentContent

public static byte[] getDocumentContent(com.wm.data.IData in)
                                 throws BizDocTypeException
Used to determine if a pipeline contains an XML document and then turns it into a byte array.

Throws:
BizDocTypeException

getDocumentEncoding

public static java.lang.String getDocumentEncoding(com.wm.data.IData in)
                                            throws BizDocTypeException
Throws:
BizDocTypeException

getDocumentContent

public static byte[] getDocumentContent(com.wm.lang.xml.Document doc)
                                 throws com.wm.lang.widl.WattException
Throws:
com.wm.lang.widl.WattException

getDocumentNode

public static com.wm.lang.xml.Document getDocumentNode(BizDocEnvelope env)
                                                throws java.io.IOException,
                                                       com.wm.lang.xml.WMDocumentException
Throws:
java.io.IOException
com.wm.lang.xml.WMDocumentException

getEncodingFromXML

public static java.lang.String getEncodingFromXML(byte[] data)
Utility method to scan for the encoding in the XML header.

Parameters:
data - the XML document content
Returns:
the encoding declaredin the XML header