Author: alexsmirnov
Date: 2009-08-17 20:57:37 -0400 (Mon, 17 Aug 2009)
New Revision: 15189
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
Log:
generate component classes
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java 2009-08-18
00:57:04 UTC (rev 15188)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java 2009-08-18
00:57:37 UTC (rev 15189)
@@ -15,7 +15,7 @@
* @author asmirnov(a)exadel.com
*
*/
-final class RichFacesConventions implements NamingConventions {
+public final class RichFacesConventions implements NamingConventions {
private static final String ABSTRACT = "Abstract";
private static final String UI = "UI";
@@ -31,7 +31,7 @@
* <p class="changed_added_4_0"></p>
* @param componentLibrary
*/
- RichFacesConventions(String baseName) {
+ public RichFacesConventions(String baseName) {
this.baseName = baseName;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2009-08-18
00:57:04 UTC (rev 15188)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2009-08-18
00:57:37 UTC (rev 15189)
@@ -23,34 +23,52 @@
package org.richfaces.cdk.generate.java;
+import java.io.File;
+
import org.richfaces.cdk.CdkContext;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.model.Component;
import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.JsfComponent;
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public class ComponentClassGenerator implements CdkWriter {
+public class ComponentClassGenerator extends FreeMarkerRenderer<Component, String>
implements CdkWriter {
/* (non-Javadoc)
* @see org.richfaces.cdk.CdkWriter#init(org.richfaces.cdk.CdkContext)
*/
@Override
- public void init(CdkContext context) {
- // TODO Auto-generated method stub
+ public void init(CdkContext context) throws CdkException {
+ super.init(context);
}
- /* (non-Javadoc)
- * @see org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary)
- */
+
@Override
- public void render(ComponentLibrary library) throws CdkException {
- // TODO Auto-generated method stub
+ protected boolean isMyComponent(JsfComponent c) {
+ if (c instanceof Component) {
+ Component component = (Component) c;
+ return !component.isExists();
+ }
+ return false;
+ }
+
+ @Override
+ protected String getOutputFile(Component c) {
+ File sourceOutput = getContext().getJavaSourceOutput();
+ return (new File(sourceOutput,c.getComponentClass().getName().replace('.',
File.separatorChar)+".java")).getAbsolutePath();
}
+
+ @Override
+ protected String getTemplateName() {
+ return "component.ftl";
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java 2009-08-18
00:57:04 UTC (rev 15188)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassDescription.java 2009-08-18
00:57:37 UTC (rev 15189)
@@ -23,6 +23,8 @@
package org.richfaces.cdk.model;
+import javax.annotation.Generated;
+
import com.google.common.collect.ImmutableMap;
/**
@@ -132,6 +134,32 @@
}
/**
+ * <p class="changed_added_4_0"></p>
+ * @return package name.
+ */
+ public String getPackage() {
+ int indexOfPeriod = name.lastIndexOf('.');
+ if(indexOfPeriod>0){
+ return name.substring(0,indexOfPeriod);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return package name.
+ */
+ public String getSimpleName() {
+ int indexOfPeriod = name.lastIndexOf('.');
+ if(indexOfPeriod>0){
+ return name.substring(indexOfPeriod+1);
+ } else {
+ return name;
+ }
+ }
+
+ /**
* <p class="changed_added_4_0">
* </p>
*
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl 2009-08-18
00:57:37 UTC (rev 15189)
@@ -0,0 +1,72 @@
+/*
+ * $Id$
+ *
+ * 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 ${componentClass.package};
+
+// Import declarations
+import javax.annotation.Generated;
+
+/**
+ * ${description}
+ **/
+@Generated({"RicFaces CDK","4.0.0-SNAPSHOT"})
+public class ${componentClass.simpleName} extends ${baseClass} {
+
+
+ public static final String COMPONENT_TYPE="${type}";
+
+ public static final String COMPONENT_FAMILY="${family}";
+
+ protected enum Properties {
+ [#list component.attributes as attribute]
+ [#if attribute.exists == false ]
+ ${attribute.hame},
+ [/#if]
+ [/#list]
+ ;
+ String toString;
+ PropertyKeys(String toString) { this.toString = toString; }
+ PropertyKeys() { }
+ public String toString() {
+ return ((toString != null) ? toString : super.toString());
+ }
+ }
+
+ [#list component.attributes as attribute]
+ [#if attribute.exists == false ]
+ /**
+ * ${attribute.description}
+ **/
+ public ${attribute.type} get${attribute.name}(){
+ return (${attribute.type})getStateHelper().eval(Properties.${attribute.name});
+ }
+
+ /**
+ * Setter for ${attribute.name}
+ **/
+ public void set${attribute.name}(${attribute.type} ${attribute.name}){
+ getStateHelper().put(Properties.${attribute.name},${attribute.name});
+ }
+ [/#if]
+ [/#list]
+
+}
\ No newline at end of file
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2009-08-18
00:57:04 UTC (rev 15188)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ClassDescriptionTest.java 2009-08-18
00:57:37 UTC (rev 15189)
@@ -45,13 +45,17 @@
private final String expectedCanonicalName;
private final String expectedBoxedName;
private final String expectedTypeParameter;
+ private final String packageName;
+ private final String simpleName;
- public ClassDescriptionTest(String className,String expectedCanonicalName,String
expectedBoxedName,String expectedTypeParameter) {
+ public ClassDescriptionTest(String className,String expectedCanonicalName,String
expectedBoxedName,String expectedTypeParameter, String packageName, String simpleName) {
this.className = className;
this.expectedCanonicalName = expectedCanonicalName;
this.expectedBoxedName = expectedBoxedName;
this.expectedTypeParameter = expectedTypeParameter;
-
+ this.packageName = packageName;
+ this.simpleName = simpleName;
+
}
/**
* Test method for {@link
org.richfaces.cdk.model.ClassDescription#ClassDescription(java.lang.String)}.
@@ -63,13 +67,16 @@
assertEquals(expectedCanonicalName, description.getName());
assertEquals(expectedBoxedName, description.getBoxingName());
assertEquals(expectedTypeParameter, description.getTypeParameters());
+ assertEquals(packageName, description.getPackage());
+ assertEquals(simpleName, description.getSimpleName());
+
}
@Parameters
public static Collection<String[]> values(){
- return Arrays.asList(new
String[]{int.class.getName(),"int","java.lang.Integer",null},
- new
String[]{"java.util.List<String>","java.util.List","java.util.List<String>","<String>"},
- new
String[]{double.class.getName(),"double","java.lang.Double",null});
+ return Arrays.asList(new
String[]{int.class.getName(),"int","java.lang.Integer",null,null,"int"},
+ new
String[]{"java.util.List<String>","java.util.List","java.util.List<String>","<String>","java.util","List"},
+ new
String[]{double.class.getName(),"double","java.lang.Double",null,null,"double"});
}
}