org.brains2b.typewriter
Class ContentTemplate

java.lang.Object
  extended byorg.brains2b.typewriter.ContentTemplate
All Implemented Interfaces:
Template
Direct Known Subclasses:
BlockTemplate, ExceptionTemplate, IfTemplate, LoopTemplate, MethodTemplate, TryTemplate

public abstract class ContentTemplate
extends java.lang.Object
implements Template

Abstract ContentTemplate which is the basis for most of what a java method can contain

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

Version:
0.10 [28-10-2002]
Author:
dennis@brains2b.nl

Field Summary
protected  java.util.List m_content
           
 
Constructor Summary
ContentTemplate()
           
 
Method Summary
 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
 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 The list will either contain Strings or other ContentTemplates
 Template getParent()
          get the direct parent of this element.

This can be the class, method, try element or loop elements

 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 The List should contain either contain Strings or other ContentTemplates
 void setParent(Template parent)
          set the direct parent of this element

The parent can be the class, method, try element or loop elements

 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_content

protected java.util.List m_content
Constructor Detail

ContentTemplate

public ContentTemplate()
Method Detail

addText

public void addText(java.lang.String text)
add a line to the content of this template.

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

Parameters:
text - String, a line to add to the content

createFor

public LoopTemplate createFor(java.lang.String condition)
create a LoopTemplate for a for-next-loop within this content

Parameters:
condition - String, the condition for this loop
Returns:
LoopTemplate

createWhile

public LoopTemplate createWhile(java.lang.String condition)
create a LoopTemplate for a while-loop within this content

Parameters:
condition - String, the condition for this loop
Returns:
LoopTemplate

createIf

public IfTemplate createIf(java.lang.String condition)
create an IfTemplate for a condition-statement within this content

Parameters:
condition - String, the expression for this condition
Returns:
IfTemplate

createTry

public TryTemplate createTry(java.lang.String exceptionClassName)
create a TryTemplate for a try-catch-block within this content

Parameters:
exceptionClassName - String, the name of this Exception
Returns:
TryTemplate

write

public 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.

Specified by:
write in interface Template
Parameters:
writer - PrintWriter, an initialized PrintWriter to write this element of the Class to
indent - int, the indention for this element.

Value is multiplied by four to give the number of spaces used for indention

See Also:
Template.write(java.io.PrintWriter, int)

getParent

public Template getParent()
get the direct parent of this element.

This can be the class, method, try element or loop elements

Specified by:
getParent in interface Template
Returns:
Template, the parent of this element

setParent

public void setParent(Template parent)
set the direct parent of this element

The parent can be the class, method, try element or loop elements

Specified by:
setParent in interface Template
Parameters:
parent - Template, the parent of this element

getContent

public java.util.List getContent()
get the content for this template

The list will either contain Strings or other ContentTemplates

Returns:
Vector, a list of objects contained in this template, will always return a List even if there is no content.

setContent

public void setContent(java.util.List content)
set the content for this Template

The List should contain either contain Strings or other ContentTemplates

Parameters:
content - Vector, 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.

makeInstance

public 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

Parameters:
className - String, the class to instantiate, could be the fully qualified className
name - String the variable name of the instantiated class
Returns:
String name, the name of the instance made, should be equal to name passed to this method
See Also:
makeInstance(String, String, Object[])

makeInstance

public 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

Parameters:
className - String, the class to instantiate, could be the fully qualified className
name - String the variable name of the instantiated class
arg - Object, a single argument passed to the constructor of the class defined by className
Returns:
String name, the name of the instance made, should be equal to name passed to this method
See Also:
makeInstance(String, String, Object[])

makeInstance

public 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

Parameters:
className - String, the class to instantiate, could be the fully qualified className
name - String the variable name of the instantiated class
args - Object[], an array of arguments passed to the constructor of the class defined by className
Returns:
String name, the name of the instance made, should be equal to name passed to this method

addImport

public void addImport(java.lang.String name)
Description copied from interface: Template
add an String as import to the top class of this element

Specified by:
addImport in interface Template
Parameters:
name - String, the fully qualified class name. Could be used to enter the complete package by adding *