freemarker.core

Class CustomAttribute


public class CustomAttribute
extends java.lang.Object

A class that allows one to associate custom data with a configuration, a template, or environment. It works pretty much like ThreadLocal, a class that allows one to associate custom data with a thread.
Version:
$Id: CustomAttribute.java,v 1.3 2003/11/10 14:05:22 ddekany Exp $
Author:
Attila Szegedi

Field Summary

static int
SCOPE_CONFIGURATION
Constant used in the constructor specifying that this attribute is scoped by the configuration.
static int
SCOPE_ENVIRONMENT
Constant used in the constructor specifying that this attribute is scoped by the environment.
static int
SCOPE_TEMPLATE
Constant used in the constructor specifying that this attribute is scoped by the template.

Constructor Summary

CustomAttribute(int scope)
Creates a new custom attribute with the specified scope

Method Summary

protected Object
create()
This method is invoked when get() is invoked without set(Object) being invoked before it to define the value in the current scope.
Object
get()
Object
get(Template t)
void
set(Object value)
Sets the value of the attribute in the context of the current environment.
void
set(Object value, Template t)
Sets the value of a template-scope attribute in the context of the given template.

Field Details

SCOPE_CONFIGURATION

public static final int SCOPE_CONFIGURATION
Constant used in the constructor specifying that this attribute is scoped by the configuration.
Field Value:
2

SCOPE_ENVIRONMENT

public static final int SCOPE_ENVIRONMENT
Constant used in the constructor specifying that this attribute is scoped by the environment.
Field Value:
0

SCOPE_TEMPLATE

public static final int SCOPE_TEMPLATE
Constant used in the constructor specifying that this attribute is scoped by the template.
Field Value:
1

Constructor Details

CustomAttribute

public CustomAttribute(int scope)
Creates a new custom attribute with the specified scope
Parameters:
scope - one of SCOPE_ constants.

Method Details

create

protected Object create()
This method is invoked when get() is invoked without set(Object) being invoked before it to define the value in the current scope. Override it to create the attribute value on-demand.
Returns:
the initial value for the custom attribute. By default returns null.

get

public final Object get()
Returns:
the value of the attribute in the context of the current environment.

get

public final Object get(Template t)
Returns:
the value of a template-scope attribute in the context of a given template.

set

public final void set(Object value)
Sets the value of the attribute in the context of the current environment.
Parameters:
value - the new value of the attribute

set

public final void set(Object value,
                      Template t)
Sets the value of a template-scope attribute in the context of the given template.
Parameters:
value - the new value of the attribute
t - the template