Author: maksimkaszynski
Date: 2007-10-29 14:13:05 -0400 (Mon, 29 Oct 2007)
New Revision: 3603
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/Argument.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaAnnotation.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaClass.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaComment.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaField.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaLanguageElement.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaMethod.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaModifier.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPackage.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/MethodBody.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaClassRenderer.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ObjectPropertyProcessor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleAccessorMethodBody.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleMutatorMethodBody.java
Log:
Statred refactoring of CDK generator
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/Argument.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/Argument.java
(rev 0)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/Argument.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,30 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class Argument {
+ private Class<?> type;
+ private String name;
+
+ public static Argument arg(String name, Class<?> type) {
+ return new Argument(name, type);
+ }
+
+ public Argument(String name, Class<?> type) {
+ super();
+ this.name = name;
+ this.type = type;
+ }
+ public Class<?> getType() {
+ return type;
+ }
+ public String getName() {
+ return name;
+ }
+
+}
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaAnnotation.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaAnnotation.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaAnnotation.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,19 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaAnnotation extends JavaLanguageElement{
+
+ public static JavaAnnotation OVERRIDE = new JavaAnnotation("Override");
+
+ public JavaAnnotation(String name) {
+ super(name);
+ }
+
+
+}
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaClass.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaClass.java
(rev 0)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaClass.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,111 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaClass extends JavaLanguageElement{
+ private List<JavaField> fields = new ArrayList<JavaField>();
+ private List<JavaMethod> methods = new ArrayList<JavaMethod>();
+ private Set<Class<?>> imports = new TreeSet<Class<?>>();
+
+ private JavaPackage pakg;
+ private Class<?> superClass = Object.class;
+
+ public JavaClass(String shortName, JavaPackage pakg, Class<?> superClass) {
+ this(shortName, pakg);
+ setSuperClass(superClass);
+ }
+
+ public JavaClass(String shortName, JavaPackage pakg) {
+ super(shortName);
+ this.pakg = pakg;
+ }
+
+ public void addImport(Class<?> claz) {
+ if (shouldAddToImports(claz)) {
+ imports.add(claz);
+ }
+ }
+
+ public void addField(JavaField field) {
+ fields.add(field);
+ addImport(field.getType());
+ }
+
+ public void addMethod(JavaMethod method) {
+ methods.add(method);
+ addImport(method.getReturnType());
+
+ List<Class<Throwable>> exceptions = method.getExceptions();
+
+ for (Class<Throwable> exception : exceptions) {
+ addImport(exception);
+ }
+
+ List<Argument> arguments =
+ method.getArguments();
+ if (arguments != null) {
+ for (Argument argument : arguments) {
+ addImport(argument.getType());
+ }
+ }
+ }
+
+ public JavaPackage getPakg() {
+ return pakg;
+ }
+ public Class<?> getSuperClass() {
+ return superClass;
+ }
+
+ public void setSuperClass(Class<?> superClass) {
+ this.superClass = superClass;
+ addImport(superClass);
+ }
+ public void setPackage(JavaPackage s) {
+ pakg = s;
+ }
+ public JavaPackage getPackage() {
+ return pakg;
+ }
+
+ public List<JavaField> getFields() {
+ return fields;
+ }
+ public List<JavaMethod> getMethods() {
+ return methods;
+ }
+ public Set<Class<?>> getImports() {
+ return imports;
+ }
+
+ private boolean shouldAddToImports(Class<?> clas) {
+
+ boolean result = false;
+
+ if (clas != null) {
+ Package p = clas.getPackage();
+
+ if (!(clas.isPrimitive() || p == null)) {
+ String importPackageName = p.getName();
+ if (importPackageName != null && importPackageName.length() != 0) {
+
+ result = !(importPackageName.equals("java.lang") || importPackageName
+ .equals(getPackage().getName()));
+ }
+ }
+ }
+
+ return result;
+ }
+
+}
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaComment.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaComment.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaComment.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,29 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaComment {
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public JavaComment(String value) {
+ super();
+ this.value = value;
+ }
+
+ public JavaComment() {
+ // TODO Auto-generated constructor stub
+ }
+}
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaField.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaField.java
(rev 0)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaField.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,44 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaField extends JavaLanguageElement{
+
+ private Class <?> type;
+ private Object value;
+
+ public JavaField(Class<?> type, String name) {
+ this(type, name, null);
+ }
+
+
+
+ public JavaField(Class<?> type, String name, Object value) {
+ super(name);
+ this.type = type;
+ this.value = value;
+ }
+
+
+
+ public Class<?> getType() {
+ return type;
+ }
+
+
+
+ public Object getValue() {
+ return value;
+ }
+
+
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaLanguageElement.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaLanguageElement.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaLanguageElement.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,36 @@
+package org.ajax4jsf.builder.model;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class JavaLanguageElement {
+
+ private Set<JavaModifier> modifiers = new HashSet<JavaModifier>();
+ private List<JavaAnnotation> annotations = new ArrayList<JavaAnnotation>();
+ private List<JavaComment> comments = new ArrayList<JavaComment>();
+ private String name;
+
+ public JavaLanguageElement(String name) {
+ super();
+ this.name = name;
+ }
+
+ public Set<JavaModifier> getModifiers() {
+ return modifiers;
+ }
+
+ public List<JavaAnnotation> getAnnotations() {
+ return annotations;
+ }
+
+ public List<JavaComment> getComments() {
+ return comments;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}
\ No newline at end of file
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaMethod.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaMethod.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaMethod.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,62 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaMethod extends JavaLanguageElement {
+
+ private Class<?> returnType;
+
+ private MethodBody methodBody;
+
+ private List <Argument> arguments = new ArrayList<Argument>();
+ private List<Class<Throwable>> exceptions = new
ArrayList<Class<Throwable>>();
+
+ public List<Class<Throwable>> getExceptions() {
+ return exceptions;
+ }
+
+ public void setExceptions(List<Class<Throwable>> exceptions) {
+ this.exceptions = exceptions;
+ }
+
+ public JavaMethod(String name) {
+ super(name);
+ this.returnType = Void.TYPE;
+ }
+
+ public JavaMethod(String name, Argument ... arguments) {
+ super(name);
+ this.arguments = Arrays.asList(arguments);
+ }
+
+ public JavaMethod(String name, Class<?> returnType, Argument ... arguments) {
+ super(name);
+ this.returnType = returnType;
+ this.arguments = Arrays.asList(arguments);
+ }
+ public List<Argument> getArguments() {
+ return arguments;
+ }
+
+ public MethodBody getMethodBody() {
+ return methodBody;
+ }
+
+
+ public Class<?> getReturnType() {
+ return returnType;
+ }
+
+ public void setMethodBody(MethodBody methodBody) {
+ this.methodBody = methodBody;
+ }
+}
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaModifier.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaModifier.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaModifier.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,26 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public enum JavaModifier {
+ PRIVATE ,
+ DEFAULT {
+ public String toString() {
+ return "";
+ }
+ },
+ PROTECTED,
+ PUBLIC,
+ STATIC,
+ FINAL;
+
+ public String toString() {
+ return super.toString().toLowerCase();
+ }
+
+}
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPackage.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPackage.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPackage.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,23 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaPackage {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public JavaPackage(String name) {
+ super();
+ this.name = name;
+ }
+
+
+}
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/MethodBody.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/MethodBody.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/MethodBody.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,33 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.model;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class MethodBody {
+
+ private JavaMethod method;
+
+ public MethodBody() {
+ // TODO Auto-generated constructor stub
+ }
+ public MethodBody(JavaMethod method) {
+ super();
+ this.method = method;
+ }
+
+ protected JavaMethod getMethod() {
+ return method;
+ }
+
+ protected void setMethod(JavaMethod method) {
+ this.method = method;
+ }
+
+ public String toCode() {
+ return "";
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,96 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.render;
+
+import java.util.Collection;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.builder.config.ComponentBean;
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.model.JavaAnnotation;
+import org.ajax4jsf.builder.model.JavaClass;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.JavaModifier;
+import org.ajax4jsf.builder.model.JavaPackage;
+
+import static org.ajax4jsf.builder.model.Argument.arg;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentModelBuilder {
+
+ private PropertyProcessor[] propertyProcessors = {};
+
+ public JavaClass build(ComponentBean componentBean) {
+
+ String superclassname =
+ componentBean.getSuperclass();
+
+ JavaClass javaClass =
+ new JavaClass(componentBean.getClassname(),
+ new JavaPackage(componentBean.getPackageName()),
+ UIComponent.class);
+
+ try {
+ Class<?> superClass =
+ Class.forName(superclassname);
+
+ javaClass.setSuperClass(superClass);
+
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+
+ Collection<PropertyBean> properties = componentBean.getProperties();
+
+ for (PropertyBean propertyBean : properties) {
+ PropertyProcessor proc = null;
+
+ for (int i = 0; i < propertyProcessors.length && proc == null; i++) {
+
+ PropertyProcessor processor =
+ propertyProcessors[i];
+
+ if (processor.accept(propertyBean)) {
+ proc = processor;
+ }
+ }
+
+ if (proc != null) {
+ proc.process(propertyBean, javaClass);
+ }
+ }
+
+ javaClass.addMethod(getSaveState());
+ javaClass.addMethod(getRestoreState());
+ return javaClass;
+
+ }
+
+ private JavaMethod getRestoreState() {
+ JavaMethod method =
+ new JavaMethod("restoreState",
+ Void.class,
+ arg("context", FacesContext.class),
+ arg("state", Object.class));
+ method.getModifiers().add(JavaModifier.PUBLIC);
+ method.getAnnotations().add(JavaAnnotation.OVERRIDE);
+
+ return method;
+ }
+
+ private JavaMethod getSaveState() {
+ JavaMethod method =
+ new JavaMethod("saveState",
+ Object.class,
+ arg("context", FacesContext.class));
+ method.getModifiers().add(JavaModifier.PUBLIC);
+ method.getAnnotations().add(JavaAnnotation.OVERRIDE);
+ return method;
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaClassRenderer.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaClassRenderer.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaClassRenderer.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,89 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.render;
+
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Set;
+
+import org.ajax4jsf.builder.model.Argument;
+import org.ajax4jsf.builder.model.JavaClass;
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaLanguageElement;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.JavaModifier;
+import org.ajax4jsf.builder.model.JavaPackage;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaClassRenderer extends JavaLanguageElementRenderer {
+
+ private MethodRenderer methodRenderer = new MethodRenderer();
+
+ public void render(JavaLanguageElement element, PrintWriter out){
+ JavaClass javaClass = (JavaClass) element;
+ out.println("package " + javaClass.getPackage().getName() + ";");
+
+ Set<Class<?>> imports = javaClass.getImports();
+
+ for (Class<?> impord : imports) {
+ out.println("import " + impord.getName());
+ }
+
+ renderModifiers(javaClass, out);
+ out.println("class " + javaClass.getName() + " {");
+
+ List<JavaMethod> methods = javaClass.getMethods();
+ for (JavaMethod javaMethod : methods) {
+ methodRenderer.render(javaMethod, out);
+ }
+
+ out.println("}");
+ out.flush();
+ out.close();
+ }
+
+ public static void main(String[] args) {
+ JavaClass javaClass = new JavaClass("MyClass", new
JavaPackage("mypackage"));
+
+ JavaField javaField = new JavaField(int.class, "count");
+ javaField.setValue(0);
+ javaField.getModifiers().add(JavaModifier.PRIVATE);
+ javaClass.addField(javaField);
+
+ JavaMethod accessor = new JavaMethod("getCount", int.class);
+ accessor.setMethodBody(
+ new MethodBody(accessor) {
+ @Override
+ public String toCode() {
+ return "return count;";
+ }
+ }
+ );
+ accessor.getModifiers().add(JavaModifier.PUBLIC);
+ accessor.getModifiers().add(JavaModifier.FINAL);
+ javaClass.addMethod(accessor);
+
+ JavaMethod mutator = new JavaMethod("setCount", int.class,
+ new Argument("i", int.class));
+ mutator.setMethodBody(
+ new MethodBody(mutator) {
+ @Override
+ public String toCode() {
+ return "count = i;";
+ }
+ }
+ );
+ mutator.getModifiers().add(JavaModifier.PUBLIC);
+ mutator.getModifiers().add(JavaModifier.FINAL);
+ javaClass.addMethod(mutator);
+
+ PrintWriter printWriter = new PrintWriter(System.out);
+ new JavaClassRenderer().render(javaClass, printWriter);
+ printWriter.flush();
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,35 @@
+package org.ajax4jsf.builder.render;
+
+import java.io.PrintWriter;
+import java.util.List;
+import java.util.Set;
+
+import org.ajax4jsf.builder.model.JavaAnnotation;
+import org.ajax4jsf.builder.model.JavaLanguageElement;
+import org.ajax4jsf.builder.model.JavaModifier;
+
+public abstract class JavaLanguageElementRenderer {
+
+ public JavaLanguageElementRenderer() {
+ super();
+ }
+
+ public void renderModifiers(JavaLanguageElement element, PrintWriter out) {
+ Set<JavaModifier> modifiers = element.getModifiers();
+ for (JavaModifier javaModifier : modifiers) {
+ out.print(javaModifier);
+ out.print(" ");
+ }
+ }
+
+ public void renderAnnotations(JavaLanguageElement element, PrintWriter out) {
+ List<JavaAnnotation> annotations = element.getAnnotations();
+ if (annotations != null) {
+ for (JavaAnnotation javaAnnotation : annotations) {
+ out.println("@" + javaAnnotation.getName());
+ }
+ }
+ }
+
+ public abstract void render(JavaLanguageElement element, PrintWriter out);
+}
\ No newline at end of file
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,59 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.render;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.ajax4jsf.builder.model.Argument;
+import org.ajax4jsf.builder.model.JavaLanguageElement;
+import org.ajax4jsf.builder.model.JavaMethod;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class MethodRenderer extends JavaLanguageElementRenderer {
+
+ @Override
+ public void render(JavaLanguageElement element, PrintWriter out) {
+ JavaMethod javaMethod = (JavaMethod) element;
+ renderModifiers(javaMethod, out);
+ renderAnnotations(element, out);
+ out.print(javaMethod.getReturnType() + " " + javaMethod.getName());
+ out.print("(");
+ List<Argument> arguments = javaMethod.getArguments();
+ if (arguments != null) {
+ for (Iterator<Argument> iterator = arguments.iterator(); iterator.hasNext();) {
+ Argument argument = iterator.next();
+ out.print(argument.getType().getSimpleName());
+ out.print(" ");
+ out.print(argument.getName());
+ if (iterator.hasNext()) {
+ out.print(", ");
+ }
+ }
+ }
+ out.print(")");
+ List<Class<Throwable>> exceptions = javaMethod.getExceptions();
+
+ if (exceptions != null && !exceptions.isEmpty()) {
+ out.print(" throws ");
+ for (Iterator<Class<Throwable>> iterator = exceptions.iterator();
iterator.hasNext();) {
+ Class<Throwable> class1 = iterator.next();
+ out.print(class1.getSimpleName());
+ if (iterator.hasNext()) {
+ out.print(", ");
+ }
+
+ }
+ }
+
+ out.println("{");
+ out.println(javaMethod.getMethodBody().toCode());
+ out.println("}");
+
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ObjectPropertyProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ObjectPropertyProcessor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ObjectPropertyProcessor.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,70 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.render;
+
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.model.Argument;
+import org.ajax4jsf.builder.model.JavaClass;
+import org.ajax4jsf.builder.model.JavaComment;
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.JavaModifier;
+import org.ajax4jsf.builder.render.methods.SimpleAccessorMethodBody;
+import org.ajax4jsf.builder.render.methods.SimpleMutatorMethodBody;
+
+/**
+ * Default property handler - a fallback one.
+ * @author Maksim Kaszynski
+ *
+ */
+public class ObjectPropertyProcessor implements PropertyProcessor {
+
+ public boolean accept(PropertyBean propertyBean) {
+ return !propertyBean.isHidden();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.builder.render.PropertyProcessor#process(org.ajax4jsf.builder.config.PropertyBean,
org.ajax4jsf.builder.model.JavaClass)
+ */
+ public void process(PropertyBean propertyBean, JavaClass javaClass) {
+
+ String classname = propertyBean.getClassname();
+ String name = propertyBean.getName();
+ String defaultvalue = propertyBean.getDefaultvalue();
+
+ try {
+ Class<?> propertyClass = Class.forName(classname);
+
+ JavaField field = new JavaField(propertyClass, "_" + name, defaultvalue);
+ field.getComments().add(new JavaComment(propertyBean.getDescription()));
+ field.getModifiers().add(JavaModifier.PRIVATE);
+ javaClass.addField(field);
+
+ javaClass.addMethod(getAccessor(propertyBean, field));
+ javaClass.addMethod(getMutator(propertyBean, field));
+
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected JavaMethod getAccessor(PropertyBean propertyBean, JavaField field) {
+ JavaMethod accessor =
+ new JavaMethod(propertyBean.getGetterName(), field.getType());
+
+ accessor.setMethodBody(new SimpleAccessorMethodBody(accessor, field));
+
+ return accessor;
+ }
+
+ protected JavaMethod getMutator(PropertyBean propertyBean, JavaField field) {
+ JavaMethod mutator =
+ new JavaMethod(propertyBean.getSetterName(),
+ new Argument(field.getName(), field.getType()));
+
+ mutator.setMethodBody(new SimpleMutatorMethodBody(mutator, field));
+
+ return mutator;
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,16 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.render;
+
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.model.JavaClass;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public interface PropertyProcessor {
+ boolean accept(PropertyBean propertyBean);
+ void process(PropertyBean propertyBean, JavaClass javaClass);
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleAccessorMethodBody.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleAccessorMethodBody.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleAccessorMethodBody.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,34 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.render.methods;
+
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimpleAccessorMethodBody extends MethodBody {
+ private JavaField field;
+
+ public SimpleAccessorMethodBody(JavaMethod method, JavaField field) {
+ super(method);
+ this.field = field;
+ }
+
+ protected JavaField getField() {
+ return field;
+ }
+
+ protected void setField(JavaField field) {
+ this.field = field;
+ }
+
+ @Override
+ public String toCode() {
+ return "return " + field.getName() + ";";
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleMutatorMethodBody.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleMutatorMethodBody.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleMutatorMethodBody.java 2007-10-29
18:13:05 UTC (rev 3603)
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.render.methods;
+
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimpleMutatorMethodBody extends MethodBody {
+
+ private JavaField field;
+
+ protected JavaField getField() {
+ return field;
+ }
+
+ protected void setField(JavaField field) {
+ this.field = field;
+ }
+
+ public SimpleMutatorMethodBody(JavaMethod method, JavaField field) {
+ super(method);
+ this.field = field;
+ }
+
+ @Override
+ public String toCode() {
+ return field.getName() + " = " +
getMethod().getArguments().get(0).getName();
+ }
+
+
+}