org.peaseplate.internal.lang.command
Class InvocationCommand

java.lang.Object
  extended by org.peaseplate.internal.lang.command.AbstractCommand
      extended by org.peaseplate.internal.lang.command.AbstractSingleParameterCommand
          extended by org.peaseplate.internal.lang.command.AbstractNativeCallCommand
              extended by org.peaseplate.internal.lang.command.AbstractObjectCallCommand
                  extended by org.peaseplate.internal.lang.command.InvocationCommand
All Implemented Interfaces:
ICommand

public class InvocationCommand
extends AbstractObjectCallCommand

This command does the whole magic. It invokes the method that matches the identifier and the parameterCommands. Since the language is not strictly type, this may be complicated some times. Any method that has a name similar to the identifier, or the identifier prefixed with "get", "is" or "set" (the case is ignored) will be taken into consideration. Next it checks the number (not the type) of the parameterCommands. Hopefully this results in just one method. If there are still multiple methods with name and the same parameter count, it searches for the method that most exactly fits the types of the parameterCommands (this may vary each time the command is called, because the language is not strictly typed). To get this whole stuff acceptable fast, it stores all possible methods in a list the first time the command is invoked. Due to the fact, that the language is not strictly typed, it even is possible that the class may change on which this command is invoked. Thus the list with the commands is stored in a hash map with the class as key.


Constructor Summary
InvocationCommand(TemplateLocator locator, int line, int column, ICommand command, java.lang.String identifier, ICommand[] parameterCommands)
           
 
Method Summary
 java.lang.Object call(BuildContext context)
           
protected  java.lang.Object callObject(BuildContext context, java.lang.Object onObject, java.lang.Object identifier)
          Usually an invocation command calls a method, but if there is no method matching the identifier and the object is a map, and the identifier is a string, and there are no parameters, then the map is accessed
protected  java.lang.reflect.Field getField(java.lang.Class<?> clazz, java.lang.String identifier)
           
protected  java.lang.reflect.Method getMethod(java.lang.Class<?> clazz, java.lang.String identifier, int numberOfParameters)
           
 java.lang.String toString()
           
 
Methods inherited from class org.peaseplate.internal.lang.command.AbstractObjectCallCommand
callArray, callField, callFieldOrMethod, callList, callMap, callMethod, callMethod, findField, scanFields
 
Methods inherited from class org.peaseplate.internal.lang.command.AbstractNativeCallCommand
callCommand, getNumberOfParameters, getParameterCommands, hasParameters
 
Methods inherited from class org.peaseplate.internal.lang.command.AbstractSingleParameterCommand
getCommand
 
Methods inherited from class org.peaseplate.internal.lang.command.AbstractCommand
getColumn, getLine, getLocator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InvocationCommand

public InvocationCommand(TemplateLocator locator,
                         int line,
                         int column,
                         ICommand command,
                         java.lang.String identifier,
                         ICommand[] parameterCommands)
Method Detail

call

public java.lang.Object call(BuildContext context)
                      throws TemplateRuntimeException
Throws:
TemplateRuntimeException
See Also:
ICommand.call(BuildContext)

callObject

protected java.lang.Object callObject(BuildContext context,
                                      java.lang.Object onObject,
                                      java.lang.Object identifier)
                               throws TemplateRuntimeException
Usually an invocation command calls a method, but if there is no method matching the identifier and the object is a map, and the identifier is a string, and there are no parameters, then the map is accessed

Specified by:
callObject in class AbstractObjectCallCommand
onObject - the object
identifier - the name of the map entry, the index of the list, or the name of the method.
Returns:
the result
Throws:
TemplateRuntimeException
See Also:
AbstractObjectCallCommand.callObject(org.peaseplate.internal.BuildContext, java.lang.Object, java.lang.Object)

getField

protected java.lang.reflect.Field getField(java.lang.Class<?> clazz,
                                           java.lang.String identifier)
                                    throws TemplateRuntimeException
Specified by:
getField in class AbstractObjectCallCommand
Throws:
TemplateRuntimeException
See Also:
org.peaseplate.internal.lang.command.AbstractNativeCallCommand#getField(java.lang.Class, java.lang.String)

getMethod

protected java.lang.reflect.Method getMethod(java.lang.Class<?> clazz,
                                             java.lang.String identifier,
                                             int numberOfParameters)
                                      throws TemplateRuntimeException
Specified by:
getMethod in class AbstractObjectCallCommand
Throws:
TemplateRuntimeException
See Also:
AbstractObjectCallCommand.getMethod(java.lang.Class, java.lang.String, int)

toString

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


Copyright © 2008. All Rights Reserved.