You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/04/05 16:24:33 UTC
svn commit: r645106 - in /tapestry/tapestry5/trunk:
quickstart/src/main/resources/archetype-resources/src/main/java/services/
quickstart/src/main/resources/archetype-resources/src/main/resources/
tapestry-annotations/src/main/java/org/apache/tapestry/i...
Author: hlship
Date: Sat Apr 5 07:24:32 2008
New Revision: 645106
URL: http://svn.apache.org/viewvc?rev=645106&view=rev
Log:
TAPESTRY-2258: Error while autobuilding BeanEditForm's bean
Added:
tapestry/tapestry5/trunk/tapestry-annotations/src/main/java/org/apache/tapestry/ioc/
tapestry/tapestry5/trunk/tapestry-annotations/src/main/java/org/apache/tapestry/ioc/annotations/
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InjectoBean.java
Modified:
tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/java/services/AppModule.java
tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/resources/log4j.properties
tapestry/tapestry5/trunk/tapestry-core/pom.xml
tapestry/tapestry5/trunk/tapestry-ioc/pom.xml
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/InternalUtils.java
tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/service.apt
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InternalUtilsTest.java
Modified: tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/java/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/java/services/AppModule.java?rev=645106&r1=645105&r2=645106&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/java/services/AppModule.java (original)
+++ tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/java/services/AppModule.java Sat Apr 5 07:24:32 2008
@@ -1,17 +1,3 @@
-// Copyright 2007, 2008 The Apache Software Foundation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
package ${packageName}.services;
import java.io.IOException;
Modified: tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/resources/log4j.properties?rev=645106&r1=645105&r2=645106&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/resources/log4j.properties (original)
+++ tapestry/tapestry5/trunk/quickstart/src/main/resources/archetype-resources/src/main/resources/log4j.properties Sat Apr 5 07:24:32 2008
@@ -23,6 +23,6 @@
# Turning on debug mode for a page or component will show all of the code changes that occur when the
# class is loaded. Turning on debug mode for a page will enable detailed output about
# the contruction of the page, including the runtime code modifications that occur. Verbose
-# mode is rarely used, as it output voluminous details about the rendering of the page.
+# mode is rarely used, as it outputs voluminous details about the rendering of the page.
# log4j.category.${packageName}.pages.Index=debug
Modified: tapestry/tapestry5/trunk/tapestry-core/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/pom.xml?rev=645106&r1=645105&r2=645106&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/pom.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/pom.xml Sat Apr 5 07:24:32 2008
@@ -1,4 +1,5 @@
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-core</artifactId>
@@ -19,11 +20,6 @@
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-ioc</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.tapestry</groupId>
- <artifactId>tapestry-annotations</artifactId>
- <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
Modified: tapestry/tapestry5/trunk/tapestry-ioc/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/pom.xml?rev=645106&r1=645105&r2=645106&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/pom.xml (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/pom.xml Sat Apr 5 07:24:32 2008
@@ -1,4 +1,5 @@
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-ioc</artifactId>
@@ -17,6 +18,12 @@
<inceptionYear>2006</inceptionYear>
<dependencies>
+ <dependency>
+ <groupId>org.apache.tapestry</groupId>
+ <artifactId>tapestry-annotations</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<dependency>
<groupId>jboss</groupId>
<artifactId>javassist</artifactId>
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/InternalUtils.java?rev=645106&r1=645105&r2=645106&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/InternalUtils.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/internal/util/InternalUtils.java Sat Apr 5 07:24:32 2008
@@ -449,7 +449,9 @@
/**
* Searches a class for the "best" constructor, the public constructor with the most parameters. Returns null if
* there are no public constructors. If there is more than one constructor with the maximum number of parameters, it
- * is not determined which will be returned (don't build a class like that!).
+ * is not determined which will be returned (don't build a class like that!). In addition, if a constructor is
+ * annotated with {@link org.apache.tapestry.ioc.annotations.Inject}, it will be used (no check for multiple such
+ * constructors is made, only at most a single constructor should have the annotation).
*
* @param clazz to search for a constructor for
* @return the constructor to be used to instantiate the class, or null if no appropriate constructor was found
@@ -470,6 +472,11 @@
default:
break;
+ }
+
+ for (Constructor c : constructors)
+ {
+ if (c.getAnnotation(Inject.class) != null) return c;
}
// Choose a constructor with the most parameters.
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/service.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/service.apt?rev=645106&r1=645105&r2=645106&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/service.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/site/apt/service.apt Sat Apr 5 07:24:32 2008
@@ -313,7 +313,9 @@
}
+---+
- If the class has multiple constructors, the constructor with the most parameters will be invoked.
+ If the class has multiple constructors, the constructor with the <most> parameters will be invoked.
+ Alternately, you may mark a single constructor with the Inject annotation, and Tapestry will use
+ <that> constructor specifically, ignoring all other constructors.
Note how we are using final fields for our dependencies; this is generally a Good Idea.
These services will often execute inside a multi-threaded environment, such as a web application,
Added: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InjectoBean.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InjectoBean.java?rev=645106&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InjectoBean.java (added)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InjectoBean.java Sat Apr 5 07:24:32 2008
@@ -0,0 +1,54 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.ioc.internal.util;
+
+import org.apache.tapestry.ioc.annotations.Inject;
+
+public class InjectoBean
+{
+ private final String _foo;
+ private final Runnable _bar;
+
+ public InjectoBean()
+ {
+ this(null);
+ }
+
+ @Inject
+ public InjectoBean(String foo)
+ {
+ this(foo, null);
+ }
+
+ /**
+ * Normally, this would be chosen as it has the most parameters.
+ */
+ public InjectoBean(String foo, Runnable bar)
+ {
+
+ _foo = foo;
+ _bar = bar;
+ }
+
+ public String getFoo()
+ {
+ return _foo;
+ }
+
+ public Runnable getBar()
+ {
+ return _bar;
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InternalUtilsTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InternalUtilsTest.java?rev=645106&r1=645105&r2=645106&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InternalUtilsTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry/ioc/internal/util/InternalUtilsTest.java Sat Apr 5 07:24:32 2008
@@ -25,6 +25,7 @@
import java.io.Closeable;
import java.io.IOException;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.*;
@@ -372,6 +373,15 @@
InternalUtils.close(c);
verify();
+ }
+
+ @Test
+ public void constructor_with_inject_annotation()
+ {
+ Constructor c = InternalUtils.findAutobuildConstructor(InjectoBean.class);
+
+ assertEquals(c.getParameterTypes().length, 1);
+ assertEquals(c.getParameterTypes()[0], String.class);
}
}