Permalink
Browse files

[Issue 4] Fix

  • Loading branch information...
1 parent cd9dec8 commit b873f2a0d819ac251649ae10f7c4f5d94878852f attonnnn committed Sep 28, 2010
@@ -23,6 +23,7 @@
import java.util.Collection;
import java.util.List;
+import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.tapestry5.annotations.Parameter;
@@ -176,7 +177,8 @@ private Attribute buildAttributeFromField(Field field)
log.debug("Processing Attribute : " + field.getName());
Attribute attribute = new Attribute();
- attribute.setName(field.getName());
+ attribute.setFieldName(field.getName());
+ attribute.setName(StringUtils.isNotEmpty(field.getAnnotation(Parameter.class).name())?field.getAnnotation(Parameter.class).name():field.getName());
attribute.setDeferredValue(field.getType().getName());
attribute.setRequired(field.getAnnotation(Parameter.class).required());
@@ -16,8 +16,11 @@
package fr.exanpe.tapestry.tldgen.taglib.mapping;
+import org.apache.tapestry5.annotations.Parameter;
+
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
+import com.thoughtworks.xstream.annotations.XStreamOmitField;
import fr.exanpe.tapestry.tldgen.ext.impl.DeferredValueConverter;
@@ -29,6 +32,17 @@
@XStreamAlias("attribute")
public class Attribute
{
+ /**
+ * Name of the field. Can be different of the name of the paramter.
+ * @see Parameter#name()
+ */
+ @XStreamOmitField
+ private String fieldName;
+
+ /**
+ * Name of the parameter as defined by the user
+ * @see Parameter#name()
+ */
private String name;
private String description;
@@ -58,6 +72,16 @@ public void setName(String name)
{
this.name = name;
}
+
+ public String getFieldName()
+ {
+ return fieldName;
+ }
+
+ public void setFieldName(String fieldName)
+ {
+ this.fieldName = fieldName;
+ }
/**
* @return the description
@@ -95,4 +119,5 @@ public void setDeferredValue(String type)
this.deferredValue = type;
}
+
}
@@ -51,7 +51,7 @@ public static void mergeToTaglib(Taglib taglib, ComponentsInfoBean infos)
for (Attribute a : t.getAttributes())
{
- ParameterBean param = comp.getParameterByName(a.getName());
+ ParameterBean param = comp.getParameterByName(a.getFieldName());
if (param != null)
{
@@ -88,7 +88,7 @@ private static String getParentAttributeDescription(ComponentBean comp, Attribut
if (comp != null)
{
- ParameterBean superParam = comp.getParameterByName(a.getName());
+ ParameterBean superParam = comp.getParameterByName(a.getFieldName());
if (superParam != null)
{
@@ -19,12 +19,15 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Iterator;
import junit.framework.TestCase;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.SystemStreamLog;
+import fr.exanpe.tapestry.tldgen.taglib.mapping.Attribute;
+import fr.exanpe.tapestry.tldgen.taglib.mapping.Tag;
import fr.exanpe.tapestry.tldgen.taglib.mapping.Taglib;
import fr.exanpe.test.heritage.components.SubSubComponent;
@@ -49,4 +52,40 @@ public void testHeritage() throws MalformedURLException, MojoExecutionException
assertEquals(3, t.getTags().get(1).getAttributes().size());
}
+
+ /**
+ * Issue 4 Junit
+ * @throws MalformedURLException
+ * @throws MojoExecutionException
+ */
+ public void testParameterName() throws MalformedURLException, MojoExecutionException
+ {
+ StructureBuilder builder = new StructureBuilder(new SystemStreamLog());
+
+ Taglib t = builder.build("fr.exanpe.test.heritage", new String[]
+ { "base", "components" }, new URL[]
+ { new File("target/test-classes/").toURI().toURL() });
+
+ assertNotNull(t);
+
+ assertEquals(2, t.getTags().size());
+
+ // on fait un test sur subsub
+ Tag subsubT = null;
+ if (t.getTags().get(0).getTagClass().equals(SubSubComponent.class.getName())){
+ subsubT = t.getTags().get(0);
+ }else{
+ subsubT = t.getTags().get(1);
+ }
+
+ boolean found = false;
+
+ Iterator<Attribute> ite = subsubT.getAttributes().iterator();
+ while(ite.hasNext()){
+ Attribute a = ite.next();
+ found |= (a.getName().equals("subnewname") && a.getFieldName().equals("subsubParam"));
+ }
+
+ assertEquals(true, found);
+ }
}
@@ -20,6 +20,6 @@
public class SubSubComponent extends SubComponent
{
- @Parameter
+ @Parameter(name="subnewname")
private String subsubParam;
}

0 comments on commit b873f2a

Please sign in to comment.