org.peaseplate.internal.lang.command
Class QueryCommand

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.QueryCommand
All Implemented Interfaces:
ICommand

public class QueryCommand
extends AbstractObjectCallCommand

This command does the whole magic. It invokes the method that matches the identifier and the parameters. 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 parameters. 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 parameters (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
QueryCommand(TemplateLocator locator, int line, int column, ICommand command, ICommand identifierCommand, 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)
          Distinguishes between maps, lists and other objects.
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

QueryCommand

public QueryCommand(TemplateLocator locator,
                    int line,
                    int column,
                    ICommand command,
                    ICommand identifierCommand,
                    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
Description copied from class: AbstractObjectCallCommand
Distinguishes between maps, lists and other objects. If object is a map, it resolves the return value from the map. If the object is a list and the identifier is a number, it resolves the return value from the list. If the object is an array and the identifier is a number, it resolves the return value from the array. In any other case, it invokes the method with the specified identifier and the parameters on the object. It depends on the call in which order the options are used.

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.