JBossWS SVN: r9961 - in container/jboss50/branches/jboss500/src/main: resources/jbossws-jboss50.deployer/META-INF and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 08:50:22 -0400 (Tue, 05 May 2009)
New Revision: 9961
Removed:
container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
Modified:
container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml
Log:
[JBWS-2634] EjbReferenceResolver available on AS 5.0.1 and above only
Deleted: container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
===================================================================
--- container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:20:45 UTC (rev 9960)
+++ container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:50:22 UTC (rev 9961)
@@ -1,114 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, 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.wsf.container.jboss50.deployment.metadata;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import javax.ejb.EJB;
-
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.ejb3.common.resolvers.spi.EjbReference;
-import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
-import org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver;
-
-/**
- * EJB reference resolver.
- *
- * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
- */
-final class EJBBeanReferenceResolver extends AbstractReferenceResolver<EJB>
-{
-
- /**
- * Deployment unit used for resolving process.
- */
- private final DeploymentUnit unit;
- /**
- * Delegate used to resolve JNDI names.
- */
- private final EjbReferenceResolver delegate;
-
- /**
- * Constructor.
- */
- EJBBeanReferenceResolver(final DeploymentUnit unit, final EjbReferenceResolver delegate)
- {
- super(EJB.class);
-
- if (unit == null)
- {
- throw new IllegalArgumentException("Deployment unit cannot be null");
- }
- if (delegate == null)
- {
- throw new IllegalArgumentException("Ejb reference resolver cannot be null");
- }
-
- this.unit = unit;
- this.delegate = delegate;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
- */
- @Override
- protected String resolveField(final Field field)
- {
- final EJB ejbAnnotation = field.getAnnotation(EJB.class);
- final Class<?> type = field.getType();
- final EjbReference reference = getEjbReference(ejbAnnotation, type);
-
- return this.delegate.resolveEjb(unit, reference);
- }
-
- /* (non-Javadoc)
- * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
- */
- @Override
- protected String resolveMethod(final Method method)
- {
- final EJB ejbAnnotation = method.getAnnotation(EJB.class);
- final Class<?> type = method.getParameterTypes()[0];
- final EjbReference reference = getEjbReference(ejbAnnotation, type);
-
- return this.delegate.resolveEjb(unit, reference);
- }
-
- /**
- * Constructs EjbReference.
- *
- * @param ejbAnnotation ejb annotation
- * @param type fall back type
- * @return ejb reference instance
- */
- private EjbReference getEjbReference(EJB ejbAnnotation, Class<?> type)
- {
- String beanInterface = ejbAnnotation.beanInterface().getName();
- if (java.lang.Object.class.getName().equals(beanInterface))
- {
- beanInterface = type.getName();
- }
- return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName());
- }
-
-}
Modified: container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
===================================================================
--- container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:20:45 UTC (rev 9960)
+++ container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:50:22 UTC (rev 9961)
@@ -31,14 +31,12 @@
import java.util.Set;
import javax.annotation.Resource;
-import javax.ejb.EJB;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.xml.ws.WebServiceProvider;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
import org.jboss.metadata.javaee.spec.EnvironmentEntriesMetaData;
@@ -66,7 +64,6 @@
private static final ReferenceResolver RESOURCE_REFERENCE_RESOLVER = new ResourceReferenceResolver();
private static final String EJB3_JNDI_PREFIX = "java:env/";
- private EjbReferenceResolver ejbReferenceResolver;
@Override
public void create(Deployment dep)
@@ -144,7 +141,6 @@
{
final Map<Class<? extends Annotation>, ReferenceResolver> resolvers = new HashMap<Class<? extends Annotation>, ReferenceResolver>();
resolvers.put(Resource.class, RESOURCE_REFERENCE_RESOLVER);
- resolvers.put(EJB.class, new EJBBeanReferenceResolver(unit, getEjbReferenceResolver()));
return resolvers;
}
@@ -207,29 +203,4 @@
return isWebService || isWebServiceProvider;
}
- /**
- * Sets ejb reference resolver. This method is invoked by MC.
- *
- * @param resolver ejb reference resolver
- */
- public void setEjbReferenceResolver(final EjbReferenceResolver resolver)
- {
- this.ejbReferenceResolver = resolver;
- }
-
- /**
- * Gets ejb reference resolver.
- *
- * @return ejb reference resolver
- */
- public EjbReferenceResolver getEjbReferenceResolver()
- {
- if (this.ejbReferenceResolver == null)
- {
- throw new IllegalStateException("No EjbReferenceResolver set by MC");
- }
-
- return this.ejbReferenceResolver;
- }
-
}
Modified: container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml
===================================================================
--- container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml 2009-05-05 12:20:45 UTC (rev 9960)
+++ container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml 2009-05-05 12:50:22 UTC (rev 9961)
@@ -172,8 +172,8 @@
</uninstall>
<depends>WebServiceDeployerEJB</depends>
</bean>
-
- <!--
+
+ <!--
Each DeploymentAspectManger maintains a list of DeploymentAspects
-->
<bean name="WSDeploymentAspectManagerPreJSE" class="org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl">
@@ -189,25 +189,24 @@
<bean name="WSDeploymentAspectManagerEndpointAPI" class="org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl">
<property name="name">WSDeploymentAspectManagerEndpointAPI</property>
</bean>
-
- <!--
+
+ <!--
The container deployment aspects
-->
<bean name="WSContainerMetaDataDeploymentAspect" class="org.jboss.wsf.container.jboss50.deployment.metadata.ContainerMetaDataDeploymentAspect">
<property name="provides">ContainerMetaData, VFSRoot</property>
</bean>
-
+
<bean name="WSInjectionMetaDataDeploymentAspect" class="org.jboss.wsf.container.jboss50.deployment.metadata.InjectionMetaDataDeploymentAspect">
<property name="requires">WebMetaData</property>
<property name="provides">InjectionMetaData</property>
- <property name="ejbReferenceResolver"><inject bean="org.jboss.ejb3.EjbReferenceResolver"/></property>
- </bean>
+ </bean>
<bean name="WSContextRootDeploymentAspect" class="org.jboss.wsf.framework.deployment.BackwardCompatibleContextRootDeploymentAspect">
<property name="requires">ContainerMetaData</property>
<property name="provides">ContextRoot</property>
</bean>
-
+
<bean name="WSVirtualHostDeploymentAspect" class="org.jboss.wsf.framework.deployment.VirtualHostDeploymentAspect">
<property name="requires">ContainerMetaData</property>
<property name="provides">VirtualHosts</property>
15 years, 7 months
JBossWS SVN: r9960 - in container/jboss50/branches: jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 08:20:45 -0400 (Tue, 05 May 2009)
New Revision: 9960
Modified:
container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
Log:
[JBWS-2074][JBWS-2634] refactoring momma
Modified: container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
===================================================================
--- container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:10:07 UTC (rev 9959)
+++ container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:20:45 UTC (rev 9960)
@@ -47,7 +47,7 @@
* Delegate used to resolve JNDI names.
*/
private final EjbReferenceResolver delegate;
-
+
/**
* Constructor.
*/
@@ -63,13 +63,13 @@
{
throw new IllegalArgumentException("Ejb reference resolver cannot be null");
}
-
+
this.unit = unit;
this.delegate = delegate;
}
-
+
/* (non-Javadoc)
- * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
+ * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
*/
@Override
protected String resolveField(final Field field)
@@ -82,7 +82,7 @@
}
/* (non-Javadoc)
- * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
+ * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
*/
@Override
protected String resolveMethod(final Method method)
@@ -93,10 +93,10 @@
return this.delegate.resolveEjb(unit, reference);
}
-
+
/**
* Constructs EjbReference.
- *
+ *
* @param ejbAnnotation ejb annotation
* @param type fall back type
* @return ejb reference instance
@@ -110,5 +110,5 @@
}
return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName());
}
-
+
}
Modified: container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
===================================================================
--- container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:10:07 UTC (rev 9959)
+++ container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:20:45 UTC (rev 9960)
@@ -67,7 +67,7 @@
private static final ReferenceResolver RESOURCE_REFERENCE_RESOLVER = new ResourceReferenceResolver();
private static final String EJB3_JNDI_PREFIX = "java:env/";
private EjbReferenceResolver ejbReferenceResolver;
-
+
@Override
public void create(Deployment dep)
{
@@ -136,7 +136,7 @@
/**
* Builds reference resolvers container.
- *
+ *
* @param unit deployment unit
* @return reference resolvers
*/
@@ -150,7 +150,7 @@
/**
* Builds JBossWS specific injection metadata from JBoss metadata.
- *
+ *
* @param envEntries environment entries
* @return JBossWS specific injection metadata
*/
@@ -195,7 +195,7 @@
/**
* Returns true if EJB represents webservice endpoint, false otherwise.
- *
+ *
* @param container to analyze
* @return true if webservice endpoint, false otherwise
*/
@@ -209,17 +209,17 @@
/**
* Sets ejb reference resolver. This method is invoked by MC.
- *
+ *
* @param resolver ejb reference resolver
*/
public void setEjbReferenceResolver(final EjbReferenceResolver resolver)
{
this.ejbReferenceResolver = resolver;
}
-
+
/**
* Gets ejb reference resolver.
- *
+ *
* @return ejb reference resolver
*/
public EjbReferenceResolver getEjbReferenceResolver()
@@ -231,5 +231,5 @@
return this.ejbReferenceResolver;
}
-
+
}
Modified: container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
===================================================================
--- container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:10:07 UTC (rev 9959)
+++ container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:20:45 UTC (rev 9960)
@@ -47,7 +47,7 @@
* Delegate used to resolve JNDI names.
*/
private final EjbReferenceResolver delegate;
-
+
/**
* Constructor.
*/
@@ -63,13 +63,13 @@
{
throw new IllegalArgumentException("Ejb reference resolver cannot be null");
}
-
+
this.unit = unit;
this.delegate = delegate;
}
-
+
/* (non-Javadoc)
- * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
+ * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
*/
@Override
protected String resolveField(final Field field)
@@ -82,7 +82,7 @@
}
/* (non-Javadoc)
- * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
+ * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
*/
@Override
protected String resolveMethod(final Method method)
@@ -93,10 +93,10 @@
return this.delegate.resolveEjb(unit, reference);
}
-
+
/**
* Constructs EjbReference.
- *
+ *
* @param ejbAnnotation ejb annotation
* @param type fall back type
* @return ejb reference instance
@@ -110,5 +110,5 @@
}
return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName());
}
-
+
}
Modified: container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
===================================================================
--- container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:10:07 UTC (rev 9959)
+++ container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:20:45 UTC (rev 9960)
@@ -67,7 +67,7 @@
private static final ReferenceResolver RESOURCE_REFERENCE_RESOLVER = new ResourceReferenceResolver();
private static final String EJB3_JNDI_PREFIX = "java:env/";
private EjbReferenceResolver ejbReferenceResolver;
-
+
@Override
public void create(Deployment dep)
{
@@ -136,7 +136,7 @@
/**
* Builds reference resolvers container.
- *
+ *
* @param unit deployment unit
* @return reference resolvers
*/
@@ -150,7 +150,7 @@
/**
* Builds JBossWS specific injection metadata from JBoss metadata.
- *
+ *
* @param envEntries environment entries
* @return JBossWS specific injection metadata
*/
@@ -195,7 +195,7 @@
/**
* Returns true if EJB represents webservice endpoint, false otherwise.
- *
+ *
* @param container to analyze
* @return true if webservice endpoint, false otherwise
*/
@@ -209,17 +209,17 @@
/**
* Sets ejb reference resolver. This method is invoked by MC.
- *
+ *
* @param resolver ejb reference resolver
*/
public void setEjbReferenceResolver(final EjbReferenceResolver resolver)
{
this.ejbReferenceResolver = resolver;
}
-
+
/**
* Gets ejb reference resolver.
- *
+ *
* @return ejb reference resolver
*/
public EjbReferenceResolver getEjbReferenceResolver()
@@ -231,5 +231,5 @@
return this.ejbReferenceResolver;
}
-
+
}
15 years, 7 months
JBossWS SVN: r9959 - in stack/native/trunk/modules/core/src/main/java/org/jboss: wsf/stack/jbws and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 08:10:07 -0400 (Tue, 05 May 2009)
New Revision: 9959
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java
Log:
[JBWS-2074][JBWS-2634] refactoring momma
Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java 2009-05-05 12:08:31 UTC (rev 9958)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/handler/HandlerResolverImpl.java 2009-05-05 12:10:07 UTC (rev 9959)
@@ -45,7 +45,7 @@
import org.jboss.ws.metadata.umdm.ServiceMetaData;
import org.jboss.wsf.common.handler.GenericHandler;
import org.jboss.wsf.common.handler.GenericSOAPHandler;
-import org.jboss.wsf.common.javax.JavaxAnnotationHelper;
+import org.jboss.wsf.common.injection.InjectionHelper;
import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
import org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedHandlerMetaData.HandlerType;
@@ -168,8 +168,8 @@
if (handler instanceof GenericSOAPHandler)
((GenericSOAPHandler)handler).setHeaders(soapHeaders);
- JavaxAnnotationHelper.injectResources(handler, injections);
- JavaxAnnotationHelper.callPostConstructMethod(handler);
+ InjectionHelper.injectResources(handler, injections);
+ InjectionHelper.callPostConstructMethod(handler);
addHandler(jaxwsMetaData, handler, type);
}
Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java
===================================================================
--- stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java 2009-05-05 12:08:31 UTC (rev 9958)
+++ stack/native/trunk/modules/core/src/main/java/org/jboss/wsf/stack/jbws/EndpointServlet.java 2009-05-05 12:10:07 UTC (rev 9959)
@@ -27,8 +27,8 @@
import org.jboss.logging.Logger;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.management.EndpointResolver;
-import org.jboss.wsf.common.javax.JavaxAnnotationHelper;
-import org.jboss.wsf.common.javax.PreDestroyHolder;
+import org.jboss.wsf.common.injection.InjectionHelper;
+import org.jboss.wsf.common.injection.PreDestroyHolder;
import org.jboss.wsf.common.servlet.AbstractEndpointServlet;
import javax.servlet.ServletConfig;
@@ -84,7 +84,7 @@
{
try
{
- JavaxAnnotationHelper.callPreDestroyMethod(holder.getObject());
+ InjectionHelper.callPreDestroyMethod(holder.getObject());
}
catch (Exception exception)
{
15 years, 7 months
JBossWS SVN: r9958 - in container/jboss50/branches: jboss500/src/main/java/org/jboss/wsf/container/jboss50/invocation and 4 other directories.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 08:08:31 -0400 (Tue, 05 May 2009)
New Revision: 9958
Added:
container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
Modified:
container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java
container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml
container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java
container/jboss50/branches/jboss501/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml
Log:
[JBWS-2074][JBWS-2634] refactoring momma
Added: container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
===================================================================
--- container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java (rev 0)
+++ container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:08:31 UTC (rev 9958)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.container.jboss50.deployment.metadata;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.ejb.EJB;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
+import org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver;
+
+/**
+ * EJB reference resolver.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+final class EJBBeanReferenceResolver extends AbstractReferenceResolver<EJB>
+{
+
+ /**
+ * Deployment unit used for resolving process.
+ */
+ private final DeploymentUnit unit;
+ /**
+ * Delegate used to resolve JNDI names.
+ */
+ private final EjbReferenceResolver delegate;
+
+ /**
+ * Constructor.
+ */
+ EJBBeanReferenceResolver(final DeploymentUnit unit, final EjbReferenceResolver delegate)
+ {
+ super(EJB.class);
+
+ if (unit == null)
+ {
+ throw new IllegalArgumentException("Deployment unit cannot be null");
+ }
+ if (delegate == null)
+ {
+ throw new IllegalArgumentException("Ejb reference resolver cannot be null");
+ }
+
+ this.unit = unit;
+ this.delegate = delegate;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
+ */
+ @Override
+ protected String resolveField(final Field field)
+ {
+ final EJB ejbAnnotation = field.getAnnotation(EJB.class);
+ final Class<?> type = field.getType();
+ final EjbReference reference = getEjbReference(ejbAnnotation, type);
+
+ return this.delegate.resolveEjb(unit, reference);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
+ */
+ @Override
+ protected String resolveMethod(final Method method)
+ {
+ final EJB ejbAnnotation = method.getAnnotation(EJB.class);
+ final Class<?> type = method.getParameterTypes()[0];
+ final EjbReference reference = getEjbReference(ejbAnnotation, type);
+
+ return this.delegate.resolveEjb(unit, reference);
+ }
+
+ /**
+ * Constructs EjbReference.
+ *
+ * @param ejbAnnotation ejb annotation
+ * @param type fall back type
+ * @return ejb reference instance
+ */
+ private EjbReference getEjbReference(EJB ejbAnnotation, Class<?> type)
+ {
+ String beanInterface = ejbAnnotation.beanInterface().getName();
+ if (java.lang.Object.class.getName().equals(beanInterface))
+ {
+ beanInterface = type.getName();
+ }
+ return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName());
+ }
+
+}
Modified: container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
===================================================================
--- container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:00:18 UTC (rev 9957)
+++ container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:08:31 UTC (rev 9958)
@@ -21,24 +21,31 @@
*/
package org.jboss.wsf.container.jboss50.deployment.metadata;
+import java.lang.annotation.Annotation;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.annotation.Resource;
+import javax.ejb.EJB;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.xml.ws.WebServiceProvider;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
import org.jboss.metadata.javaee.spec.EnvironmentEntriesMetaData;
import org.jboss.metadata.javaee.spec.EnvironmentEntryMetaData;
import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.wsf.common.injection.resolvers.ResourceReferenceResolver;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.DeploymentAspect;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -47,46 +54,50 @@
import org.jboss.wsf.spi.deployment.integration.WebServiceDeployment;
import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
+import org.jboss.wsf.spi.metadata.injection.ReferenceResolver;
/**
* Deployment aspect that builds injection meta data.
*
- * @author ropalka(a)redhat.com
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
*/
public final class InjectionMetaDataDeploymentAspect extends DeploymentAspect
{
+ private static final ReferenceResolver RESOURCE_REFERENCE_RESOLVER = new ResourceReferenceResolver();
private static final String EJB3_JNDI_PREFIX = "java:env/";
-
+ private EjbReferenceResolver ejbReferenceResolver;
+
@Override
public void create(Deployment dep)
{
super.create(dep);
+ DeploymentUnit unit = dep.getAttachment(DeploymentUnit.class);
+ if (unit == null)
+ throw new IllegalStateException("DeploymentUnit not found");
+
+ JBossWebMetaData webMD = dep.getAttachment(JBossWebMetaData.class);
+ if (webMD == null)
+ throw new IllegalStateException("JBossWebMetaData not found");
+
List<InjectionMetaData> injectionMD = new LinkedList<InjectionMetaData>();
+ Map<Class<? extends Annotation>, ReferenceResolver> resolvers = createResolvers(unit);
DeploymentType deploymentType = dep.getType();
try
{
if (deploymentType == DeploymentType.JAXWS_JSE)
{
- JBossWebMetaData webMD = dep.getAttachment(JBossWebMetaData.class);
- if (webMD == null)
- throw new IllegalStateException("JBossWebMetaData not found");
-
injectionMD.addAll(buildInjectionMetaData(webMD.getEnvironmentEntries()));
for (Endpoint endpoint : dep.getService().getEndpoints())
{
- InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, null);
+ InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, resolvers, null);
endpoint.addAttachment(InjectionsMetaData.class, injectionsMD);
}
}
else if (deploymentType == DeploymentType.JAXWS_EJB3)
{
- DeploymentUnit unit = dep.getAttachment(DeploymentUnit.class);
- if (unit == null)
- throw new IllegalStateException("DeploymentUnit not found");
-
JBossMetaData jbossMD = unit.getAttachment(JBossMetaData.class);
JBossEnterpriseBeansMetaData jebMDs = jbossMD.getEnterpriseBeans();
@@ -103,7 +114,7 @@
EnvironmentEntriesMetaData ejbEnvEntries = jebMDs.get(ejbName).getEnvironmentEntries();
injectionMD.addAll(buildInjectionMetaData(ejbEnvEntries));
Endpoint endpoint = dep.getService().getEndpointByName(ejbName);
- InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, ctx);
+ InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, resolvers, ctx);
endpoint.addAttachment(InjectionsMetaData.class, injectionsMD);
}
}
@@ -123,6 +134,26 @@
super.destroy(dep);
}
+ /**
+ * Builds reference resolvers container.
+ *
+ * @param unit deployment unit
+ * @return reference resolvers
+ */
+ private Map<Class<? extends Annotation>, ReferenceResolver> createResolvers(DeploymentUnit unit)
+ {
+ final Map<Class<? extends Annotation>, ReferenceResolver> resolvers = new HashMap<Class<? extends Annotation>, ReferenceResolver>();
+ resolvers.put(Resource.class, RESOURCE_REFERENCE_RESOLVER);
+ resolvers.put(EJB.class, new EJBBeanReferenceResolver(unit, getEjbReferenceResolver()));
+ return resolvers;
+ }
+
+ /**
+ * Builds JBossWS specific injection metadata from JBoss metadata.
+ *
+ * @param envEntries environment entries
+ * @return JBossWS specific injection metadata
+ */
private List<InjectionMetaData> buildInjectionMetaData(EnvironmentEntriesMetaData envEntries)
{
if ((envEntries == null) || (envEntries.size() == 0))
@@ -162,6 +193,12 @@
return retVal;
}
+ /**
+ * Returns true if EJB represents webservice endpoint, false otherwise.
+ *
+ * @param container to analyze
+ * @return true if webservice endpoint, false otherwise
+ */
private boolean isWebServiceBean(WebServiceDeclaration container)
{
boolean isWebService = container.getAnnotation(WebService.class) != null;
@@ -170,4 +207,29 @@
return isWebService || isWebServiceProvider;
}
+ /**
+ * Sets ejb reference resolver. This method is invoked by MC.
+ *
+ * @param resolver ejb reference resolver
+ */
+ public void setEjbReferenceResolver(final EjbReferenceResolver resolver)
+ {
+ this.ejbReferenceResolver = resolver;
+ }
+
+ /**
+ * Gets ejb reference resolver.
+ *
+ * @return ejb reference resolver
+ */
+ public EjbReferenceResolver getEjbReferenceResolver()
+ {
+ if (this.ejbReferenceResolver == null)
+ {
+ throw new IllegalStateException("No EjbReferenceResolver set by MC");
+ }
+
+ return this.ejbReferenceResolver;
+ }
+
}
Modified: container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java
===================================================================
--- container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java 2009-05-05 12:00:18 UTC (rev 9957)
+++ container/jboss50/branches/jboss500/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java 2009-05-05 12:08:31 UTC (rev 9958)
@@ -26,8 +26,8 @@
import javax.xml.ws.WebServiceContext;
import org.jboss.wsf.common.JavaUtils;
-import org.jboss.wsf.common.javax.JavaxAnnotationHelper;
-import org.jboss.wsf.common.javax.PreDestroyHolder;
+import org.jboss.wsf.common.injection.InjectionHelper;
+import org.jboss.wsf.common.injection.PreDestroyHolder;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -82,8 +82,8 @@
throw new IllegalStateException("Cannot get target bean instance", ex);
}
- JavaxAnnotationHelper.injectResources(targetBean, ep.getAttachment(InjectionsMetaData.class));
- JavaxAnnotationHelper.callPostConstructMethod(targetBean);
+ InjectionHelper.injectResources(targetBean, ep.getAttachment(InjectionsMetaData.class));
+ InjectionHelper.callPostConstructMethod(targetBean);
ep.addAttachment(PreDestroyHolder.class, new PreDestroyHolder(targetBean));
}
Modified: container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml
===================================================================
--- container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml 2009-05-05 12:00:18 UTC (rev 9957)
+++ container/jboss50/branches/jboss500/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml 2009-05-05 12:08:31 UTC (rev 9958)
@@ -200,6 +200,7 @@
<bean name="WSInjectionMetaDataDeploymentAspect" class="org.jboss.wsf.container.jboss50.deployment.metadata.InjectionMetaDataDeploymentAspect">
<property name="requires">WebMetaData</property>
<property name="provides">InjectionMetaData</property>
+ <property name="ejbReferenceResolver"><inject bean="org.jboss.ejb3.EjbReferenceResolver"/></property>
</bean>
<bean name="WSContextRootDeploymentAspect" class="org.jboss.wsf.framework.deployment.BackwardCompatibleContextRootDeploymentAspect">
Added: container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java
===================================================================
--- container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java (rev 0)
+++ container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/EJBBeanReferenceResolver.java 2009-05-05 12:08:31 UTC (rev 9958)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.container.jboss50.deployment.metadata;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.ejb.EJB;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.resolvers.spi.EjbReference;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
+import org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver;
+
+/**
+ * EJB reference resolver.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+final class EJBBeanReferenceResolver extends AbstractReferenceResolver<EJB>
+{
+
+ /**
+ * Deployment unit used for resolving process.
+ */
+ private final DeploymentUnit unit;
+ /**
+ * Delegate used to resolve JNDI names.
+ */
+ private final EjbReferenceResolver delegate;
+
+ /**
+ * Constructor.
+ */
+ EJBBeanReferenceResolver(final DeploymentUnit unit, final EjbReferenceResolver delegate)
+ {
+ super(EJB.class);
+
+ if (unit == null)
+ {
+ throw new IllegalArgumentException("Deployment unit cannot be null");
+ }
+ if (delegate == null)
+ {
+ throw new IllegalArgumentException("Ejb reference resolver cannot be null");
+ }
+
+ this.unit = unit;
+ this.delegate = delegate;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
+ */
+ @Override
+ protected String resolveField(final Field field)
+ {
+ final EJB ejbAnnotation = field.getAnnotation(EJB.class);
+ final Class<?> type = field.getType();
+ final EjbReference reference = getEjbReference(ejbAnnotation, type);
+
+ return this.delegate.resolveEjb(unit, reference);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.common.javax.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
+ */
+ @Override
+ protected String resolveMethod(final Method method)
+ {
+ final EJB ejbAnnotation = method.getAnnotation(EJB.class);
+ final Class<?> type = method.getParameterTypes()[0];
+ final EjbReference reference = getEjbReference(ejbAnnotation, type);
+
+ return this.delegate.resolveEjb(unit, reference);
+ }
+
+ /**
+ * Constructs EjbReference.
+ *
+ * @param ejbAnnotation ejb annotation
+ * @param type fall back type
+ * @return ejb reference instance
+ */
+ private EjbReference getEjbReference(EJB ejbAnnotation, Class<?> type)
+ {
+ String beanInterface = ejbAnnotation.beanInterface().getName();
+ if (java.lang.Object.class.getName().equals(beanInterface))
+ {
+ beanInterface = type.getName();
+ }
+ return new EjbReference(ejbAnnotation.beanName(), beanInterface, ejbAnnotation.mappedName());
+ }
+
+}
Modified: container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java
===================================================================
--- container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:00:18 UTC (rev 9957)
+++ container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/deployment/metadata/InjectionMetaDataDeploymentAspect.java 2009-05-05 12:08:31 UTC (rev 9958)
@@ -21,24 +21,31 @@
*/
package org.jboss.wsf.container.jboss50.deployment.metadata;
+import java.lang.annotation.Annotation;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.annotation.Resource;
+import javax.ejb.EJB;
import javax.jws.WebService;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.xml.ws.WebServiceProvider;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.resolvers.spi.EjbReferenceResolver;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
import org.jboss.metadata.javaee.spec.EnvironmentEntriesMetaData;
import org.jboss.metadata.javaee.spec.EnvironmentEntryMetaData;
import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.wsf.common.injection.resolvers.ResourceReferenceResolver;
import org.jboss.wsf.spi.deployment.Deployment;
import org.jboss.wsf.spi.deployment.DeploymentAspect;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -47,46 +54,50 @@
import org.jboss.wsf.spi.deployment.integration.WebServiceDeployment;
import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
+import org.jboss.wsf.spi.metadata.injection.ReferenceResolver;
/**
* Deployment aspect that builds injection meta data.
*
- * @author ropalka(a)redhat.com
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
*/
public final class InjectionMetaDataDeploymentAspect extends DeploymentAspect
{
+ private static final ReferenceResolver RESOURCE_REFERENCE_RESOLVER = new ResourceReferenceResolver();
private static final String EJB3_JNDI_PREFIX = "java:env/";
-
+ private EjbReferenceResolver ejbReferenceResolver;
+
@Override
public void create(Deployment dep)
{
super.create(dep);
+ DeploymentUnit unit = dep.getAttachment(DeploymentUnit.class);
+ if (unit == null)
+ throw new IllegalStateException("DeploymentUnit not found");
+
+ JBossWebMetaData webMD = dep.getAttachment(JBossWebMetaData.class);
+ if (webMD == null)
+ throw new IllegalStateException("JBossWebMetaData not found");
+
List<InjectionMetaData> injectionMD = new LinkedList<InjectionMetaData>();
+ Map<Class<? extends Annotation>, ReferenceResolver> resolvers = createResolvers(unit);
DeploymentType deploymentType = dep.getType();
try
{
if (deploymentType == DeploymentType.JAXWS_JSE)
{
- JBossWebMetaData webMD = dep.getAttachment(JBossWebMetaData.class);
- if (webMD == null)
- throw new IllegalStateException("JBossWebMetaData not found");
-
injectionMD.addAll(buildInjectionMetaData(webMD.getEnvironmentEntries()));
for (Endpoint endpoint : dep.getService().getEndpoints())
{
- InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, null);
+ InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, resolvers, null);
endpoint.addAttachment(InjectionsMetaData.class, injectionsMD);
}
}
else if (deploymentType == DeploymentType.JAXWS_EJB3)
{
- DeploymentUnit unit = dep.getAttachment(DeploymentUnit.class);
- if (unit == null)
- throw new IllegalStateException("DeploymentUnit not found");
-
JBossMetaData jbossMD = unit.getAttachment(JBossMetaData.class);
JBossEnterpriseBeansMetaData jebMDs = jbossMD.getEnterpriseBeans();
@@ -103,7 +114,7 @@
EnvironmentEntriesMetaData ejbEnvEntries = jebMDs.get(ejbName).getEnvironmentEntries();
injectionMD.addAll(buildInjectionMetaData(ejbEnvEntries));
Endpoint endpoint = dep.getService().getEndpointByName(ejbName);
- InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, ctx);
+ InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD, resolvers, ctx);
endpoint.addAttachment(InjectionsMetaData.class, injectionsMD);
}
}
@@ -123,6 +134,26 @@
super.destroy(dep);
}
+ /**
+ * Builds reference resolvers container.
+ *
+ * @param unit deployment unit
+ * @return reference resolvers
+ */
+ private Map<Class<? extends Annotation>, ReferenceResolver> createResolvers(DeploymentUnit unit)
+ {
+ final Map<Class<? extends Annotation>, ReferenceResolver> resolvers = new HashMap<Class<? extends Annotation>, ReferenceResolver>();
+ resolvers.put(Resource.class, RESOURCE_REFERENCE_RESOLVER);
+ resolvers.put(EJB.class, new EJBBeanReferenceResolver(unit, getEjbReferenceResolver()));
+ return resolvers;
+ }
+
+ /**
+ * Builds JBossWS specific injection metadata from JBoss metadata.
+ *
+ * @param envEntries environment entries
+ * @return JBossWS specific injection metadata
+ */
private List<InjectionMetaData> buildInjectionMetaData(EnvironmentEntriesMetaData envEntries)
{
if ((envEntries == null) || (envEntries.size() == 0))
@@ -162,6 +193,12 @@
return retVal;
}
+ /**
+ * Returns true if EJB represents webservice endpoint, false otherwise.
+ *
+ * @param container to analyze
+ * @return true if webservice endpoint, false otherwise
+ */
private boolean isWebServiceBean(WebServiceDeclaration container)
{
boolean isWebService = container.getAnnotation(WebService.class) != null;
@@ -170,4 +207,29 @@
return isWebService || isWebServiceProvider;
}
+ /**
+ * Sets ejb reference resolver. This method is invoked by MC.
+ *
+ * @param resolver ejb reference resolver
+ */
+ public void setEjbReferenceResolver(final EjbReferenceResolver resolver)
+ {
+ this.ejbReferenceResolver = resolver;
+ }
+
+ /**
+ * Gets ejb reference resolver.
+ *
+ * @return ejb reference resolver
+ */
+ public EjbReferenceResolver getEjbReferenceResolver()
+ {
+ if (this.ejbReferenceResolver == null)
+ {
+ throw new IllegalStateException("No EjbReferenceResolver set by MC");
+ }
+
+ return this.ejbReferenceResolver;
+ }
+
}
Modified: container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java
===================================================================
--- container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java 2009-05-05 12:00:18 UTC (rev 9957)
+++ container/jboss50/branches/jboss501/src/main/java/org/jboss/wsf/container/jboss50/invocation/InvocationHandlerJSE.java 2009-05-05 12:08:31 UTC (rev 9958)
@@ -26,8 +26,8 @@
import javax.xml.ws.WebServiceContext;
import org.jboss.wsf.common.JavaUtils;
-import org.jboss.wsf.common.javax.JavaxAnnotationHelper;
-import org.jboss.wsf.common.javax.PreDestroyHolder;
+import org.jboss.wsf.common.injection.InjectionHelper;
+import org.jboss.wsf.common.injection.PreDestroyHolder;
import org.jboss.wsf.spi.SPIProvider;
import org.jboss.wsf.spi.SPIProviderResolver;
import org.jboss.wsf.spi.deployment.Endpoint;
@@ -82,8 +82,8 @@
throw new IllegalStateException("Cannot get target bean instance", ex);
}
- JavaxAnnotationHelper.injectResources(targetBean, ep.getAttachment(InjectionsMetaData.class));
- JavaxAnnotationHelper.callPostConstructMethod(targetBean);
+ InjectionHelper.injectResources(targetBean, ep.getAttachment(InjectionsMetaData.class));
+ InjectionHelper.callPostConstructMethod(targetBean);
ep.addAttachment(PreDestroyHolder.class, new PreDestroyHolder(targetBean));
}
Modified: container/jboss50/branches/jboss501/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml
===================================================================
--- container/jboss50/branches/jboss501/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml 2009-05-05 12:00:18 UTC (rev 9957)
+++ container/jboss50/branches/jboss501/src/main/resources/jbossws-jboss50.deployer/META-INF/jbossws-deployer-jboss-beans.xml 2009-05-05 12:08:31 UTC (rev 9958)
@@ -200,6 +200,7 @@
<bean name="WSInjectionMetaDataDeploymentAspect" class="org.jboss.wsf.container.jboss50.deployment.metadata.InjectionMetaDataDeploymentAspect">
<property name="requires">WebMetaData</property>
<property name="provides">InjectionMetaData</property>
+ <property name="ejbReferenceResolver"><inject bean="org.jboss.ejb3.EjbReferenceResolver"/></property>
</bean>
<bean name="WSContextRootDeploymentAspect" class="org.jboss.wsf.framework.deployment.BackwardCompatibleContextRootDeploymentAspect">
15 years, 7 months
JBossWS SVN: r9957 - in framework/trunk/src/main/java/org/jboss/wsf/framework: invocation and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 08:00:18 -0400 (Tue, 05 May 2009)
New Revision: 9957
Modified:
framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java
framework/trunk/src/main/java/org/jboss/wsf/framework/invocation/WebServiceContextInjector.java
Log:
[JBWS-2074][JBWS-2634] refactoring momma
Modified: framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java
===================================================================
--- framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java 2009-05-05 11:58:55 UTC (rev 9956)
+++ framework/trunk/src/main/java/org/jboss/wsf/framework/deployment/DefaultEndpoint.java 2009-05-05 12:00:18 UTC (rev 9957)
@@ -28,7 +28,7 @@
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
-import org.jboss.wsf.common.javax.PreDestroyHolder;
+import org.jboss.wsf.common.injection.PreDestroyHolder;
import org.jboss.wsf.spi.deployment.AbstractExtensible;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.deployment.LifecycleHandler;
Modified: framework/trunk/src/main/java/org/jboss/wsf/framework/invocation/WebServiceContextInjector.java
===================================================================
--- framework/trunk/src/main/java/org/jboss/wsf/framework/invocation/WebServiceContextInjector.java 2009-05-05 11:58:55 UTC (rev 9956)
+++ framework/trunk/src/main/java/org/jboss/wsf/framework/invocation/WebServiceContextInjector.java 2009-05-05 12:00:18 UTC (rev 9957)
@@ -23,7 +23,7 @@
import javax.xml.ws.WebServiceContext;
-import org.jboss.wsf.common.javax.JavaxAnnotationHelper;
+import org.jboss.wsf.common.injection.InjectionHelper;
import org.jboss.wsf.spi.invocation.ResourceInjector;
/**
@@ -36,6 +36,6 @@
{
public void inject(Object instance, WebServiceContext context)
{
- JavaxAnnotationHelper.injectWebServiceContext(instance, context);
+ InjectionHelper.injectWebServiceContext(instance, context);
}
}
15 years, 7 months
JBossWS SVN: r9956 - in common/trunk/src/main/java/org/jboss/wsf/common: injection and 2 other directories.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 07:58:55 -0400 (Tue, 05 May 2009)
New Revision: 9956
Added:
common/trunk/src/main/java/org/jboss/wsf/common/injection/
common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java
common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java
Removed:
common/trunk/src/main/java/org/jboss/wsf/common/javax/
Log:
[JBWS-2074][JBWS-2634] refactoring momma
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionException.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Represents generic injection error.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public class InjectionException extends RuntimeException
+{
+
+ /**
+ * Serial version UID.
+ */
+ private static final long serialVersionUID = 1L;
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = Logger.getLogger(InjectionException.class);
+
+ /**
+ * Constructor.
+ */
+ public InjectionException()
+ {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ */
+ public InjectionException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param cause
+ */
+ public InjectionException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param message
+ * @param cause
+ */
+ public InjectionException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ /**
+ * Rethrows Injection exception that will wrap passed reason.
+ *
+ * @param reason to wrap.
+ */
+ public static void rethrow(final Exception reason)
+ {
+ rethrow(null, reason);
+ }
+
+ /**
+ * Rethrows Injection exception that will wrap passed reason.
+ *
+ * @param message custom message
+ * @param reason to wrap.
+ */
+ public static void rethrow(final String message, final Exception reason)
+ {
+ if (reason == null)
+ {
+ throw new IllegalArgumentException("Reason expected");
+ }
+
+ LOG.error(message == null ? reason.getMessage() : message, reason);
+ throw new InjectionException(message, reason);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/InjectionHelper.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,522 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.wsf.common.injection.finders.EJBFieldFinder;
+import org.jboss.wsf.common.injection.finders.EJBMethodFinder;
+import org.jboss.wsf.common.injection.finders.InjectionFieldFinder;
+import org.jboss.wsf.common.injection.finders.InjectionMethodFinder;
+import org.jboss.wsf.common.injection.finders.PostConstructMethodFinder;
+import org.jboss.wsf.common.injection.finders.PreDestroyMethodFinder;
+import org.jboss.wsf.common.injection.finders.ResourceFieldFinder;
+import org.jboss.wsf.common.injection.finders.ResourceMethodFinder;
+import org.jboss.wsf.common.reflection.ClassProcessor;
+import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
+import org.jboss.wsf.spi.metadata.injection.InjectionsMetaData;
+import org.jboss.wsf.spi.metadata.injection.ReferenceResolver;
+
+/**
+ * An injection helper class for <b>javax.*</b> annotations.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class InjectionHelper
+{
+
+ private static final Logger LOG = Logger.getLogger(InjectionHelper.class);
+ private static final String POJO_JNDI_PREFIX = "java:comp/env/";
+
+ private static final ClassProcessor<Method> POST_CONSTRUCT_METHOD_FINDER = new PostConstructMethodFinder();
+ private static final ClassProcessor<Method> PRE_DESTROY_METHOD_FINDER = new PreDestroyMethodFinder();
+ private static final ClassProcessor<Method> RESOURCE_METHOD_FINDER = new ResourceMethodFinder(WebServiceContext.class, false);
+ private static final ClassProcessor<Field> RESOURCE_FIELD_FINDER = new ResourceFieldFinder(WebServiceContext.class, false);
+ private static final ClassProcessor<Method> EJB_METHOD_FINDER = new EJBMethodFinder();
+ private static final ClassProcessor<Field> EJB_FIELD_FINDER = new EJBFieldFinder();
+ private static final ClassProcessor<Method> WEB_SERVICE_CONTEXT_METHOD_FINDER = new ResourceMethodFinder(WebServiceContext.class, true);
+ private static final ClassProcessor<Field> WEB_SERVICE_CONTEXT_FIELD_FINDER = new ResourceFieldFinder(WebServiceContext.class, true);
+
+ /**
+ * Forbidden constructor.
+ */
+ private InjectionHelper()
+ {
+ super();
+ }
+
+ /**
+ * The resource annotations mark resources that are needed by the application. These annotations may be applied
+ * to an application component class, or to fields or methods of the component class. When the annotation is
+ * applied to a field or method, the container will inject an instance of the requested resource into the
+ * application component when the component is initialized. If the annotation is applied to the component class,
+ * the annotation declares a resource that the application will look up at runtime.
+ *
+ * This method handles the following injection types:
+ * <ul>
+ * <li>Descriptor specified injections</li>
+ * <li>@Resource annotated methods and fields</li>
+ * <li>@EJB annotated methods and fields</li>
+ * </ul>
+ *
+ * @param instance to inject resources on
+ * @param injections injections metadata
+ * @see javax.annotation.Resource
+ * @see javax.ejb.EJB
+ */
+ public static void injectResources(final Object instance, final InjectionsMetaData injections)
+ {
+ if (instance == null)
+ throw new IllegalArgumentException("Object instance cannot be null");
+
+ if (injections == null)
+ return;
+
+ final Context ctx = getContext(injections);
+
+ // inject descriptor driven annotations
+ final Collection<InjectionMetaData> injectionMDs = injections.getInjectionsMetaData(instance.getClass());
+ for (InjectionMetaData injectionMD : injectionMDs)
+ {
+ injectDescriptorAnnotatedAccessibleObjects(instance, ctx, injectionMD);
+ }
+
+ // inject @Resource annotated methods and fields
+ injectResourceAnnotatedAccessibleObjects(instance, ctx, injections);
+
+ // inject @EJB annotated methods and fields
+ injectEJBAnnotatedAccessibleObjects(instance, ctx, injections);
+ }
+
+ /**
+ * Injects @Resource annotated accessible objects referencing WebServiceContext.
+ *
+ * @param instance to operate on
+ * @param ctx current web service context
+ */
+ public static void injectWebServiceContext(final Object instance, final WebServiceContext ctx)
+ {
+ final Class<?> instanceClass = instance.getClass();
+
+ // inject @Resource annotated methods accepting WebServiceContext parameter
+ Collection<Method> resourceAnnotatedMethods = WEB_SERVICE_CONTEXT_METHOD_FINDER.process(instanceClass);
+ for(Method method : resourceAnnotatedMethods)
+ {
+ try
+ {
+ invokeMethod(instance, method, new Object[] {ctx});
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject @Resource annotated method: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ // inject @Resource annotated fields of WebServiceContext type
+ final Collection<Field> resourceAnnotatedFields = WEB_SERVICE_CONTEXT_FIELD_FINDER.process(instanceClass);
+ for (Field field : resourceAnnotatedFields)
+ {
+ try
+ {
+ setField(instance, field, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject @Resource annotated field: " + field;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Calls @PostConstruct annotated method if exists.
+ *
+ * @param instance to invoke @PostConstruct annotated method on
+ * @see org.jboss.wsf.common.injection.finders.PostConstructMethodFinder
+ * @see javax.annotation.PostConstruct
+ */
+ public static void callPostConstructMethod(final Object instance)
+ {
+ if (instance == null)
+ throw new IllegalArgumentException("Object instance cannot be null");
+
+ Collection<Method> methods = POST_CONSTRUCT_METHOD_FINDER.process(instance.getClass());
+
+ if (methods.size() > 0)
+ {
+ Method method = methods.iterator().next();
+ LOG.debug("Calling @PostConstruct annotated method: " + method);
+ try
+ {
+ invokeMethod(instance, method, null);
+ }
+ catch (Exception e)
+ {
+ final String message = "Calling of @PostConstruct annotated method failed: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Calls @PreDestroy annotated method if exists.
+ *
+ * @param instance to invoke @PreDestroy annotated method on
+ * @see org.jboss.wsf.common.injection.finders.PreDestroyMethodFinder
+ * @see javax.annotation.PreDestroy
+ */
+ public static void callPreDestroyMethod(final Object instance)
+ {
+ if (instance == null)
+ throw new IllegalArgumentException("Object instance cannot be null");
+
+ Collection<Method> methods = PRE_DESTROY_METHOD_FINDER.process(instance.getClass());
+
+ if (methods.size() > 0)
+ {
+ Method method = methods.iterator().next();
+ LOG.debug("Calling @PreDestroy annotated method: " + method);
+ try
+ {
+ invokeMethod(instance, method, null);
+ }
+ catch (Exception e)
+ {
+ final String message = "Calling of @PreDestroy annotated method failed: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Gets JNDI context.
+ *
+ * @param injections injection metadata to get context from.
+ * @return JNDI context
+ */
+ private static Context getContext(final InjectionsMetaData injections)
+ {
+ final Context ctx = injections.getContext();
+ if (ctx == null)
+ {
+ try
+ {
+ return (Context)new InitialContext().lookup(POJO_JNDI_PREFIX);
+ }
+ catch (NamingException ne)
+ {
+ InjectionException.rethrow("Cannot lookup JNDI context: " + POJO_JNDI_PREFIX, ne);
+ }
+ }
+
+ return ctx;
+ }
+
+ /**
+ * Performs descriptor driven injections.
+ *
+ * @param instance to operate on
+ * @param ctx JNDI context
+ * @param injectionMD injections metadata
+ */
+ private static void injectDescriptorAnnotatedAccessibleObjects(final Object instance, final Context ctx, final InjectionMetaData injectionMD)
+ {
+ final Method method = getMethod(injectionMD, instance.getClass());
+ if (method != null)
+ {
+ try
+ {
+ inject(instance, method, injectionMD.getEnvEntryName(), ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject method (descriptor driven injection): " + injectionMD;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ else
+ {
+ final Field field = getField(injectionMD, instance.getClass());
+ if (field != null)
+ {
+ try
+ {
+ inject(instance, field, injectionMD.getEnvEntryName(), ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject field (descriptor driven injection): " + injectionMD;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ else
+ {
+ final String message = "Cannot find injection target for: " + injectionMD;
+ throw new InjectionException(message);
+ }
+ }
+ }
+
+ /**
+ * Injects @Resource annotated accessible objects.
+ *
+ * @param instance to operate on
+ * @param ctx JNDI context
+ * @param injections injections meta data
+ */
+ private static void injectResourceAnnotatedAccessibleObjects(final Object instance, final Context ctx, final InjectionsMetaData injections)
+ {
+ final ReferenceResolver referenceResolver = injections.getResolver(Resource.class);
+
+ // Inject @Resource annotated fields
+ final Collection<Field> resourceAnnotatedFields = RESOURCE_FIELD_FINDER.process(instance.getClass());
+ for (Field field : resourceAnnotatedFields)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(field);
+ inject(instance, field, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject field annotated with @Resource annotation: " + field;
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ // Inject @Resource annotated methods
+ final Collection<Method> resourceAnnotatedMethods = RESOURCE_METHOD_FINDER.process(instance.getClass());
+ for(Method method : resourceAnnotatedMethods)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(method);
+ inject(instance, method, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject method annotated with @Resource annotation: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Injects @EJB annotated accessible objects.
+ *
+ * @param instance to operate on
+ * @param ctx JNDI context
+ * @param injections injections meta data
+ */
+ private static void injectEJBAnnotatedAccessibleObjects(final Object instance, final Context ctx, final InjectionsMetaData injections)
+ {
+ final ReferenceResolver referenceResolver = injections.getResolver(EJB.class);
+
+ // Inject @EJB annotated fields
+ final Collection<Field> ejbAnnotatedFields = EJB_FIELD_FINDER.process(instance.getClass());
+ for (Field field : ejbAnnotatedFields)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(field);
+ inject(instance, field, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject field annotated with @EJB annotation: " + field;
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ // Inject @EJB annotated methods
+ final Collection<Method> ejbAnnotatedMethods = EJB_METHOD_FINDER.process(instance.getClass());
+ for(Method method : ejbAnnotatedMethods)
+ {
+ try
+ {
+ final String jndiName = referenceResolver.resolve(method);
+ inject(instance, method, jndiName, ctx);
+ }
+ catch (Exception e)
+ {
+ final String message = "Cannot inject method annotated with @EJB annotation: " + method;
+ InjectionException.rethrow(message, e);
+ }
+ }
+ }
+
+ /**
+ * Injects @Resource annotated method.
+ *
+ * @param instance to invoke method on
+ * @param method to invoke
+ * @param resourceName resource name
+ * @param cxt JNDI context
+ * @see org.jboss.wsf.common.injection.finders.ResourceMethodFinder
+ */
+ private static void inject(final Object instance, final Method method, final String jndiName, final Context ctx)
+ {
+ final Object value = lookup(jndiName, ctx);
+ LOG.debug("Injecting method: " + method);
+ invokeMethod(instance, method, new Object[] {value});
+ }
+
+ /**
+ * Injects @Resource annotated field.
+ *
+ * @param field to set
+ * @param instance to modify field on
+ * @param resourceName resource name
+ * @param cxt JNDI context
+ * @see org.jboss.wsf.common.injection.finders.ResourceFieldFinder
+ */
+ private static void inject(final Object instance, final Field field, final String jndiName, final Context ctx)
+ {
+ final Object value = lookup(jndiName, ctx);
+ LOG.debug("Injecting field: " + field);
+ setField(instance, field, value);
+ }
+
+ /**
+ * Lookups object in JNDI namespace.
+ *
+ * @param jndiName jndi name
+ * @param ctx context to use
+ * @return Object if found
+ */
+ private static Object lookup(final String jndiName, final Context ctx)
+ {
+ Object value = null;
+ try
+ {
+ value = ctx.lookup(jndiName);
+ }
+ catch (NamingException ne)
+ {
+ try
+ {
+ value = new InitialContext().lookup(jndiName);
+ }
+ catch (Exception e)
+ {
+ final String message = "Resource '" + jndiName + "' not found";
+ InjectionException.rethrow(message, e);
+ }
+ }
+
+ return value;
+ }
+
+ /**
+ * Invokes method on object with specified arguments.
+ *
+ * @param instance to invoke method on
+ * @param method method to invoke
+ * @param args arguments to pass
+ */
+ private static void invokeMethod(final Object instance, final Method method, final Object[] args)
+ {
+ boolean accessability = method.isAccessible();
+
+ try
+ {
+ method.setAccessible(true);
+ method.invoke(instance, args);
+ }
+ catch (Exception e)
+ {
+ InjectionException.rethrow(e);
+ }
+ finally
+ {
+ method.setAccessible(accessability);
+ }
+ }
+
+ /**
+ * Sets field on object with specified value.
+ *
+ * @param instance to set field on
+ * @param field to set
+ * @param value to be set
+ */
+ private static void setField(final Object instance, final Field field, final Object value)
+ {
+ boolean accessability = field.isAccessible();
+
+ try
+ {
+ field.setAccessible(true);
+ field.set(instance, value);
+ }
+ catch (Exception e)
+ {
+ InjectionException.rethrow(e);
+ }
+ finally
+ {
+ field.setAccessible(accessability);
+ }
+ }
+
+ /**
+ * Returns method that matches the descriptor injection metadata or null if not found.
+ *
+ * @param injectionMD descriptor injection metadata
+ * @param clazz to process
+ * @return method that matches the criteria or null if not found
+ * @see org.jboss.wsf.common.injection.finders.InjectionMethodFinder
+ */
+ private static Method getMethod(final InjectionMetaData injectionMD, final Class<?> clazz)
+ {
+ final Collection<Method> result = new InjectionMethodFinder(injectionMD).process(clazz);
+
+ return result.isEmpty() ? null : result.iterator().next();
+ }
+
+ /**
+ * Returns field that matches the descriptor injection metadata or null if not found.
+ *
+ * @param injectionMD descriptor injection metadata
+ * @param clazz to process
+ * @return field that matches the criteria or null if not found
+ * @see org.jboss.wsf.common.injection.finders.InjectionFieldFinder
+ */
+ private static Field getField(final InjectionMetaData injectionMD, final Class<?> clazz)
+ {
+ final Collection<Field> result = new InjectionFieldFinder(injectionMD).process(clazz);
+
+ return result.isEmpty() ? null : result.iterator().next();
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/PreDestroyHolder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, 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.wsf.common.injection;
+
+/**
+ * Utility class for pre destroy registration.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class PreDestroyHolder
+{
+ private final Object object;
+ private final int hashCode;
+
+ public PreDestroyHolder(Object object)
+ {
+ super();
+ this.hashCode = System.identityHashCode(object);
+ this.object = object;
+ }
+
+ public final Object getObject()
+ {
+ return this.object;
+ }
+
+ public final boolean equals(Object o)
+ {
+ if (o instanceof PreDestroyHolder)
+ {
+ return ((PreDestroyHolder)o).hashCode == this.hashCode;
+ }
+
+ return false;
+ }
+
+ public final int hashCode()
+ {
+ return this.hashCode;
+ }
+
+}
\ No newline at end of file
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/AbstractPostConstructPreDestroyAnnotatedMethodFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import org.jboss.wsf.common.reflection.AnnotatedMethodFinder;
+
+/**
+ * Abstract @PostConstruct and @PreDestroy annotations method finder.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+abstract class AbstractPostConstructPreDestroyAnnotatedMethodFinder<A extends Annotation>
+extends AnnotatedMethodFinder<A>
+{
+
+ /**
+ * Constructor.
+ *
+ * @param annotationClass annotation.
+ */
+ AbstractPostConstructPreDestroyAnnotatedMethodFinder(final Class<A> annotationClass)
+ {
+ super(annotationClass);
+ }
+
+ @Override
+ public void validate(final Collection<Method> methods)
+ {
+ super.validate(methods);
+
+ // Ensure all methods preconditions
+ ReflectionUtils.assertOnlyOneMethod(methods, getAnnotation());
+ }
+
+ @Override
+ public void validate(final Method method)
+ {
+ super.validate(method);
+
+ // Ensure all method preconditions
+ Class<A> annotation = getAnnotation();
+ ReflectionUtils.assertNoParameters(method, annotation);
+ ReflectionUtils.assertVoidReturnType(method, annotation);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method, annotation);
+ ReflectionUtils.assertNotStatic(method, annotation);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBFieldFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.reflect.Field;
+
+import javax.ejb.EJB;
+
+import org.jboss.wsf.common.reflection.AnnotatedFieldFinder;
+
+/**
+ * Field based EJB injection.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class EJBFieldFinder
+extends AnnotatedFieldFinder<EJB>
+{
+
+ /**
+ * Constructor.
+ */
+ public EJBFieldFinder()
+ {
+ super(EJB.class);
+ }
+
+ @Override
+ public void validate(Field field)
+ {
+ super.validate(field);
+
+ // Ensure all method preconditions
+ Class<EJB> annotation = getAnnotation();
+ ReflectionUtils.assertNotVoidType(field, annotation);
+ ReflectionUtils.assertNotStatic(field, annotation);
+ ReflectionUtils.assertNotFinal(field, annotation);
+ ReflectionUtils.assertNotPrimitiveType(field, annotation);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/EJBMethodFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,62 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.reflect.Method;
+
+import javax.ejb.EJB;
+
+import org.jboss.wsf.common.reflection.AnnotatedMethodFinder;
+
+/**
+ * Setter based EJB injection.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class EJBMethodFinder
+extends AnnotatedMethodFinder<EJB>
+{
+
+ /**
+ * Constructor.
+ */
+ public EJBMethodFinder()
+ {
+ super(EJB.class);
+ }
+
+ @Override
+ public void validate(Method method)
+ {
+ super.validate(method);
+
+ // Ensure all method preconditions
+ Class<EJB> annotation = getAnnotation();
+ ReflectionUtils.assertVoidReturnType(method, annotation);
+ ReflectionUtils.assertOneParameter(method, annotation);
+ ReflectionUtils.assertNoPrimitiveParameters(method, annotation);
+ ReflectionUtils.assertValidSetterName(method, annotation);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method, annotation);
+ ReflectionUtils.assertNotStatic(method, annotation);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionFieldFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+
+import org.jboss.wsf.common.injection.InjectionException;
+import org.jboss.wsf.common.reflection.FieldFinder;
+import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
+
+/**
+ * Lookups field that matches descriptor specified injection metadata.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class InjectionFieldFinder
+extends FieldFinder
+{
+
+ /**
+ * Descriptor injection metadata.
+ */
+ private final InjectionMetaData injectionMD;
+
+ /**
+ * Constructor.
+ *
+ * @param injectionMD descriptor injection metadata
+ */
+ public InjectionFieldFinder(final InjectionMetaData injectionMD)
+ {
+ if (injectionMD == null)
+ throw new IllegalArgumentException("Injection metadata cannot be null");
+
+ this.injectionMD = injectionMD;
+ }
+
+ @Override
+ public boolean matches(final Field field)
+ {
+ if (field.getName().equals(injectionMD.getTargetName()))
+ {
+ if (injectionMD.getValueClass() != null)
+ {
+ final Class<?> expectedClass = injectionMD.getValueClass();
+ final Class<?> fieldClass = field.getType();
+
+ return expectedClass.equals(fieldClass);
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void validate(final Collection<Field> fields)
+ {
+ super.validate(fields);
+
+ if (fields.size() > 2)
+ {
+ throw new InjectionException("More than one field found matching the criteria: " + injectionMD);
+ }
+ }
+
+ @Override
+ public void validate(final Field field)
+ {
+ super.validate(field);
+
+ ReflectionUtils.assertNotVoidType(field);
+ ReflectionUtils.assertNotStatic(field);
+ ReflectionUtils.assertNotFinal(field);
+ ReflectionUtils.assertNotPrimitiveType(field);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/InjectionMethodFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.reflect.Method;
+import java.util.Collection;
+
+import org.jboss.wsf.common.injection.InjectionException;
+import org.jboss.wsf.common.reflection.MethodFinder;
+import org.jboss.wsf.spi.metadata.injection.InjectionMetaData;
+
+/**
+ * Lookups method that matches descriptor specified injection metadata.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class InjectionMethodFinder
+extends MethodFinder
+{
+
+ /**
+ * Descriptor injection metadata.
+ */
+ private final InjectionMetaData injectionMD;
+
+ /**
+ * Constructor.
+ *
+ * @param injectionMD descriptor injection metadata
+ */
+ public InjectionMethodFinder(final InjectionMetaData injectionMD)
+ {
+ if (injectionMD == null)
+ throw new IllegalArgumentException("Injection metadata cannot be null");
+
+ this.injectionMD = injectionMD;
+ }
+
+ @Override
+ public boolean matches(final Method method)
+ {
+ if (method.getName().equals(injectionMD.getTargetName()))
+ {
+ if (injectionMD.getValueClass() != null)
+ {
+ if (method.getParameterTypes().length == 1)
+ {
+ final Class<?> expectedClass = injectionMD.getValueClass();
+ final Class<?> parameterClass = method.getParameterTypes()[0];
+
+ return expectedClass.equals(parameterClass);
+ }
+ }
+ else
+ {
+ if (method.getParameterTypes().length == 1)
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void validate(final Collection<Method> methods)
+ {
+ super.validate(methods);
+
+ if (methods.size() > 2)
+ {
+ throw new InjectionException("More than one method found matching the criteria: " + injectionMD);
+ }
+ }
+
+ @Override
+ public void validate(final Method method)
+ {
+ super.validate(method);
+
+ ReflectionUtils.assertVoidReturnType(method);
+ ReflectionUtils.assertOneParameter(method);
+ ReflectionUtils.assertNoPrimitiveParameters(method);
+ ReflectionUtils.assertValidSetterName(method);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method);
+ ReflectionUtils.assertNotStatic(method);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PostConstructMethodFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * @PostConstruct method finder.
+ *
+ * The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done
+ * to perform any initialization. This method MUST be invoked before the class is put into service. This annotation
+ * MUST be supported on all classes that support dependency injection. The method annotated with PostConstruct MUST
+ * be invoked even if the class does not request any resources to be injected. Only one method can be annotated with
+ * this annotation. The method on which the PostConstruct annotation is applied MUST fulfill all of the following criteria:
+ * <ul>
+ * <li>The method MUST NOT have any parameters.
+ * <li>The return type of the method MUST be void.
+ * <li>The method MUST NOT throw a checked exception.
+ * <li>The method on which PostConstruct is applied MAY be public, protected, package private or private.
+ * <li>The method MUST NOT be static.
+ * <li>The method MAY be final.
+ * <li>If the method throws an unchecked exception the class MUST NOT be put into service.
+ * </ul>
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class PostConstructMethodFinder
+extends AbstractPostConstructPreDestroyAnnotatedMethodFinder<PostConstruct>
+{
+
+ /**
+ * Constructor.
+ */
+ public PostConstructMethodFinder()
+ {
+ super(PostConstruct.class);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/PreDestroyMethodFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import javax.annotation.PreDestroy;
+
+/**
+ * @PreDestroy method finder.
+ *
+ * The PreDestroy annotation is used on methods as a callback notification to signal that the instance
+ * is in the process of being removed by the container. The method annotated with PreDestroy is typically
+ * used to release resources that it has been holding. This annotation MUST be supported by all container
+ * managed objects that support PostConstruct except the application client container in Java EE 5.
+ * The method on which the PreDestroy annotation is applied MUST fulfill all of the following criteria:
+ * <ul>
+ * <li>The method MUST NOT have any parameters.
+ * <li>The return type of the method MUST be void.
+ * <li>The method MUST NOT throw a checked exception.
+ * <li>The method on which PreDestroy is applied MAY be public, protected, package private or private.
+ * <li>The method MUST NOT be static.
+ * <li>The method MAY be final.
+ * <li>If the method throws an unchecked exception it is ignored.
+ * </ul>
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class PreDestroyMethodFinder
+extends AbstractPostConstructPreDestroyAnnotatedMethodFinder<PreDestroy>
+{
+
+ /**
+ * Constructor.
+ */
+ public PreDestroyMethodFinder()
+ {
+ super(PreDestroy.class);
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ReflectionUtils.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,360 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+
+import org.jboss.wsf.common.injection.InjectionException;
+
+/**
+ * Reflection utility class.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+final class ReflectionUtils
+{
+
+ /**
+ * Constructor.
+ */
+ private ReflectionUtils()
+ {
+ super();
+ }
+
+ /**
+ * Asserts method don't declare primitive parameters.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNoPrimitiveParameters(final Method method, Class<? extends Annotation> annotation)
+ {
+ for (Class<?> type : method.getParameterTypes())
+ {
+ if (type.isPrimitive())
+ {
+ throw new InjectionException("Method " + getAnnotationMessage(annotation) + "can't declare primitive parameters: " + method);
+ }
+ }
+ }
+
+ /**
+ * Asserts method don't declare primitive parameters.
+ *
+ * @param method to validate
+ */
+ public static void assertNoPrimitiveParameters(final Method method)
+ {
+ assertNoPrimitiveParameters(method, null);
+ }
+
+ /**
+ * Asserts field is not of primitive type.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotPrimitiveType(final Field field, Class<? extends Annotation> annotation)
+ {
+ if (field.getType().isPrimitive())
+ {
+ throw new InjectionException("Field " + getAnnotationMessage(annotation) + "can't be of primitive type: " + field);
+ }
+ }
+
+ /**
+ * Asserts field is not of primitive type.
+ *
+ * @param method to validate
+ */
+ public static void assertNotPrimitiveType(final Field field)
+ {
+ assertNotPrimitiveType(field, null);
+ }
+
+ /**
+ * Asserts method have no parameters.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNoParameters(final Method method, Class<? extends Annotation> annotation)
+ {
+ if (method.getParameterTypes().length != 0)
+ {
+ throw new InjectionException("Method " + getAnnotationMessage(annotation) + "have to have no parameters: " + method);
+ }
+ }
+
+ /**
+ * Asserts method have no parameters.
+ *
+ * @param method to validate
+ */
+ public static void assertNoParameters(final Method method)
+ {
+ assertNoParameters(method, null);
+ }
+
+ /**
+ * Asserts method return void.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertVoidReturnType(final Method method, Class<? extends Annotation> annotation)
+ {
+ if ((!method.getReturnType().equals(Void.class)) && (!method.getReturnType().equals(Void.TYPE)))
+ {
+ throw new InjectionException("Method " + getAnnotationMessage(annotation) + "have to return void: " + method);
+ }
+ }
+
+ /**
+ * Asserts method return void.
+ *
+ * @param method to validate
+ */
+ public static void assertVoidReturnType(final Method method)
+ {
+ assertVoidReturnType(method, null);
+ }
+
+ /**
+ * Asserts field isn't of void type.
+ *
+ * @param field to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotVoidType(final Field field, Class<? extends Annotation> annotation)
+ {
+ if ((field.getClass().equals(Void.class)) && (field.getClass().equals(Void.TYPE)))
+ {
+ throw new InjectionException("Field " + getAnnotationMessage(annotation) + "cannot be of void type: " + field);
+ }
+ }
+
+ /**
+ * Asserts field isn't of void type.
+ *
+ * @param field to validate
+ */
+ public static void assertNotVoidType(final Field field)
+ {
+ assertNotVoidType(field, null);
+ }
+
+ /**
+ * Asserts method don't throw checked exceptions.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNoCheckedExceptionsAreThrown(final Method method, Class<? extends Annotation> annotation)
+ {
+ Class<?>[] declaredExceptions = method.getExceptionTypes();
+ for (int i = 0; i < declaredExceptions.length; i++)
+ {
+ Class<?> exception = declaredExceptions[i];
+ if (!exception.isAssignableFrom(RuntimeException.class))
+ {
+ throw new InjectionException("Method " + getAnnotationMessage(annotation) + "cannot throw checked exceptions: " + method);
+ }
+ }
+ }
+
+ /**
+ * Asserts method don't throw checked exceptions.
+ *
+ * @param method to validate
+ */
+ public static void assertNoCheckedExceptionsAreThrown(final Method method)
+ {
+ assertNoCheckedExceptionsAreThrown(method, null);
+ }
+
+ /**
+ * Asserts method is not static.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotStatic(final Method method, Class<? extends Annotation> annotation)
+ {
+ if (Modifier.isStatic(method.getModifiers()))
+ {
+ throw new InjectionException("Method " + getAnnotationMessage(annotation) + "cannot be static: " + method);
+ }
+ }
+
+ /**
+ * Asserts method is not static.
+ *
+ * @param method to validate
+ */
+ public static void assertNotStatic(final Method method)
+ {
+ assertNotStatic(method, null);
+ }
+
+ /**
+ * Asserts field is not static.
+ *
+ * @param field to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotStatic(final Field field, Class<? extends Annotation> annotation)
+ {
+ if (Modifier.isStatic(field.getModifiers()))
+ {
+ throw new InjectionException("Field " + getAnnotationMessage(annotation) + "cannot be static: " + field);
+ }
+ }
+
+ /**
+ * Asserts field is not static.
+ *
+ * @param field to validate
+ */
+ public static void assertNotStatic(final Field field)
+ {
+ assertNotStatic(field, null);
+ }
+
+ /**
+ * Asserts field is not final.
+ *
+ * @param field to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertNotFinal(final Field field, Class<? extends Annotation> annotation)
+ {
+ if (Modifier.isFinal(field.getModifiers()))
+ {
+ throw new InjectionException("Field " + getAnnotationMessage(annotation) + "cannot be final: " + field);
+ }
+ }
+
+ /**
+ * Asserts field is not final.
+ *
+ * @param field to validate
+ */
+ public static void assertNotFinal(final Field field)
+ {
+ assertNotFinal(field, null);
+ }
+
+ /**
+ * Asserts method have exactly one parameter.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertOneParameter(final Method method, Class<? extends Annotation> annotation)
+ {
+ if (method.getParameterTypes().length != 1)
+ {
+ throw new InjectionException("Method " + getAnnotationMessage(annotation) + "have to declare exactly one parameter: " + method);
+ }
+ }
+
+ /**
+ * Asserts method have exactly one parameter.
+ *
+ * @param method to validate
+ */
+ public static void assertOneParameter(final Method method)
+ {
+ assertOneParameter(method, null);
+ }
+
+ /**
+ * Asserts valid Java Beans setter method name.
+ *
+ * @param method to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertValidSetterName(final Method method, Class<? extends Annotation> annotation)
+ {
+ final String methodName = method.getName();
+ final boolean correctMethodNameLength = methodName.length() > 3;
+ final boolean isSetterMethodName = methodName.startsWith("set");
+ final boolean isUpperCasedPropertyName = correctMethodNameLength ? Character.isUpperCase(methodName.charAt(3)) : false;
+
+ if (!correctMethodNameLength || !isSetterMethodName || !isUpperCasedPropertyName)
+ {
+ throw new InjectionException("Method " + getAnnotationMessage(annotation) + "doesn't follow Java Beans setter method name: " + method);
+ }
+ }
+
+ /**
+ * Asserts valid Java Beans setter method name.
+ *
+ * @param method to validate
+ */
+ public static void assertValidSetterName(final Method method)
+ {
+ assertValidSetterName(method, null);
+ }
+
+ /**
+ * Asserts only one method is annotated with annotation.
+ *
+ * @param method collection of methods to validate
+ * @param annotation annotation to propagate in exception message
+ */
+ public static void assertOnlyOneMethod(final Collection<Method> methods, Class<? extends Annotation> annotation)
+ {
+ if (methods.size() > 1)
+ {
+ throw new InjectionException("Only one method " + getAnnotationMessage(annotation) + "can exist");
+ }
+ }
+
+ /**
+ * Asserts only one method is annotated with annotation.
+ *
+ * @param method collection of methods to validate
+ */
+ public static void assertOnlyOneMethod(final Collection<Method> methods)
+ {
+ assertOnlyOneMethod(methods, null);
+ }
+
+ /**
+ * Constructs annotation message. If annotation class is null it returns empty string.
+ *
+ * @param annotation to construct message for
+ * @return annotation message or empty string
+ */
+ private static String getAnnotationMessage(Class<? extends Annotation> annotation)
+ {
+ return annotation == null ? "" : "annotated with @" + annotation + " annotation ";
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceFieldFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.annotation.Resource;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.wsf.common.reflection.AnnotatedFieldFinder;
+
+/**
+ * Field based resource injection.
+ *
+ * To access a resource a developer declares a setter method and annotates it as being a
+ * resource reference. The name and type of resource maybe inferred by inspecting the
+ * method declaration if necessary. The name of the resource, if not declared, is the
+ * name of the JavaBeans property as determined starting from the name of the setter
+ * method in question. The setter method must follow the standard JavaBeans
+ * convention - name starts with a “set”, void return type and only one parameter.
+ * Additionally, the type of the parameter must be compatible with the type specified
+ * as a property of the Resource if present.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class ResourceFieldFinder
+extends AnnotatedFieldFinder<Resource>
+{
+
+ /**
+ * Parameter type to accept/ignore.
+ */
+ private final Class<?> accept;
+ /**
+ * If <b>accept</b> field is not null then:
+ * <ul>
+ * <li><b>true</b> means include only methods with <b>accept</b> parameter,
+ * <li><b>false</b> means exclude all methods with <b>accept</b> parameter
+ * </ul>
+ */
+ private final boolean include;
+
+ /**
+ * Constructor.
+ *
+ * @param accept filtering class
+ * @param include whether include/exclude filtering class
+ */
+ public ResourceFieldFinder(final Class<?> accept, boolean include)
+ {
+ super(Resource.class);
+
+ this.accept = accept;
+ this.include = include;
+ }
+
+ @Override
+ public void validate(Field field)
+ {
+ super.validate(field);
+
+ // Ensure all method preconditions
+ Class<Resource> annotation = getAnnotation();
+ ReflectionUtils.assertNotVoidType(field, annotation);
+ ReflectionUtils.assertNotStatic(field, annotation);
+ ReflectionUtils.assertNotFinal(field, annotation);
+ ReflectionUtils.assertNotPrimitiveType(field, annotation);
+ }
+
+ @Override
+ public boolean matches(Field field)
+ {
+ final boolean matches = super.matches(field);
+
+ if (matches)
+ {
+ // processing @Resource annotated method
+ if (this.accept != null)
+ {
+ // filtering
+ final Class<?> fieldType = field.getType();
+ final boolean parameterMatch = this.accept.equals(fieldType);
+ // include/exclude filtering
+ return this.include ? parameterMatch : !parameterMatch;
+ }
+ }
+
+ return matches;
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/finders/ResourceMethodFinder.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,115 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.finders;
+
+import java.lang.reflect.Method;
+
+import javax.annotation.Resource;
+import javax.xml.ws.WebServiceContext;
+
+import org.jboss.wsf.common.reflection.AnnotatedMethodFinder;
+
+/**
+ * Setter based resource injection.
+ *
+ * To access a resource a developer declares a setter method and annotates it as being a
+ * resource reference. The name and type of resource maybe inferred by inspecting the
+ * method declaration if necessary. The name of the resource, if not declared, is the
+ * name of the JavaBeans property as determined starting from the name of the setter
+ * method in question. The setter method must follow the standard JavaBeans
+ * convention - name starts with a “set”, void return type and only one parameter.
+ * Additionally, the type of the parameter must be compatible with the type specified
+ * as a property of the Resource if present.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public final class ResourceMethodFinder
+extends AnnotatedMethodFinder<Resource>
+{
+
+ /**
+ * Parameter type to accept/ignore.
+ */
+ private final Class<?> accept;
+ /**
+ * If <b>accept</b> field is not null then:
+ * <ul>
+ * <li><b>true</b> means include only methods with <b>accept</b> parameter,
+ * <li><b>false</b> means exclude all methods with <b>accept</b> parameter
+ * </ul>
+ */
+ private final boolean include;
+
+ /**
+ * Constructor.
+ *
+ * @param accept filtering class
+ * @param include whether include/exclude filtering class
+ */
+ public ResourceMethodFinder(final Class<?> accept, boolean include)
+ {
+ super(Resource.class);
+
+ this.accept = accept;
+ this.include = include;
+ }
+
+ @Override
+ public void validate(Method method)
+ {
+ super.validate(method);
+
+ // Ensure all method preconditions
+ Class<Resource> annotation = getAnnotation();
+ ReflectionUtils.assertVoidReturnType(method, annotation);
+ ReflectionUtils.assertOneParameter(method, annotation);
+ ReflectionUtils.assertNoPrimitiveParameters(method, annotation);
+ ReflectionUtils.assertValidSetterName(method, annotation);
+ ReflectionUtils.assertNoCheckedExceptionsAreThrown(method, annotation);
+ ReflectionUtils.assertNotStatic(method, annotation);
+ }
+
+ @Override
+ public boolean matches(Method method)
+ {
+ final boolean matches = super.matches(method);
+
+ if (matches)
+ {
+ // processing @Resource annotated method
+ if (this.accept != null)
+ {
+ // filtering
+ if (method.getParameterTypes().length == 1)
+ {
+ final Class<?> param = method.getParameterTypes()[0];
+ final boolean parameterMatch = this.accept.equals(param);
+ // include/exclude filtering
+ return this.include ? parameterMatch : !parameterMatch;
+ }
+ }
+ }
+
+ return matches;
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/AbstractReferenceResolver.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.resolvers;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.jboss.wsf.spi.metadata.injection.ReferenceResolver;
+
+/**
+ * This class adds support for notion of annotated fields and methods.
+ * It also ensures passed methods and fields are non null references
+ * plus it implements some common logic that would otherwise be
+ * implemented in all subclasses. It is highly recommended that all
+ * reference resolvers extend this base class for high code reuse.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public abstract class AbstractReferenceResolver<A extends Annotation>
+implements ReferenceResolver
+{
+
+ /**
+ * Resolved annotation.
+ */
+ private final Class<A> annotationClass;
+
+ /**
+ * Constructor.
+ */
+ public AbstractReferenceResolver(final Class<A> annotationClass)
+ {
+ super();
+
+ if (annotationClass == null)
+ {
+ throw new IllegalArgumentException("Annotation class cannot be null");
+ }
+
+ this.annotationClass = annotationClass;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.spi.metadata.injection.ReferenceResolver#resolve(java.lang.reflect.Method)
+ */
+ public final String resolve(final AccessibleObject accessibleObject)
+ {
+ if (!this.canResolve(accessibleObject))
+ {
+ throw new IllegalArgumentException("Cannot resolve: " + accessibleObject);
+ }
+
+ if (accessibleObject.getClass().equals(Method.class))
+ {
+ return this.resolveMethod((Method)accessibleObject);
+ }
+ else
+ {
+ return this.resolveField((Field)accessibleObject);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.spi.metadata.injection.ReferenceResolver#canResolve(java.lang.reflect.AccessibleObject)
+ */
+ public final boolean canResolve(final AccessibleObject accessibleObject)
+ {
+ this.assertNotNull(accessibleObject);
+
+ final boolean isField = accessibleObject.getClass().equals(Field.class);
+ final boolean isMethod = accessibleObject.getClass().equals(Method.class);
+ final boolean hasAnnotation = accessibleObject.getAnnotation(this.annotationClass) != null;
+
+ return (isField || isMethod) && hasAnnotation;
+ }
+
+ /**
+ * All subclasses have to implement this template method.
+ *
+ * @param Method method
+ * @return JNDI name
+ */
+ protected abstract String resolveMethod(Method method);
+
+ /**
+ * All subclasses have to implement this template method.
+ *
+ * @param Field field
+ * @return JNDI name
+ */
+ protected abstract String resolveField(Field field);
+
+ /**
+ * Asserts passed object is not null
+ *
+ * @param accessibleObject to validate
+ */
+ private void assertNotNull(final AccessibleObject accessibleObject)
+ {
+ if (accessibleObject == null)
+ {
+ throw new IllegalArgumentException("AccessibleObject cannot be null");
+ }
+ }
+
+}
Added: common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java
===================================================================
--- common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java (rev 0)
+++ common/trunk/src/main/java/org/jboss/wsf/common/injection/resolvers/ResourceReferenceResolver.java 2009-05-05 11:58:55 UTC (rev 9956)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.common.injection.resolvers;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import javax.annotation.Resource;
+
+/**
+ * JNDI reference resolver for @Resource annotated methods and fields.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ * @see org.jboss.wsf.spi.metadata.injection.ReferenceResolver
+ */
+public final class ResourceReferenceResolver extends AbstractReferenceResolver<Resource>
+{
+
+ /**
+ * Constructor.
+ */
+ public ResourceReferenceResolver()
+ {
+ super(Resource.class);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
+ */
+ @Override
+ protected String resolveField(Field field)
+ {
+ final String fallBackName = field.getName();
+ final String resourceName = field.getAnnotation(Resource.class).name();
+
+ return getName(resourceName, fallBackName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
+ */
+ @Override
+ protected String resolveMethod(Method method)
+ {
+ final String fallBackName = convertToBeanName(method.getName());
+ final String resourceName = method.getAnnotation(Resource.class).name();
+
+ return getName(resourceName, fallBackName);
+ }
+
+ /**
+ * Returns JNDI resource name.
+ *
+ * @param resourceName to use if specified
+ * @param fallBackName fall back bean name otherwise
+ * @return JNDI resource name
+ */
+ private static String getName(final String resourceName, final String fallBackName)
+ {
+ return resourceName.length() > 0 ? resourceName : fallBackName;
+ }
+
+ /**
+ * Translates "setBeanName" to "beanName" string.
+ *
+ * @param methodName to translate
+ * @return bean name
+ */
+ private static String convertToBeanName(final String methodName)
+ {
+ return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
+ }
+
+}
15 years, 7 months
JBossWS SVN: r9955 - framework/branches/jbossws-framework-2.0.1.GA_CP/src/main/etc.
by jbossws-commits@lists.jboss.org
Author: darran.lofthouse(a)jboss.com
Date: 2009-05-05 07:14:31 -0400 (Tue, 05 May 2009)
New Revision: 9955
Modified:
framework/branches/jbossws-framework-2.0.1.GA_CP/src/main/etc/wsprovide.bat
Log:
[JBPAPP-1887] WSPROVIDE.bat does not put jaxb-xjc.jar in the classpath.
Modified: framework/branches/jbossws-framework-2.0.1.GA_CP/src/main/etc/wsprovide.bat
===================================================================
--- framework/branches/jbossws-framework-2.0.1.GA_CP/src/main/etc/wsprovide.bat 2009-05-05 09:35:13 UTC (rev 9954)
+++ framework/branches/jbossws-framework-2.0.1.GA_CP/src/main/etc/wsprovide.bat 2009-05-05 11:14:31 UTC (rev 9955)
@@ -44,6 +44,7 @@
set WSPROVIDE_CLASSPATH=%WSPROVIDE_CLASSPATH%;%JBOSS_HOME%/client/log4j.jar
set WSPROVIDE_CLASSPATH=%WSPROVIDE_CLASSPATH%;%JBOSS_HOME%/client/mail.jar
set WSPROVIDE_CLASSPATH=%WSPROVIDE_CLASSPATH%;%JBOSS_HOME%/client/jbossws-spi.jar
+set WSPROVIDE_CLASSPATH=%WSPROVIDE_CLASSPATH%;%JBOSS_HOME%/client/jaxb-xjc.jar
rem Execute the JVM
"%JAVA%" %JAVA_OPTS% -Djava.endorsed.dirs="%JBOSS_ENDORSED_DIRS%" -Dlog4j.configuration=wstools-log4j.xml -classpath "%WSPROVIDE_CLASSPATH%" org.jboss.wsf.spi.tools.cmd.WSProvide %*
15 years, 7 months
JBossWS SVN: r9954 - in framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634: webservice and 1 other directory.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 05:35:13 -0400 (Tue, 05 May 2009)
New Revision: 9954
Modified:
framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/JBWS2634TestCase.java
framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/webservice/POJOBean.java
Log:
[JBWS-2634] final test case
Modified: framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/JBWS2634TestCase.java
===================================================================
--- framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/JBWS2634TestCase.java 2009-05-05 09:33:28 UTC (rev 9953)
+++ framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/JBWS2634TestCase.java 2009-05-05 09:35:13 UTC (rev 9954)
@@ -52,7 +52,5 @@
Service service = Service.create(wsdlURL, serviceName);
POJOIface proxy = (POJOIface)service.getPort(POJOIface.class);
assertEquals(proxy.getMessage(), "Injected hello message");
-
- System.out.println("[JBWS-2634] test javax.ejb.EJB annotation defaults as well, see POJOBean");
}
}
Modified: framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/webservice/POJOBean.java
===================================================================
--- framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/webservice/POJOBean.java 2009-05-05 09:33:28 UTC (rev 9953)
+++ framework/trunk/testsuite/test/java/org/jboss/test/ws/jaxws/jbws2634/webservice/POJOBean.java 2009-05-05 09:35:13 UTC (rev 9954)
@@ -21,8 +21,10 @@
*/
package org.jboss.test.ws.jaxws.jbws2634.webservice;
+import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.jws.WebService;
+import javax.xml.ws.WebServiceException;
import org.jboss.test.ws.jaxws.jbws2634.shared.BeanIface;
@@ -40,13 +42,35 @@
public class POJOBean implements POJOIface
{
- // TODO: this should work without name attribute as well
+ private boolean correctState;
+ @EJB
+ private BeanIface testBean2;
@EJB(name = "jaxws-jbws2634/BeanImpl1/local-org.jboss.test.ws.jaxws.jbws2634.shared.BeanIface")
- private BeanIface testBean;
+ private BeanIface testBean1;
public String getMessage()
{
- return this.testBean.printString();
+ if (this.correctState)
+ {
+ return this.testBean2.printString();
+ }
+
+ throw new WebServiceException("@EJB reference injection failed!");
}
+ @PostConstruct
+ private void init()
+ {
+ if (this.testBean1 == null)
+ return;
+ if (!"Injected hello message".equals(testBean1.printString()))
+ return;
+ if (this.testBean2 == null)
+ return;
+ if (!"Injected hello message".equals(testBean2.printString()))
+ return;
+
+ this.correctState = true;
+ }
+
}
15 years, 7 months
JBossWS SVN: r9953 - spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-05 05:33:28 -0400 (Tue, 05 May 2009)
New Revision: 9953
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/ReferenceResolver.java
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionMetaData.java
spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionsMetaData.java
Log:
[JBWS-2634] extending SPI
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionMetaData.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionMetaData.java 2009-05-04 08:09:01 UTC (rev 9952)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionMetaData.java 2009-05-05 09:33:28 UTC (rev 9953)
@@ -25,7 +25,7 @@
* An injection target specifies a class and a name within
* that class into which a resource should be injected.
*
- * @author ropalka(a)redhat.com
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
*/
public final class InjectionMetaData
{
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionsMetaData.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionsMetaData.java 2009-05-04 08:09:01 UTC (rev 9952)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/InjectionsMetaData.java 2009-05-05 09:33:28 UTC (rev 9953)
@@ -21,16 +21,18 @@
*/
package org.jboss.wsf.spi.metadata.injection;
+import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.Map;
import javax.naming.Context;
/**
* Injections metadata container.
*
- * @author ropalka(a)redhat.com
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
*/
public final class InjectionsMetaData
{
@@ -46,6 +48,11 @@
private final Collection<InjectionMetaData> injections;
/**
+ * Reference resolvers.
+ */
+ private final Map<Class<? extends Annotation>, ReferenceResolver> referenceResolvers;
+
+ /**
* JNDI context.
*/
private final Context ctx;
@@ -56,14 +63,17 @@
* @param injections injection definitions list
* @param ctx JNDI context
*/
- public InjectionsMetaData(Collection<InjectionMetaData> injections, Context ctx)
+ public InjectionsMetaData(Collection<InjectionMetaData> injections, Map<Class<? extends Annotation>, ReferenceResolver> referenceResolvers, Context ctx)
{
super();
if (injections == null)
throw new IllegalArgumentException("injections metadata list cannot be null");
+ if ((referenceResolvers == null) || (referenceResolvers.size() == 0))
+ throw new IllegalArgumentException("reference resolvers list cannot be null or empty collection");
this.injections = injections;
+ this.referenceResolvers = referenceResolvers;
this.ctx = ctx;
}
@@ -111,4 +121,21 @@
return (retVal == null) ? EMPTY_LIST : retVal;
}
+ /**
+ * Returns reference resolver for annotation.
+ *
+ * @param annotation to find resolver for
+ * @return reference resolver
+ */
+ public ReferenceResolver getResolver(final Class<? extends Annotation> annotation)
+ {
+ final ReferenceResolver resolver = this.referenceResolvers.get(annotation);
+ if (resolver == null)
+ {
+ throw new IllegalArgumentException("No registered reference resolver for: " + annotation.getClass());
+ }
+
+ return resolver;
+ }
+
}
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/ReferenceResolver.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/ReferenceResolver.java (rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/metadata/injection/ReferenceResolver.java 2009-05-05 09:33:28 UTC (rev 9953)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, 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.wsf.spi.metadata.injection;
+
+import java.lang.reflect.AccessibleObject;
+
+/**
+ * JNDI reference resolver.
+ *
+ * @author <a href="mailto:richard.opalka@jboss.org">Richard Opalka</a>
+ */
+public interface ReferenceResolver
+{
+
+ /**
+ * Resolves JNDI name.
+ *
+ * @param accessibleObject object
+ * @return JNDI name.
+ */
+ String resolve(AccessibleObject accessibleObject);
+
+ /**
+ * Returns <b>true</b> if can resolve, <b>false</b> otherwise.
+ *
+ * @param accessibleObject object
+ * @return true if can resolve, false otherwise
+ */
+ boolean canResolve(AccessibleObject accessibleObject);
+
+}
15 years, 7 months
JBossWS SVN: r9952 - stack/cxf/trunk/modules/testsuite.
by jbossws-commits@lists.jboss.org
Author: richard.opalka(a)jboss.com
Date: 2009-05-04 04:09:01 -0400 (Mon, 04 May 2009)
New Revision: 9952
Modified:
stack/cxf/trunk/modules/testsuite/test-excludes-jboss500.txt
stack/cxf/trunk/modules/testsuite/test-excludes-jboss501.txt
stack/cxf/trunk/modules/testsuite/test-excludes-jboss510.txt
stack/cxf/trunk/modules/testsuite/test-excludes-jboss600.txt
Log:
[JBWS-2596] fixing issue indentification
Modified: stack/cxf/trunk/modules/testsuite/test-excludes-jboss500.txt
===================================================================
--- stack/cxf/trunk/modules/testsuite/test-excludes-jboss500.txt 2009-05-04 08:07:17 UTC (rev 9951)
+++ stack/cxf/trunk/modules/testsuite/test-excludes-jboss500.txt 2009-05-04 08:09:01 UTC (rev 9952)
@@ -41,7 +41,7 @@
# [JBWS-1655] Add support for endpoint address rewriting
org/jboss/test/ws/jaxws/jbws2150/**
-# [JBWS-2074] Resource injection in jaxws endpoints and handlers
+# [JBWS-2596] Resource injection in jaxws endpoints and handlers
org/jboss/test/ws/jaxws/jbws2074/**
org/jboss/test/ws/jaxws/jbws2634/**
Modified: stack/cxf/trunk/modules/testsuite/test-excludes-jboss501.txt
===================================================================
--- stack/cxf/trunk/modules/testsuite/test-excludes-jboss501.txt 2009-05-04 08:07:17 UTC (rev 9951)
+++ stack/cxf/trunk/modules/testsuite/test-excludes-jboss501.txt 2009-05-04 08:09:01 UTC (rev 9952)
@@ -41,7 +41,7 @@
# [JBWS-1655] Add support for endpoint address rewriting
org/jboss/test/ws/jaxws/jbws2150/**
-# [JBWS-2074] Resource injection in jaxws endpoints and handlers
+# [JBWS-2596] Resource injection in jaxws endpoints and handlers
org/jboss/test/ws/jaxws/jbws2074/**
org/jboss/test/ws/jaxws/jbws2634/**
Modified: stack/cxf/trunk/modules/testsuite/test-excludes-jboss510.txt
===================================================================
--- stack/cxf/trunk/modules/testsuite/test-excludes-jboss510.txt 2009-05-04 08:07:17 UTC (rev 9951)
+++ stack/cxf/trunk/modules/testsuite/test-excludes-jboss510.txt 2009-05-04 08:09:01 UTC (rev 9952)
@@ -41,7 +41,7 @@
# [JBWS-1655] Add support for endpoint address rewriting
org/jboss/test/ws/jaxws/jbws2150/**
-# [JBWS-2074] Resource injection in jaxws endpoints and handlers
+# [JBWS-2596] Resource injection in jaxws endpoints and handlers
org/jboss/test/ws/jaxws/jbws2074/**
org/jboss/test/ws/jaxws/jbws2634/**
Modified: stack/cxf/trunk/modules/testsuite/test-excludes-jboss600.txt
===================================================================
--- stack/cxf/trunk/modules/testsuite/test-excludes-jboss600.txt 2009-05-04 08:07:17 UTC (rev 9951)
+++ stack/cxf/trunk/modules/testsuite/test-excludes-jboss600.txt 2009-05-04 08:09:01 UTC (rev 9952)
@@ -41,7 +41,7 @@
# [JBWS-1655] Add support for endpoint address rewriting
org/jboss/test/ws/jaxws/jbws2150/**
-# [JBWS-2074] Resource injection in jaxws endpoints and handlers
+# [JBWS-2596] Resource injection in jaxws endpoints and handlers
org/jboss/test/ws/jaxws/jbws2074/**
org/jboss/test/ws/jaxws/jbws2634/**
15 years, 7 months