Cantaloop CGimlet - API Documentation, Version: 0.2.0, Date: 2002-05-13 21:30 CEST

org.cantaloop.cgimlet.lang
Interface CGUtils

All Known Implementing Classes:
AbstractUtils

public interface CGUtils

Interface that defines helper methods for generating common expression and statements in a programming language independent way.

Version:
0.2.0 ($Revision: 1.7 $)
Author:
Stefan Heimann

Method Summary
 java.lang.String callReturn(java.lang.String expr)
          Generates a return statement that returns expr.
 java.lang.String callSet(java.lang.String var, java.lang.String property, java.lang.String value)
          Generate a statement for calling a set method.
 java.lang.String caseConcat(java.lang.String s1, java.lang.String s2)
          Concats s1 and s2 and makes sure that the first letter of s2 is an upper case letter.
 java.lang.String caseConcat(java.lang.String s1, java.lang.String s2, java.lang.String s3)
          Concats s1, s2 and s3 and makes sure that the first letter of s2 and s3 is an upper case letter.
 java.lang.String caseConcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4)
          Concats s1, s2, s3 and s4 and makes sure that the first letter of s2, s3 and s4 is an upper case letter.
 MethodTemplate getter(FieldTemplate field)
          Factory method that returns a template for a get-method.
 MethodTemplate getter(java.lang.String externalName, FieldTemplate field)
          Factory method that returns a template for a get-method.
 java.lang.String invoke(java.lang.String methodName)
          Returns a statement that invokes the method named methodName.
 java.lang.String invoke(java.lang.String methodName, java.lang.String param1)
          Returns a statement that invokes the method named methodName with the given parameter.
 java.lang.String invoke(java.lang.String methodName, java.lang.String[] params)
          Returns a statement that invokes the method named methodName with the given parameters.
 java.lang.String invoke(java.lang.String methodName, java.lang.String param1, java.lang.String param2)
          Returns a statement that invokes the method named methodName with param1, param2 as parameter.
 java.lang.String invokeExpr(java.lang.String methodName)
          Returns a expression that invokes the method named methodName.
 java.lang.String invokeExpr(java.lang.String methodName, java.lang.String param1)
          Returns a expression that invokes the method named methodName with param1 as parameter.
 java.lang.String invokeExpr(java.lang.String methodName, java.lang.String[] params)
          Returns a expression that invokes the method named methodName with the given parameters.
 java.lang.String invokeExpr(java.lang.String methodName, java.lang.String param1, java.lang.String param2)
          Returns a expression that invokes the method named methodName with param1, param2 as parameter.
 java.lang.String invokeOn(java.lang.String varName, java.lang.String methodName)
          Returns a statement that invokes the method named methodName.
 java.lang.String invokeOn(java.lang.String varName, java.lang.String methodName, java.lang.String param1)
          Returns a statement that invokes the method named methodName with the given parameter.
 java.lang.String invokeOn(java.lang.String varName, java.lang.String methodName, java.lang.String[] params)
          Returns a statement that invokes the method named methodName with the given parameters.
 java.lang.String invokeOn(java.lang.String varName, java.lang.String methodName, java.lang.String param1, java.lang.String param2)
          Returns a statement that invokes the method named methodName with param1, param2 as parameter.
 java.lang.String invokeOnExpr(java.lang.String varName, java.lang.String methodName)
          Returns a expression that invokes the method named methodName.
 java.lang.String invokeOnExpr(java.lang.String varName, java.lang.String methodName, java.lang.String param1)
          Returns a expression that invokes the method named methodName with param1 as parameter.
 java.lang.String invokeOnExpr(java.lang.String varName, java.lang.String methodName, java.lang.String[] params)
          Returns a expression that invokes the method named methodName with the given parameters.
 java.lang.String invokeOnExpr(java.lang.String varName, java.lang.String methodName, java.lang.String param1, java.lang.String param2)
          Returns a expression that invokes the method named methodName with param1, param2 as parameter.
 java.lang.String makeClassName(java.lang.String template, java.lang.String baseName, char placeholder)
          Create a classname based on a template.
 java.lang.String mapPut(java.lang.String key, java.lang.String value)
          Shorthand for: mapPut("map", key, value).
 java.lang.String mapPut(java.lang.String mapName, java.lang.String key, java.lang.String value)
          Returns a statement that invokes the put method on the map named mapName with the given key and value.
 java.lang.String mapStrPut(java.lang.String key, java.lang.String value)
          Shorthand for: mapStrPut("map", key, value).
 java.lang.String mapStrPut(java.lang.String mapName, java.lang.String key, java.lang.String value)
          Same as mapPut except that key will be quoted.
 java.lang.String newInstance(Type type, java.lang.String name)
          Shorthand for newInstance(type, name, type);.
 java.lang.String newInstance(Type interfaceType, java.lang.String name, Type implType)
          Creates a statement that icreates a instance of implType and stores that instance in the variable name.
 java.lang.String nonfinalToFinalIdentifier(java.lang.String s)
          Convert a (valid) identifier to a final identifier.
 java.lang.String quote(java.lang.String s)
           
 MethodTemplate setter(FieldTemplate field)
          Factory method that returns a template for a set-method.
 MethodTemplate setter(java.lang.String externalName, FieldTemplate field)
          Factory method that returns a template for a set-method.
 java.lang.String sprintf(java.lang.String str, java.lang.String arg1)
          Shorthand for sprintf(str, new String[]{arg1}).
 java.lang.String sprintf(java.lang.String str, java.lang.String[] args)
          This method acts like the sprintf routine in C.
 java.lang.String sprintf(java.lang.String str, java.lang.String arg1, java.lang.String arg2)
          Shorthand for sprintf(str, new String[]{arg1,arg2}).
 java.lang.String sprintf(java.lang.String str, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3)
          Shorthand for sprintf(str, new String[]{arg1,arg2,arg3}).
 boolean stringToBoolean(java.lang.String s, boolean def)
          Converts a String into a boolean. The "boolean value" of a string is defined as following:
"yes".equals(s) || "true".equals(s) || "on".equals(s). If s == null the value of def is returned.
 java.lang.String toFinalIdentifier(java.lang.String s)
          Convert s into a identifier which can be used for final fields etc.
 java.lang.String toIdentifier(java.lang.String s)
          Shorthand for toIdentifier(s, false);
 java.lang.String toIdentifier(java.lang.String s, boolean capitalize)
          Convert s into an indentifier.
 

Method Detail

stringToBoolean

public boolean stringToBoolean(java.lang.String s,
                               boolean def)

Converts a String into a boolean.

The "boolean value" of a string is defined as following:
"yes".equals(s) || "true".equals(s) || "on".equals(s).

If s == null the value of def is returned.

Parameters:
s - a String value
def - the value to return if s == null
Returns:
a boolean value

newInstance

public java.lang.String newInstance(Type type,
                                    java.lang.String name)
Shorthand for newInstance(type, name, type);.

newInstance

public java.lang.String newInstance(Type interfaceType,
                                    java.lang.String name,
                                    Type implType)
Creates a statement that icreates a instance of implType and stores that instance in the variable name. The type of this variable is determined by the interfaceType parameter.

callSet

public java.lang.String callSet(java.lang.String var,
                                java.lang.String property,
                                java.lang.String value)
Generate a statement for calling a set method.
Parameters:
var - the name of the variable on which to invoke the method
property - the name of the property that should be set.
value - the value to which the property should be set to.
Returns:
a String value

toIdentifier

public java.lang.String toIdentifier(java.lang.String s)
Shorthand for toIdentifier(s, false);

toIdentifier

public java.lang.String toIdentifier(java.lang.String s,
                                     boolean capitalize)
Convert s into an indentifier. Whitespace characters and '-' are treated as word bounderies and converted accordingly to the coding conventions of the programming language.
Parameters:
s - the string to convert.
capitalize - specify if the first letter should be capitalized or not.
Returns:
a String value
Throws:
CodeGenerationException - if s cannot be converted properly

toFinalIdentifier

public java.lang.String toFinalIdentifier(java.lang.String s)
Convert s into a identifier which can be used for final fields etc.

nonfinalToFinalIdentifier

public java.lang.String nonfinalToFinalIdentifier(java.lang.String s)
Convert a (valid) identifier to a final identifier.

makeClassName

public java.lang.String makeClassName(java.lang.String template,
                                      java.lang.String baseName,
                                      char placeholder)
Create a classname based on a template. A template is a string that contains a placeholder. This placeholder is replaced by the given basename. If several placeholder characters are found, the first one is used.
Parameters:
template - a String value
baseName - a String value
placeholder - the caracter which should be treated as the placeholder
Returns:
a String value

mapPut

public java.lang.String mapPut(java.lang.String mapName,
                               java.lang.String key,
                               java.lang.String value)
Returns a statement that invokes the put method on the map named mapName with the given key and value.

mapPut

public java.lang.String mapPut(java.lang.String key,
                               java.lang.String value)
Shorthand for: mapPut("map", key, value).

mapStrPut

public java.lang.String mapStrPut(java.lang.String mapName,
                                  java.lang.String key,
                                  java.lang.String value)
Same as mapPut except that key will be quoted.

mapStrPut

public java.lang.String mapStrPut(java.lang.String key,
                                  java.lang.String value)
Shorthand for: mapStrPut("map", key, value).

quote

public java.lang.String quote(java.lang.String s)

invokeExpr

public java.lang.String invokeExpr(java.lang.String methodName,
                                   java.lang.String param1)
Returns a expression that invokes the method named methodName with param1 as parameter.

invokeExpr

public java.lang.String invokeExpr(java.lang.String methodName,
                                   java.lang.String param1,
                                   java.lang.String param2)
Returns a expression that invokes the method named methodName with param1, param2 as parameter.

invokeExpr

public java.lang.String invokeExpr(java.lang.String methodName)
Returns a expression that invokes the method named methodName.

invokeExpr

public java.lang.String invokeExpr(java.lang.String methodName,
                                   java.lang.String[] params)
Returns a expression that invokes the method named methodName with the given parameters.

invoke

public java.lang.String invoke(java.lang.String methodName,
                               java.lang.String param1)
Returns a statement that invokes the method named methodName with the given parameter.

invoke

public java.lang.String invoke(java.lang.String methodName,
                               java.lang.String param1,
                               java.lang.String param2)
Returns a statement that invokes the method named methodName with param1, param2 as parameter.

invoke

public java.lang.String invoke(java.lang.String methodName)
Returns a statement that invokes the method named methodName.

invoke

public java.lang.String invoke(java.lang.String methodName,
                               java.lang.String[] params)
Returns a statement that invokes the method named methodName with the given parameters.

invokeOnExpr

public java.lang.String invokeOnExpr(java.lang.String varName,
                                     java.lang.String methodName,
                                     java.lang.String param1)
Returns a expression that invokes the method named methodName with param1 as parameter.

invokeOnExpr

public java.lang.String invokeOnExpr(java.lang.String varName,
                                     java.lang.String methodName,
                                     java.lang.String param1,
                                     java.lang.String param2)
Returns a expression that invokes the method named methodName with param1, param2 as parameter.

invokeOnExpr

public java.lang.String invokeOnExpr(java.lang.String varName,
                                     java.lang.String methodName)
Returns a expression that invokes the method named methodName.

invokeOnExpr

public java.lang.String invokeOnExpr(java.lang.String varName,
                                     java.lang.String methodName,
                                     java.lang.String[] params)
Returns a expression that invokes the method named methodName with the given parameters.

invokeOn

public java.lang.String invokeOn(java.lang.String varName,
                                 java.lang.String methodName,
                                 java.lang.String param1)
Returns a statement that invokes the method named methodName with the given parameter.

invokeOn

public java.lang.String invokeOn(java.lang.String varName,
                                 java.lang.String methodName,
                                 java.lang.String param1,
                                 java.lang.String param2)
Returns a statement that invokes the method named methodName with param1, param2 as parameter.

invokeOn

public java.lang.String invokeOn(java.lang.String varName,
                                 java.lang.String methodName)
Returns a statement that invokes the method named methodName.

invokeOn

public java.lang.String invokeOn(java.lang.String varName,
                                 java.lang.String methodName,
                                 java.lang.String[] params)
Returns a statement that invokes the method named methodName with the given parameters.

sprintf

public java.lang.String sprintf(java.lang.String str,
                                java.lang.String[] args)
This method acts like the sprintf routine in C. It replaces the the n-th occurence of either %s or %q in str with the n-th element of args. If %s is used, the string argument will be inserted as is. If %q is used, the quote(java.lang.String) method will be used to quote the inserted string.

sprintf

public java.lang.String sprintf(java.lang.String str,
                                java.lang.String arg1)
Shorthand for sprintf(str, new String[]{arg1}).

sprintf

public java.lang.String sprintf(java.lang.String str,
                                java.lang.String arg1,
                                java.lang.String arg2)
Shorthand for sprintf(str, new String[]{arg1,arg2}).

sprintf

public java.lang.String sprintf(java.lang.String str,
                                java.lang.String arg1,
                                java.lang.String arg2,
                                java.lang.String arg3)
Shorthand for sprintf(str, new String[]{arg1,arg2,arg3}).

caseConcat

public java.lang.String caseConcat(java.lang.String s1,
                                   java.lang.String s2)
Concats s1 and s2 and makes sure that the first letter of s2 is an upper case letter.

caseConcat

public java.lang.String caseConcat(java.lang.String s1,
                                   java.lang.String s2,
                                   java.lang.String s3)
Concats s1, s2 and s3 and makes sure that the first letter of s2 and s3 is an upper case letter.

caseConcat

public java.lang.String caseConcat(java.lang.String s1,
                                   java.lang.String s2,
                                   java.lang.String s3,
                                   java.lang.String s4)
Concats s1, s2, s3 and s4 and makes sure that the first letter of s2, s3 and s4 is an upper case letter.

callReturn

public java.lang.String callReturn(java.lang.String expr)
Generates a return statement that returns expr.

setter

public MethodTemplate setter(FieldTemplate field)
Factory method that returns a template for a set-method.
Parameters:
field - the field to set.

setter

public MethodTemplate setter(java.lang.String externalName,
                             FieldTemplate field)
Factory method that returns a template for a set-method.
Parameters:
externalName - the name that is used outside the class for this property
field - the field that should be set.
Returns:
a MethodTemplate value

getter

public MethodTemplate getter(FieldTemplate field)
Factory method that returns a template for a get-method.
Parameters:
field - the field to get.

getter

public MethodTemplate getter(java.lang.String externalName,
                             FieldTemplate field)
Factory method that returns a template for a get-method.
Parameters:
externalName - the name that is used outside the class for this property
field - the field whose value should be retrieved.
Returns:
a MethodTemplate value

Copyright 2001, 2002 Stefan Heimann, David Leuschner. All rights reserved.