xmlBlaster 2.2.0 client API

org.xmlBlaster.client.script
Class XmlScriptInterpreter

java.lang.Object
  extended by org.xmlBlaster.util.SaxHandlerBase
      extended by org.xmlBlaster.client.script.XmlScriptInterpreter
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler
Direct Known Subclasses:
XmlScriptClient, XmlScriptParser

public abstract class XmlScriptInterpreter
extends SaxHandlerBase

Abstract class to parse and construct a XML represantation of xmlBlaster invocations for scripting.

Example for command line scripting usage:

java javaclients.XmlScript -requestFile inFile.xml -responseFile outFile.xml -updateFile updFile.xml

Author:
Michele Laghi
See Also:
The client.script requirement

Field Summary
protected  java.lang.StringBuffer cdata
           
 java.lang.String CONTENT_TAG
           
protected  EncodableData contentData
          Encapsulates the content of the current message (useful for encoding)
 java.lang.String ECHO_TAG
           
protected  boolean forceReadable
           
protected  Global glob
           
protected  boolean inhibitContentCDATAWrapping
           
 java.lang.String INPUT_TAG
           
protected  java.lang.StringBuffer key
           
 java.lang.String KEY_TAG
           
protected  java.util.ArrayList messageList
          used to accumulate all messages to be sent with publishArr
protected  boolean needsRootEndTag
           
protected  java.io.OutputStream out
           
protected  java.lang.StringBuffer qos
           
 java.lang.String QOS_TAG
           
protected  java.lang.StringBuffer response
          buffer used as a place holder for the responses of the xmlBlaster invocations
static java.lang.String ROOT_TAG
           
static java.lang.String ROOTRESPONSE_TAG
           
protected  boolean sendSimpleExceptionFormat
          Set true to send a simple exception format like
protected  java.lang.String simpleExceptionFormatList
           
protected  long updateCounter
           
 java.lang.String WAIT_TAG
           
protected  java.lang.Object waitMutex
           
protected  int waitNumUpdates
           
 
Fields inherited from class org.xmlBlaster.util.SaxHandlerBase
character, locator, xmlLiteral, xmlSource
 
Constructor Summary
XmlScriptInterpreter()
          You need to call initialize() if using this default constructor.
XmlScriptInterpreter(Global glob, java.util.HashMap attachments, java.io.OutputStream out)
          This constructor is the most generic one (more degrees of freedom)
 
Method Summary
protected  MsgUnit buildMsgUnit()
           
 void characters(char[] ch, int start, int length)
          Characters.
static java.lang.String dumpToFile(java.lang.String path, java.lang.String fn, java.lang.String xml)
           
 void endCDATA()
          Report the end of a CDATA section.
 void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
           
abstract  boolean fireMethod(MethodName methodName, java.lang.String sessionId, java.lang.String requestId, byte type)
          On each remote method invocation this function is called.
protected  void flushResponse()
           
 void initialize(Global glob, java.util.HashMap attachments, java.io.OutputStream out)
           
static void main(java.lang.String[] args)
           
 void parse(java.io.Reader in)
          Parses the given reader and executes the specified commands.
 java.lang.String replaceVariable(java.lang.String text)
          Replace e.g.
protected  void serialize(MethodName methodName, java.lang.String sessionId, java.lang.String requestId, MsgUnitRaw[] msgUnits, java.lang.String header, java.lang.String comment, java.lang.String schemaDecl, java.io.OutputStream out, byte type)
          Dump the given MsgUnitRaw to XML.
abstract  void setProperty(java.lang.String key, java.lang.String value)
          Set a property into Global scope.
static java.lang.String simplifiedErrorCode(java.lang.String codeList, java.lang.String errCode)
          made public only for testing purposes
 void startCDATA()
          Report the start of a CDATA section.
 void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          Receive notification of the beginning of an element.
 java.lang.String update(java.lang.String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos)
          If a callback handler was registered, we will be notified here about updates as well
 java.lang.String wrapForScripting(MsgUnit msgUnit, java.lang.String comment)
           
static java.lang.String wrapForScripting(java.lang.String rootTag, MsgUnit[] msgUnitArr, java.lang.String comment)
           
static java.lang.String wrapForScripting(java.lang.String rootTag, MsgUnit msgUnit, java.lang.String comment)
          Dump the MsgUnit to XML, the dump includes the xml header (UTF-8).
protected  java.lang.String writeElementStart(java.lang.String qName, org.xml.sax.Attributes attr)
          converts the tag sctart to a string
 
Methods inherited from class org.xmlBlaster.util.SaxHandlerBase
comment, endDocument, endDTD, endEntity, endPrefixMapping, error, fatalError, getUseLexicalHandler, ignorableWhitespace, init, init, init, notationDecl, processingInstruction, setDocumentLocator, setUseLexicalHandler, skippedEntity, startDocument, startDTD, startEntity, startPrefixMapping, toString, toXml, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

glob

protected Global glob

qos

protected java.lang.StringBuffer qos

key

protected java.lang.StringBuffer key

cdata

protected java.lang.StringBuffer cdata

contentData

protected EncodableData contentData
Encapsulates the content of the current message (useful for encoding)


messageList

protected java.util.ArrayList messageList
used to accumulate all messages to be sent with publishArr


response

protected java.lang.StringBuffer response
buffer used as a place holder for the responses of the xmlBlaster invocations


needsRootEndTag

protected boolean needsRootEndTag

out

protected java.io.OutputStream out

waitMutex

protected java.lang.Object waitMutex

updateCounter

protected long updateCounter

waitNumUpdates

protected int waitNumUpdates

sendSimpleExceptionFormat

protected boolean sendSimpleExceptionFormat
Set true to send a simple exception format like
      <update type='E'>
       <qos><state id='ERROR' info='user'/></qos>
      </update>
      

Note: The errorCode is stripped to the main category


simpleExceptionFormatList

protected java.lang.String simpleExceptionFormatList

forceReadable

protected boolean forceReadable

inhibitContentCDATAWrapping

protected boolean inhibitContentCDATAWrapping

ROOT_TAG

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

ROOTRESPONSE_TAG

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

KEY_TAG

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

CONTENT_TAG

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

QOS_TAG

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

ECHO_TAG

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

INPUT_TAG

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

WAIT_TAG

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

XmlScriptInterpreter

public XmlScriptInterpreter()
You need to call initialize() if using this default constructor.


XmlScriptInterpreter

public XmlScriptInterpreter(Global glob,
                            java.util.HashMap attachments,
                            java.io.OutputStream out)
This constructor is the most generic one (more degrees of freedom)

Parameters:
glob - the global to use
attachments - the attachments where to search when a content is stored in the attachment (with the 'link' attribute); can be null
out - the OutputStream where to send the responses of the invocations done to xmlBlaster
Method Detail

initialize

public void initialize(Global glob,
                       java.util.HashMap attachments,
                       java.io.OutputStream out)
Parameters:
glob - the global to use
attachments - the attachments where to search when a content is stored in the attachment (with the 'link' attribute)
out - the OutputStream where to send the responses of the invocations done to xmlBlaster

writeElementStart

protected java.lang.String writeElementStart(java.lang.String qName,
                                             org.xml.sax.Attributes attr)
converts the tag sctart to a string

Parameters:
qName -
attr -
Returns:

parse

public void parse(java.io.Reader in)
           throws XmlBlasterException
Parses the given reader and executes the specified commands.

Parameters:
in - the reader from which to read the xml input.
Throws:
XmlBlasterException

characters

public void characters(char[] ch,
                       int start,
                       int length)
Description copied from class: SaxHandlerBase
Characters. The text between two tags, in the following example 'Hello': Hello

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class SaxHandlerBase

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
Description copied from class: SaxHandlerBase
Receive notification of the beginning of an element. The Parser will invoke this method at the beginning of every element in the XML document; there will be a corresponding endElement event for every startElement event (even when the element is empty). All of the element's content will be reported, in order, before the corresponding endElement event.

Example:

With a namespace: <database:adapter xmlns:database='http://www.xmlBlaster.org/jdbc'/>

uri=http://www.xmlBlaster.org/jdbc localName=adapter name=database:adapter

Without a namespace: <adapter/>

uri= localName=adapter name=adapter

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class SaxHandlerBase

replaceVariable

public java.lang.String replaceVariable(java.lang.String text)
Replace e.g. ${XY} with the variable from global properties.

Parameters:
text - The complete string which may contain zero to many ${...} variables, if null we return null
Returns:
The new value where all found ${} are replaced.

fireMethod

public abstract boolean fireMethod(MethodName methodName,
                                   java.lang.String sessionId,
                                   java.lang.String requestId,
                                   byte type)
                            throws XmlBlasterException
On each remote method invocation this function is called.

Parameters:
methodName -
type - 'I'=invoke 'R'=response 'E'=exception
Returns:
true: The methodName was known and is successfully processed false: The methodName is not known and nothing is processed
Throws:
XmlBlasterException - Will lead to stop parsing further

setProperty

public abstract void setProperty(java.lang.String key,
                                 java.lang.String value)
                          throws XmlBlasterException
Set a property into Global scope.

Throws:
XmlBlasterException

flushResponse

protected void flushResponse()
                      throws XmlBlasterException
Throws:
XmlBlasterException

buildMsgUnit

protected MsgUnit buildMsgUnit()
                        throws XmlBlasterException
Throws:
XmlBlasterException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qName)
Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class SaxHandlerBase

startCDATA

public void startCDATA()
Description copied from class: SaxHandlerBase
Report the start of a CDATA section. (interface LexicalHandler)

Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
startCDATA in class SaxHandlerBase

endCDATA

public void endCDATA()
Description copied from class: SaxHandlerBase
Report the end of a CDATA section. (interface LexicalHandler)

Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
endCDATA in class SaxHandlerBase

wrapForScripting

public java.lang.String wrapForScripting(MsgUnit msgUnit,
                                         java.lang.String comment)

wrapForScripting

public static java.lang.String wrapForScripting(java.lang.String rootTag,
                                                MsgUnit msgUnit,
                                                java.lang.String comment)
Dump the MsgUnit to XML, the dump includes the xml header (UTF-8).
Example:
 String xml = XmlScriptInterpreter.wrapForScripting(
      XmlScriptInterpreter.ROOT_TAG,
       msgUnit,
      "XmlScripting dump");

Parameters:
rootTag - Usually XmlScriptInterpreter.ROOT_TAG="xmlBlaster"
msgUnit - null is OK
comment - Some comment you want to add or null
Returns:

wrapForScripting

public static java.lang.String wrapForScripting(java.lang.String rootTag,
                                                MsgUnit[] msgUnitArr,
                                                java.lang.String comment)

serialize

protected void serialize(MethodName methodName,
                         java.lang.String sessionId,
                         java.lang.String requestId,
                         MsgUnitRaw[] msgUnits,
                         java.lang.String header,
                         java.lang.String comment,
                         java.lang.String schemaDecl,
                         java.io.OutputStream out,
                         byte type)
                  throws java.io.IOException
Dump the given MsgUnitRaw to XML. Example for a PublishReturnQos:
 <-- A comment -->
   <publish>
     <qos>
      <key oid='1'/>
      <rcvTimestamp nanos='1131654994574000000'/>
     <isPublish/>
     </qos>
  </publish>

Parameters:
methodName - The method to invoke, like "publishArr"
sessionId - An optional sessionId or null
requestId - An optional requestId or null
msgUnits - The msgUnits to serialize
header - For example
comment - An optional comment to add, can be null
schemaDecl - Used for root tag, for example xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='xmlBlasterPublish.xsd'
out - The output sink for the result
type - 'I' is for invoke, 'R' for reply and 'E' for exception
Throws:
XmlBlasterException
java.io.IOException

simplifiedErrorCode

public static java.lang.String simplifiedErrorCode(java.lang.String codeList,
                                                   java.lang.String errCode)
made public only for testing purposes

Parameters:
errCode -
Returns:

dumpToFile

public static java.lang.String dumpToFile(java.lang.String path,
                                          java.lang.String fn,
                                          java.lang.String xml)
                                   throws XmlBlasterException
Throws:
XmlBlasterException

update

public java.lang.String update(java.lang.String cbSessionId,
                               UpdateKey updateKey,
                               byte[] content,
                               UpdateQos updateQos)
                        throws XmlBlasterException
If a callback handler was registered, we will be notified here about updates as well

Parameters:
cbSessionId -
updateKey -
content -
updateQos -
Returns:
Throws:
XmlBlasterException

main

public static void main(java.lang.String[] args)

xmlBlaster 2.2.0 client API

Copyright © 1999-2014 The xmlBlaster.org contributers.