org.jscience.ml.cml.cmlimpl
Class BaseToolImpl

java.lang.Object
  extended by org.jscience.ml.cml.cmlimpl.BaseToolImpl
All Implemented Interfaces:
BaseTool

public class BaseToolImpl
extends java.lang.Object
implements BaseTool

Performs editing functions on a generic CMLObject


Field Summary
protected  AbstractBase abstractBase
           
protected static java.util.Hashtable baseToolTable
           
protected static java.lang.String CONSTRUCT
           
protected  boolean debug
           
protected  java.lang.reflect.Constructor[] declaredPublicConstructors
           
protected  java.lang.reflect.Method[] declaredPublicMethods
           
protected  AbstractCMLDocument document
           
protected static java.lang.String editorPackageName
           
protected  java.util.Hashtable ignoreAttributeTable
           
protected static JumboLogger jumboLogger
           
protected static java.lang.String TEST
           
protected  Workflow workflow
           
 
Fields inherited from interface org.jscience.ml.cml.BaseTool
DOUBLE, INTEGER, STRING, XSD_DOUBLE, XSD_INTEGER, XSD_STRING
 
Constructor Summary
protected BaseToolImpl()
          new BaseTool.
protected BaseToolImpl(AbstractBase base)
           
  BaseToolImpl(AbstractCMLDocument document)
          new BaseTool containing a new AbstractBase.
 
Method Summary
 void characters(SaxHandler saxHandler, java.lang.String content)
          SAX2 parsing routine - called from characters() callback

NOT namespace aware

static void clear(java.util.Hashtable editorTable)
          clears an editorTable.
protected  void constructorsUsage()
           
static java.lang.String convertClassToInterface(java.lang.String className)
          converts CML classname to interface.
static java.lang.String convertInterfaceToClass(java.lang.String interfaceName)
          converts CMLInterface to class.
 void copyAttributesFromTo(AbstractBase from, AbstractBase to)
          copy attributes from one AbstractBase to another.
static BaseTool createToolForName(java.lang.String baseName)
          constructs a tools class object.
protected  void debug(java.lang.String s)
          output string if debug set
 void endElement(SaxHandler saxHandler)
          SAX2 parsing routine - called from endElement() callback

NOT namespace aware

 boolean equals(BaseTool baseTool)
          is the contained object equal to the other contained object.
 java.lang.String formatNumber(java.lang.String s)
           
 AbstractBase getAbstractBase()
          get abstract base

only defined for implemented editors (default => null)

 AbstractCMLDocument getCMLDocument()
           
protected  java.lang.reflect.Constructor getConstructor(java.util.List argVector)
           
 boolean getDebug()
          debug status
 java.lang.reflect.Constructor[] getDeclaredPublicConstructors()
          get all public constructors belonging just to this class.
 java.lang.reflect.Method[] getDeclaredPublicMethods()
          get all public methods belonging just to this class.
protected static double[] getDoubleArgs(int start, int nargs, java.lang.String[] args)
           
protected  java.lang.reflect.Method getMethod(java.lang.String methodS, java.util.List argVector)
           
 BaseTool getTestInstance(AbstractCMLDocument doc, int serial)
          a standard instance for testing.
static BaseTool getTool(AbstractBase base)
          gets tool or creates new one.
static BaseTool getTool(AbstractBase base, BaseTool tool)
          gets existing tool for base or returns tool after initialising it with base.
protected  java.lang.reflect.Method getUniqueMethod(java.lang.String methodS)
          gets unique method if possible does not use args at present
 Workflow getWorkflow()
          get the workflow.
protected  void methodsUsage()
           
 void mustEqual(BaseTool otherTool)
          throws exception if the contained object is not equal to the other contained object.
 void mustEqualAttributes(BaseTool otherTool)
           
 void mustEqualChildNodes(BaseTool otherTool)
           
 void processArgs(java.lang.String[] args)
          process args.
 int processCommandLine(java.lang.String[] args, int offset, java.util.List argVector, AbstractCMLDocument doc)
          process the commandline from main routines.
 void processCurrentCommand(Workflow workflow)
          run workflow script or object.
 org.w3c.dom.Element removeElement(java.lang.String elementName)
          removes the first element by tagName

finds first element with that name and removes it from its parent.

 java.lang.Object runConstructor(java.util.List argVector)
          run any public constructor introspects the above constructors Example: CMLVector3 projectOnto(CMLVector3 v) is called with v as arg v1, v2 and floatArg as dontCare and returns Object of type CMLVector3
 java.lang.Object runMethod(java.lang.String methodS, java.util.List argVector)
          run any public method introspects the above methods Example: CMLVector3 projectOnto(CMLVector3 v) is called with v as arg v1, v2 and floatArg as dontCare and returns Object of type CMLVector3 Returns without action if duplicate method name
 void setAbstractBase(AbstractBase ab)
          set abstract base

only defined for implemented editors (default => null) should not be required in user code

 void setDebug(boolean d)
          toggle debugging
 void setIgnoreAttribute(java.lang.String name, boolean descend)
          ignore an attribute
static void setToolPackage(java.lang.String pName)
          set Tool package.
 void startElement(SaxHandler saxHandler, org.xml.sax.Attributes attributes)
          SAX2 parsing routine - called from startElement() callback

NOT namespace aware

protected  void superInit(AbstractBase base)
           
 void testMethods()
          test all declared public methods.
 void transferChildrenFromTo(AbstractBase from, AbstractBase to)
          transfer children from one AbstractBase to another.
protected  void usage(java.lang.String className)
           
 void writeXML(java.io.Writer w, java.lang.String control)
          write XML, using class-specific information

NOT namespace aware

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jumboLogger

protected static JumboLogger jumboLogger

editorPackageName

protected static java.lang.String editorPackageName

CONSTRUCT

protected static java.lang.String CONSTRUCT

TEST

protected static java.lang.String TEST

baseToolTable

protected static java.util.Hashtable baseToolTable

abstractBase

protected AbstractBase abstractBase

document

protected AbstractCMLDocument document

debug

protected boolean debug

ignoreAttributeTable

protected java.util.Hashtable ignoreAttributeTable

workflow

protected Workflow workflow

declaredPublicMethods

protected java.lang.reflect.Method[] declaredPublicMethods

declaredPublicConstructors

protected java.lang.reflect.Constructor[] declaredPublicConstructors
Constructor Detail

BaseToolImpl

protected BaseToolImpl()
new BaseTool.

only for use by subclasses


BaseToolImpl

public BaseToolImpl(AbstractCMLDocument document)
new BaseTool containing a new AbstractBase.

uses document as owner

Parameters:
document - the owner document

BaseToolImpl

protected BaseToolImpl(AbstractBase base)
Method Detail

superInit

protected void superInit(AbstractBase base)

getTool

public static BaseTool getTool(AbstractBase base)
gets tool or creates new one.

Parameters:
base -
Returns:
the tool (null if molecule is null)

getTool

public static BaseTool getTool(AbstractBase base,
                               BaseTool tool)
gets existing tool for base or returns tool after initialising it with base.

Parameters:
base - the item that you want a tool for
tool - the tool to use should base not already have one
Returns:
the tool (null if molecule is null)

getCMLDocument

public AbstractCMLDocument getCMLDocument()

getAbstractBase

public AbstractBase getAbstractBase()
get abstract base

only defined for implemented editors (default => null)

Specified by:
getAbstractBase in interface BaseTool
Returns:
the element associated with this editor (null for default)

setAbstractBase

public void setAbstractBase(AbstractBase ab)
set abstract base

only defined for implemented editors (default => null) should not be required in user code

Specified by:
setAbstractBase in interface BaseTool
Parameters:
ab - the element associated with this editor

equals

public boolean equals(BaseTool baseTool)
is the contained object equal to the other contained object.

The two objects contained in the elements are compared. The default is to use an element-by-element and attribute-by-attribute comparison. This can be overridden for subclasses. For example the order of children in some elements matters while in others (e.g. molecules) it does not. The compared object must be of the same class but may have different namespace prefix, etc. By default ownerDocuments are ignored (thus molecules in different documents can be compared.)

childElements are compared using their equals() methods

The editors may have special methods to affect of control equality. Thus it is possible to ignore Ids.

If the reason for non-equality is required, the mustEqual() method should be used.

Specified by:
equals in interface BaseTool
Parameters:
baseTool - the other element editor (must be of same class)

mustEqual

public void mustEqual(BaseTool otherTool)
               throws CMLException
throws exception if the contained object is not equal to the other contained object.

see equals() for strategy.

Specified by:
mustEqual in interface BaseTool
Parameters:
otherTool - the other element (must be of same class)
Throws:
CMLException - the reason for non-equality

mustEqualAttributes

public void mustEqualAttributes(BaseTool otherTool)
                         throws CMLException
Throws:
CMLException

mustEqualChildNodes

public void mustEqualChildNodes(BaseTool otherTool)
                         throws CMLException
Throws:
CMLException

setIgnoreAttribute

public void setIgnoreAttribute(java.lang.String name,
                               boolean descend)
ignore an attribute

Specified by:
setIgnoreAttribute in interface BaseTool
Parameters:
name - attribute to ignore
descend - carry over to descendants

removeElement

public org.w3c.dom.Element removeElement(java.lang.String elementName)
removes the first element by tagName

finds first element with that name and removes it from its parent. mainly for debugging

Specified by:
removeElement in interface BaseTool
Returns:
the element removed

characters

public void characters(SaxHandler saxHandler,
                       java.lang.String content)
                throws CMLException
SAX2 parsing routine - called from characters() callback

NOT namespace aware

Specified by:
characters in interface BaseTool
Parameters:
saxHandler - SaxHandler
content - throws exception (probably application specific)
Throws:
CMLException

endElement

public void endElement(SaxHandler saxHandler)
                throws CMLException
SAX2 parsing routine - called from endElement() callback

NOT namespace aware

Specified by:
endElement in interface BaseTool
Parameters:
saxHandler - Saxhandler throws exception (probably application specific)
Throws:
CMLException

startElement

public void startElement(SaxHandler saxHandler,
                         org.xml.sax.Attributes attributes)
                  throws CMLException
SAX2 parsing routine - called from startElement() callback

NOT namespace aware

Specified by:
startElement in interface BaseTool
Parameters:
saxHandler - Saxhandler
attributes - the attribute list throws exception (probably application specific)
Throws:
CMLException

writeXML

public void writeXML(java.io.Writer w,
                     java.lang.String control)
              throws CMLException,
                     java.io.IOException
write XML, using class-specific information

NOT namespace aware

Specified by:
writeXML in interface BaseTool
Parameters:
w - the writer
control - (concatenation of CML version and array)
Throws:
exception - (probably application specific)
CMLException
java.io.IOException

setDebug

public void setDebug(boolean d)
toggle debugging

Parameters:
d - debug

getDebug

public boolean getDebug()
debug status

Returns:
is debug set

debug

protected void debug(java.lang.String s)
output string if debug set

Parameters:
s - string to output

copyAttributesFromTo

public void copyAttributesFromTo(AbstractBase from,
                                 AbstractBase to)
copy attributes from one AbstractBase to another.

overwrites existing atts

Specified by:
copyAttributesFromTo in interface BaseTool
Parameters:
from - element to copy from
to - element to copy to

transferChildrenFromTo

public void transferChildrenFromTo(AbstractBase from,
                                   AbstractBase to)
transfer children from one AbstractBase to another.

Specified by:
transferChildrenFromTo in interface BaseTool
Parameters:
from - element to copy from
to - element to copy to

clear

public static void clear(java.util.Hashtable editorTable)
clears an editorTable.

Parameters:
editorTable - the table to clear

setToolPackage

public static void setToolPackage(java.lang.String pName)
set Tool package.

Parameters:
pName - the package in which Tools will be found

createToolForName

public static BaseTool createToolForName(java.lang.String baseName)
constructs a tools class object.

at present converts "moleculeTool" to [currentPackage].MoleculeToolImpl Does NOT use or create a DOM, so only use for accesing class methods e.g. in workflow

Returns:
object (or null if cannot create)

processCurrentCommand

public void processCurrentCommand(Workflow workflow)
                           throws CMLException
run workflow script or object.

sets workflow to the tool and runs the current command all information (current command, symbolTables can be accessed from workflow

Specified by:
processCurrentCommand in interface BaseTool
Parameters:
workflow - to process.
Throws:
CMLException

getWorkflow

public Workflow getWorkflow()
get the workflow.

Specified by:
getWorkflow in interface BaseTool
Returns:
workflow

formatNumber

public java.lang.String formatNumber(java.lang.String s)

getDeclaredPublicConstructors

public java.lang.reflect.Constructor[] getDeclaredPublicConstructors()
get all public constructors belonging just to this class.

Returns:
array of constructors

getDeclaredPublicMethods

public java.lang.reflect.Method[] getDeclaredPublicMethods()
get all public methods belonging just to this class.

Specified by:
getDeclaredPublicMethods in interface BaseTool
Returns:
array of methods

runConstructor

public java.lang.Object runConstructor(java.util.List argVector)
run any public constructor introspects the above constructors Example: CMLVector3 projectOnto(CMLVector3 v) is called with v as arg v1, v2 and floatArg as dontCare and returns Object of type CMLVector3

Parameters:
argVector - arguments in order.
Returns:
the constructor value

runMethod

public java.lang.Object runMethod(java.lang.String methodS,
                                  java.util.List argVector)
run any public method introspects the above methods Example: CMLVector3 projectOnto(CMLVector3 v) is called with v as arg v1, v2 and floatArg as dontCare and returns Object of type CMLVector3 Returns without action if duplicate method name

Specified by:
runMethod in interface BaseTool
Parameters:
methodS - case-sensitive method.
argVector - arguments in order. First arg is instance of this
Returns:
any return value (see Method.invoke for classes)

getMethod

protected java.lang.reflect.Method getMethod(java.lang.String methodS,
                                             java.util.List argVector)

getConstructor

protected java.lang.reflect.Constructor getConstructor(java.util.List argVector)

getUniqueMethod

protected java.lang.reflect.Method getUniqueMethod(java.lang.String methodS)
gets unique method if possible does not use args at present

Parameters:
methodS - method name
Returns:
unique method for that name

getDoubleArgs

protected static double[] getDoubleArgs(int start,
                                        int nargs,
                                        java.lang.String[] args)

usage

protected void usage(java.lang.String className)

constructorsUsage

protected void constructorsUsage()

methodsUsage

protected void methodsUsage()

testMethods

public void testMethods()
test all declared public methods. introspects args and creates test instances from primitives or getTestInstance(); cannot create arg which require arrays so skips method also may skip some superclasses


convertInterfaceToClass

public static java.lang.String convertInterfaceToClass(java.lang.String interfaceName)
converts CMLInterface to class. e.g. converts org.jscience.ml.cml.CMLVector3 to org.jscience.ml.cml.cmlimpl.Vector3Impl and AbstractBase to CMLBaseImpl

Parameters:
interfaceName - the interface
Returns:
the class name

convertClassToInterface

public static java.lang.String convertClassToInterface(java.lang.String className)
converts CML classname to interface. e.g. converts org.jscience.ml.cml.cmlimpl.Vector3Impl to org.jscience.ml.cml.CMLVector3 and CMLBaseImpl to AbstractBase

Parameters:
className -
Returns:
the interface name

processArgs

public void processArgs(java.lang.String[] args)
process args.

Parameters:
args -

getTestInstance

public BaseTool getTestInstance(AbstractCMLDocument doc,
                                int serial)
a standard instance for testing. returns null unless subclassed

Specified by:
getTestInstance in interface BaseTool
Parameters:
doc - the owner document
serial - the instance (1,2,3)
Returns:
null

processCommandLine

public int processCommandLine(java.lang.String[] args,
                              int offset,
                              java.util.List argVector,
                              AbstractCMLDocument doc)
process the commandline from main routines. normally subclassed

Specified by:
processCommandLine in interface BaseTool
Parameters:
args - the arguments
offset - current position in args
argVector - vector to accumulate arguments
doc - owner document
Returns:
position in args after parsing