public abstract class ContentTemplate extends java.lang.Object implements Template
Provides methods for creating contents for a method for conditions, loops and exceptions
Every class which extends this should implement it's own write(PrintWriter,indent)
method and call super.write(PrintWriter,indent) to write out the content of this
method
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List |
m_content |
| Constructor and Description |
|---|
ContentTemplate() |
| Modifier and Type | Method and Description |
|---|---|
void |
addImport(java.lang.String name)
add an String as import to the top class of this element
|
void |
addText(java.lang.String text)
add a line to the content of this template.
|
LoopTemplate |
createFor(java.lang.String condition)
create a LoopTemplate for a
for-next-loop within this content |
IfTemplate |
createIf(java.lang.String condition)
create an IfTemplate for a
condition-statement within this content |
TryTemplate |
createTry(java.lang.String exceptionClassName)
create a TryTemplate for a
try-catch-block within this content |
TryTemplate |
createTry(java.lang.String exceptionClassName,
java.lang.String withResource)
create a TryTemplate for a
try-catch-block within this content |
LoopTemplate |
createWhile(java.lang.String condition)
create a LoopTemplate for a
while-loop within this content |
java.util.List |
getContent()
get the content for this template
|
Template |
getParent()
get the direct parent of this element.
|
java.lang.String |
makeInstance(java.lang.String className,
java.lang.String name)
create a local instance for a class by calling its constructor
with the given parameter and adds it to the content
|
java.lang.String |
makeInstance(java.lang.String className,
java.lang.String name,
java.lang.Object arg)
create a local instance for a class by calling its constructor
with the given parameter and adds it to the content
|
java.lang.String |
makeInstance(java.lang.String className,
java.lang.String name,
java.lang.Object[] args)
Create a local instance for a class by calling its constructor
with the given parameters and adds it to the content
|
void |
setContent(java.util.List content)
set the content for this Template
|
void |
setParent(Template parent)
set the direct parent of this element
|
void |
write(java.io.PrintWriter writer,
int indent)
overwrite this to implement a content types specific needs and
call
super.write(PrintWriter,int) to write out
the content for this method. |
public void addText(java.lang.String text)
A line can be anything, but make sure you end it with ;
if it needs to be a valid java statement
The line-end will be added by this Template
text - String, a line to add to the contentpublic LoopTemplate createFor(java.lang.String condition)
for-next-loop within this contentcondition - String, the condition for this looppublic LoopTemplate createWhile(java.lang.String condition)
while-loop within this contentcondition - String, the condition for this looppublic IfTemplate createIf(java.lang.String condition)
condition-statement within this contentcondition - String, the expression for this conditionpublic TryTemplate createTry(java.lang.String exceptionClassName)
try-catch-block within this contentexceptionClassName - String, the name of this Exceptionpublic TryTemplate createTry(java.lang.String exceptionClassName, java.lang.String withResource)
try-catch-block within this contentexceptionClassName - String, the name of this Exceptionpublic void write(java.io.PrintWriter writer,
int indent)
super.write(PrintWriter,int) to write out
the content for this method.write in interface Templatewriter - PrintWriter, an initialized PrintWriter to write this
element of the Class toindent - int, the indention for this element.
Value is multiplied by four to give the number of spaces used for indention
Template.write(java.io.PrintWriter, int)public Template getParent()
This can be the class, method, try element or loop elements
public void setParent(Template parent)
The parent can be the class, method, try element or loop elements
public java.util.List getContent()
The list will either contain Strings or other ContentTemplates
public void setContent(java.util.List content)
The List should contain either contain Strings or other ContentTemplates
content - List, a list of objects contained in this template, if null is inserted
the content of this ContentTemplate will be removed and getContent() will return
an empty List, not null.public java.lang.String makeInstance(java.lang.String className,
java.lang.String name)
className - String, the class to instantiate, could be the fully
qualified classNamename - String the variable name of the instantiated classmakeInstance(String, String, Object[])public java.lang.String makeInstance(java.lang.String className,
java.lang.String name,
java.lang.Object arg)
className - String, the class to instantiate, could be the fully
qualified classNamename - String the variable name of the instantiated classarg - Object, a single argument passed to the constructor of
the class defined by classNamemakeInstance(String, String, Object[])public java.lang.String makeInstance(java.lang.String className,
java.lang.String name,
java.lang.Object[] args)
className - String, the class to instantiate, could be the fully
qualified classNamename - String the variable name of the instantiated classargs - Object[], an array of arguments passed to the constructor of
the class defined by classNamepublic void addImport(java.lang.String name)
Template