Author: maksimkaszynski
Date: 2007-10-23 15:18:11 -0400 (Tue, 23 Oct 2007)
New Revision: 3491
Added:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/velocity/
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/velocity/ResourceLoader.java
trunk/cdk/maven-cdk-plugin/src/main/resources/META-INF/
trunk/cdk/maven-cdk-plugin/src/main/resources/META-INF/plexus/
trunk/cdk/maven-cdk-plugin/src/main/resources/META-INF/plexus/components.xml
Removed:
trunk/cdk/generator/src/main/resources/VM_global_library.vm
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/BuilderConfig.java
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBaseBean.java
trunk/cdk/generator/src/main/resources/META-INF/templates12/VM_global_library.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/component.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/componentTag.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/converterTag.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/listener_tag.vm
trunk/cdk/generator/src/main/resources/META-INF/templates12/validatorTag.vm
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java
trunk/cdk/maven-cdk-plugin/src/main/resources/VM_global_library.vm
Log:
Refactoring of 1.2 templates
Modified:
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/BuilderConfig.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/BuilderConfig.java 2007-10-23
15:51:34 UTC (rev 3490)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/BuilderConfig.java 2007-10-23
19:18:11 UTC (rev 3491)
@@ -21,16 +21,21 @@
package org.ajax4jsf.builder.config;
+import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
import javax.naming.ConfigurationException;
import org.ajax4jsf.builder.generator.Logger;
+import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.ExtendedBaseRules;
import org.apache.tools.ant.BuildException;
@@ -415,20 +420,42 @@
if (bean.getSuperclass() != null) {
Class<?> componentSClass = Class.forName(bean
.getSuperclass(), false, getLoader());
-
+
if (listenerClass.isAssignableFrom(componentSClass)) {
PropertyBean listenerProperty = bean
.getProperty(listener.getName());
+
if (null == listenerProperty) {
- listenerProperty = new PropertyBean();
- listenerProperty.setName(listener.getName());
- bean.addProperty(listenerProperty);
-
+ listenerProperty = new PropertyBean();
+ listenerProperty.setName(listener.getName());
+ bean.addProperty(listenerProperty);
+ listenerProperty.setClassname("javax.el.MethodExpression");
}
+
+ Map<String, PropertyDescriptor> map =
+ getPropertyDescriptors(componentSClass);
+
+ PropertyDescriptor propertyDescriptor =
+ map.get(listener.getName());
+
+ if (propertyDescriptor != null) {
+ String componentPropertyName = propertyDescriptor.getPropertyType().getName();
+
+ if (!componentPropertyName.equals(listenerProperty.getClassname())) {
+ _log.error(
+ String.format("Overriding property type %s with %s for %s.%s",
+ listenerProperty.getClassname(),
+ componentPropertyName,
+ bean.getClassname(),
+ listener.getName()
+ ));
+ }
+
+ listenerProperty.setClassname(componentPropertyName);
+ }
+
// TODO - check existing property for compability with this listener.
- listenerProperty
- .setClassname("javax.faces.el.MethodBinding");
listenerProperty.setEl(true);
listenerProperty.setElonly(true);
listenerProperty.setAttachedstate(true);
@@ -460,6 +487,38 @@
}
+
+ private Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?>
clazz) {
+
+ if (clazz.equals(Object.class)) {
+ return Collections.emptyMap();
+ }
+
+ Map<String, PropertyDescriptor> m =
+ new TreeMap<String, PropertyDescriptor>();
+
+ Class<?> superclass = clazz.getSuperclass();
+ if (superclass != null) {
+ m.putAll(getPropertyDescriptors(superclass));
+ }
+
+ Class<?>[] interfaces = clazz.getInterfaces();
+ if (interfaces != null) {
+ for (Class<?> intrfc : interfaces) {
+ m.putAll(getPropertyDescriptors(intrfc));
+ }
+ }
+
+ PropertyDescriptor[] descriptors =
+ PropertyUtils.getPropertyDescriptors(clazz);
+
+ for (PropertyDescriptor propertyDescriptor : descriptors) {
+ m.put(propertyDescriptor.getName(), propertyDescriptor);
+ }
+
+ return m;
+ }
+
/*
* (non-Javadoc)
*
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-23
15:51:34 UTC (rev 3490)
+++
trunk/cdk/generator/src/main/java/org/ajax4jsf/builder/config/ComponentBaseBean.java 2007-10-23
19:18:11 UTC (rev 3491)
@@ -37,6 +37,8 @@
"java.util.List",
"javax.faces.el.MethodBinding",
"javax.faces.el.ValueBinding",
+ "javax.el.MethodExpression",
+ "javax.el.ValueExpression",
"javax.faces.convert.Converter"
};
/**
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates12/VM_global_library.vm
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates12/VM_global_library.vm 2007-10-23
15:51:34 UTC (rev 3490)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates12/VM_global_library.vm 2007-10-23
19:18:11 UTC (rev 3491)
@@ -3,8 +3,8 @@
#if($a)$a#end
#end
-
+
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/component.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/component.vm 2007-10-23
15:51:34 UTC (rev 3490)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/component.vm 2007-10-23
19:18:11 UTC (rev 3491)
@@ -96,7 +96,7 @@
if (null != this._${prop.name})
{
return this._${prop.name};
- #if( !$prop.isInstanceof("javax.el.MethodExpression") &&
!$prop.isInstanceof("javax.el.ValueExpression"))
+ #if( !$prop.isInstanceof("javax.el.MethodExpression") &&
!$prop.isInstanceof("javax.el.ValueExpression")&&
!$prop.isInstanceof("javax.faces.el.ValueBinding")&&
!$prop.isInstanceof("javax.faces.el.MethodBinding"))
}
ValueExpression ve = getValueExpression("${prop.name}");
if (null != ve){
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/componentTag.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/componentTag.vm 2007-10-23
15:51:34 UTC (rev 3490)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/componentTag.vm 2007-10-23
19:18:11 UTC (rev 3491)
@@ -21,56 +21,13 @@
public class $tag.simpleClassName extends $tag.superclass {
-// Fields
-#foreach( $prop in $component.properties )
- #if( !$prop.existintag && !$prop.hidden)
- #if($prop.classname == "javax.el.MethodExpression" || $prop.classname ==
"javax.faces.el.MethodBinding")
- #set($type = "MethodExpression")
- #else
- #set($type = "ValueExpression")
- #end
-
- /*
- * $prop.name
- * ${prop.xmlEncodedDescription}
- */
- private $type _${prop.name};
- /**
- * $prop.description
- * Setter for $prop.name
- * @param $prop.name - new value
- */
- public void ${prop.setterName}( $type __${prop.name} ){
- this._${prop.name} = __${prop.name};
- }
-
- #if( $prop.alias)
- /**
- * ${prop.xmlEncodedDescription}
- * Setter for alias of $prop.name as $prop.alias
- * @param $prop.name - new value
- */
- public void set${prop.upperFirstChar($prop.alias)}( $type __${prop.alias} ){
- this.${prop.setterName}(__${prop.alias});
- }
- #end
- #end
-#end
-
-// Release
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.components.taglib.html.HtmlCommandButtonTagBase#release()
- */
+ #tagPropertyMethods12($component)
+
public void release()
{
// TODO Auto-generated method stub
super.release();
-#foreach( $prop in $component.properties )
- #if( !$prop.existintag && !$prop.hidden)
- this._${prop.name} = null;
- #end
-#end
+ #tagPropertyRelease($component)
}
/* (non-Javadoc)
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/converterTag.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/converterTag.vm 2007-10-23
15:51:34 UTC (rev 3490)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/converterTag.vm 2007-10-23
19:18:11 UTC (rev 3491)
@@ -7,11 +7,16 @@
#foreach($import in $imports)
import $import ;
#end
+import javax.el.ELException;
+import javax.faces.FacesException;
import javax.faces.component.UIComponent;
+import javax.el.MethodExpression;
+import javax.faces.el.MethodBinding;
+import javax.faces.el.ValueBinding;
+import javax.el.ValueExpression;
import javax.faces.convert.Converter;
import javax.faces.webapp.UIComponentTag;
import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
import org.apache.commons.beanutils.ConvertUtils;
import javax.servlet.jsp.JspException;
import ${converter.classname};
@@ -19,44 +24,8 @@
public class $tag.simpleClassName extends $tag.superclass
{
-// Fields
-#foreach( $prop in $converter.properties )
-#if( !$prop.existintag )
- /*
- * $prop.name
- * ${prop.xmlEncodedDescription}
- */
- private String _$prop.name = null;
+#tagPropertyMethods12($converter)
-#end
-#end
-// Setters
-#foreach( $prop in $converter.properties )
-#if( !$prop.existintag )
- /*
- * $prop.description
- * Setter for $prop.name
- * @param $prop.name - new value
- */
- public void ${prop.setterName}(String __${prop.name})
- {
- this._${prop.name} = __${prop.name};
- }
-
-#end
-#if( $prop.alias)
- /*
- * ${prop.xmlEncodedDescription}
- * Setter for alias of $prop.name as $prop.alias
- * @param $prop.name - new value
- */
- public void set${prop.upperFirstChar($prop.alias)}(String __${prop.alias})
- {
- this.${prop.setterName}(__${prop.alias});
- }
-#end
-#end
-
protected Converter createConverter() throws JspException
{
${converter.simpleClassName} converter = (${converter.simpleClassName})
FacesContext.getCurrentInstance().getApplication().createConverter("${converter.id}");
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/listener_tag.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/listener_tag.vm 2007-10-23
15:51:34 UTC (rev 3490)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/listener_tag.vm 2007-10-23
19:18:11 UTC (rev 3491)
@@ -49,6 +49,8 @@
private String type;
private String binding;
+ #tagPropertyMethods12($listener)
+
public int doStartTag() throws JspException {
UIComponentTag parentTag = UIComponentTag
@@ -175,47 +177,8 @@
public void release() {
type = null;
binding = null;
+ #tagPropertyRelease($listener)
}
-// Fields
-#foreach( $prop in $listener.properties )
-#if( !$prop.existintag )
- /*
- * $prop.name
- * ${prop.xmlEncodedDescription}
- */
- private String _$prop.name = null;
-#end
-#end
-// Setters
-#foreach( $prop in $listener.properties )
-#if( !$prop.existintag )
- /*
- * $prop.description
- * Setter for $prop.name
- * @param $prop.name - new value
- */
- public void ${prop.setterName}(String __${prop.name})
- {
- this._${prop.name} = __${prop.name};
- }
-
-#end
-#if( $prop.alias)
- /*
- * ${prop.xmlEncodedDescription}
- * Setter for alias of $prop.name as $prop.alias
- * @param $prop.name - new value
- */
- public void set${prop.upperFirstChar($prop.alias)}(String __${prop.alias})
- {
- this.${prop.setterName}(__${prop.alias});
- }
-#end
-#end
-
-
-
-
}
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates12/validatorTag.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates12/validatorTag.vm 2007-10-23
15:51:34 UTC (rev 3490)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates12/validatorTag.vm 2007-10-23
19:18:11 UTC (rev 3491)
@@ -18,43 +18,8 @@
public class $tag.simpleClassName extends $tag.superclass {
- // Fields
-#foreach( $prop in $validator.properties )
-#if( !$prop.existintag )
- /*
- * $prop.name
- * ${prop.xmlEncodedDescription}
- */
- private String _$prop.name = null;
-#end
-#end
-// Setters
-#foreach( $prop in $validator.properties )
-#if( !$prop.existintag )
- /*
- * $prop.description
- * Setter for $prop.name
- * @param $prop.name - new value
- */
- public void ${prop.setterName}( String __${prop.name} )
- {
- this._${prop.name} = __${prop.name};
- }
-
-#end
-#if( $prop.alias)
- /*
- * ${prop.xmlEncodedDescription}
- * Setter for alias of $prop.name as $prop.alias
- * @param $prop.name - new value
- */
- public void set${prop.upperFirstChar($prop.alias)}( String __${prop.alias} )
- {
- this.${prop.setterName}(__${prop.alias});
- }
-#end
-#end
+#tagPropertyMethods12($validator)
protected Validator createValidator() throws JspException
{
Deleted: trunk/cdk/generator/src/main/resources/VM_global_library.vm
===================================================================
--- trunk/cdk/generator/src/main/resources/VM_global_library.vm 2007-10-23 15:51:34 UTC
(rev 3490)
+++ trunk/cdk/generator/src/main/resources/VM_global_library.vm 2007-10-23 19:18:11 UTC
(rev 3491)
@@ -1,6 +0,0 @@
-#macro( quietnull $a)
-#if($a)$a#end
-#end
-
-
-
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java 2007-10-23
15:51:34 UTC (rev 3490)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/AbstractCDKMojo.java 2007-10-23
19:18:11 UTC (rev 3491)
@@ -40,6 +40,7 @@
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
+import org.codehaus.plexus.velocity.DefaultVelocityComponent;
import org.codehaus.plexus.velocity.VelocityComponent;
/**
@@ -178,6 +179,9 @@
}
library.setJsfVersion(version);
}
+
+ //velocity = new DefaultVelocityComponent();
+
getLog().debug("Generate files for a JSF "+library.getJsfVersion());
Renderkit[] renderkits = library.getRenderkits();
if (null != renderkits) {
@@ -264,16 +268,16 @@
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
try {
- List compileClasspathElements = project
+ List<?> compileClasspathElements = project
.getCompileClasspathElements();
String outputDirectory = project.getBuild().getOutputDirectory();
URL[] urls = new URL[compileClasspathElements.size() + 1];
int i = 0;
- urls[i++] = new File(outputDirectory).toURL();
- for (Iterator iter = compileClasspathElements.iterator(); iter
+ urls[i++] = new File(outputDirectory).toURI().toURL();
+ for (Iterator<?> iter = compileClasspathElements.iterator(); iter
.hasNext();) {
String element = (String) iter.next();
- urls[i++] = new File(element).toURL();
+ urls[i++] = new File(element).toURI().toURL();
}
if (useCCL) {
Modified:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java 2007-10-23
15:51:34 UTC (rev 3490)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/mojo/GenerateMojo.java 2007-10-23
19:18:11 UTC (rev 3491)
@@ -81,6 +81,11 @@
*/
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().debug("GenerateMojo components");
+
+ //FIXME: configure plexus component instead of programmatic property set.
+
+ // velocity.getEngine().setProperty("velocimacro.library",
getTemplatesPath() + "/VM_global_library.vm");
+
if (null != executedProject) {
Taglib taglib = checkLibraryConfig();
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
Added:
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/velocity/ResourceLoader.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/velocity/ResourceLoader.java
(rev 0)
+++
trunk/cdk/maven-cdk-plugin/src/main/java/org/ajax4jsf/builder/velocity/ResourceLoader.java 2007-10-23
19:18:11 UTC (rev 3491)
@@ -0,0 +1,58 @@
+/**
+ *
+ */
+package org.ajax4jsf.builder.velocity;
+
+import java.io.InputStream;
+
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.resource.Resource;
+
+/**
+ * @author Maksim Kaszynski
+ *
+ */
+public class ResourceLoader extends
+ org.apache.velocity.runtime.resource.loader.ResourceLoader {
+
+ public void init( ExtendedProperties configuration)
+ {
+ rsvc.info("ClasspathResourceLoader : initialization starting.");
+
+ rsvc.info("ClasspathResourceLoader : initialization complete.");
+ }
+
+ public synchronized InputStream getResourceStream( String name )
+ throws ResourceNotFoundException
+ {
+ InputStream result = null;
+
+ if (name == null || name.length() == 0)
+ {
+ throw new ResourceNotFoundException ("No template name provided");
+ }
+
+ try
+ {
+ ClassLoader classLoader = getClass().getClassLoader();
+
+ result= classLoader.getResourceAsStream( name );
+ }
+ catch( Exception fnfe )
+ {
+ throw new ResourceNotFoundException( fnfe.getMessage() );
+ }
+
+ return result;
+ }
+
+ public boolean isSourceModified(Resource resource)
+ {
+ return false;
+ }
+
+ public long getLastModified(Resource resource)
+ {
+ return 0;
+ }}
Added: trunk/cdk/maven-cdk-plugin/src/main/resources/META-INF/plexus/components.xml
===================================================================
--- trunk/cdk/maven-cdk-plugin/src/main/resources/META-INF/plexus/components.xml
(rev 0)
+++
trunk/cdk/maven-cdk-plugin/src/main/resources/META-INF/plexus/components.xml 2007-10-23
19:18:11 UTC (rev 3491)
@@ -0,0 +1,32 @@
+<component-set>
+ <components>
+ <component>
+ <role>org.codehaus.plexus.velocity.VelocityComponent</role>
+
<implementation>org.codehaus.plexus.velocity.DefaultVelocityComponent</implementation>
+ <configuration>
+ <properties>
+ <property>
+ <name>resource.loader</name>
+ <value>classpath,cdk</value>
+ </property>
+ <property>
+ <name>classpath.resource.loader.class</name>
+
<value>org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader</value>
+ </property>
+ <property>
+ <name>cdk.resource.loader.class</name>
+ <value>org.ajax4jsf.builder.velocity.ResourceLoader</value>
+ </property>
+ <property>
+ <name>velocimacro.messages.on</name>
+ <value>false</value>
+ </property>
+ <property>
+ <name>resource.manager.logwhenfound</name>
+ <value>false</value>
+ </property>
+ </properties>
+ </configuration>
+ </component>
+ </components>
+</component-set>
Modified: trunk/cdk/maven-cdk-plugin/src/main/resources/VM_global_library.vm
===================================================================
--- trunk/cdk/maven-cdk-plugin/src/main/resources/VM_global_library.vm 2007-10-23 15:51:34
UTC (rev 3490)
+++ trunk/cdk/maven-cdk-plugin/src/main/resources/VM_global_library.vm 2007-10-23 19:18:11
UTC (rev 3491)
@@ -2,5 +2,54 @@
#if($a)$a#end
#end
+## generate getters and setters for Tag Properties
+#macro(tagPropertyMethods12 $source)
+ // Fields
+ #foreach( $prop in $source.properties )
+ #if( !$prop.existintag && !$prop.hidden)
+ #if($prop.classname == "javax.el.MethodExpression" || $prop.classname ==
"javax.faces.el.MethodBinding")
+ #set($type = "MethodExpression")
+ #else
+ #set($type = "ValueExpression")
+ #end
+
+ /*
+ * $prop.name
+ * ${prop.xmlEncodedDescription}
+ */
+ private $type _${prop.name};
+ /**
+ * $prop.description
+ * Setter for $prop.name
+ * @param $prop.name - new value
+ */
+ public void ${prop.setterName}( $type __${prop.name} ){
+ this._${prop.name} = __${prop.name};
+ }
+
+ #if( $prop.alias)
+ /**
+ * ${prop.xmlEncodedDescription}
+ * Setter for alias of $prop.name as $prop.alias
+ * @param $prop.name - new value
+ */
+ public void set${prop.upperFirstChar($prop.alias)}( $type __${prop.alias} ){
+ this.${prop.setterName}(__${prop.alias});
+ }
+ #end
+ #end
+ #end
+#end
+## release Tag Properties
+#macro(tagPropertyRelease $source)
+ #foreach( $prop in $source.properties )
+ #if( !$prop.existintag && !$prop.hidden)
+ this._${prop.name} = null;
+ #end
+ #end
+#end
+
+
+