Author: maksimkaszynski
Date: 2007-10-30 16:39:59 -0400 (Tue, 30 Oct 2007)
New Revision: 3626
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentModelBuilder.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentPropertyProcessor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ELPropertyProcessor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PrimitivePropertyProcessor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PropertyProcessor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/ELPropertyAccessorMethodBody.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleAccessor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleMutator.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/VelocityMethodBody.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/AttachedStateDescriptor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateDescriptor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateManager.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/PrimitiveStateDescriptor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/SimplePropertyDescriptor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentGenerator2.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaConstructor.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPrimitive.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaFieldRenderer.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaMethodRenderer.java
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/el-property-accessor.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-el-property-accessor.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-accessor.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-mutator.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/restore-state.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/save-state.vm
Removed:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.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/
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleAccessorMethodBody.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleMutatorMethodBody.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBaseBean.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/PropertyBean.java
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/JavaClassRenderer.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java
Log:
added Java Class model to be able to generate java class sources on the fly.
Copied:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentModelBuilder.java
(from rev 3610,
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java)
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentModelBuilder.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentModelBuilder.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,204 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component;
+
+import static org.ajax4jsf.builder.model.Argument.arg;
+
+import java.util.Collection;
+
+import javax.faces.component.UIComponentBase;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.builder.component.state.ComponentStateManager;
+import org.ajax4jsf.builder.config.ComponentBean;
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.config.RendererBean;
+import org.ajax4jsf.builder.generator.GeneratorException;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+import org.ajax4jsf.builder.model.JavaClass;
+import org.ajax4jsf.builder.model.JavaConstructor;
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.JavaModifier;
+import org.ajax4jsf.builder.model.JavaPackage;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * Build component class model from configs
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentModelBuilder {
+
+ private PropertyProcessor[] propertyProcessors = {
+ new PrimitivePropertyProcessor(),
+ new ELPropertyProcessor(),
+ new ComponentPropertyProcessor()};
+
+ public JavaClass build(ComponentBean componentBean, JSFGeneratorConfiguration
configuration) {
+
+ String superclassname =
+ componentBean.getSuperclass();
+
+ JavaClass javaClass =
+ new JavaClass(componentBean.getSimpleClassName(),
+ new JavaPackage(componentBean.getPackageName()));
+
+ try {
+ Class<?> superClass =
+ Class.forName(superclassname, false, configuration.getClassLoader());
+
+ javaClass.setSuperClass(superClass);
+
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ javaClass.setSuperClass(UIComponentBase.class);
+ }
+
+ javaClass.addModifier(JavaModifier.PUBLIC);
+
+ javaClass.addField(getComponentFamily(componentBean));
+ javaClass.addField(getComponentType(componentBean));
+
+ javaClass.addMethod(getConstructor(componentBean, javaClass));
+
+ 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, configuration);
+ }
+ }
+
+ javaClass.addMethod(getComponentFamilyMethod(componentBean));
+
+ ComponentStateManager stateManager = new ComponentStateManager(javaClass);
+
+ JavaMethod saveState = getSaveStateTemplate();
+ try {
+ saveState.setMethodBody(stateManager.getSaveStateMethodBody(configuration));
+ } catch (GeneratorException e) {
+ e.printStackTrace();
+ }
+ javaClass.addMethod(saveState);
+
+ JavaMethod restoreState = getRestoreStateTemplate();
+ try {
+ restoreState.setMethodBody(stateManager.getRestoreStateMethodBody(configuration));
+ } catch (GeneratorException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ javaClass.addMethod(restoreState);
+
+
+
+ return javaClass;
+
+ }
+
+ private JavaMethod getComponentFamilyMethod(ComponentBean componentBean) {
+ JavaMethod javaMethod = new JavaMethod("getFamily", String.class);
+ javaMethod.addModifier(JavaModifier.PUBLIC);
+ javaMethod.setMethodBody(new MethodBody() {
+ @Override
+ public String toCode() {
+ return "return COMPONENT_FAMILY;";
+ }
+ });
+ return javaMethod;
+ }
+
+ private JavaMethod getRestoreStateTemplate() {
+ JavaMethod method =
+ new JavaMethod("restoreState",
+ Void.TYPE,
+ arg("context", FacesContext.class),
+ arg("state", Object.class));
+ method.addModifier(JavaModifier.PUBLIC);
+ method.addAnnotation(Override.class);
+
+ return method;
+ }
+
+ private JavaMethod getSaveStateTemplate() {
+ JavaMethod method =
+ new JavaMethod("saveState",
+ Object.class,
+ arg("context", FacesContext.class));
+ method.addModifier(JavaModifier.PUBLIC);
+ method.addAnnotation(Override.class);
+ method.setMethodBody(new MethodBody() {
+ @Override
+ public String toCode() {
+ return "return super.saveState(context);";
+ }
+ });
+ return method;
+ }
+
+ private JavaField getComponentType(ComponentBean componentBean) {
+ JavaField field = new JavaField(String.class, "COMPONENT_TYPE");
+ field.addModifier(JavaModifier.PUBLIC);
+ field.addModifier(JavaModifier.STATIC);
+ field.addModifier(JavaModifier.FINAL);
+ field.setValue("\"" + componentBean.getName() + "\"");
+ return field;
+ }
+ private JavaField getComponentFamily(ComponentBean componentBean) {
+ JavaField field = new JavaField(String.class, "COMPONENT_FAMILY");
+ field.addModifier(JavaModifier.PUBLIC);
+ field.addModifier(JavaModifier.STATIC);
+ field.addModifier(JavaModifier.FINAL);
+ field.setValue("\"" + componentBean.getFamily() + "\"");
+ return field;
+ }
+
+ private JavaMethod getConstructor(ComponentBean componentBean, JavaClass javaClass) {
+ final RendererBean renderer = componentBean.getRenderer();
+ JavaMethod method = new JavaConstructor(javaClass);
+ method.addModifier(JavaModifier.PUBLIC);
+ method.setMethodBody(new MethodBody(method) {
+ @Override
+ public String toCode() {
+ if (renderer != null) {
+ return "setRendererType(\"" + renderer.getName() +
"\");";
+ }
+ return super.toCode();
+ }
+ });
+
+ return method;
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentPropertyProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentPropertyProcessor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ComponentPropertyProcessor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,120 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component;
+
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+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.model.JavaPrimitive;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * Default property handler - a fallback one.
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentPropertyProcessor implements PropertyProcessor {
+
+ public boolean accept(PropertyBean propertyBean) {
+ return !propertyBean.isExist();
+ }
+
+ /* (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,
JSFGeneratorConfiguration configuration) {
+ JavaField field = getField(propertyBean, configuration.getClassLoader());
+
+ javaClass.addField(field);
+ javaClass.addMethod(getAccessor(configuration, propertyBean, field));
+ javaClass.addMethod(getMutator(configuration, propertyBean, field));
+ }
+
+ protected JavaField getField(PropertyBean propertyBean, ClassLoader classLoader) {
+ String name = propertyBean.getName();
+ String defaultvalue = propertyBean.getDefaultvalue();
+ Class<?> propertyClass = getType(propertyBean, classLoader);
+ JavaField field = new JavaField(propertyClass, "_" + name, defaultvalue);
+ field.getComments().add(new JavaComment(propertyBean.getDescription()));
+ field.getModifiers().add(JavaModifier.PRIVATE);
+
+ return field;
+ }
+
+ protected Class<?> getType(PropertyBean propertyBean, ClassLoader classLoader) {
+ if (propertyBean.isSimpleType()) {
+ try {
+ Class<?> clazz = JavaPrimitive.forName(propertyBean.getClassname());
+ return clazz;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ Class<?> clazz = Class.forName(propertyBean.getClassname(), false,
classLoader);
+ return clazz;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ return Object.class;
+ }
+
+ protected JavaMethod getAccessor(JSFGeneratorConfiguration configuration, PropertyBean
propertyBean, final JavaField field) {
+ JavaMethod accessor =
+ new JavaMethod(propertyBean.getGetterName(), field.getType());
+
+ accessor.setMethodBody(new MethodBody() {
+ @Override
+ public String toCode() {
+ return "return " + field.getName() + ";";
+ }
+ });
+
+ accessor.addModifier(JavaModifier.PUBLIC);
+
+ return accessor;
+ }
+
+ protected JavaMethod getMutator(JSFGeneratorConfiguration configuration, PropertyBean
propertyBean, final JavaField field) {
+ JavaMethod mutator =
+ new JavaMethod(propertyBean.getSetterName(),
+ new Argument(field.getName(), field.getType()));
+
+ mutator.setMethodBody(new MethodBody(mutator) {
+ @Override
+ public String toCode() {
+ return "this." + field.getName() + " = " + field.getName() +
";";
+ }
+ });
+
+ mutator.addModifier(JavaModifier.PUBLIC);
+
+ return mutator;
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ELPropertyProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ELPropertyProcessor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/ELPropertyProcessor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,64 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component;
+
+import org.ajax4jsf.builder.component.methods.ELPropertyAccessorMethodBody;
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.generator.GeneratorException;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * Processing of EL-enabled properties
+ * @author Maksim Kaszynski
+ *
+ */
+public class ELPropertyProcessor extends ComponentPropertyProcessor {
+
+ @Override
+ public boolean accept(PropertyBean propertyBean) {
+ return !(propertyBean.isExist() || propertyBean.isSimpleType() ||
propertyBean.isElonly()) && propertyBean.isEl() ;
+ }
+
+ @Override
+ protected JavaMethod getAccessor(JSFGeneratorConfiguration config, PropertyBean
propertyBean, JavaField field) {
+ field.setValue("null");
+
+ JavaMethod accessor = super.getAccessor(config, propertyBean, field);
+
+ try {
+ ELPropertyAccessorMethodBody propertyAccessorMethodBody =
+ new ELPropertyAccessorMethodBody(config, propertyBean, field);
+
+ accessor.setMethodBody(propertyAccessorMethodBody);
+
+ } catch (GeneratorException e) {
+ accessor.setMethodBody(new MethodBody());
+ e.printStackTrace();
+ }
+
+ return accessor;
+ }
+
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PrimitivePropertyProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PrimitivePropertyProcessor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PrimitivePropertyProcessor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,139 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+
+import org.ajax4jsf.builder.component.methods.VelocityMethodBody;
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.generator.GeneratorException;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+import org.ajax4jsf.builder.model.JavaClass;
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.JavaModifier;
+import org.ajax4jsf.builder.model.JavaPrimitive;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * Handle primitive properties
+ * @author Maksim Kaszynski
+ *
+ */
+public class PrimitivePropertyProcessor extends ComponentPropertyProcessor {
+
+ class PrimitiveELPropertyAccessorMethodBody extends VelocityMethodBody {
+
+ public PrimitiveELPropertyAccessorMethodBody(
+ JSFGeneratorConfiguration configuration, JavaField field, JavaField field2,
PropertyBean property)
+ throws GeneratorException {
+ super(configuration);
+ getContext().put("field1", field);
+ getContext().put("field2", field2);
+ getContext().put("wrapperClass",
JavaPrimitive.wrapperType(field.getType()));
+ getContext().put("property", property);
+ addType(ValueExpression.class);
+ addType(ELException.class);
+ addType(FacesException.class);
+ }
+
+ @Override
+ public String getTemplate() {
+ return "snippets/primitive-el-property-accessor.vm";
+ }
+ }
+
+ class PrimitivePropertyAccessorMethodBody extends VelocityMethodBody {
+
+ public PrimitivePropertyAccessorMethodBody(
+ JSFGeneratorConfiguration configuration, JavaField field, JavaField field2)
+ throws GeneratorException {
+ super(configuration);
+ getContext().put("field1", field);
+ getContext().put("field2", field2);
+ }
+
+ @Override
+ public String getTemplate() {
+ return "snippets/primitive-property-accessor.vm";
+ }
+ }
+
+ class PrimitivePropertyMutatorMethodBody extends VelocityMethodBody {
+
+ public PrimitivePropertyMutatorMethodBody(
+ JSFGeneratorConfiguration configuration, JavaField field, JavaField field2)
+ throws GeneratorException {
+ super(configuration);
+ getContext().put("field1", field);
+ getContext().put("field2", field2);
+ }
+
+ @Override
+ public String getTemplate() {
+ return "snippets/primitive-property-mutator.vm";
+ }
+ }
+
+ @Override
+ public boolean accept(PropertyBean propertyBean) {
+ return propertyBean.isSimpleType() && super.accept(propertyBean);
+ }
+
+ @Override
+ public void process(PropertyBean propertyBean, JavaClass javaClass,
JSFGeneratorConfiguration configuration) {
+ JavaField field = getField(propertyBean, configuration.getClassLoader());
+ JavaField field2 = new JavaField(boolean.class, field.getName() + "Set",
"false");
+ field2.addModifier(JavaModifier.PRIVATE);
+
+ JavaMethod accessor = getAccessor(configuration, propertyBean, field);
+ MethodBody accessorMethodBody;
+
+ try {
+ if (propertyBean.isEl()) {
+ accessorMethodBody = new PrimitiveELPropertyAccessorMethodBody(configuration, field,
field2, propertyBean);
+ } else {
+ accessorMethodBody = new PrimitivePropertyAccessorMethodBody(configuration, field,
field2);
+ }
+ accessor.setMethodBody(accessorMethodBody);
+ } catch (GeneratorException e) {
+ e.printStackTrace();
+ }
+
+ JavaMethod mutator = getMutator(configuration, propertyBean, field);
+
+ try {
+ PrimitivePropertyMutatorMethodBody mutatorBody = new
PrimitivePropertyMutatorMethodBody(configuration, field, field2);
+ mutator.setMethodBody(mutatorBody);
+ } catch (GeneratorException e) {
+ e.printStackTrace();
+ }
+
+ javaClass.addField(field);
+ javaClass.addField(field2);
+ javaClass.addMethod(accessor);
+ javaClass.addMethod(mutator);
+ }
+
+}
Copied:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PropertyProcessor.java
(from rev 3610,
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java)
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PropertyProcessor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/PropertyProcessor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,36 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component;
+
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+import org.ajax4jsf.builder.model.JavaClass;
+
+/**
+ * Process single property - add field to class, accessor, mutator, etc.
+ * @author Maksim Kaszynski
+ *
+ */
+public interface PropertyProcessor {
+ boolean accept(PropertyBean propertyBean);
+ void process(PropertyBean propertyBean, JavaClass javaClass, JSFGeneratorConfiguration
configuration);
+}
Copied: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods (from rev
3610, trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods)
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/ELPropertyAccessorMethodBody.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/ELPropertyAccessorMethodBody.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/ELPropertyAccessorMethodBody.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,58 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.methods;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.generator.GeneratorException;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+import org.ajax4jsf.builder.model.JavaField;
+
+/**
+ * Render accessor for EL-enabled property
+ * @author Maksim Kaszynski
+ *
+ */
+public class ELPropertyAccessorMethodBody extends VelocityMethodBody {
+
+ public ELPropertyAccessorMethodBody(JSFGeneratorConfiguration configuration,
+ PropertyBean propertyBean,
+ JavaField field)
+ throws GeneratorException {
+ super(configuration);
+
+ getContext().put("field", field);
+ getContext().put("property", propertyBean);
+ addType(ValueExpression.class);
+ addType(ELException.class);
+ addType(FacesException.class);
+ }
+
+ @Override
+ public String getTemplate() {
+ return "snippets/el-property-accessor.vm";
+ }
+
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleAccessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleAccessor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleAccessor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,40 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.methods;
+
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.JavaModifier;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimpleAccessor extends JavaMethod {
+
+ public SimpleAccessor(String name, JavaField field) {
+ super(name, field.getType());
+ addModifier(JavaModifier.PUBLIC);
+ setMethodBody(new SimpleAccessorMethodBody(this, field));
+ }
+
+}
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleAccessorMethodBody.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleAccessorMethodBody.java 2007-10-30
01:07:16 UTC (rev 3610)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleAccessorMethodBody.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,8 +1,26 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-package org.ajax4jsf.builder.render.methods;
+package org.ajax4jsf.builder.component.methods;
+
import org.ajax4jsf.builder.model.JavaField;
import org.ajax4jsf.builder.model.JavaMethod;
import org.ajax4jsf.builder.model.MethodBody;
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleMutator.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleMutator.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleMutator.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,40 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.methods;
+
+import org.ajax4jsf.builder.model.Argument;
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaMethod;
+import org.ajax4jsf.builder.model.JavaModifier;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimpleMutator extends JavaMethod {
+
+ public SimpleMutator(String name, JavaField field) {
+ super(name, new Argument(field.getName().substring(1), field.getType()));
+ addModifier(JavaModifier.PUBLIC);
+ setMethodBody(new SimpleMutatorMethodBody(this, field));
+ }
+}
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleMutatorMethodBody.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/methods/SimpleMutatorMethodBody.java 2007-10-30
01:07:16 UTC (rev 3610)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/SimpleMutatorMethodBody.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,8 +1,26 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-package org.ajax4jsf.builder.render.methods;
+package org.ajax4jsf.builder.component.methods;
+
import org.ajax4jsf.builder.model.JavaField;
import org.ajax4jsf.builder.model.JavaMethod;
import org.ajax4jsf.builder.model.MethodBody;
@@ -15,6 +33,11 @@
private JavaField field;
+ public SimpleMutatorMethodBody(JavaMethod method, JavaField field) {
+ super(method);
+ this.field = field;
+ }
+
protected JavaField getField() {
return field;
}
@@ -23,11 +46,6 @@
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();
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/VelocityMethodBody.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/VelocityMethodBody.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/methods/VelocityMethodBody.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,76 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.methods;
+
+import java.io.StringWriter;
+
+import org.ajax4jsf.builder.generator.GeneratorException;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+import org.ajax4jsf.builder.model.MethodBody;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+
+/**
+ * Render method body by using Velocity
+ * @author Maksim Kaszynski
+ *
+ */
+public abstract class VelocityMethodBody extends MethodBody {
+
+ private Template template;
+ private VelocityContext context;
+
+ public abstract String getTemplate();
+
+ protected Template loadTemplate(String id, JSFGeneratorConfiguration configuration)
throws GeneratorException{
+ return configuration.getTemplate(configuration.getTemplatesPath() + "/" +
id);
+ }
+
+ public VelocityMethodBody(JSFGeneratorConfiguration configuration) throws
GeneratorException{
+ String t = getTemplate();
+ try {
+ template = loadTemplate(t, configuration);
+ } catch (Exception e) {
+
+ }
+ context = new VelocityContext();
+ }
+
+ protected VelocityContext getContext() {
+ return context;
+ }
+
+ @Override
+ public String toCode() {
+
+ StringWriter stringWriter = new StringWriter();
+
+ try {
+ template.merge(context, stringWriter);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return stringWriter.toString();
+ }
+
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/AttachedStateDescriptor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/AttachedStateDescriptor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/AttachedStateDescriptor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,51 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.state;
+
+import org.ajax4jsf.builder.model.JavaField;
+
+/**
+ * Save attached state,
+ * @author Maksim Kaszynski
+ *
+ */
+public class AttachedStateDescriptor extends ComponentStateDescriptor {
+
+ private static final String restoreTemplate = "(%s)restoreAttachedState(context,
%s)";
+
+ private static final String saveTemplate = "saveAttachedState(context, %s)";
+
+
+ public AttachedStateDescriptor(JavaField field) {
+ super(field);
+ }
+
+ @Override
+ public String saveStateCode() {
+ return String.format(saveTemplate, getField().getName());
+ }
+
+ @Override
+ public String restoreStateCode(String stateFragment) {
+ return String.format(restoreTemplate, getField().getType().getSimpleName(),
stateFragment);
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateDescriptor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateDescriptor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateDescriptor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,52 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.state;
+
+import org.ajax4jsf.builder.model.JavaField;
+
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentStateDescriptor {
+
+ private JavaField field;
+
+ public ComponentStateDescriptor(JavaField field) {
+ super();
+ this.field = field;
+
+ }
+
+ public JavaField getField() {
+ return field;
+ }
+
+ public String saveStateCode() {
+ return "null";
+ }
+
+ public String restoreStateCode(String stateFragment) {
+ return "null";
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateManager.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateManager.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/ComponentStateManager.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,138 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.state;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.ajax4jsf.builder.component.methods.VelocityMethodBody;
+import org.ajax4jsf.builder.config.PropertyBean;
+import org.ajax4jsf.builder.generator.GeneratorException;
+import org.ajax4jsf.builder.generator.JSFGeneratorConfiguration;
+import org.ajax4jsf.builder.model.JavaClass;
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaModifier;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * Class responsible for generating save/restore state methods.
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentStateManager {
+
+ private class SaveStateMethodBody extends VelocityMethodBody {
+
+ public SaveStateMethodBody(JSFGeneratorConfiguration configuration)
+ throws GeneratorException {
+ super(configuration);
+ getContext().put("size", componentStates.size() + 1);
+ getContext().put("descriptors", componentStates);
+ }
+
+ @Override
+ public String getTemplate() {
+ return "snippets/save-state.vm";
+ }
+ }
+
+ private class RestoreStateMethodBody extends VelocityMethodBody {
+
+ public RestoreStateMethodBody(JSFGeneratorConfiguration configuration)
+ throws GeneratorException {
+ super(configuration);
+ getContext().put("size", componentStates.size() + 1);
+ getContext().put("descriptors", componentStates);
+ }
+
+ @Override
+ public String getTemplate() {
+ return "snippets/restore-state.vm";
+ }
+
+ }
+
+
+ @SuppressWarnings("serial")
+ private static final List<Class<?>> detached = new
ArrayList<Class<?>>() {
+ {
+ add(String.class);
+ add(Integer.class);
+ add(Boolean.class);
+ add(Long.class);
+ add(Float.class);
+ add(Double.class);
+ add(BigDecimal.class);
+ }
+ };
+
+ private List<ComponentStateDescriptor> componentStates =
+ new ArrayList<ComponentStateDescriptor>();
+
+
+ public ComponentStateManager(JavaClass componentClass) {
+ List<JavaField> fields = componentClass.getFields();
+ for (JavaField javaField : fields) {
+ registerField(javaField);
+ }
+ }
+
+ public ComponentStateDescriptor getDesriptor(PropertyBean propertyBean, JavaField field)
{
+
+ Set<JavaModifier> modifiers = field.getModifiers();
+ if (modifiers.contains(JavaModifier.FINAL) ||
modifiers.contains(JavaModifier.STATIC)){
+ return null;
+ }
+
+ Class<?> type = field.getType();
+ if (type.isPrimitive()) {
+ return new PrimitiveStateDescriptor(field);
+ }
+ if (detached.contains(type)) {
+ return new SimplePropertyDescriptor(field);
+ }
+
+ return new AttachedStateDescriptor(field);
+ }
+
+
+
+ public void registerField(JavaField field) {
+ ComponentStateDescriptor desriptor = getDesriptor(null, field);
+ if (desriptor != null){
+ componentStates.add(desriptor);
+ }
+ }
+
+ public MethodBody getSaveStateMethodBody(JSFGeneratorConfiguration configuration)
+ throws GeneratorException{
+ return new SaveStateMethodBody(configuration);
+ }
+
+ public MethodBody getRestoreStateMethodBody(JSFGeneratorConfiguration configuration)
+ throws GeneratorException{
+ return new RestoreStateMethodBody(configuration);
+ }
+
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/PrimitiveStateDescriptor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/PrimitiveStateDescriptor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/PrimitiveStateDescriptor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,54 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.state;
+
+import org.ajax4jsf.builder.model.JavaField;
+import org.ajax4jsf.builder.model.JavaPrimitive;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class PrimitiveStateDescriptor extends ComponentStateDescriptor {
+
+ private static final String saveTemplate = "%s.valueOf(%s)";
+ private static final String restoreTemplate = "((%s)%s).%sValue()";
+
+ private Class<?> wrapperType;
+
+
+ public PrimitiveStateDescriptor(JavaField field) {
+ super(field);
+ wrapperType = JavaPrimitive.wrapperType(field.getType());
+ }
+
+ @Override
+ public String restoreStateCode(String stateFragment) {
+ return String.format(restoreTemplate, wrapperType.getSimpleName(), stateFragment,
getField().getType().getSimpleName());
+ }
+
+ @Override
+ public String saveStateCode() {
+ return String.format(saveTemplate, wrapperType.getSimpleName(), getField().getName());
+ }
+
+}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/SimplePropertyDescriptor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/SimplePropertyDescriptor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/component/state/SimplePropertyDescriptor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,45 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.component.state;
+
+import org.ajax4jsf.builder.model.JavaField;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class SimplePropertyDescriptor extends ComponentStateDescriptor {
+
+ public SimplePropertyDescriptor(JavaField field) {
+ super(field);
+ }
+
+ @Override
+ public String saveStateCode() {
+ return getField().getName();
+ }
+
+ @Override
+ public String restoreStateCode(String stateFragment) {
+ return "(" + getField().getType().getSimpleName() + ")" +
stateFragment + ";";
+ }
+}
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBaseBean.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBaseBean.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBaseBean.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -139,14 +139,14 @@
getLog().debug("Parse properties for Component "+getName()+" with
superclass "+getSuperclass());
if (getSuperclass() != null)
{
- Class superClass = getLoader().loadClass(getSuperclass());
+ Class <?> superClass = getLoader().loadClass(getSuperclass());
- Class superSuperClass = superClass;
+ Class<?> superSuperClass = superClass;
while (null != superSuperClass ) {
- Class[] interfaces = superSuperClass.getInterfaces();
+ Class<?>[] interfaces = superSuperClass.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
- Class interfaceClass = interfaces[i];
+ Class<?> interfaceClass = interfaces[i];
checkPropertiesForClass(interfaceClass);
}
superSuperClass = superSuperClass.getSuperclass();
@@ -205,7 +205,7 @@
/**
* @param superClass
*/
- private void checkPropertiesForClass(Class superClass) {
+ private void checkPropertiesForClass(Class<?> superClass) {
getLog().debug("Check properties for class "+superClass.getName());
// get all property descriptors
PropertyDescriptor[] properties = PropertyUtils.getPropertyDescriptors(superClass);
@@ -218,7 +218,7 @@
if(isIgnorableProperty(superClass, descriptor.getName())) {
continue;
}
- Class type = descriptor.getPropertyType();
+ Class<?> type = descriptor.getPropertyType();
getLog().debug("Register property "+descriptor.getName()+" with type
name "+type.getCanonicalName());
property = new PropertyBean();
property.setName(descriptor.getName());
@@ -250,7 +250,7 @@
Method setter = descriptor.getWriteMethod();
// Abstract methods
if(null != setter && null != getter ){
- if( Modifier.isAbstract(getter.getModifiers()) &&
Modifier.isAbstract(setter.getModifiers())&&
Modifier.isPublic(setter.getModifiers()) ){
+ if( (Modifier.isAbstract(getter.getModifiers()) &&
Modifier.isAbstract(setter.getModifiers())) || superClass.isInterface()){
getLog().debug("Detect as abstract property "+descriptor.getName());
property.setExist(false);
}
@@ -270,7 +270,7 @@
}
}
- private boolean isIgnorableProperty(Class base, String name) {
+ private boolean isIgnorableProperty(Class<?> base, String name) {
return Arrays.asList(ignorableComponentProperties).contains(name);
}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/PropertyBean.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/PropertyBean.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/PropertyBean.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -389,4 +389,5 @@
}
return null;
}
+
}
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentGenerator2.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentGenerator2.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/generator/ComponentGenerator2.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,96 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.generator;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.io.Writer;
+import java.util.List;
+
+import org.ajax4jsf.builder.component.ComponentModelBuilder;
+import org.ajax4jsf.builder.config.BuilderConfig;
+import org.ajax4jsf.builder.config.ComponentBean;
+import org.ajax4jsf.builder.model.JavaClass;
+import org.ajax4jsf.builder.render.JavaClassRenderer;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ComponentGenerator2 extends InnerGenerator {
+
+ private ComponentModelBuilder componentModelBuilder = new ComponentModelBuilder();
+ private JavaClassRenderer classRenderer = new JavaClassRenderer();
+
+ public ComponentGenerator2(JSFGeneratorConfiguration task, Logger log) {
+ super(task,log);
+ }
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.builder.generator.InnerGenerator#createFiles(org.ajax4jsf.builder.config.BuilderConfig)
+ */
+ @Override
+ public void createFiles(BuilderConfig config) throws GeneratorException {
+ List<ComponentBean> components = config.getComponents();
+ for (ComponentBean componentBean : components) {
+ if (componentBean.isGenerate()) {
+ JavaClass componentClass =
+ componentModelBuilder.build(componentBean, getConfig());
+
+ String resultPath = componentBean.getClassname().replace('.', '/')
+ + ".java";
+ File javaFile = new File(getDestDir(), resultPath);
+ File javaDir = javaFile.getParentFile();
+ if (!javaDir.exists()) {
+ javaDir.mkdirs();
+ }
+ try {
+ if (javaFile.exists()) {
+ javaFile.delete();
+ }
+ Writer out = new BufferedWriter(new FileWriter(javaFile));
+ PrintWriter printWriter = new PrintWriter(out);
+
+ classRenderer.render(componentClass, printWriter);
+
+ printWriter.flush();
+ out.close();
+ } catch (Exception e) {
+ throw new GeneratorException(
+ "Error create new Component Java file ", e);
+ }
+ }
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.builder.generator.InnerGenerator#getDefaultTemplateName()
+ */
+ @Override
+ protected String getDefaultTemplateName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/Argument.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/Argument.java 2007-10-30
18:10:44 UTC (rev 3625)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/Argument.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,9 +1,28 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
/**
+ * Representation of method argument
* @author Maksim Kaszynski
*
*/
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaAnnotation.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaAnnotation.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaAnnotation.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,19 +1,44 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
+
+
/**
+ * Wrapper for '@annotations
* @author Maksim Kaszynski
*
*/
-public class JavaAnnotation extends JavaLanguageElement{
+public class JavaAnnotation {
- public static JavaAnnotation OVERRIDE = new JavaAnnotation("Override");
+ private Class<?> type;
+
+ public JavaAnnotation(Class<?> type) {
+ super();
+ this.type = type;
+ }
- public JavaAnnotation(String name) {
- super(name);
+ public Class<?> getType() {
+ return type;
}
-
}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaClass.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaClass.java 2007-10-30
18:10:44 UTC (rev 3625)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaClass.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,21 +1,47 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
/**
+ * Java Class model.
+ * Intended for building java classes.
* @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 Set<Class<?>> imports = new TreeSet<Class<?>>(
+ new Comparator<Class<?>> () {
+ public int compare(Class<?> o1, Class<?> o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ });
private JavaPackage pakg;
private Class<?> superClass = Object.class;
@@ -36,9 +62,22 @@
}
}
+ @Override
+ public void addAnnotation(JavaAnnotation annotation) {
+ super.addAnnotation(annotation);
+ addImport(annotation.getType());
+ }
+
public void addField(JavaField field) {
fields.add(field);
addImport(field.getType());
+
+ List<JavaAnnotation> annotations2 = field.getAnnotations();
+ if (annotations2 != null) {
+ for (JavaAnnotation javaAnnotation : annotations2) {
+ addImport(javaAnnotation.getType());
+ }
+ }
}
public void addMethod(JavaMethod method) {
@@ -53,11 +92,28 @@
List<Argument> arguments =
method.getArguments();
+
if (arguments != null) {
for (Argument argument : arguments) {
addImport(argument.getType());
}
}
+
+ List<JavaAnnotation> annotations2 = method.getAnnotations();
+ if (annotations2 != null) {
+ for (JavaAnnotation javaAnnotation : annotations2) {
+ addImport(javaAnnotation.getType());
+ }
+ }
+
+ MethodBody methodBody = method.getMethodBody();
+ if (methodBody != null) {
+ Set<Class<?>> usedClasses = methodBody.getUsedClasses();
+ for (Class<?> class1 : usedClasses) {
+ addImport(class1);
+ }
+ }
+
}
public JavaPackage getPakg() {
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaComment.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaComment.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaComment.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,9 +1,28 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
/**
+ * Java comment representation
* @author Maksim Kaszynski
*
*/
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaConstructor.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaConstructor.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaConstructor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,35 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.model;
+
+
+/**
+ * Constructor method
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaConstructor extends JavaMethod {
+
+ public JavaConstructor(JavaClass javaClass, Argument ... arguments) {
+ super(javaClass.getName(), null, arguments);
+ }
+}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaField.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaField.java 2007-10-30
18:10:44 UTC (rev 3625)
+++ trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaField.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,9 +1,28 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
/**
+ * Class field abstraction
* @author Maksim Kaszynski
*
*/
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaLanguageElement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaLanguageElement.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaLanguageElement.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,3 +1,24 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
package org.ajax4jsf.builder.model;
import java.util.ArrayList;
@@ -4,7 +25,11 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
+/**
+ *
+ * @author Maksim Kaszynski
+ *
+ */
public class JavaLanguageElement {
private Set<JavaModifier> modifiers = new HashSet<JavaModifier>();
@@ -32,5 +57,16 @@
public String getName() {
return name;
}
+
+ public void addModifier(JavaModifier modifier) {
+ modifiers.add(modifier);
+ }
+
+ public void addAnnotation(JavaAnnotation annotation) {
+ annotations.add(annotation);
+ }
+ public void addAnnotation(Class<?> annotation) {
+ annotations.add(new JavaAnnotation(annotation));
+ }
}
\ No newline at end of file
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaMethod.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaMethod.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaMethod.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,6 +1,24 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
import java.util.ArrayList;
@@ -34,12 +52,12 @@
}
public JavaMethod(String name, Argument ... arguments) {
- super(name);
+ this(name);
this.arguments = Arrays.asList(arguments);
}
public JavaMethod(String name, Class<?> returnType, Argument ... arguments) {
- super(name);
+ this(name);
this.returnType = returnType;
this.arguments = Arrays.asList(arguments);
}
@@ -58,5 +76,8 @@
public void setMethodBody(MethodBody methodBody) {
this.methodBody = methodBody;
+ if (methodBody != null) {
+ methodBody.setMethod(this);
+ }
}
}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaModifier.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaModifier.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaModifier.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,6 +1,24 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
/**
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPackage.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPackage.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPackage.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,6 +1,24 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
/**
Added: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPrimitive.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPrimitive.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/JavaPrimitive.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,75 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaPrimitive {
+
+ @SuppressWarnings("serial")
+ private static Map<String, Class<?>> types =
+ new HashMap<String, Class<?>> () {{
+ put("boolean", boolean.class);
+ put("byte", byte.class);
+ put("short", short.class);
+ put("char", char.class);
+ put("int", int.class);
+ put("long", long.class);
+ put("float", float.class);
+ put("double", double.class);
+ }};
+
+ @SuppressWarnings("serial")
+ private static Map<String, Class<?>> wrappers =
+ new HashMap<String, Class<?>>() {
+ {
+ put(boolean.class.getName(), Boolean.class);
+ put(byte.class.getName(), Byte.class);
+ put(short.class.getName(), Short.class);
+ put(char.class.getName(), Character.class);
+ put(int.class.getName(), Integer.class);
+ put(float.class.getName(), Float.class);
+ put(long.class.getName(), Long.class);
+ put(double.class.getName(), Double.class);
+ }};
+
+ public static final Class<?> forName(String name) throws ClassNotFoundException{
+ Class<?> class1 = types.get(name);
+ if (class1 == null) {
+ throw new ClassNotFoundException(name);
+ }
+ return class1;
+ }
+
+ public static final Class<?> wrapperType(Class<?> primitive) {
+ if (!primitive.isPrimitive()) {
+ throw new IllegalArgumentException("Class " + primitive + " is not
primitive.");
+ }
+
+ return wrappers.get(primitive.getName());
+ }
+}
Modified: trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/MethodBody.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/MethodBody.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/model/MethodBody.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,8 +1,29 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.model;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* @author Maksim Kaszynski
*
@@ -11,6 +32,8 @@
private JavaMethod method;
+ private Set<Class<?>> usedClasses = new HashSet<Class<?>>();
+
public MethodBody() {
// TODO Auto-generated constructor stub
}
@@ -30,4 +53,12 @@
public String toCode() {
return "";
}
+
+ public void addType(Class<?> clazz) {
+ usedClasses.add(clazz);
+ }
+
+ public Set<Class<?>> getUsedClasses() {
+ return usedClasses;
+ }
}
Deleted:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ComponentModelBuilder.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,96 +0,0 @@
-/**
- *
- */
-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;
- }
-}
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaClassRenderer.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaClassRenderer.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaClassRenderer.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,16 +1,35 @@
/**
- *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+
package org.ajax4jsf.builder.render;
import java.io.PrintWriter;
import java.util.List;
import java.util.Set;
+import javax.faces.component.UIComponentBase;
+
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;
@@ -20,33 +39,66 @@
* @author Maksim Kaszynski
*
*/
-public class JavaClassRenderer extends JavaLanguageElementRenderer {
+public class JavaClassRenderer extends JavaLanguageElementRenderer<JavaClass> {
- private MethodRenderer methodRenderer = new MethodRenderer();
+ private JavaMethodRenderer methodRenderer = new JavaMethodRenderer();
- public void render(JavaLanguageElement element, PrintWriter out){
- JavaClass javaClass = (JavaClass) element;
+ private JavaFieldRenderer fieldRenderer = new JavaFieldRenderer();
+
+ public void render(JavaClass javaClass, PrintWriter out){
out.println("package " + javaClass.getPackage().getName() + ";");
-
+ out.println();
Set<Class<?>> imports = javaClass.getImports();
for (Class<?> impord : imports) {
- out.println("import " + impord.getName());
+ out.println("import " + impord.getName() + ";");
}
+ out.println();
+
+ renderAnnotations(javaClass, out);
+
renderModifiers(javaClass, out);
- out.println("class " + javaClass.getName() + " {");
+ out.print("class " + javaClass.getName() );
+ Class<?> superClass =
+ javaClass.getSuperClass();
+
+ if (!Object.class.getName().equals(superClass.getName())) {
+ out.print(" extends " + superClass.getSimpleName());
+ }
+
+ out.println("{");
+
+ out.println();
+
+ List<JavaField> fields = javaClass.getFields();
+ for (JavaField javaField : fields) {
+ fieldRenderer.render(javaField, out);
+ out.println();
+
+ }
+
+ out.println();
+
+
List<JavaMethod> methods = javaClass.getMethods();
for (JavaMethod javaMethod : methods) {
methodRenderer.render(javaMethod, out);
+ out.println();
+
}
+
out.println("}");
out.flush();
out.close();
}
+ @interface Tezt {
+
+ }
+
public static void main(String[] args) {
JavaClass javaClass = new JavaClass("MyClass", new
JavaPackage("mypackage"));
@@ -55,6 +107,14 @@
javaField.getModifiers().add(JavaModifier.PRIVATE);
javaClass.addField(javaField);
+ JavaField field =
+ new JavaField(UIComponentBase.class, "component", "null");
+ field.addModifier(JavaModifier.PUBLIC);
+ field.addAnnotation(Deprecated.class);
+ javaClass.addField(field);
+
+ javaClass.addAnnotation(Deprecated.class);
+
JavaMethod accessor = new JavaMethod("getCount", int.class);
accessor.setMethodBody(
new MethodBody(accessor) {
@@ -68,7 +128,7 @@
accessor.getModifiers().add(JavaModifier.FINAL);
javaClass.addMethod(accessor);
- JavaMethod mutator = new JavaMethod("setCount", int.class,
+ JavaMethod mutator = new JavaMethod("setCount",
new Argument("i", int.class));
mutator.setMethodBody(
new MethodBody(mutator) {
@@ -78,8 +138,9 @@
}
}
);
- mutator.getModifiers().add(JavaModifier.PUBLIC);
- mutator.getModifiers().add(JavaModifier.FINAL);
+ mutator.addAnnotation(Tezt.class);
+ mutator.addModifier(JavaModifier.PUBLIC);
+ mutator.addModifier(JavaModifier.FINAL);
javaClass.addMethod(mutator);
PrintWriter printWriter = new PrintWriter(System.out);
Added:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaFieldRenderer.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaFieldRenderer.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaFieldRenderer.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,50 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.builder.render;
+
+import java.io.PrintWriter;
+
+import org.ajax4jsf.builder.model.JavaField;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaFieldRenderer extends JavaLanguageElementRenderer<JavaField> {
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.builder.render.JavaLanguageElementRenderer#render(org.ajax4jsf.builder.model.JavaLanguageElement,
java.io.PrintWriter)
+ */
+ @Override
+ public void render(JavaField field, PrintWriter out) {
+ renderComments(field, out);
+ renderAnnotations(field, out);
+ renderModifiers(field, out);
+ out.print(" " + field.getType().getSimpleName());
+ out.print(" " + field.getName());
+ if (field.getValue() != null) {
+ out.print(" = " + field.getValue());
+ }
+ out.println(";");
+ }
+
+}
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaLanguageElementRenderer.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,3 +1,23 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
package org.ajax4jsf.builder.render;
import java.io.PrintWriter;
@@ -5,16 +25,22 @@
import java.util.Set;
import org.ajax4jsf.builder.model.JavaAnnotation;
+import org.ajax4jsf.builder.model.JavaComment;
import org.ajax4jsf.builder.model.JavaLanguageElement;
import org.ajax4jsf.builder.model.JavaModifier;
+/**
+ *
+ * @author Maksim Kaszynski
+ *
+ * @param <T>
+ */
+public abstract class JavaLanguageElementRenderer<T extends JavaLanguageElement> {
-public abstract class JavaLanguageElementRenderer {
-
public JavaLanguageElementRenderer() {
super();
}
- public void renderModifiers(JavaLanguageElement element, PrintWriter out) {
+ public void renderModifiers(T element, PrintWriter out) {
Set<JavaModifier> modifiers = element.getModifiers();
for (JavaModifier javaModifier : modifiers) {
out.print(javaModifier);
@@ -22,14 +48,23 @@
}
}
- public void renderAnnotations(JavaLanguageElement element, PrintWriter out) {
+ public void renderAnnotations(T element, PrintWriter out) {
List<JavaAnnotation> annotations = element.getAnnotations();
if (annotations != null) {
for (JavaAnnotation javaAnnotation : annotations) {
- out.println("@" + javaAnnotation.getName());
+ out.println("@" + javaAnnotation.getType().getSimpleName());
}
}
}
- public abstract void render(JavaLanguageElement element, PrintWriter out);
+ public void renderComments(T element, PrintWriter out) {
+ List<JavaComment> comments = element.getComments();
+ for (JavaComment javaComment : comments) {
+ out.println("/*");
+ out.println("* " + javaComment.getValue());
+ out.println("*/");
+ }
+ }
+
+ public abstract void render(T element, PrintWriter out);
}
\ No newline at end of file
Copied:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaMethodRenderer.java
(from rev 3610,
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java)
===================================================================
--- trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaMethodRenderer.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/JavaMethodRenderer.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,88 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+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.JavaMethod;
+import org.ajax4jsf.builder.model.MethodBody;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class JavaMethodRenderer extends JavaLanguageElementRenderer<JavaMethod> {
+
+ @Override
+ public void render(JavaMethod javaMethod, PrintWriter out) {
+ renderComments(javaMethod, out);
+ renderAnnotations(javaMethod, out);
+ renderModifiers(javaMethod, out);
+
+ Class<?> returnType = javaMethod.getReturnType();
+
+ if (returnType != null) {
+ out.print(returnType.getSimpleName() + " ");
+ }
+
+ out.print(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("{");
+ MethodBody methodBody = javaMethod.getMethodBody();
+ if (methodBody != null){
+ out.println(methodBody.toCode());
+ }
+ out.println("}");
+
+ }
+}
Deleted:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/MethodRenderer.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,59 +0,0 @@
-/**
- *
- */
-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("}");
-
- }
-}
Deleted:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ObjectPropertyProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ObjectPropertyProcessor.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/ObjectPropertyProcessor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,70 +0,0 @@
-/**
- *
- */
-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;
- }
-}
Deleted:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java 2007-10-30
18:10:44 UTC (rev 3625)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/render/PropertyProcessor.java 2007-10-30
20:39:59 UTC (rev 3626)
@@ -1,16 +0,0 @@
-/**
- *
- */
-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/resources/META-INF/templates12/snippets/el-property-accessor.vm
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/el-property-accessor.vm
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/el-property-accessor.vm 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,18 @@
+ if (this.${field.name} != null) {
+ return this.${field.name};
+ }
+ ValueExpression ve = getValueExpression("${property.name}");
+ if (ve != null) {
+ ${field.type.simpleName} value = null;
+
+ try {
+ value = (${field.type.simpleName}) ve.getValue(getFacesContext().getELContext());
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+
+ return value;
+ }
+
+ return ${property.defaultvalue};
+
Added:
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-el-property-accessor.vm
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-el-property-accessor.vm
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-el-property-accessor.vm 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,21 @@
+ if (this.${field2.name}) {
+ return (this.${field1.name});
+ }
+ ValueExpression ve = getValueExpression("${property.name}");
+ if (ve != null) {
+ ${wrapperClass.simpleName} value = null;
+
+ try {
+ value = (${wrapperClass.simpleName}) ve.getValue(getFacesContext().getELContext());
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+
+ if (null == value) {
+ return (this.${field1.name});
+ }
+
+ return value;
+ } else {
+ return (this.${field1.name});
+ }
Added:
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-accessor.vm
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-accessor.vm
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-accessor.vm 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1 @@
+return ${field1.name};
\ No newline at end of file
Added:
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-mutator.vm
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-mutator.vm
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/primitive-property-mutator.vm 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,2 @@
+this.${field1.name} = ${field1.name};
+this.${field2.name} = true;
\ No newline at end of file
Added:
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/restore-state.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/restore-state.vm
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/restore-state.vm 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,8 @@
+Object[] states = (Object[]) state;
+super.restoreState(context, states[0]);
+#set($counter = 1)
+#foreach($descriptor in $descriptors)
+ #set($fragment = "states[${counter}]")
+ ${descriptor.field.name} = ${descriptor.restoreStateCode($fragment)};
+ #set($counter = $counter+1)
+#end
\ No newline at end of file
Added: trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/save-state.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/save-state.vm
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/snippets/save-state.vm 2007-10-30
20:39:59 UTC (rev 3626)
@@ -0,0 +1,8 @@
+Object [] state = new Object[$size];
+state[0] = super.saveState(context);
+#set($counter = 1)
+#foreach($descriptor in $descriptors)
+state[$counter] = ${descriptor.saveStateCode()};
+#set($counter = $counter + 1)
+#end
+return state;
\ No newline at end of file