|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.sahits.phpclassgenerator.CodeGenerator
public class CodeGenerator
The CodeGenerator produces the PHP code for the resulting PHP class.
Therefore it uses the XML template parsed by XMLTemplateParser
and the DBStructure provided by DBConnection. The template
may contain several template or marker strings that are replaced in this class.
The replacement needs knowledge of the underling DB structure.
The schema of the XML template can be found at Sahits.
The marker strings are defined in Constants.
members: member variables for all DB fields are generatedmethods: getter methods for the DB fields are generatedmethods: setter methods for the DB fields are generatedmethods: load methods for all foreign keys are generated. Method body fragment needed.method: load method for the primary keys are generated. Method body fragment needed.method: convert the data read from the DB into a formatted string.method: initialize the object by values found in the $_POST arraymethod: initialize the object by values found in the $_GET arraymethod: initialize the object by values found in the argument arraymethod: insert method is generated. Method body fragment needed.method: update method is generated. Method body fragment needed.body in combination with PK or FK.
body in combination with _WHERE to generate the where clause using the primary keybody in combination with _WHERE to generate the where clause using the foreign keys
Constants| Field Summary | |
|---|---|
private ClassDeclaration |
_class
|
private java.lang.String |
db
|
private java.lang.String |
host
|
private java.lang.String |
nl
|
private XMLTemplateParser |
parser
|
private java.lang.String |
passwd
|
private java.lang.String |
product
|
private DBStructure |
structur
|
private java.lang.String |
tableName
|
private java.lang.String |
templatePath
|
private java.lang.String |
user
|
| Constructor Summary | |
|---|---|
CodeGenerator(java.lang.String templatePath,
java.lang.String product,
java.lang.String host,
java.lang.String db,
java.lang.String user,
java.lang.String passwd,
java.lang.String tableName)
Constructor initializes the connection data |
|
| Method Summary | |
|---|---|
java.lang.String |
generate()
Generate the contents of the php file |
private void |
generateCode4Constants(ClassDeclaration cd)
The class definition may contain constants defined in Constants
that have to be replaced by actual code. |
private java.util.Vector<MethodDeclaration> |
generateGetterMethods()
Produce the PHP code for the getter methods |
private MethodDeclaration |
generateInitGetMethod()
Produce the PHP code for the initGET method. |
private MethodDeclaration |
generateInitMethod()
Produce the PHP code for the init method |
private MethodDeclaration |
generateInitPostMethod()
Produce the PHP code for the initPOST method. |
private MethodDeclaration |
generateInsertMethod(MethodDeclaration methodDeclaration)
Generate the PHP code for the insert method based on the method fragment. |
private java.util.Vector<MethodDeclaration> |
generateLoadByFKMethods(MethodDeclaration methodDeclaration)
Produce the PHP code for the loadbyFK... methods. |
private MethodDeclaration |
generateLoadUniqueMethods(MethodDeclaration methodDeclaration)
Produce the PHP code for the loadUnique method. |
private java.util.Vector<MethodDeclaration> |
generateSetterMethods()
Produce the PHP code for the setter methods |
private MethodDeclaration |
generateToStringMethod()
Produce the PHP code for the toSting methods |
private MethodDeclaration |
generateUpdateMethod(MethodDeclaration methodDeclaration)
Generate the PHP code for the update method based on the method fragment. |
private java.lang.String |
getClassName()
Get the name of the class by the table name |
private java.lang.String |
getFieldArray()
Generate an array PHP style of all the DB fields |
private java.lang.String |
getWhereClause(java.lang.String[] columns)
Generate a where clause for the given columns The values of the columns is in a variable name like DBField.getFormatedFieldName() |
private void |
init()
|
private java.lang.String |
replaceAll(java.lang.String needle,
java.lang.String haystack,
java.lang.String with)
Re-implementation of the replaceAll method of String to circumvent the inconvinience with regular expressions |
private java.lang.String |
replaceConstants(java.lang.String input)
Replace constants in the input |
private java.lang.String[] |
replaceMember(java.lang.String[] members)
check all member variable definition. |
private MethodDeclaration[] |
replaceMethod(MethodDeclaration[] methods)
Check all methods. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.lang.String templatePath
private java.lang.String product
private java.lang.String host
private java.lang.String db
private java.lang.String user
private java.lang.String passwd
private java.lang.String tableName
private XMLTemplateParser parser
private DBStructure structur
private ClassDeclaration _class
private java.lang.String nl
| Constructor Detail |
|---|
public CodeGenerator(java.lang.String templatePath,
java.lang.String product,
java.lang.String host,
java.lang.String db,
java.lang.String user,
java.lang.String passwd,
java.lang.String tableName)
throws org.xml.sax.SAXException,
java.io.IOException,
javax.xml.parsers.ParserConfigurationException,
java.sql.SQLException
templatePath - path to the XML template to be parsedproduct - what kind of DB (MySQL, PostgeSQL, Oracle, Derby, MS SQL Server, ...)host - of the db eg. localhostuser - user name to connect to the DBpasswd - password of the userdb - or schema of the tabletableName - table name
java.sql.SQLException - Connecting failed probably due to incorrect input
org.xml.sax.SAXException - Something in the parsing is gone wrong
java.io.IOException - The template could not be read
javax.xml.parsers.ParserConfigurationException - Bad configuration of the parser.| Method Detail |
|---|
private void init()
throws org.xml.sax.SAXException,
java.io.IOException,
javax.xml.parsers.ParserConfigurationException,
java.sql.SQLException
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
java.sql.SQLExceptionprivate void generateCode4Constants(ClassDeclaration cd)
Constants
that have to be replaced by actual code.
private MethodDeclaration[] replaceMethod(MethodDeclaration[] methods)
Constants.DB_FIELD_GETTER or Constants.DB_FIELD_SETTER
generate the getter or setter methods of the DB fields.
methods - array with method declarations
MethodDeclarationprivate MethodDeclaration generateInsertMethod(MethodDeclaration methodDeclaration)
MethodDeclaration describing the insert methodprivate MethodDeclaration generateUpdateMethod(MethodDeclaration methodDeclaration)
MethodDeclaration describing the insert methodprivate java.util.Vector<MethodDeclaration> generateLoadByFKMethods(MethodDeclaration methodDeclaration)
methodDeclaration - method declaration fragment
MethodDeclaration describing the loadUnique methodprivate MethodDeclaration generateLoadUniqueMethods(MethodDeclaration methodDeclaration)
methodDeclaration - method declaration fragment
MethodDeclaration describing the loadUnique methodprivate MethodDeclaration generateInitMethod()
MethodDeclaration describing the init methodprivate MethodDeclaration generateInitPostMethod()
DBField.getFormatedFieldName() suggests.
MethodDeclaration describing the initPOST methodprivate MethodDeclaration generateInitGetMethod()
DBField.getFormatedFieldName() suggests.
MethodDeclaration describing the initGET methodprivate java.util.Vector<MethodDeclaration> generateGetterMethods()
MethodDeclarations containing the getter methodsprivate java.util.Vector<MethodDeclaration> generateSetterMethods()
MethodDeclarations containing the getter methodsprivate MethodDeclaration generateToStringMethod()
MethodDeclaration containing the toString methodprivate java.lang.String[] replaceMember(java.lang.String[] members)
Constants.DB_FIELDS replace it with member
variables for all DB fields. If in this member declaration
the there is a value assigned that is the initial value for the
primary key.
members - array with member variable declarations
public java.lang.String generate()
private java.lang.String getClassName()
private java.lang.String getWhereClause(java.lang.String[] columns)
DBField.getFormatedFieldName()
columns - Array of the columns in the where clause
private java.lang.String replaceConstants(java.lang.String input)
input - String
private java.lang.String getFieldArray()
private java.lang.String replaceAll(java.lang.String needle,
java.lang.String haystack,
java.lang.String with)
needle - String to be replacedhaystack - String in which to searchwith - replacement string
haystack with all occurrences of needle replaced by with
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||