Weld SVN: r6010 - in extensions/trunk/core/src/main/java/org/jboss/weld/extensions: util/annotated and 1 other directory.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-03-05 15:37:57 -0500 (Fri, 05 Mar 2010)
New Revision: 6010
Modified:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java
Log:
Fixed a bug with NewAnnotatedType where you could not annotate non-public members
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java 2010-03-05 14:32:12 UTC (rev 6009)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java 2010-03-05 20:37:57 UTC (rev 6010)
@@ -2,6 +2,13 @@
import javax.enterprise.context.spi.CreationalContext;
+/**
+ * Hanlder for the create/destroy methods of CustomBean
+ *
+ * @author stuart
+ *
+ * @param <T>
+ */
public interface BeanLifecycle<T>
{
public T create(CustomBean<T> bean, CreationalContext<T> arg0);
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java 2010-03-05 14:32:12 UTC (rev 6009)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java 2010-03-05 20:37:57 UTC (rev 6010)
@@ -11,6 +11,13 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
+/**
+ * An immutable bean.
+ *
+ * @author stuart
+ *
+ * @param <T>
+ */
public class CustomBean<T> implements Bean<T>
{
final Class<?> beanClass;
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java 2010-03-05 14:32:12 UTC (rev 6009)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedType.java 2010-03-05 20:37:57 UTC (rev 6010)
@@ -7,6 +7,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedField;
@@ -29,28 +30,64 @@
private final Class<X> javaClass;
+ /**
+ * We make sure that there is a NewAnnotatedMember for every public
+ * method/field/constructor
+ *
+ * If annotation have been added to other methods as well we add them to
+ *
+ */
NewAnnotatedType(Class<X> clazz, AnnotationStore typeAnnotations, Map<Field, AnnotationStore> fieldAnnotations, Map<Method, AnnotationStore> methodAnnotations, Map<Method, Map<Integer, AnnotationStore>> methodParameterAnnotations, Map<Constructor<X>, AnnotationStore> constructorAnnotations, Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnotations)
{
super(clazz, typeAnnotations);
this.javaClass = clazz;
this.constructors = new HashSet<AnnotatedConstructor<X>>();
+ Set<Constructor<?>> cset = new HashSet<Constructor<?>>();
+ Set<Method> mset = new HashSet<Method>();
+ Set<Field> fset = new HashSet<Field>();
for (Constructor<?> c : clazz.getConstructors())
{
NewAnnotatedConstructor<X> nc = new NewAnnotatedConstructor<X>(this, c, constructorAnnotations.get(c), constructorParameterAnnotations.get(c));
constructors.add(nc);
+ cset.add(c);
}
+ for (Entry<Constructor<X>, AnnotationStore> c : constructorAnnotations.entrySet())
+ {
+ if (!cset.contains(c.getKey()))
+ {
+ NewAnnotatedConstructor<X> nc = new NewAnnotatedConstructor<X>(this, c.getKey(), c.getValue(), constructorParameterAnnotations.get(c.getKey()));
+ constructors.add(nc);
+ }
+ }
this.methods = new HashSet<AnnotatedMethod<? super X>>();
for (Method m : clazz.getMethods())
{
NewAnnotatedMethod<X> met = new NewAnnotatedMethod<X>(this, m, methodAnnotations.get(m), methodParameterAnnotations.get(m));
methods.add(met);
+ mset.add(m);
}
+ for (Entry<Method, AnnotationStore> c : methodAnnotations.entrySet())
+ {
+ if (!mset.contains(c.getKey()))
+ {
+ NewAnnotatedMethod<X> nc = new NewAnnotatedMethod<X>(this, c.getKey(), c.getValue(), methodParameterAnnotations.get(c.getKey()));
+ methods.add(nc);
+ }
+ }
this.fields = new HashSet<AnnotatedField<? super X>>();
for (Field f : clazz.getFields())
{
NewAnnotatedField<X> b = new NewAnnotatedField<X>(this, f, fieldAnnotations.get(f));
fields.add(b);
+ fset.add(f);
}
+ for (Entry<Field, AnnotationStore> e : fieldAnnotations.entrySet())
+ {
+ if (fset.contains(e.getKey()))
+ {
+ fields.add(new NewAnnotatedField<X>(this, e.getKey(), e.getValue()));
+ }
+ }
}
public Set<AnnotatedConstructor<X>> getConstructors()
14 years, 10 months
Weld SVN: r6009 - in archetypes/trunk: jsf/jee-minimal and 1 other directory.
by weld-commits@lists.jboss.org
Author: mgencur(a)redhat.com
Date: 2010-03-05 09:32:12 -0500 (Fri, 05 Mar 2010)
New Revision: 6009
Modified:
archetypes/trunk/jsf/jee-minimal/pom.xml
archetypes/trunk/pom.xml
Log:
WELDX-70 another small change
Modified: archetypes/trunk/jsf/jee-minimal/pom.xml
===================================================================
--- archetypes/trunk/jsf/jee-minimal/pom.xml 2010-03-05 14:26:54 UTC (rev 6008)
+++ archetypes/trunk/jsf/jee-minimal/pom.xml 2010-03-05 14:32:12 UTC (rev 6009)
@@ -156,7 +156,6 @@
<execution>
<id>deploy-project</id>
<phase>compile</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
Modified: archetypes/trunk/pom.xml
===================================================================
--- archetypes/trunk/pom.xml 2010-03-05 14:26:54 UTC (rev 6008)
+++ archetypes/trunk/pom.xml 2010-03-05 14:32:12 UTC (rev 6009)
@@ -371,7 +371,6 @@
<property name="tmpdir" value="${maven.private.repo}"/>
<delete dir="${tmpdir}" failonerror="false"/>
<mkdir dir="${tmpdir}"/>
-
<copy todir="${tmpdir}" overwrite="true">
<fileset dir="${user.home}/.m2/repository/org/jboss/weld/archetypes">
<include name="**/*"/>
@@ -616,8 +615,8 @@
<configuration>
<tasks>
<property name="tmpdir" value="${maven.private.repo}"/>
- <!-- <delete dir="${tmpdir}" failonerror="false"/>-->
- <!-- <mkdir dir="${tmpdir}"/>-->
+ <delete dir="${tmpdir}" failonerror="false"/>
+ <mkdir dir="${tmpdir}"/>
<copy todir="${tmpdir}" overwrite="true">
<fileset dir="${user.home}/.m2/repository/org/jboss/weld/archetypes">
<include name="**/*"/>
14 years, 10 months
Weld SVN: r6008 - in archetypes/trunk: jsf/jee-minimal and 1 other directories.
by weld-commits@lists.jboss.org
Author: mgencur(a)redhat.com
Date: 2010-03-05 09:26:54 -0500 (Fri, 05 Mar 2010)
New Revision: 6008
Modified:
archetypes/trunk/jsf/jee-minimal/pom.xml
archetypes/trunk/jsf/servlet-minimal/pom.xml
archetypes/trunk/pom.xml
Log:
WELDX-70 added testing of weld-jsf-jee-minimal with glassfish standalone
Modified: archetypes/trunk/jsf/jee-minimal/pom.xml
===================================================================
--- archetypes/trunk/jsf/jee-minimal/pom.xml 2010-03-05 14:04:35 UTC (rev 6007)
+++ archetypes/trunk/jsf/jee-minimal/pom.xml 2010-03-05 14:26:54 UTC (rev 6008)
@@ -90,7 +90,6 @@
<goal>run</goal>
</goals>
</execution>
-
<!-- tomcat:run has to be executed in background otherwise it would block further maven execution -->
<execution>
<id>wait-for-project</id>
@@ -114,13 +113,11 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
-
<executions>
<!-- generate project using weld archetypes -->
<execution>
<id>generate-project-artifacts</id>
<phase>generate-resources</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}</workingDirectory>
@@ -135,17 +132,14 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
</execution>
-
<!-- just compile generated project -->
<execution>
<id>package-project</id>
<phase>compile</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
@@ -154,12 +148,10 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
</execution>
-
<!-- deploy -->
<execution>
<id>deploy-project</id>
@@ -173,17 +165,13 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
</execution>
-
- <!-- run unit tests -->
<execution>
<id>run-unit-tests</id>
<phase>integration-test</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
@@ -192,17 +180,13 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
</execution>
-
- <!-- undeploy -->
<execution>
<id>undeploy-project</id>
<phase>post-integration-test</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
@@ -211,7 +195,6 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
@@ -222,5 +205,151 @@
</plugins>
</build>
</profile>
+
+ <profile>
+ <id>ftest-glassfish</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+
+ <properties>
+ <ftest.artifact>ftest-archetypes</ftest.artifact>
+ <ftest.version>0.1${ftest.version.discriminator}</ftest.version>
+ <selenium.browser.url>http://localhost:8080</selenium.browser.url>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>${ftest.artifact}</artifactId>
+ <version>${ftest.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>selenium-maven-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>failsafe-maven-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.glassfish.maven.plugin</groupId>
+ <artifactId>maven-glassfish-plugin</artifactId>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <!-- remove a project generated earlier -->
+ <execution>
+ <id>remove-old-project</id>
+ <phase>process-sources</phase>
+ <configuration>
+ <tasks>
+ <echo message="Removing old project" />
+ <delete dir="${java.io.tmpdir}/${project.artifactId}" failonerror="false"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ <!-- tomcat:run has to be executed in background otherwise it would block further maven execution -->
+ <execution>
+ <id>deploy-project</id>
+ <phase>pre-integration-test</phase>
+ <configuration>
+ <tasks>
+ <property name="url.to.wait" value="http://localhost:8080/${project.artifactId}" />
+ <echo message="Waiting for application at ${url.to.wait} using Glassfish container" />
+ <waitfor maxwait="${application.deploy.timeout}" maxwaitunit="second">
+ <http url="${url.to.wait}" errorsBeginAt="404" />
+ </waitfor>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <executions>
+ <!-- generate project using weld archetypes -->
+ <execution>
+ <id>generate-project-artifacts</id>
+ <phase>generate-resources</phase>
+ <configuration>
+ <executable>mvn</executable>
+ <workingDirectory>${java.io.tmpdir}</workingDirectory>
+ <arguments>
+ <argument>archetype:generate</argument>
+ <argument>-DinteractiveMode=n</argument>
+ <argument>-DarchetypeArtifactId=${project.artifactId}</argument>
+ <argument>-DarchetypeGroupId=org.jboss.weld.archetypes</argument>
+ <argument>-DarchetypeVersion=${archetype.test.version}</argument>
+ <argument>-DgroupId=com.mycompany</argument>
+ <argument>-DartifactId=${project.artifactId}</argument>
+ <argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
+ </arguments>
+ </configuration>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ <!-- just compile generated project -->
+ <execution>
+ <id>compile-project</id>
+ <phase>compile</phase>
+ <configuration>
+ <executable>mvn</executable>
+ <workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
+ <arguments>
+ <argument>package</argument>
+ <argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
+ </arguments>
+ </configuration>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ <!-- run unit tests -->
+ <execution>
+ <id>run-unit-tests</id>
+ <phase>integration-test</phase>
+ <configuration>
+ <executable>mvn</executable>
+ <workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
+ <arguments>
+ <argument>test</argument>
+ <argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
+ </arguments>
+ </configuration>
+ <goals>
+ <goal>exec</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+ </profile>
</profiles>
</project>
Modified: archetypes/trunk/jsf/servlet-minimal/pom.xml
===================================================================
--- archetypes/trunk/jsf/servlet-minimal/pom.xml 2010-03-05 14:04:35 UTC (rev 6007)
+++ archetypes/trunk/jsf/servlet-minimal/pom.xml 2010-03-05 14:26:54 UTC (rev 6008)
@@ -90,7 +90,6 @@
<goal>run</goal>
</goals>
</execution>
-
<!-- tomcat:run has to be executed in background otherwise it would block further maven execution -->
<execution>
<id>deploy-project</id>
@@ -113,7 +112,6 @@
<goal>run</goal>
</goals>
</execution>
-
<!-- killing container running in background -->
<execution>
<id>stop-container</id>
@@ -131,7 +129,6 @@
</goals>
</execution>
</executions>
-
</plugin>
<plugin>
@@ -142,7 +139,6 @@
<execution>
<id>generate-project-artifacts</id>
<phase>generate-resources</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}</workingDirectory>
@@ -157,17 +153,14 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
</execution>
-
<!-- just compile generated project -->
<execution>
<id>compile-project</id>
<phase>compile</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
@@ -176,17 +169,14 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
</execution>
-
<!-- run unit tests -->
<execution>
<id>run-unit-tests</id>
<phase>integration-test</phase>
-
<configuration>
<executable>mvn</executable>
<workingDirectory>${java.io.tmpdir}/${project.artifactId}</workingDirectory>
@@ -195,13 +185,13 @@
<argument>-Dmaven.repo.local=${maven.private.repo}/</argument>
</arguments>
</configuration>
-
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
+
</plugins>
</build>
</profile>
Modified: archetypes/trunk/pom.xml
===================================================================
--- archetypes/trunk/pom.xml 2010-03-05 14:04:35 UTC (rev 6007)
+++ archetypes/trunk/pom.xml 2010-03-05 14:26:54 UTC (rev 6008)
@@ -85,7 +85,6 @@
<selenium.debug>false</selenium.debug>
<application.deploy.timeout>600</application.deploy.timeout>
<archetype.test.version>1.0.0-BETA1</archetype.test.version>
-
</properties>
<!-- SCM and distribution management -->
@@ -120,6 +119,7 @@
<build>
<pluginManagement>
<plugins>
+
<!-- get functional tests from ftest artifact -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -170,36 +170,30 @@
</executions>
</plugin>
- <!-- stop Selenium -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven.antrun.plugin.version}</version>
<executions>
- <!-- deploy application to farm directory and waiting for the application to be ready -->
<execution>
<id>prepare-private-local-repo</id>
<phase>process-sources</phase>
<configuration>
<tasks>
-
- <property name="tmpdir" value="${maven.private.repo}"/>
- <delete dir="${tmpdir}" failonerror="false"/>
- <mkdir dir="${tmpdir}"/>
-
- <copy todir="${tmpdir}" overwrite="true">
- <fileset dir="${user.home}/.m2/repository/org/jboss/weld/archetypes">
- <include name="**/*"/>
- </fileset>
- </copy>
-
+ <property name="tmpdir" value="${maven.private.repo}"/>
+ <delete dir="${tmpdir}" failonerror="false"/>
+ <mkdir dir="${tmpdir}"/>
+ <copy todir="${tmpdir}" overwrite="true">
+ <fileset dir="${user.home}/.m2/repository/org/jboss/weld/archetypes">
+ <include name="**/*"/>
+ </fileset>
+ </copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
-
<!-- this ant script runs testng natively -->
<execution>
<id>stop-selenium</id>
@@ -215,7 +209,6 @@
<goal>run</goal>
</goals>
</execution>
-
</executions>
</plugin>
@@ -365,6 +358,251 @@
</executions>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>${maven.antrun.plugin.version}</version>
+ <executions>
+ <execution>
+ <id>prepare-private-local-repo</id>
+ <phase>process-sources</phase>
+ <configuration>
+ <tasks>
+ <property name="tmpdir" value="${maven.private.repo}"/>
+ <delete dir="${tmpdir}" failonerror="false"/>
+ <mkdir dir="${tmpdir}"/>
+
+ <copy todir="${tmpdir}" overwrite="true">
+ <fileset dir="${user.home}/.m2/repository/org/jboss/weld/archetypes">
+ <include name="**/*"/>
+ </fileset>
+ </copy>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ <!-- this ant script runs testng natively -->
+ <execution>
+ <id>stop-selenium</id>
+ <phase>post-integration-test</phase>
+ <configuration>
+ <tasks>
+ <echo message="Undeploying application..." />
+ <get taskname="selenium-shutdown" src="http://${selenium.server.host}:${selenium.server.port}/selenium-server/driver/?cmd=shutDownSeleniumServer" ignoreerrors="true" dest="${project.build.directory}/selenium.stop.msg" />
+ <echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>${exec.maven.plugin.version}</version>
+ </plugin>
+
+ <!-- run functional tests -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>failsafe-maven-plugin</artifactId>
+ <version>${failsafe.maven.plugin.version}</version>
+ <configuration>
+ <testClassesDirectory>${project.build.directory}/ftest</testClassesDirectory>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/selenium/${ftest.testsuite}</suiteXmlFile>
+ </suiteXmlFiles>
+ <argLine>-Xmx748m</argLine>
+ <forkMode>once</forkMode>
+ <systemProperties>
+ <property>
+ <name>selenium.server.port</name>
+ <value>${selenium.server.port}</value>
+ </property>
+ <property>
+ <name>selenium.server.host</name>
+ <value>${selenium.server.host}</value>
+ </property>
+ <property>
+ <name>selenium.browser</name>
+ <value>${selenium.browser}</value>
+ </property>
+ <property>
+ <name>selenium.browser.url</name>
+ <value>${selenium.browser.url}</value>
+ </property>
+ <property>
+ <name>selenium.speed</name>
+ <value>${selenium.speed}</value>
+ </property>
+ <property>
+ <name>selenium.timeout</name>
+ <value>${selenium.timeout}</value>
+ </property>
+ <property>
+ <name>basedir</name>
+ <value>${basedir}</value>
+ </property>
+ </systemProperties>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <phase>integration-test</phase>
+ <goals>
+ <goal>integration-test</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>verify</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
+
+ <profile>
+ <id>ftest-glassfish</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>maven.java.net</id>
+ <name>Java.net Maven2 Repository</name>
+ <url>http://download.java.net/maven/2</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+ <properties>
+ <maven.private.repo>${java.io.tmpdir}/maven_private_repo</maven.private.repo>
+ <ftest.testsuite>testsuite.xml</ftest.testsuite>
+ <glassfish.admin.user>admin</glassfish.admin.user>
+ <glassfish.admin.password>changeit</glassfish.admin.password>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.seleniumhq.selenium.client-drivers</groupId>
+ <artifactId>selenium-java-client-driver</artifactId>
+ <version>${selenium.java.client.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+
+ <!-- get functional tests from ftest artifact -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-ftest</id>
+ <phase>process-sources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/ftest</outputDirectory>
+ <stripVersion>true</stripVersion>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.jboss.weld.examples.ftest</groupId>
+ <artifactId>${ftest.artifact}</artifactId>
+ <overWrite>true</overWrite>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.glassfish.maven.plugin</groupId>
+ <artifactId>maven-glassfish-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <glassfishDirectory>${env.GLASSFISH_HOME}</glassfishDirectory>
+ <user>${glassfish.admin.user}</user>
+ <adminPassword>${glassfish.admin.password}</adminPassword>
+ <echo>true</echo>
+ <domain>
+ <name>domain1</name>
+ <adminPort>4848</adminPort>
+ <httpPort>8080</httpPort>
+ </domain>
+ <components>
+ <component>
+ <name>${project.artifactId}</name>
+ <artifact>${java.io.tmpdir}/${project.artifactId}/target/${project.artifactId}.war</artifact>
+ </component>
+ </components>
+ </configuration>
+ <executions>
+ <execution>
+ <id>deploy-project</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>deploy</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>undeploy-project</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>undeploy</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-domain</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop-domain</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- start Selenium server -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>selenium-maven-plugin</artifactId>
+ <version>${selenium.maven.plugin.version}</version>
+ <executions>
+ <execution>
+ <id>start-selenium</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start-server</goal>
+ </goals>
+ <configuration>
+ <background>true</background>
+ <port>${selenium.server.port}</port>
+ <logOutput>true</logOutput>
+ <logFile>${project.build.directory}/selenium/selenium-server.log</logFile>
+ <browserSideLog>${selenium.debug}</browserSideLog>
+ <debug>${selenium.debug}</debug>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
<!-- stop Selenium -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -377,24 +615,20 @@
<phase>process-sources</phase>
<configuration>
<tasks>
-
- <property name="tmpdir" value="${maven.private.repo}"/>
- <delete dir="${tmpdir}" failonerror="false"/>
- <mkdir dir="${tmpdir}"/>
-
- <copy todir="${tmpdir}" overwrite="true">
- <fileset dir="${user.home}/.m2/repository/org/jboss/weld/archetypes">
- <include name="**/*"/>
- </fileset>
- </copy>
-
+ <property name="tmpdir" value="${maven.private.repo}"/>
+ <!-- <delete dir="${tmpdir}" failonerror="false"/>-->
+ <!-- <mkdir dir="${tmpdir}"/>-->
+ <copy todir="${tmpdir}" overwrite="true">
+ <fileset dir="${user.home}/.m2/repository/org/jboss/weld/archetypes">
+ <include name="**/*"/>
+ </fileset>
+ </copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
-
<!-- this ant script runs testng natively -->
<execution>
<id>stop-selenium</id>
@@ -479,7 +713,7 @@
</execution>
</executions>
</plugin>
-
+
</plugins>
</pluginManagement>
</build>
14 years, 10 months
Weld SVN: r6007 - core/trunk/impl/src/main/java/org/jboss/weld/servlet.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-03-05 09:04:35 -0500 (Fri, 05 Mar 2010)
New Revision: 6007
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
Log:
context cleanup
Modified: core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-03-05 12:18:51 UTC (rev 6006)
+++ core/trunk/impl/src/main/java/org/jboss/weld/servlet/ServletLifecycle.java 2010-03-05 14:04:35 UTC (rev 6007)
@@ -22,12 +22,10 @@
*/
package org.jboss.weld.servlet;
-import static org.jboss.weld.jsf.JsfHelper.getServletContext;
import static org.jboss.weld.logging.messages.ServletMessage.REQUEST_SCOPE_BEAN_STORE_MISSING;
import static org.jboss.weld.servlet.BeanProvider.conversationManager;
import static org.jboss.weld.servlet.BeanProvider.httpSessionManager;
-import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
@@ -52,8 +50,11 @@
public static final String REQUEST_ATTRIBUTE_NAME = ServletLifecycle.class.getName() + ".requestBeanStore";
+
/**
+ * Constructor
*
+ * @param lifecycle The lifecycle to work against
*/
public ServletLifecycle(ContextLifecycle lifecycle)
{
@@ -149,7 +150,7 @@
}
/**
- * Begins a HTTP request Sets the session into the session context
+ * Begins a HTTP request. Sets the session into the session context
*
* @param request The request
*/
@@ -171,24 +172,38 @@
*/
public void endRequest(HttpServletRequest request)
{
- if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) != null)
+ if (request.getAttribute(REQUEST_ATTRIBUTE_NAME) == null)
{
- HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore) lifecycle.getSessionContext().getBeanStore();
- if ((sessionBeanStore != null) && (sessionBeanStore.isInvalidated()))
- {
- conversationManager(request.getSession().getServletContext()).teardownContext();
- lifecycle.endSession(request.getRequestedSessionId(), sessionBeanStore);
- }
- lifecycle.getSessionContext().setActive(false);
- lifecycle.getSessionContext().setBeanStore(null);
- BeanStore beanStore = (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
- if (beanStore == null)
- {
- throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
- }
- lifecycle.endRequest(request.getRequestURI(), beanStore);
- request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
+ return;
}
+ teardownSession(request);
+ teardownRequest(request);
+ lifecycle.getConversationContext().setBeanStore(null);
+ lifecycle.getConversationContext().setActive(false);
}
+
+ private void teardownSession(HttpServletRequest request)
+ {
+ HttpPassThruSessionBeanStore sessionBeanStore = (HttpPassThruSessionBeanStore) lifecycle.getSessionContext().getBeanStore();
+ if ((sessionBeanStore != null) && (sessionBeanStore.isInvalidated()))
+ {
+ conversationManager(request.getSession().getServletContext()).teardownContext();
+ lifecycle.endSession(request.getRequestedSessionId(), sessionBeanStore);
+ }
+ lifecycle.getSessionContext().setActive(false);
+ lifecycle.getSessionContext().setBeanStore(null);
+
+ }
+
+ private void teardownRequest(HttpServletRequest request)
+ {
+ BeanStore beanStore = (BeanStore) request.getAttribute(REQUEST_ATTRIBUTE_NAME);
+ if (beanStore == null)
+ {
+ throw new ForbiddenStateException(REQUEST_SCOPE_BEAN_STORE_MISSING);
+ }
+ lifecycle.endRequest(request.getRequestURI(), beanStore);
+ request.removeAttribute(REQUEST_ATTRIBUTE_NAME);
+ }
}
14 years, 10 months
Weld SVN: r6006 - in extensions/trunk: core/src/main/java/org/jboss/weld/extensions/beans and 2 other directories.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-03-05 07:18:51 -0500 (Fri, 05 Mar 2010)
New Revision: 6006
Added:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBeanBuilder.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/PassivationCapableCustomBean.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/SimpleBeanLifecycle.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java
Modified:
extensions/trunk/genericbeans/src/main/java/org/jboss/weld/extensions/genericbeans/GenericExtension.java
Log:
Added Custom bean implementation
Added: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/BeanLifecycle.java 2010-03-05 12:18:51 UTC (rev 6006)
@@ -0,0 +1,11 @@
+package org.jboss.weld.extensions.beans;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+public interface BeanLifecycle<T>
+{
+ public T create(CustomBean<T> bean, CreationalContext<T> arg0);
+
+ public void destroy(CustomBean<T> bean, T arg0, CreationalContext<T> arg1);
+
+}
Added: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBean.java 2010-03-05 12:18:51 UTC (rev 6006)
@@ -0,0 +1,101 @@
+package org.jboss.weld.extensions.beans;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+public class CustomBean<T> implements Bean<T>
+{
+ final Class<?> beanClass;
+ final InjectionTarget<T> injectionTarget;
+ final String name;
+ final Set<Annotation> qualifiers;
+ final Class<? extends Annotation> scope;
+ final Set<Class<? extends Annotation>> stereotypes;
+ final Set<Type> types;
+ final boolean alternative;
+ final boolean nullable;
+ final BeanLifecycle<T> beanLifecycle;
+
+ CustomBean(Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+ {
+ this.beanClass = beanClass;
+ this.injectionTarget = injectionTarget;
+ this.name = name;
+ this.qualifiers = new HashSet<Annotation>(qualifiers);
+ this.scope = scope;
+ this.stereotypes = new HashSet<Class<? extends Annotation>>(stereotypes);
+ this.types = new HashSet<Type>(types);
+ this.alternative = alternative;
+ this.nullable = nullable;
+ this.beanLifecycle = beanLifecycle;
+ }
+
+ public Class<?> getBeanClass()
+ {
+ return beanClass;
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return injectionTarget.getInjectionPoints();
+ }
+
+ public InjectionTarget<T> getInjectionTarget()
+ {
+ return injectionTarget;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return Collections.unmodifiableSet(qualifiers);
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return scope;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return Collections.unmodifiableSet(stereotypes);
+ }
+
+ public Set<Type> getTypes()
+ {
+ return Collections.unmodifiableSet(types);
+ }
+
+ public boolean isAlternative()
+ {
+ return alternative;
+ }
+
+ public boolean isNullable()
+ {
+ return nullable;
+ }
+
+ public T create(CreationalContext<T> arg0)
+ {
+ return beanLifecycle.create(this, arg0);
+ }
+
+ public void destroy(T arg0, CreationalContext<T> arg1)
+ {
+ beanLifecycle.destroy(this, arg0, arg1);
+ }
+
+}
Added: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBeanBuilder.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBeanBuilder.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/CustomBeanBuilder.java 2010-03-05 12:18:51 UTC (rev 6006)
@@ -0,0 +1,226 @@
+package org.jboss.weld.extensions.beans;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.inject.Named;
+
+import org.jboss.weld.extensions.util.AnnotatedTypeUtils;
+
+/**
+ * class that can build a bean from an AnnotatedType.
+ *
+ * @author stuart
+ *
+ */
+public class CustomBeanBuilder<T>
+{
+
+ final AnnotatedType<T> type;
+ final BeanManager beanManager;
+ InjectionTarget<T> injectionTarget;
+ String name;
+ Set<Annotation> qualifiers;
+ Class<? extends Annotation> scope;
+ Set<Class<? extends Annotation>> stereotypes;
+ Set<Type> types = new HashSet<Type>();
+ boolean alternative = false;
+ boolean nullable = false;
+ BeanLifecycle<T> beanLifecycle;
+ boolean passivationCapable;
+ String id;
+
+ public CustomBeanBuilder(AnnotatedType<T> type, BeanManager beanManager)
+ {
+ this(type, beanManager, beanManager.createInjectionTarget(type));
+ }
+
+ public CustomBeanBuilder(AnnotatedType<T> type, BeanManager beanManager, InjectionTarget<T> injectionTarget)
+ {
+ this.type = type;
+ this.beanManager = beanManager;
+ this.injectionTarget = injectionTarget;
+ qualifiers = new HashSet<Annotation>();
+ stereotypes = new HashSet<Class<? extends Annotation>>();
+ for (Annotation a : type.getAnnotations())
+ {
+ if (beanManager.isQualifier(a.annotationType()))
+ {
+ qualifiers.add(a);
+ }
+ else if (beanManager.isScope(a.annotationType()))
+ {
+ scope = a.annotationType();
+ }
+ else if (beanManager.isStereotype(a.annotationType()))
+ {
+ stereotypes.add(a.annotationType());
+ }
+ if (a instanceof Named)
+ {
+ Named n = (Named) a;
+ name = n.value();
+ }
+ if (a instanceof Alternative)
+ {
+ alternative = true;
+ }
+ }
+ if (scope == null)
+ {
+ scope = Dependent.class;
+ }
+
+ Class<?> c = type.getJavaClass();
+ do
+ {
+ types.add(c);
+ c = c.getSuperclass();
+ }
+ while (c != null);
+ for (Class<?> i : type.getJavaClass().getInterfaces())
+ {
+ types.add(i);
+ }
+ beanLifecycle = new SimpleBeanLifecycle<T>(type.getJavaClass(), beanManager);
+ id = CustomBean.class.getName() + ":" + AnnotatedTypeUtils.createTypeId(type);
+ }
+
+ public Bean<T> build()
+ {
+ if (!passivationCapable)
+ {
+ return new CustomBean<T>(type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+ }
+ return new PassivationCapableCustomBean<T>(id, type.getJavaClass(), injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+
+ }
+
+ public InjectionTarget<T> getInjectionTarget()
+ {
+ return injectionTarget;
+ }
+
+ public void setInjectionTarget(InjectionTarget<T> injectionTarget)
+ {
+ this.injectionTarget = injectionTarget;
+ }
+ public Set<Annotation> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public void setQualifiers(Set<Annotation> qualifiers)
+ {
+ this.qualifiers = qualifiers;
+ }
+
+ public Class<? extends Annotation> getScope()
+ {
+ return scope;
+ }
+
+ public void setScope(Class<? extends Annotation> scope)
+ {
+ this.scope = scope;
+ }
+
+ public Set<Class<? extends Annotation>> getStereotypes()
+ {
+ return stereotypes;
+ }
+
+ public void setStereotypes(Set<Class<? extends Annotation>> stereotypes)
+ {
+ this.stereotypes = stereotypes;
+ }
+
+ public Set<Type> getTypes()
+ {
+ return types;
+ }
+
+ public void setTypes(Set<Type> types)
+ {
+ this.types = types;
+ }
+
+ public boolean isAlternative()
+ {
+ return alternative;
+ }
+
+ public void setAlternative(boolean alternative)
+ {
+ this.alternative = alternative;
+ }
+
+ public boolean isNullable()
+ {
+ return nullable;
+ }
+
+ public void setNullable(boolean nullable)
+ {
+ this.nullable = nullable;
+ }
+
+ public BeanLifecycle<T> getBeanLifecycle()
+ {
+ return beanLifecycle;
+ }
+
+ public void setBeanLifecycle(BeanLifecycle<T> beanLifecycle)
+ {
+ this.beanLifecycle = beanLifecycle;
+ }
+
+ public AnnotatedType<T> getType()
+ {
+ return type;
+ }
+
+ public BeanManager getBeanManager()
+ {
+ return beanManager;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public boolean isPassivationCapable()
+ {
+ return passivationCapable;
+ }
+
+ public void setPassivationCapable(boolean passivationCapable)
+ {
+ this.passivationCapable = passivationCapable;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId(String id)
+ {
+ this.id = id;
+ }
+
+}
Added: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/PassivationCapableCustomBean.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/PassivationCapableCustomBean.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/PassivationCapableCustomBean.java 2010-03-05 12:18:51 UTC (rev 6006)
@@ -0,0 +1,25 @@
+package org.jboss.weld.extensions.beans;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.PassivationCapable;
+
+public class PassivationCapableCustomBean<T> extends CustomBean<T> implements PassivationCapable
+{
+ final String id;
+
+ PassivationCapableCustomBean(String id, Class<?> beanClass, InjectionTarget<T> injectionTarget, String name, Set<Annotation> qualifiers, Class<? extends Annotation> scope, Set<Class<? extends Annotation>> stereotypes, Set<Type> types, boolean alternative, boolean nullable, BeanLifecycle<T> beanLifecycle)
+ {
+ super(beanClass, injectionTarget, name, qualifiers, scope, stereotypes, types, alternative, nullable, beanLifecycle);
+ this.id = id;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+}
Added: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/SimpleBeanLifecycle.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/SimpleBeanLifecycle.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/beans/SimpleBeanLifecycle.java 2010-03-05 12:18:51 UTC (rev 6006)
@@ -0,0 +1,38 @@
+package org.jboss.weld.extensions.beans;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
+
+public class SimpleBeanLifecycle<T> implements BeanLifecycle<T>
+{
+ final Class<T> type;
+ final BeanManager beanManager;
+
+ public SimpleBeanLifecycle(Class<T> type, BeanManager beanManager)
+ {
+ this.type = type;
+ this.beanManager = beanManager;
+ }
+
+ public T create(CustomBean<T> bean, CreationalContext<T> creationalContext)
+ {
+ T instance = bean.getInjectionTarget().produce(creationalContext);
+ bean.getInjectionTarget().inject(instance, creationalContext);
+ bean.getInjectionTarget().postConstruct(instance);
+ return instance;
+ }
+
+ public void destroy(CustomBean<T> bean, T instance, CreationalContext<T> creationalContext)
+ {
+ try
+ {
+ bean.getInjectionTarget().preDestroy(instance);
+ creationalContext.release();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/AnnotatedTypeUtils.java 2010-03-05 12:18:51 UTC (rev 6006)
@@ -0,0 +1,564 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.weld.extensions.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedCallable;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+/**
+ * Class that can take an AnnotatedType and return a unique string
+ * representation of that type
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ */
+public class AnnotatedTypeUtils
+{
+
+ /**
+ * Does the first stage of comparing AnnoatedCallables, however it cannot
+ * compare the method parameters
+ */
+ private static class AnnotatedCallableComparator<T> implements Comparator<AnnotatedCallable<? super T>>
+ {
+
+ public int compare(AnnotatedCallable<? super T> arg0, AnnotatedCallable<? super T> arg1)
+ {
+ // compare the names first
+ int result = (arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName()));
+ if (result != 0)
+ {
+ return result;
+ }
+ result = arg0.getJavaMember().getDeclaringClass().getName().compareTo(arg1.getJavaMember().getDeclaringClass().getName());
+ if (result != 0)
+ {
+ return result;
+ }
+ result = arg0.getParameters().size() - arg1.getParameters().size();
+ return result;
+ }
+
+ }
+
+ private static class AnnotatedMethodComparator<T> implements Comparator<AnnotatedMethod<? super T>>
+ {
+
+ public static <T> Comparator<AnnotatedMethod<? super T>> instance()
+ {
+ return new AnnotatedMethodComparator<T>();
+ }
+
+ private AnnotatedCallableComparator<T> callableComparator = new AnnotatedCallableComparator<T>();
+
+ public int compare(AnnotatedMethod<? super T> arg0, AnnotatedMethod<? super T> arg1)
+ {
+ int result = callableComparator.compare(arg0, arg1);
+ if (result != 0)
+ {
+ return result;
+ }
+ for (int i = 0; i < arg0.getJavaMember().getParameterTypes().length; ++i)
+ {
+ Class<?> p0 = arg0.getJavaMember().getParameterTypes()[i];
+ Class<?> p1 = arg1.getJavaMember().getParameterTypes()[i];
+ result = p0.getName().compareTo(p1.getName());
+ if (result != 0)
+ {
+ return result;
+ }
+ }
+ return 0;
+ }
+
+ }
+
+ private static class AnnotatedConstructorComparator<T> implements Comparator<AnnotatedConstructor<? super T>>
+ {
+
+ public static <T> Comparator<AnnotatedConstructor<? super T>> instance()
+ {
+ return new AnnotatedConstructorComparator<T>();
+ }
+
+ private AnnotatedCallableComparator<T> callableComparator = new AnnotatedCallableComparator<T>();
+
+ public int compare(AnnotatedConstructor<? super T> arg0, AnnotatedConstructor<? super T> arg1)
+ {
+ int result = callableComparator.compare(arg0, arg1);
+ if (result != 0)
+ {
+ return result;
+ }
+ for (int i = 0; i < arg0.getJavaMember().getParameterTypes().length; ++i)
+ {
+ Class<?> p0 = arg0.getJavaMember().getParameterTypes()[i];
+ Class<?> p1 = arg1.getJavaMember().getParameterTypes()[i];
+ result = p0.getName().compareTo(p1.getName());
+ if (result != 0)
+ {
+ return result;
+ }
+ }
+ return 0;
+ }
+
+ }
+
+ private static class AnnotatedFieldComparator<T> implements Comparator<AnnotatedField<? super T>>
+ {
+
+ public static <T> Comparator<AnnotatedField<? super T>> instance()
+ {
+ return new AnnotatedFieldComparator<T>();
+ }
+
+ public int compare(AnnotatedField<? super T> arg0, AnnotatedField<? super T> arg1)
+ {
+ if (arg0.getJavaMember().getName().equals(arg1.getJavaMember().getName()))
+ {
+ return arg0.getJavaMember().getDeclaringClass().getName().compareTo(arg1.getJavaMember().getDeclaringClass().getName());
+ }
+ return arg0.getJavaMember().getName().compareTo(arg1.getJavaMember().getName());
+ }
+
+ }
+
+ private static class AnnotationComparator implements Comparator<Annotation>
+ {
+
+ public static final Comparator<Annotation> INSTANCE = new AnnotationComparator();
+
+ public int compare(Annotation arg0, Annotation arg1)
+ {
+ return arg0.annotationType().getName().compareTo(arg1.annotationType().getName());
+ }
+ }
+
+ private static class MethodComparator implements Comparator<Method>
+ {
+
+ public static final Comparator<Method> INSTANCE = new MethodComparator();
+
+ public int compare(Method arg0, Method arg1)
+ {
+ return arg0.getName().compareTo(arg1.getName());
+ }
+ }
+
+ private static final char SEPERATOR = ';';
+
+ /**
+ * Generates a unique signature for an annotated type. Members without
+ * annotations are omitted to reduce the length of the signature
+ *
+ * @param <X>
+ * @param annotatedType
+ * @return
+ */
+ public static <X> String createTypeId(AnnotatedType<X> annotatedType)
+ {
+ return createTypeId(annotatedType.getJavaClass(), annotatedType.getAnnotations(), annotatedType.getMethods(), annotatedType.getFields(), annotatedType.getConstructors());
+ }
+
+ /**
+ * Generates a unique signature for a concrete class
+ *
+ * @param <X>
+ * @param annotatedType
+ * @return
+ */
+ public static <X> String createTypeId(Class<X> clazz, Collection<Annotation> annotations, Collection<AnnotatedMethod<? super X>> methods, Collection<AnnotatedField<? super X>> fields, Collection<AnnotatedConstructor<X>> constructors)
+ {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append(clazz.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ builder.append("{");
+
+ // now deal with the fields
+ List<AnnotatedField<? super X>> sortedFields = new ArrayList<AnnotatedField<? super X>>();
+ sortedFields.addAll(fields);
+ Collections.sort(sortedFields, AnnotatedFieldComparator.<X> instance());
+ for (AnnotatedField<? super X> field : sortedFields)
+ {
+ if (!field.getAnnotations().isEmpty())
+ {
+ builder.append(createFieldId(field));
+ builder.append(SEPERATOR);
+ }
+ }
+
+ // methods
+ List<AnnotatedMethod<? super X>> sortedMethods = new ArrayList<AnnotatedMethod<? super X>>();
+ sortedMethods.addAll(methods);
+ Collections.sort(sortedMethods, AnnotatedMethodComparator.<X> instance());
+ for (AnnotatedMethod<? super X> method : sortedMethods)
+ {
+ if (!method.getAnnotations().isEmpty() || hasMethodParameters(method))
+ {
+ builder.append(createCallableId(method));
+ builder.append(SEPERATOR);
+ }
+ }
+
+ // constructors
+ List<AnnotatedConstructor<? super X>> sortedConstructors = new ArrayList<AnnotatedConstructor<? super X>>();
+ sortedConstructors.addAll(constructors);
+ Collections.sort(sortedConstructors, AnnotatedConstructorComparator.<X> instance());
+ for (AnnotatedConstructor<? super X> constructor : sortedConstructors)
+ {
+ if (!constructor.getAnnotations().isEmpty() || hasMethodParameters(constructor))
+ {
+ builder.append(createCallableId(constructor));
+ builder.append(SEPERATOR);
+ }
+ }
+ builder.append("}");
+
+ return builder.toString();
+ }
+
+ private static <X> boolean hasMethodParameters(AnnotatedCallable<X> callable)
+ {
+ for (AnnotatedParameter<X> parameter : callable.getParameters())
+ {
+ if (!parameter.getAnnotations().isEmpty())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static String createAnnotationCollectionId(Collection<Annotation> annotations)
+ {
+ if (annotations.isEmpty())
+ {
+ return "";
+ }
+
+ StringBuilder builder = new StringBuilder();
+ builder.append('[');
+
+ List<Annotation> annotationList = new ArrayList<Annotation>(annotations.size());
+ annotationList.addAll(annotations);
+ Collections.sort(annotationList, AnnotationComparator.INSTANCE);
+
+ for (Annotation a : annotationList)
+ {
+ builder.append('@');
+ builder.append(a.annotationType().getName());
+ builder.append('(');
+ Method[] declaredMethods = a.annotationType().getDeclaredMethods();
+ List<Method> methods = new ArrayList<Method>(declaredMethods.length);
+ for (Method m : declaredMethods)
+ {
+ methods.add(m);
+ }
+ Collections.sort(methods, MethodComparator.INSTANCE);
+
+ for (int i = 0; i < methods.size(); ++i)
+ {
+ Method method = methods.get(i);
+ try
+ {
+ Object value = method.invoke(a);
+ builder.append(method.getName());
+ builder.append('=');
+ builder.append(value.toString());
+ }
+ catch (NullPointerException e)
+ {
+ throw new RuntimeException("NullPointerException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new RuntimeException("IllegalArgumentException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException("IllegalAccessException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new RuntimeException("InvocationTargetException accessing annotation member, annotation:" + a.annotationType().getName() + " member: " + method.getName(), e);
+ }
+ if (i + 1 != methods.size())
+ {
+ builder.append(',');
+ }
+ }
+ builder.append(')');
+ }
+ builder.append(']');
+ return builder.toString();
+ }
+
+ public static <X> String createFieldId(AnnotatedField<X> field)
+ {
+ return createFieldId(field.getJavaMember(), field.getAnnotations());
+ }
+
+ public static <X> String createFieldId(Field field, Collection<Annotation> annotations)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(field.getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(field.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ return builder.toString();
+ }
+
+ public static <X> String createCallableId(AnnotatedCallable<X> method)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(method.getJavaMember().getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(method.getJavaMember().getName());
+ builder.append(createAnnotationCollectionId(method.getAnnotations()));
+ builder.append(createParameterListId(method.getParameters()));
+ return builder.toString();
+ }
+
+ public static <X> String createMethodId(Method method, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(method.getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(method.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ builder.append(createParameterListId(parameters));
+ return builder.toString();
+ }
+
+ public static <X> String createConstructorId(Constructor<X> constructor, Set<Annotation> annotations, List<AnnotatedParameter<X>> parameters)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(constructor.getDeclaringClass().getName());
+ builder.append('.');
+ builder.append(constructor.getName());
+ builder.append(createAnnotationCollectionId(annotations));
+ builder.append(createParameterListId(parameters));
+ return builder.toString();
+ }
+
+ public static <X> String createParameterListId(List<AnnotatedParameter<X>> parameters)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("(");
+ for (int i = 0; i < parameters.size(); ++i)
+ {
+ AnnotatedParameter<X> ap = parameters.get(i);
+ builder.append(createParameterId(ap));
+ if (i + 1 != parameters.size())
+ {
+ builder.append(',');
+ }
+ }
+ builder.append(")");
+ return builder.toString();
+ }
+
+ public static <X> String createParameterId(AnnotatedParameter<X> annotatedParameter)
+ {
+ return createParameterId(annotatedParameter.getBaseType(), annotatedParameter.getAnnotations());
+ }
+
+ public static <X> String createParameterId(Type type, Set<Annotation> annotations)
+ {
+ StringBuilder builder = new StringBuilder();
+ if (type instanceof Class<?>)
+ {
+ Class<?> c = (Class<?>) type;
+ builder.append(c.getName());
+ }
+ else
+ {
+ builder.append(type.toString());
+ }
+ builder.append(createAnnotationCollectionId(annotations));
+ return builder.toString();
+ }
+
+ /**
+ * compares two annotated elemetes to see if they have the same annotations
+ *
+ * @param a1
+ * @param a2
+ * @return
+ */
+ private static boolean compareAnnotated(Annotated a1, Annotated a2)
+ {
+ return a1.getAnnotations().equals(a2.getAnnotations());
+ }
+
+ /**
+ * compares two annotated elements to see if they have the same annotations
+ *
+ */
+ private static boolean compareAnnotatedParameters(List<? extends AnnotatedParameter<?>> p1, List<? extends AnnotatedParameter<?>> p2)
+ {
+ if (p1.size() != p2.size())
+ {
+ return false;
+ }
+ for (int i = 0; i < p1.size(); ++i)
+ {
+ if (!compareAnnotated(p1.get(i), p2.get(i)))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean compareAnnotatedField(AnnotatedField<?> f1, AnnotatedField<?> f2)
+ {
+ if (!f1.getJavaMember().equals(f2.getJavaMember()))
+ {
+ return false;
+ }
+ return compareAnnotated(f1, f2);
+ }
+
+ public static boolean compareAnnotatedCallable(AnnotatedCallable<?> m1, AnnotatedCallable<?> m2)
+ {
+ if (!m1.getJavaMember().equals(m2.getJavaMember()))
+ {
+ return false;
+ }
+ if(!compareAnnotated(m1, m2))
+ {
+ return false;
+ }
+ return compareAnnotatedParameters(m1.getParameters(), m2.getParameters());
+ }
+
+ /**
+ * Compares two annotated types and returns true if they are the same
+ */
+ public static boolean compareAnnotatedTypes(AnnotatedType<?> t1, AnnotatedType<?> t2)
+ {
+ if (!t1.getJavaClass().equals(t2.getJavaClass()))
+ {
+ return false;
+ }
+ if (!compareAnnotated(t1, t2))
+ {
+ return false;
+ }
+
+ if (t1.getFields().size() != t2.getFields().size())
+ {
+ return false;
+ }
+ Map<Field, AnnotatedField<?>> fields = new HashMap<Field, AnnotatedField<?>>();
+ for (AnnotatedField<?> f : t2.getFields())
+ {
+ fields.put(f.getJavaMember(), f);
+ }
+ for (AnnotatedField<?> f : t1.getFields())
+ {
+ if (fields.containsKey(f.getJavaMember()))
+ {
+ if (!compareAnnotatedField(f, fields.get(f.getJavaMember())))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ if (t1.getMethods().size() != t2.getMethods().size())
+ {
+ return false;
+ }
+ Map<Method, AnnotatedMethod<?>> methods = new HashMap<Method, AnnotatedMethod<?>>();
+ for (AnnotatedMethod<?> f : t2.getMethods())
+ {
+ methods.put(f.getJavaMember(), f);
+ }
+ for (AnnotatedMethod<?> f : t1.getMethods())
+ {
+ if (methods.containsKey(f.getJavaMember()))
+ {
+ if (!compareAnnotatedCallable(f, methods.get(f.getJavaMember())))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ if (t1.getConstructors().size() != t2.getConstructors().size())
+ {
+ return false;
+ }
+ Map<Constructor<?>, AnnotatedConstructor<?>> constructors = new HashMap<Constructor<?>, AnnotatedConstructor<?>>();
+ for (AnnotatedConstructor<?> f : t2.getConstructors())
+ {
+ constructors.put(f.getJavaMember(), f);
+ }
+ for (AnnotatedConstructor<?> f : t1.getConstructors())
+ {
+ if (constructors.containsKey(f.getJavaMember()))
+ {
+ if (!compareAnnotatedCallable(f, constructors.get(f.getJavaMember())))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return true;
+
+ }
+
+
+ private AnnotatedTypeUtils()
+ {
+ }
+
+}
Modified: extensions/trunk/genericbeans/src/main/java/org/jboss/weld/extensions/genericbeans/GenericExtension.java
===================================================================
--- extensions/trunk/genericbeans/src/main/java/org/jboss/weld/extensions/genericbeans/GenericExtension.java 2010-03-05 12:17:06 UTC (rev 6005)
+++ extensions/trunk/genericbeans/src/main/java/org/jboss/weld/extensions/genericbeans/GenericExtension.java 2010-03-05 12:18:51 UTC (rev 6006)
@@ -29,10 +29,10 @@
import javax.inject.Inject;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.BeanImpl;
import org.jboss.weld.extensions.util.reannotated.ReannotatedField;
import org.jboss.weld.extensions.util.reannotated.ReannotatedParameter;
import org.jboss.weld.extensions.util.reannotated.ReannotatedType;
+import org.jboss.weld.extensions.beans.CustomBeanBuilder;
public class GenericExtension implements Extension
{
@@ -221,8 +221,8 @@
InjectionTarget<?> it = beanManager.createInjectionTarget(rt);
it = new GenericBeanInjectionTargetWrapper(rt, it, conc);
- BeanImpl<?> bean = new BeanImpl(it, rt);
- event.addBean(bean);
+ CustomBeanBuilder<?> builder = new CustomBeanBuilder(rt,beanManager,it);
+ event.addBean(builder.build());
}
}
14 years, 10 months
Weld SVN: r6005 - in extensions/trunk: genericbeans and 1 other directory.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-03-05 07:17:06 -0500 (Fri, 05 Mar 2010)
New Revision: 6005
Modified:
extensions/trunk/bom/pom.xml
extensions/trunk/genericbeans/pom.xml
Log:
updated poms to use a released version of weld
Modified: extensions/trunk/bom/pom.xml
===================================================================
--- extensions/trunk/bom/pom.xml 2010-03-05 01:55:32 UTC (rev 6004)
+++ extensions/trunk/bom/pom.xml 2010-03-05 12:17:06 UTC (rev 6005)
@@ -33,7 +33,7 @@
<properties>
<weld.api.version>1.0</weld.api.version>
- <weld.core.version>1.0.1-CR1</weld.core.version>
+ <weld.core.version>1.0.1-Final</weld.core.version>
<slf4j.version>1.5.10</slf4j.version>
<jta.version>1.1</jta.version>
</properties>
Modified: extensions/trunk/genericbeans/pom.xml
===================================================================
--- extensions/trunk/genericbeans/pom.xml 2010-03-05 01:55:32 UTC (rev 6004)
+++ extensions/trunk/genericbeans/pom.xml 2010-03-05 12:17:06 UTC (rev 6005)
@@ -2,14 +2,13 @@
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <!--
+
<parent>
<artifactId>weld-extensions-parent</artifactId>
<groupId>org.jboss.weld</groupId>
<version>1.0.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
- -->
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.weld</groupId>
@@ -21,17 +20,15 @@
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
- <version>1.0-SP1</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
- <version>1.0.1-Final</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
- <artifactId>weld-extensions</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <artifactId>weld-extensions-core</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
@@ -42,7 +39,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
- <version>5.10</version>
+ <version>5.11</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>test</scope>
14 years, 10 months
Weld SVN: r6004 - extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-03-04 20:55:32 -0500 (Thu, 04 Mar 2010)
New Revision: 6004
Modified:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
Log:
Added the ability to merge annotations from another AnnotatedType to NewAnnotatedTypeBuilder
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-03-05 01:08:34 UTC (rev 6003)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-03-05 01:55:32 UTC (rev 6004)
@@ -8,6 +8,7 @@
import java.util.Map;
import java.util.Map.Entry;
+import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
@@ -391,6 +392,100 @@
}
}
+ /**
+ * merges the annotations from an existing AnnoatedType. If they both have the same annotation
+ * on an element overwriteExisting determines which one to keep
+ * @param type
+ * @param overwriteExisting
+ * @return
+ */
+ public NewAnnotatedTypeBuilder<X> mergeAnnotations(AnnotatedType<X> type, boolean overwriteExisting)
+ {
+ mergeAnnotationsOnElement(type, overwriteExisting, typeAnnotations);
+ for (AnnotatedField<? super X> field : type.getFields())
+ {
+ AnnotationBuilder ans = fields.get(field.getJavaMember());
+ if (ans == null)
+ {
+ ans = new AnnotationBuilder();
+ fields.put(field.getJavaMember(), ans);
+ }
+ mergeAnnotationsOnElement(field, overwriteExisting, ans);
+ }
+ for (AnnotatedMethod<? super X> method : type.getMethods())
+ {
+ AnnotationBuilder ans = methods.get(method.getJavaMember());
+ if (ans == null)
+ {
+ ans = new AnnotationBuilder();
+ methods.put(method.getJavaMember(), ans);
+ }
+ mergeAnnotationsOnElement(method, overwriteExisting, ans);
+ for (AnnotatedParameter<? super X> p : method.getParameters())
+ {
+ Map<Integer, AnnotationBuilder> params = methodParameters.get(method.getJavaMember());
+ if (params == null)
+ {
+ params = new HashMap<Integer, AnnotationBuilder>();
+ methodParameters.put(method.getJavaMember(), params);
+ }
+ AnnotationBuilder builder = params.get(p.getPosition());
+ if(builder == null)
+ {
+ builder = new AnnotationBuilder();
+ params.put(p.getPosition(), builder);
+ }
+ mergeAnnotationsOnElement(p, overwriteExisting, builder);
+ }
+ }
+ for (AnnotatedConstructor<? super X> constructor : type.getConstructors())
+ {
+ AnnotationBuilder ans = constructors.get(constructor.getJavaMember());
+ if (ans == null)
+ {
+ ans = new AnnotationBuilder();
+ constructors.put((Constructor) constructor.getJavaMember(), ans);
+ }
+ mergeAnnotationsOnElement(constructor, overwriteExisting, ans);
+ for (AnnotatedParameter<? super X> p : constructor.getParameters())
+ {
+ Map<Integer, AnnotationBuilder> params = constructorParameters.get(constructor.getJavaMember());
+ if (params == null)
+ {
+ params = new HashMap<Integer, AnnotationBuilder>();
+ constructorParameters.put((Constructor) constructor.getJavaMember(), params);
+ }
+ AnnotationBuilder builder = params.get(p.getPosition());
+ if (builder == null)
+ {
+ builder = new AnnotationBuilder();
+ params.put(p.getPosition(), builder);
+ }
+ mergeAnnotationsOnElement(p, overwriteExisting, builder);
+ }
+ }
+ return this;
+ }
+
+ protected void mergeAnnotationsOnElement(Annotated annotated, boolean overwriteExisting, AnnotationBuilder typeAnnotations)
+ {
+ for (Annotation a : annotated.getAnnotations())
+ {
+ if (typeAnnotations.getAnnotation(a.annotationType()) != null)
+ {
+ if (overwriteExisting)
+ {
+ typeAnnotations.remove(a.annotationType());
+ typeAnnotations.add(a);
+ }
+ }
+ else
+ {
+ typeAnnotations.add(a);
+ }
+ }
+ }
+
public AnnotatedType<X> create()
{
Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,AnnotationStore>>();
14 years, 10 months
Weld SVN: r6003 - extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated.
by weld-commits@lists.jboss.org
Author: swd847
Date: 2010-03-04 20:08:34 -0500 (Thu, 04 Mar 2010)
New Revision: 6003
Added:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java
Modified:
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
Log:
Updated NewAnnotatedTypeBuilder with functionality needed for the XML extensions
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-03-04 21:08:12 UTC (rev 6002)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationBuilder.java 2010-03-05 01:08:34 UTC (rev 6003)
@@ -4,6 +4,7 @@
import java.lang.reflect.AnnotatedElement;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
/**
@@ -19,10 +20,24 @@
public AnnotationBuilder add(Annotation a)
{
annotationSet.add(a);
- annotationMap.put(a.getClass(), a);
+ annotationMap.put(a.annotationType(), a);
return this;
}
+ public void remove(Class<? extends Annotation> a)
+ {
+ Iterator<Annotation> it = annotationSet.iterator();
+ while (it.hasNext())
+ {
+ Annotation an = it.next();
+ if (a.isAssignableFrom(an.annotationType()))
+ {
+ it.remove();
+ }
+ }
+ annotationMap.remove(a);
+ }
+
public AnnotationStore create()
{
return new AnnotationStore(annotationMap, annotationSet);
@@ -55,4 +70,9 @@
return this;
}
+ public <T extends Annotation> T getAnnotation(Class<T> anType)
+ {
+ return (T) annotationMap.get(anType);
+ }
+
}
Added: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java (rev 0)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/AnnotationRedefiner.java 2010-03-05 01:08:34 UTC (rev 6003)
@@ -0,0 +1,8 @@
+package org.jboss.weld.extensions.util.annotated;
+
+import java.lang.annotation.Annotation;
+
+public interface AnnotationRedefiner<X extends Annotation>
+{
+ public X redefine(X annotation, AnnotationBuilder annotations);
+}
Modified: extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java
===================================================================
--- extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-03-04 21:08:12 UTC (rev 6002)
+++ extensions/trunk/core/src/main/java/org/jboss/weld/extensions/util/annotated/NewAnnotatedTypeBuilder.java 2010-03-05 01:08:34 UTC (rev 6003)
@@ -8,14 +8,18 @@
import java.util.Map;
import java.util.Map.Entry;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
/**
* Class for constructing a new AnnotatedType. A new instance of builder must be
* used for each annotated type.
*
- * No annotations will be read from the underlying class definition, all
- * annotations must be added explicitly
+ * In can either be created with no annotations, or the annotations can be read
+ * from the underlying class or an AnnotatedType
*
* @author Stuart Douglas
* @author Pete Muir
@@ -33,15 +37,148 @@
public NewAnnotatedTypeBuilder(Class<X> underlying)
{
+ this(underlying, false);
+ }
+
+ public NewAnnotatedTypeBuilder(Class<X> underlying, boolean readAnnotations)
+ {
this.underlying = underlying;
+ if (readAnnotations)
+ {
+ for (Annotation a : underlying.getAnnotations())
+ {
+ typeAnnotations.add(a);
+ }
+
+ for (Field f : underlying.getFields())
+ {
+ AnnotationBuilder ab = new AnnotationBuilder();
+ fields.put(f, ab);
+ for (Annotation a : f.getAnnotations())
+ {
+ ab.add(a);
+ }
+ }
+
+ for (Method m : underlying.getMethods())
+ {
+ AnnotationBuilder ab = new AnnotationBuilder();
+ methods.put(m, ab);
+ for (Annotation a : m.getAnnotations())
+ {
+ ab.add(a);
+ }
+ Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
+ methodParameters.put(m, mparams);
+ for (int i = 0; i < m.getParameterTypes().length; ++i)
+ {
+ AnnotationBuilder mab = new AnnotationBuilder();
+ mparams.put(i, mab);
+ for (Annotation a : m.getParameterAnnotations()[i])
+ {
+ mab.add(a);
+ }
+ }
+ }
+
+ for (Constructor m : underlying.getConstructors())
+ {
+ AnnotationBuilder ab = new AnnotationBuilder();
+ constructors.put(m, ab);
+ for (Annotation a : m.getAnnotations())
+ {
+ ab.add(a);
+ }
+ Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
+ constructorParameters.put(m, mparams);
+ for (int i = 0; i < m.getParameterTypes().length; ++i)
+ {
+ AnnotationBuilder mab = new AnnotationBuilder();
+ mparams.put(i, mab);
+ for (Annotation a : m.getParameterAnnotations()[i])
+ {
+ mab.add(a);
+ }
+ }
+ }
+
+ }
}
+ public NewAnnotatedTypeBuilder(AnnotatedType<X> type)
+ {
+ this.underlying = type.getJavaClass();
+ for (Annotation a : type.getAnnotations())
+ {
+ typeAnnotations.add(a);
+ }
+
+ for (AnnotatedField<? super X> f : type.getFields())
+ {
+ AnnotationBuilder ab = new AnnotationBuilder();
+ fields.put(f.getJavaMember(), ab);
+ for (Annotation a : f.getAnnotations())
+ {
+ ab.add(a);
+ }
+ }
+
+ for (AnnotatedMethod<? super X> m : type.getMethods())
+ {
+ AnnotationBuilder ab = new AnnotationBuilder();
+ methods.put(m.getJavaMember(), ab);
+ for (Annotation a : m.getAnnotations())
+ {
+ ab.add(a);
+ }
+ Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
+ methodParameters.put(m.getJavaMember(), mparams);
+ for (AnnotatedParameter<? super X> p : m.getParameters())
+ {
+ AnnotationBuilder mab = new AnnotationBuilder();
+ mparams.put(p.getPosition(), mab);
+ for (Annotation a : p.getAnnotations())
+ {
+ mab.add(a);
+ }
+ }
+ }
+
+ for (AnnotatedConstructor<X> m : type.getConstructors())
+ {
+ AnnotationBuilder ab = new AnnotationBuilder();
+ constructors.put(m.getJavaMember(), ab);
+ for (Annotation a : m.getAnnotations())
+ {
+ ab.add(a);
+ }
+ Map<Integer, AnnotationBuilder> mparams = new HashMap<Integer, AnnotationBuilder>();
+ constructorParameters.put(m.getJavaMember(), mparams);
+ for (AnnotatedParameter<? super X> p : m.getParameters())
+ {
+ AnnotationBuilder mab = new AnnotationBuilder();
+ mparams.put(p.getPosition(), mab);
+ for (Annotation a : p.getAnnotations())
+ {
+ mab.add(a);
+ }
+ }
+ }
+
+ }
+
public NewAnnotatedTypeBuilder<X> addToClass(Annotation a)
{
typeAnnotations.add(a);
return this;
}
+ public NewAnnotatedTypeBuilder<X> removeFromClass(Class<? extends Annotation> annotation)
+ {
+ typeAnnotations.remove(annotation);
+ return this;
+ }
+
public NewAnnotatedTypeBuilder<X> addToField(Field field, Annotation a)
{
AnnotationBuilder annotations = fields.get(field);
@@ -54,6 +191,16 @@
return this;
}
+ public NewAnnotatedTypeBuilder<X> removeFromField(Field field, Class<? extends Annotation> a)
+ {
+ AnnotationBuilder annotations = fields.get(field);
+ if (annotations != null)
+ {
+ annotations.remove(a);
+ }
+ return this;
+ }
+
public NewAnnotatedTypeBuilder<X> addToMethod(Method method, Annotation a)
{
AnnotationBuilder annotations = methods.get(method);
@@ -66,6 +213,16 @@
return this;
}
+ public NewAnnotatedTypeBuilder<X> removeFromMethod(Method method, Class<? extends Annotation> a)
+ {
+ AnnotationBuilder annotations = methods.get(method);
+ if (annotations != null)
+ {
+ annotations.remove(a);
+ }
+ return this;
+ }
+
public NewAnnotatedTypeBuilder<X> addToMethodParameter(Method method, int parameter, Annotation a)
{
Map<Integer, AnnotationBuilder> anmap = methodParameters.get(method);
@@ -84,6 +241,20 @@
return this;
}
+ public NewAnnotatedTypeBuilder<X> removeFromMethodParameter(Method method, int parameter, Class<? extends Annotation> a)
+ {
+ Map<Integer, AnnotationBuilder> anmap = methodParameters.get(method);
+ if (anmap != null)
+ {
+ AnnotationBuilder annotations = anmap.get(parameter);
+ if (annotations != null)
+ {
+ annotations.remove(a);
+ }
+ }
+ return this;
+ }
+
public NewAnnotatedTypeBuilder<X> addToConstructor(Constructor<X> constructor, Annotation a)
{
AnnotationBuilder annotations = constructors.get(constructor);
@@ -96,6 +267,16 @@
return this;
}
+ public NewAnnotatedTypeBuilder<X> removeFromConstructor(Constructor constructor, Class<? extends Annotation> a)
+ {
+ AnnotationBuilder annotations = constructors.get(constructor);
+ if (annotations != null)
+ {
+ annotations.remove(a);
+ }
+ return this;
+ }
+
public NewAnnotatedTypeBuilder<X> addToConstructorParameter(Constructor<X> constructor, int parameter, Annotation a)
{
Map<Integer, AnnotationBuilder> anmap = constructorParameters.get(constructor);
@@ -114,6 +295,102 @@
return this;
}
+ public NewAnnotatedTypeBuilder<X> removeFromConstructorParameter(Constructor<X> constructor, int parameter, Class<? extends Annotation> a)
+ {
+ Map<Integer, AnnotationBuilder> anmap = constructorParameters.get(constructor);
+ if (anmap != null)
+ {
+ AnnotationBuilder annotations = anmap.get(parameter);
+ if (annotations != null)
+ {
+ annotations.remove(a);
+ }
+ }
+ return this;
+ }
+
+ public NewAnnotatedTypeBuilder<X> removeFromAll(Class<? extends Annotation> a)
+ {
+ removeFromClass(a);
+ for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
+ {
+ e.getValue().remove(a);
+ }
+ for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
+ {
+ e.getValue().remove(a);
+ Map<Integer, AnnotationBuilder> params = methodParameters.get(e.getKey());
+ if (params != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
+ {
+ p.getValue().remove(a);
+ }
+ }
+ }
+ for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
+ {
+ e.getValue().remove(a);
+ Map<Integer, AnnotationBuilder> params = constructorParameters.get(e.getKey());
+ if (params != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
+ {
+ p.getValue().remove(a);
+ }
+ }
+ }
+ return this;
+ }
+
+ public <T extends Annotation> NewAnnotatedTypeBuilder<X> redefine(Class<T> annotationType, AnnotationRedefiner<T> redefinition)
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, typeAnnotations);
+ for (Entry<Field, AnnotationBuilder> e : fields.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
+ }
+ for (Entry<Method, AnnotationBuilder> e : methods.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
+ Map<Integer, AnnotationBuilder> params = methodParameters.get(e.getKey());
+ if (params != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
+ }
+ }
+ }
+ for (Entry<Constructor<X>, AnnotationBuilder> e : constructors.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, e.getValue());
+ Map<Integer, AnnotationBuilder> params = constructorParameters.get(e.getKey());
+ if (params != null)
+ {
+ for (Entry<Integer, AnnotationBuilder> p : params.entrySet())
+ {
+ redefineAnnotationBuilder(annotationType, redefinition, p.getValue());
+ }
+ }
+ }
+ return this;
+ }
+
+ protected <T extends Annotation> void redefineAnnotationBuilder(Class<T> annotationType, AnnotationRedefiner<T> redefinition, AnnotationBuilder builder)
+ {
+ T an = builder.getAnnotation(annotationType);
+ if(an != null)
+ {
+ builder.remove(annotationType);
+ T newAn = redefinition.redefine(an, builder);
+ if (newAn != null)
+ {
+ builder.add(newAn);
+ }
+ }
+ }
+
public AnnotatedType<X> create()
{
Map<Constructor<X>, Map<Integer, AnnotationStore>> constructorParameterAnnnotations = new HashMap<Constructor<X>, Map<Integer,AnnotationStore>>();
14 years, 10 months
Weld SVN: r6002 - in core/trunk/impl/src/main/java/org/jboss/weld: util and 1 other directory.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-03-04 16:08:12 -0500 (Thu, 04 Mar 2010)
New Revision: 6002
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
Log:
fix method filter
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2010-03-04 20:57:38 UTC (rev 6001)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2010-03-04 21:08:12 UTC (rev 6002)
@@ -93,11 +93,6 @@
*/
public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[] args) throws Throwable
{
- // FIXME: Temporary fix until we have serializable method filters
- if (proxiedMethod.getName().equals("finalize"))
- {
- return null;
- }
if (bean == null)
{
bean = Container.instance().services().get(ContextualStore.class).<Bean<Object>, Object>getContextual(id);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java 2010-03-04 20:57:38 UTC (rev 6001)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java 2010-03-04 21:08:12 UTC (rev 6002)
@@ -54,7 +54,7 @@
public boolean isHandled(Method m)
{
- return m.getName().equals("finalize");
+ return !m.getName().equals("finalize");
}
}
@@ -103,9 +103,8 @@
public ProxyFactory createProxyFactory()
{
ProxyFactory proxyFactory = new ProxyFactory();
- ProxyFactory.useCache = false;
-// FIXME: Check for calls to "finalize" in ClientProxyMethodHandler until serialization stuff is sorted out
-// proxyFactory.setFilter(new IgnoreFinalizeMethodFilter());
+ ProxyFactory.useCache = false;
+ proxyFactory.setFilter(new IgnoreFinalizeMethodFilter());
Class<?> superClass = getSuperClass();
if(superClass != null && superClass != Object.class)
{
14 years, 10 months
Weld SVN: r6001 - in core/trunk/impl/src/main/java/org/jboss/weld: util and 1 other directory.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-03-04 15:57:38 -0500 (Thu, 04 Mar 2010)
New Revision: 6001
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
Log:
Temp fix for non-serializable method filters when ignoring calls to finalize
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2010-03-04 19:01:22 UTC (rev 6000)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2010-03-04 20:57:38 UTC (rev 6001)
@@ -93,6 +93,11 @@
*/
public Object invoke(Object self, Method proxiedMethod, Method proceed, Object[] args) throws Throwable
{
+ // FIXME: Temporary fix until we have serializable method filters
+ if (proxiedMethod.getName().equals("finalize"))
+ {
+ return null;
+ }
if (bean == null)
{
bean = Container.instance().services().get(ContextualStore.class).<Bean<Object>, Object>getContextual(id);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java 2010-03-04 19:01:22 UTC (rev 6000)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java 2010-03-04 20:57:38 UTC (rev 6001)
@@ -20,6 +20,7 @@
import static org.jboss.weld.logging.messages.UtilMessage.INSTANCE_NOT_A_PROXY;
import static org.jboss.weld.util.reflection.Reflections.EMPTY_CLASSES;
+import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -48,7 +49,7 @@
public class Proxies
{
- private static class IgnoreFinalizeMethodFilter implements MethodFilter
+ private static class IgnoreFinalizeMethodFilter implements MethodFilter, Serializable
{
public boolean isHandled(Method m)
@@ -103,7 +104,8 @@
{
ProxyFactory proxyFactory = new ProxyFactory();
ProxyFactory.useCache = false;
- proxyFactory.setFilter(new IgnoreFinalizeMethodFilter());
+// FIXME: Check for calls to "finalize" in ClientProxyMethodHandler until serialization stuff is sorted out
+// proxyFactory.setFilter(new IgnoreFinalizeMethodFilter());
Class<?> superClass = getSuperClass();
if(superClass != null && superClass != Object.class)
{
14 years, 10 months