com.github.mustachejava.codes
Class DefaultCode
java.lang.Object
com.github.mustachejava.codes.DefaultCode
- All Implemented Interfaces:
- Code
- Direct Known Subclasses:
- DefaultMustache, ExtendNameCode, IterableCode, NotIterableCode, PartialCode, ValueCode, WriteCode
public class DefaultCode
- extends java.lang.Object
- implements Code
Simplest possible code implementaion with some default shared behavior
Method Summary |
protected java.lang.Object[] |
addScope(java.lang.Object next,
java.lang.Object[] scopes)
Allocating new scopes is currently the only place where we are activtely allocating
memory within the templating system. |
void |
append(java.lang.String text)
|
protected java.io.Writer |
appendText(java.io.Writer writer)
|
java.io.Writer |
execute(java.io.Writer writer,
java.lang.Object scope)
|
java.io.Writer |
execute(java.io.Writer writer,
java.lang.Object[] scopes)
The default behavior is to run the codes and append the captured text. |
java.lang.Object |
get(java.lang.Object[] scopes)
Retrieve the first value in the stacks of scopes that matches
the give name. |
Code[] |
getCodes()
|
protected Wrapper |
getWrapper(java.lang.String name,
java.lang.Object[] scopes)
|
void |
identity(java.io.Writer writer)
|
void |
init()
|
protected java.io.Writer |
runCodes(java.io.Writer writer,
java.lang.Object[] scopes)
|
protected void |
runIdentity(java.io.Writer writer)
|
void |
setCodes(Code[] newcodes)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
appended
protected java.lang.StringBuilder appended
oh
protected final ObjectHandler oh
name
protected final java.lang.String name
tc
protected final TemplateContext tc
mustache
protected final Mustache mustache
type
protected final java.lang.String type
returnThis
protected final boolean returnThis
debug
protected static boolean debug
logger
protected static java.util.logging.Logger logger
DefaultCode
public DefaultCode()
DefaultCode
public DefaultCode(TemplateContext tc,
ObjectHandler oh,
Mustache mustache,
java.lang.String name,
java.lang.String type)
getCodes
public Code[] getCodes()
- Specified by:
getCodes
in interface Code
init
public void init()
- Specified by:
init
in interface Code
setCodes
public void setCodes(Code[] newcodes)
- Specified by:
setCodes
in interface Code
get
public java.lang.Object get(java.lang.Object[] scopes)
- Retrieve the first value in the stacks of scopes that matches
the give name. The method wrappers are cached and guarded against
the type or number of scopes changing.
Methods will be found using the object handler, called here with
another lookup on a guard failure and finally coerced to a final
value based on the ObjectHandler you provide.
- Parameters:
scopes
- An array of scopes to interrogate from right to left.
- Returns:
- The value of the field or method
getWrapper
protected Wrapper getWrapper(java.lang.String name,
java.lang.Object[] scopes)
execute
public java.io.Writer execute(java.io.Writer writer,
java.lang.Object scope)
- Specified by:
execute
in interface Code
execute
public java.io.Writer execute(java.io.Writer writer,
java.lang.Object[] scopes)
- The default behavior is to run the codes and append the captured text.
- Specified by:
execute
in interface Code
- Parameters:
writer
- The writer to write the output toscopes
- The scopes to evaluate the embedded names against.
identity
public void identity(java.io.Writer writer)
- Specified by:
identity
in interface Code
runIdentity
protected void runIdentity(java.io.Writer writer)
appendText
protected java.io.Writer appendText(java.io.Writer writer)
runCodes
protected java.io.Writer runCodes(java.io.Writer writer,
java.lang.Object[] scopes)
append
public void append(java.lang.String text)
- Specified by:
append
in interface Code
addScope
protected java.lang.Object[] addScope(java.lang.Object next,
java.lang.Object[] scopes)
- Allocating new scopes is currently the only place where we are activtely allocating
memory within the templating system. It is possible that recycling these might lend
some additional benefit or using the same one in each thread. The only time this
grows is when there are recursive calls to the same scope. In most non-degenerate cases
we won't encounter that. Also, since we are copying the results across these boundaries
we don't have to worry about threads.
Copyright © 2012. All Rights Reserved.