org.apache.torque.generator.template.velocity

## Class TorqueGenVelocity

- java.lang.Object
- - org.apache.torque.generator.template.velocity.TorqueGenVelocity

-     public class TorqueGenVelocity
      extends Object

  This class acts as an interface to the Torque generator from the templates. It lets the user access Torque generator properties from the templates, and allows to execute certain action from within the templates.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TorqueGenVelocity(VelocityOutlet outlet, ControllerState controllerState)` Constructs a generator interface within the given controllerState.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `booleanOption(String key)` Returns the option with the given key as boolean value.
    `SourceElement` | `getChild(String name)` Returns the first child of the current source element with the given name.
    `List<SourceElement>` | `getChildren()` Returns all children of the current source element.
    `List<SourceElement>` | `getChildren(String name)` Returns the children of the current source element with a certain name.
    `ControllerState` | `getControllerState()` Returns the current controller state.
    `static int` | `getCounter()` Returns a counter value which is increased each time this function is accessed.
    `Object` | `getModel()` Returns the current model object.
    `SourceElement` | `getParent()` Returns the parent of the current source element.
    `SourceElement` | `getSourceElement()` Returns the current source element, if it is a SourceElement.
    `File` | `getSourceFile()` Returns the currently processed source file.
    `Object` | `getVariable(String key)` Returns the variable with the given key.
    `int` | `intOption(String key)` Returns the option with the given key as int value.
    `String` | `mergepoint(String mergepointName)` Processes the mergepoint with the given name.
    `Date` | `now()` Returns the current date.
    `Object` | `option(String key)` Returns the option with the given key.
    `static void` | `resetCounter()` Resets the counter accessible though `getCounter()` back to 1.
    `void` | `setVariable(String key, Object value)` Sets a variable.
    `void` | `setVariable(String key, Object value, String scope)` Sets a variable.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TorqueGenVelocity

          public TorqueGenVelocity(VelocityOutlet outlet,
                                   ControllerState controllerState)

      Constructs a generator interface within the given controllerState.
      Parameters:
        `outlet` - the outlet in which this generator interface will be used, not null.
        `controllerState` - the controller context.
      Throws:
        `NullPointerException` - if outlet or controllerState are null.

  - ### Method Detail

    - #### mergepoint

          public String mergepoint(String mergepointName)
                            throws GeneratorException

      Processes the mergepoint with the given name.
      Parameters:
        `mergepointName` - the name of the mergepoint.
      Returns:
        the output generated by the mergepoint.
      Throws:
        `GeneratorException` - if the mergepoint could not be processed completely.

    - #### getControllerState

          public ControllerState getControllerState()

      Returns the current controller state.
      Returns:
        The current controller state, never null.

    - #### getModel

          public Object getModel()

      Returns the current model object. This method is shorthand for `getControllerState().getModel()`
      Returns:
        the current source element, never null.

    - #### getSourceElement

          public SourceElement getSourceElement()
                                         throws SourceException

      Returns the current source element, if it is a SourceElement. This method is shorthand for `(SourceElement)getControllerState().getModel()`
      Returns:
        the current source element, never null.
      Throws:
        `SourceException` - if the model is no SourceElement

    - #### getChildren

          public List<SourceElement> getChildren()
                                          throws SourceException

      Returns all children of the current source element. This method is shorthand for `getSourceElement().getChildren()`
      Returns:
        the children of the current source element, never null.
      Throws:
        `SourceException` - if the model is no SourceElement

    - #### getChildren

          public List<SourceElement> getChildren(String name)
                                          throws SourceException

      Returns the children of the current source element with a certain name. This method is shorthand for `getSourceElement().getChildren(name)`
      Parameters:
        `name` - the name of the children elements to select.
      Returns:
        the children of the current source element with the name name, never null.
      Throws:
        `SourceException` - if the model is no SourceElement

    - #### getChild

          public SourceElement getChild(String name)
                                 throws SourceException

      Returns the first child of the current source element with the given name. This method is shorthand for `getSourceElement().getChild(name)`
      Parameters:
        `name` - the name of the child element to select.
      Returns:
        the first child with the given name, or null if no such child exists.
      Throws:
        `SourceException` - if the model is no SourceElement

    - #### getParent

          public SourceElement getParent()
                                  throws SourceException

      Returns the parent of the current source element. `getSourceElement().getParent()`
      Returns:
        the parent of the current source element, or null if the current source element has no parent.
      Throws:
        `SourceException` - if the model is no SourceElement

    - #### option

          public Object option(String key)

      Returns the option with the given key. The key can either be a name prefixed with a namespace, or a name without namespace, in which case the namespace of the currently active outlet is used. In the case that the option is not set in this namespace, the parent namespaces are searched recursively. If the option is not set in any of the parent namespaces, null is returned.
      Parameters:
        `key` - the key for the option to retrieve.
      Returns:
        the option for the given key.

    - #### booleanOption

          public boolean booleanOption(String key)

      Returns the option with the given key as boolean value. The key can either be a name prefixed with a namespace, or a name without namespace, in which case the namespace of the currently active outlet is used. In the case that the option is not set in this namespace, the parent namespaces are searched recursively. If the option is not set in any of the parent namespaces, false is returned.
      Parameters:
        `key` - the key for the option to retrieve.
      Returns:
        the option for the given key, converted to a boolean

    - #### intOption

          public int intOption(String key)

      Returns the option with the given key as int value. The key can either be a name prefixed with a namespace, or a name without namespace, in which case the namespace of the currently active outlet is used. In the case that the option is not set in this namespace, the parent namespaces are searched recursively. If the option is not set in any of the parent namespaces or empty, 0 is returned.
      Parameters:
        `key` - the key for the option to retrieve.
      Returns:
        the option for the given key, converted to a boolean

    - #### getVariable

          public Object getVariable(String key)

      Returns the variable with the given key. The key can either be a name prefixed with a namespace, or a name without namespace, in which case the namespace of the currently active outlet is used. In the case that the variable is not set in this namespace, the parent namespaces are searched recursively. If the variable is not set in any of the parent namespaces, null is returned.
      Parameters:
        `key` - the key for the variable to retrieve.
      Returns:
        the variable for the given key, or null if the variable is not set or explicitly set to null.

    - #### setVariable

          public void setVariable(String key,
                                  Object value)

      Sets a variable. The key can be given with or without namespace; in the latter case, the variable is set in the namespace of the currently active outlet. The Scope of the variable is this outlet and its children.
      Parameters:
        `key` - the name of the variable, not null
        `value` - the value of the variable, may be null.
      Throws:
        `NullPointerException` - if key or scope is null.
        `IllegalArgumentException` - if the key is no valid QualifiedName.

    - #### setVariable

          public void setVariable(String key,
                                  Object value,
                                  String scope)

      Sets a variable. The key can be given with or without namespace; in the latter case, the variable is set in the namespace of the currently active outlet.
      Parameters:
        `key` - the name of the variable, not null.
        `value` - the value of the variable, may be null.
        `scope` - the scope of the variable, not null.
      Throws:
        `NullPointerException` - if key or scope is null.
        `IllegalArgumentException` - if the key is no valid QualifiedName.

    - #### getSourceFile

          public File getSourceFile()

      Returns the currently processed source file.
      Returns:
        the source file which is currently processed.

    - #### now

          public Date now()

      Returns the current date.
      Returns:
        the current date, not null.

    - #### getCounter

          public static int getCounter()

      Returns a counter value which is increased each time this function is accessed. Start value is 1. If `resetCounter` is not called, the returned value is unique over the generation process.
      Returns:
        the counter value.

    - #### resetCounter

          public static void resetCounter()

      Resets the counter accessible though `getCounter()` back to 1.

Copyright © 2000–2020 The Apache Software Foundation. All rights reserved.