Class BaseScope

All Implemented Interfaces:
Scope, TemplateHashModel, TemplateHashModelEx, TemplateModel
Direct Known Subclasses:
BlockScope, TemplateNamespace

public class BaseScope extends AbstractScope
A basic scope that stores variables locally in a hash map.
  • Method Details

    • put

      public void put(String key, TemplateModel value)
      Description copied from interface: Scope
      Set a variable in this scope. This will typically only be used internally by the FreeMarker engine.
    • remove

      public TemplateModel remove(String key)
      Description copied from interface: Scope
      Removes a variable in this scope. This will typically only be used by FreeMarker engine internals
    • get

      public TemplateModel get(String key)
      Description copied from interface: TemplateHashModel
      Gets a TemplateModel from the hash.
      Parameters:
      key - the name by which the TemplateModel is identified in the template.
      Returns:
      the TemplateModel referred to by the key, or null if not found.
    • definesVariable

      public boolean definesVariable(String key)
      Returns:
      whether the variable is defined in this specific scope. (It could be defined in a fallback scope and this method will return false.)
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface TemplateHashModel
      Overrides:
      isEmpty in class AbstractScope
    • keys

      Returns:
      a collection containing the keys in the hash. Every element of the returned collection must implement the TemplateScalarModel (as the keys of hashes are always strings).
      Throws:
      TemplateModelException
    • values

      Returns:
      a collection containing the values in the hash.
      Throws:
      TemplateModelException
    • size

      public int size() throws TemplateModelException
      Returns:
      the number of key/value mappings in the hash.
      Throws:
      TemplateModelException
    • clear

      public void clear()
    • getDirectVariableNames

      public Collection<String> getDirectVariableNames()
      Description copied from interface: Scope
      Returns the names of variables directly managed by this scope (i.e. it does not traverse the chain of enclosing scopes, but limits itself to this scope only).
      Returns:
      a collection of known variable names for this scope, without enclosing scopes. The returned collection should be either immutable, or it should be disconnected from the scope, so any modifications to the collection don't affect the scope.