[jboss-cvs] JBossAS SVN: r112204 - in branches/JBPAPP_5_1: testsuite/src/main/org/jboss/test/web/jbas8318 and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Sep 6 10:40:12 EDT 2011
Author: jaikiran
Date: 2011-09-06 10:40:12 -0400 (Tue, 06 Sep 2011)
New Revision: 112204
Added:
branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanWithAnnotationsOnlyInBaseClass.java
Modified:
branches/JBPAPP_5_1/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java
branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/WEB-INF/faces-config.xml
branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp
Log:
JBPAPP-7104 Fix resource injection in base classes of (non-annotated) JSF managed beans
Modified: branches/JBPAPP_5_1/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java
===================================================================
--- branches/JBPAPP_5_1/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java 2011-09-06 14:28:31 UTC (rev 112203)
+++ branches/JBPAPP_5_1/server/src/main/org/jboss/deployment/AnnotationMetaDataDeployer.java 2011-09-06 14:40:12 UTC (rev 112204)
@@ -406,14 +406,9 @@
if (classes == null || classes.isEmpty()) {
return eligibleClasses;
}
- Collection<String> jsfManagedBeanClasses = Collections.emptySet();
// get the JSFDeployment metadata
- JSFDeployment jsfDeployment = unit.getAttachment(JSFDeployment.class);
- if (jsfDeployment != null)
- {
- // collection of JSF managed beans
- jsfManagedBeanClasses = jsfDeployment.getManagedBeans();
- }
+ final JSFDeployment jsfDeployment = unit.getAttachment(JSFDeployment.class);
+ final Collection<Class<?>> jsfManagedBeanClasses = this.loadJSFManagedBeanClasses(jsfDeployment, unit);
for (Class<?> klass : classes)
{
if (klass == null)
@@ -461,14 +456,48 @@
{
eligibleClasses.add(klass);
}
- else if (jsfManagedBeanClasses.contains(klass.getName())) // JSF managed bean
+ else
{
- eligibleClasses.add(klass);
+ // JSF managed bean
+ for (final Class<?> jsfManagedBeanClass : jsfManagedBeanClasses) {
+ if (klass.isAssignableFrom(jsfManagedBeanClass)) {
+ eligibleClasses.add(klass);
+ break;
+ }
+ }
}
}
return eligibleClasses;
}
+ private Collection<Class<?>> loadJSFManagedBeanClasses(final JSFDeployment jsfDeployment, final DeploymentUnit unit) {
+ if (jsfDeployment == null) {
+ return Collections.emptySet();
+ }
+ final Collection<String> managedBeanClassNames = jsfDeployment.getManagedBeans();
+ if (managedBeanClassNames == null || managedBeanClassNames.isEmpty()) {
+ return Collections.emptySet();
+ }
+ final ClassLoader cl = unit.getClassLoader();
+ final Collection<Class<?>> managedBeanClasses = new HashSet<Class<?>>(managedBeanClassNames.size());
+ for (final String managedBeanClassName : managedBeanClassNames) {
+ try
+ {
+ final Class<?> managedBeanClass = Class.forName(managedBeanClassName, false, cl);
+ managedBeanClasses.add(managedBeanClass);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ // ignore the CNFE. The JSF spec allows non-existent classes to be referred in the faces-config.xml
+ // and until that JSF managed bean is accessed in the application, it doesn't fail that application.
+ // So we just ignore that CNFE and effectively the managed bean
+ log.debug("Ignoring JSF managed bean class " + managedBeanClassName + " since the class cannot be found " +
+ "in classloader " + cl + " of unit " + unit);
+ }
+ }
+ return managedBeanClasses;
+ }
+
}
Added: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanWithAnnotationsOnlyInBaseClass.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanWithAnnotationsOnlyInBaseClass.java (rev 0)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/web/jbas8318/JSFManagedBeanWithAnnotationsOnlyInBaseClass.java 2011-09-06 14:40:12 UTC (rev 112204)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.web.jbas8318;
+
+import javax.faces.FacesException;
+
+/**
+ * User: jpai
+ */
+public class JSFManagedBeanWithAnnotationsOnlyInBaseClass extends JSFBaseComponent
+{
+ public boolean isBaseClassResourcesInjected()
+ {
+ if (this.envEntryStringInBaseClass == null)
+ {
+ throw new FacesException("Simple env-entry string in base class of JSF managed bean was not injected");
+ }
+ if (this.utInBaseClass == null)
+ {
+ throw new FacesException("UserTransaction in base class of JSF managed bean was not injected");
+ }
+ return true;
+ }
+}
Modified: branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/WEB-INF/faces-config.xml
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/WEB-INF/faces-config.xml 2011-09-06 14:28:31 UTC (rev 112203)
+++ branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/WEB-INF/faces-config.xml 2011-09-06 14:40:12 UTC (rev 112204)
@@ -32,4 +32,11 @@
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
+ <managed-bean>
+ <description>Managed bean with no annotations</description>
+ <managed-bean-name>managedBeanWithAnnotationsOnlyInBaseClass</managed-bean-name>
+ <managed-bean-class>org.jboss.test.web.jbas8318.JSFManagedBeanWithAnnotationsOnlyInBaseClass</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+
</faces-config>
Modified: branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp 2011-09-06 14:28:31 UTC (rev 112203)
+++ branches/JBPAPP_5_1/testsuite/src/resources/web/jbas-8318/test-jsf-injection.jsp 2011-09-06 14:40:12 UTC (rev 112204)
@@ -27,6 +27,10 @@
<h:outputText rendered="#{libJarJSFManagedBean.queueInjected}" value="Success: Injection of Queue in JSF managed bean configured in .war/lib/*.jar/META-INF/faces-config.xml is ok" />
<br/>
+
+ <h:outputText rendered="#{managedBeanWithAnnotationsOnlyInBaseClass.baseClassResourcesInjected}" value="Success: Injection of resources in a managed bean with annotations only in the base class, is ok" />
+ <br/>
+
</f:view>
</body>
</html>
More information about the jboss-cvs-commits
mailing list