Author: richard.opalka(a)jboss.com
Date: 2009-08-12 06:29:29 -0400 (Wed, 12 Aug 2009)
New Revision: 10523
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/EJBBeanReferenceResolver.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/InjectionMetaDataDeploymentAspect.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java
Log:
[JBWS-2320] refactoring + javadoc
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/EJBBeanReferenceResolver.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/EJBBeanReferenceResolver.java 2009-08-12
08:18:41 UTC (rev 10522)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/EJBBeanReferenceResolver.java 2009-08-12
10:29:29 UTC (rev 10523)
@@ -50,6 +50,9 @@
/**
* Constructor.
+ *
+ * @param unit deployment unit
+ * @param delegate EJB reference resolver
*/
public EJBBeanReferenceResolver(final DeploymentUnit unit, final EjbReferenceResolver
delegate)
{
@@ -68,30 +71,36 @@
this.delegate = delegate;
}
- /* (non-Javadoc)
+ /**
* @see
org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveField(java.lang.reflect.Field)
+ *
+ * @param field to be resolved
+ * @return JNDI name of referenced EJB object
*/
@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);
+ final EjbReference reference = this.getEjbReference(ejbAnnotation, type);
- return this.delegate.resolveEjb(unit, reference);
+ return this.delegate.resolveEjb(this.unit, reference);
}
- /* (non-Javadoc)
+ /**
* @see
org.jboss.wsf.common.injection.resolvers.AbstractReferenceResolver#resolveMethod(java.lang.reflect.Method)
+ *
+ * @param method to be resolved
+ * @return JNDI name of referenced EJB object
*/
@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);
+ final EjbReference reference = this.getEjbReference(ejbAnnotation, type);
- return this.delegate.resolveEjb(unit, reference);
+ return this.delegate.resolveEjb(this.unit, reference);
}
/**
@@ -101,7 +110,7 @@
* @param type fall back type
* @return ejb reference instance
*/
- private EjbReference getEjbReference(EJB ejbAnnotation, Class<?> type)
+ private EjbReference getEjbReference(final EJB ejbAnnotation, final Class<?>
type)
{
String beanInterface = ejbAnnotation.beanInterface().getName();
if (java.lang.Object.class.getName().equals(beanInterface))
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/InjectionMetaDataDeploymentAspect.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/InjectionMetaDataDeploymentAspect.java 2009-08-12
08:18:41 UTC (rev 10522)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/injection/InjectionMetaDataDeploymentAspect.java 2009-08-12
10:29:29 UTC (rev 10523)
@@ -24,7 +24,6 @@
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;
@@ -32,10 +31,8 @@
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;
@@ -65,55 +62,124 @@
public final class InjectionMetaDataDeploymentAspect extends DeploymentAspect
{
- private static final ReferenceResolver RESOURCE_REFERENCE_RESOLVER = new
ResourceReferenceResolver();
+ /** EJB 3 JNDI prefix. */
private static final String EJB3_JNDI_PREFIX = "java:env/";
+
+ /** Resolver handling @Resource injections. */
+ private static final ReferenceResolver RESOURCE_RESOLVER = new
ResourceReferenceResolver();
+
+ /** EJB 3 reference resolver. */
private EjbReferenceResolver ejbReferenceResolver;
+ /**
+ * Constructor.
+ */
+ public InjectionMetaDataDeploymentAspect()
+ {
+ super();
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Builds injection meta data for all endpoints in deployment.
+ *
+ * @param dep webservice deployment
+ */
@Override
- public void start(Deployment dep)
+ public void start(final Deployment dep)
{
- super.start(dep);
+ final DeploymentUnit unit = WSHelper.getRequiredAttachment(dep,
DeploymentUnit.class);
+ final JBossWebMetaData jbossWebMD = WSHelper.getRequiredAttachment(dep,
JBossWebMetaData.class);
+ final Map<Class<? extends Annotation>, ReferenceResolver> resolvers =
this.getResolvers(unit);
- DeploymentUnit unit = WSHelper.getRequiredAttachment(dep, DeploymentUnit.class);
- JBossWebMetaData webMD = WSHelper.getRequiredAttachment(dep,
JBossWebMetaData.class);
+ if (WSHelper.isJaxwsJseDeployment(dep))
+ {
+ final EnvironmentEntriesMetaData envEntriesMD =
jbossWebMD.getEnvironmentEntries();
- List<InjectionMetaData> injectionMD = new
LinkedList<InjectionMetaData>();
- Map<Class<? extends Annotation>, ReferenceResolver> resolvers =
createResolvers(unit);
+ // iterate through all POJO endpoints
+ for (Endpoint endpoint : dep.getService().getEndpoints())
+ {
+ // build POJO injections meta data
+ final InjectionsMetaData injectionsMD =
this.buildInjectionsMetaData(envEntriesMD, resolvers, null);
- try
+ // associate injections meta data with POJO endpoint
+ endpoint.addAttachment(InjectionsMetaData.class, injectionsMD);
+ }
+ }
+ else if (WSHelper.isJaxwsEjbDeployment(dep))
{
+ final WebServiceDeployment webServiceDeployment =
ASHelper.getRequiredAttachment(unit, WebServiceDeployment.class);
- if (WSHelper.isJaxwsJseDeployment(dep))
+ // iterate through all EJB3 endpoints
+ for (final WebServiceDeclaration container :
webServiceDeployment.getServiceEndpoints())
{
- injectionMD.addAll(buildInjectionMetaData(webMD.getEnvironmentEntries()));
- for (Endpoint endpoint : dep.getService().getEndpoints())
+ if (ASHelper.isWebServiceBean(container))
{
- InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD,
resolvers, null);
+ final String ejbName = container.getComponentName();
+
+ // build EJB 3 injections meta data
+ final EnvironmentEntriesMetaData ejbEnvEntries =
this.getEnvironmentEntries(ejbName, unit);
+ final Context jndiContext = this.getJndiContext(container);
+ final InjectionsMetaData injectionsMD =
this.buildInjectionsMetaData(ejbEnvEntries, resolvers, jndiContext);
+
+ // associate injections meta data with EJB 3 endpoint
+ final Endpoint endpoint = dep.getService().getEndpointByName(ejbName);
endpoint.addAttachment(InjectionsMetaData.class, injectionsMD);
}
}
- else if (WSHelper.isJaxwsEjbDeployment(dep))
- {
- WebServiceDeployment webServiceDeployment =
ASHelper.getRequiredAttachment(unit, WebServiceDeployment.class);
- JBossMetaData jbossMD = ASHelper.getRequiredAttachment(unit,
JBossMetaData.class);
- JBossEnterpriseBeansMetaData jebMDs = jbossMD.getEnterpriseBeans();
+ }
+ }
+
+ /**
+ * Returns environment entries meta data associated with specified EJB 3 bean.
+ *
+ * @param ejbName EJB 3 bean to lookup environment entries for
+ * @param unit deployment unit
+ * @return environment entries meta data
+ */
+ private EnvironmentEntriesMetaData getEnvironmentEntries(final String ejbName, final
DeploymentUnit unit)
+ {
+ final JBossMetaData jbossMD = ASHelper.getRequiredAttachment(unit,
JBossMetaData.class);
+ final JBossEnterpriseBeansMetaData enterpriseBeansMDs =
jbossMD.getEnterpriseBeans();
+
+ return enterpriseBeansMDs.get(ejbName).getEnvironmentEntries();
+ }
- Iterator<WebServiceDeclaration> it =
webServiceDeployment.getServiceEndpoints().iterator();
- while (it.hasNext())
- {
- WebServiceDeclaration container = it.next();
- if (isWebServiceBean(container))
- {
- final Context ctx =
(Context)container.getContext().lookup(EJB3_JNDI_PREFIX);
- String ejbName = container.getComponentName();
- EnvironmentEntriesMetaData ejbEnvEntries =
jebMDs.get(ejbName).getEnvironmentEntries();
- injectionMD.addAll(buildInjectionMetaData(ejbEnvEntries));
- Endpoint endpoint = dep.getService().getEndpointByName(ejbName);
- InjectionsMetaData injectionsMD = new InjectionsMetaData(injectionMD,
resolvers, ctx);
- endpoint.addAttachment(InjectionsMetaData.class, injectionsMD);
- }
- }
- }
+ /**
+ * Returns JNDI context associated with EJB 3 container.
+ *
+ * @param container EJB 3 container
+ * @return JNDI context
+ */
+ private Context getJndiContext(final WebServiceDeclaration container)
+ {
+ try
+ {
+ return
(Context)container.getContext().lookup(InjectionMetaDataDeploymentAspect.EJB3_JNDI_PREFIX);
}
catch (NamingException ne)
{
@@ -121,66 +187,84 @@
}
}
- @Override
- public void stop(Deployment dep)
- {
- dep.getService().removeAttachment(InjectionMetaData.class);
-
- super.stop(dep);
- }
-
/**
- * Builds reference resolvers container.
+ * Returns reference resolvers container.
*
* @param unit deployment unit
* @return reference resolvers
*/
- private Map<Class<? extends Annotation>, ReferenceResolver>
createResolvers(DeploymentUnit unit)
+ private Map<Class<? extends Annotation>, ReferenceResolver>
getResolvers(final 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()));
+
+ resolvers.put(Resource.class,
InjectionMetaDataDeploymentAspect.RESOURCE_RESOLVER);
+ resolvers.put(EJB.class, new EJBBeanReferenceResolver(unit,
this.getEjbReferenceResolver()));
+
return resolvers;
}
/**
- * Builds JBossWS specific injection metadata from JBoss metadata.
+ * Builds JBossWS specific injections meta data.
+ *
+ * @param envEntriesMD environment entries meta data
+ * @param resolvers known annotation resolvers
+ * @param jndiContext JNDI context to be propagated
+ * @return injections meta data
+ */
+ private InjectionsMetaData buildInjectionsMetaData(final EnvironmentEntriesMetaData
envEntriesMD,
+ final Map<Class<? extends Annotation>, ReferenceResolver> resolvers,
final Context jndiContext)
+ {
+ final List<InjectionMetaData> injectionMD = new
LinkedList<InjectionMetaData>();
+ injectionMD.addAll(this.buildInjectionMetaData(envEntriesMD));
+
+ return new InjectionsMetaData(injectionMD, resolvers, jndiContext);
+ }
+
+ /**
+ * Builds JBossWS specific injection meta data.
*
- * @param envEntries environment entries
- * @return JBossWS specific injection metadata
+ * @param envEntriesMD environment entries meta data
+ * @return injection meta data
*/
- private List<InjectionMetaData>
buildInjectionMetaData(EnvironmentEntriesMetaData envEntries)
+ private List<InjectionMetaData> buildInjectionMetaData(final
EnvironmentEntriesMetaData envEntriesMD)
{
- if ((envEntries == null) || (envEntries.size() == 0))
+ if ((envEntriesMD == null) || (envEntriesMD.size() == 0))
{
return Collections.emptyList();
}
- EnvironmentEntryMetaData eeMD = null;
- LinkedList<InjectionMetaData> retVal = new
LinkedList<InjectionMetaData>();
- String envEntryName = null;
- String envEntryValue = null;
- String targetClass = null;
- String targetName = null;
- String valueClass = null;
+ final LinkedList<InjectionMetaData> retVal = new
LinkedList<InjectionMetaData>();
- for (Iterator<EnvironmentEntryMetaData> i = envEntries.iterator();
i.hasNext();)
+ Set<ResourceInjectionTargetMetaData> injectionTargets;
+ String envEntryName;
+ String envEntryValue;
+ String targetClass;
+ String targetName;
+ String envEntryValueClass;
+ boolean hasInjectionTargets;
+
+ // iterate through defined environment entries
+ for (final EnvironmentEntryMetaData envEntryMD : envEntriesMD)
{
- eeMD = i.next();
- envEntryName = eeMD.getEnvEntryName();
- envEntryValue = eeMD.getValue();
- valueClass = eeMD.getType();
+ injectionTargets = envEntryMD.getInjectionTargets();
+ hasInjectionTargets = (injectionTargets != null) &&
(injectionTargets.size() > 0);
- Set<ResourceInjectionTargetMetaData> injectionTargets =
eeMD.getInjectionTargets();
- if ((injectionTargets != null) && (injectionTargets.size() > 0))
+ if (hasInjectionTargets)
{
- for (Iterator<ResourceInjectionTargetMetaData> j =
injectionTargets.iterator(); j.hasNext();)
+ // prepare env entry meta data
+ envEntryName = envEntryMD.getEnvEntryName();
+ envEntryValue = envEntryMD.getValue();
+ envEntryValueClass = envEntryMD.getType();
+
+ // env entry can specify multiple injection targets
+ for (final ResourceInjectionTargetMetaData resourceInjectionTargetMD :
injectionTargets)
{
- ResourceInjectionTargetMetaData ritMD = j.next();
- targetClass = ritMD.getInjectionTargetClass();
- targetName = ritMD.getInjectionTargetName();
- InjectionMetaData injectionMD = new InjectionMetaData(targetClass,
targetName, valueClass, envEntryName, envEntryValue != null);
- retVal.add(injectionMD);
+ // prepare injection target meta data
+ targetClass = resourceInjectionTargetMD.getInjectionTargetClass();
+ targetName = resourceInjectionTargetMD.getInjectionTargetName();
+
+ // build injection meta data for injection target
+ retVal.add(new InjectionMetaData(targetClass, targetName,
envEntryValueClass, envEntryName, envEntryValue != null));
}
}
}
@@ -188,43 +272,4 @@
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;
- boolean isWebServiceProvider = container.getAnnotation(WebServiceProvider.class) !=
null;
-
- 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/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java 2009-08-12
08:18:41 UTC (rev 10522)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerEJB21.java 2009-08-12
10:29:29 UTC (rev 10523)
@@ -149,8 +149,8 @@
{
// prepare for invocation
final org.jboss.invocation.Invocation jbossInvocation =
this.getMBeanInvocation(wsInvocation);
- final String[] signature = {org.jboss.invocation.Invocation.class.getName()};
- final Object[] args = new Object[] {jbossInvocation};
+ final String[] signature = { org.jboss.invocation.Invocation.class.getName() };
+ final Object[] args = new Object[] { jbossInvocation };
// invoke method
final Object retObj = this.server.invoke(ejb21Name, "invoke", args,
signature);
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java 2009-08-12
08:18:41 UTC (rev 10522)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java 2009-08-12
10:29:29 UTC (rev 10523)
@@ -64,7 +64,7 @@
((ServiceLifecycle)targetBean).init(sepContext);
}
}
-
+
/**
* Calls {@link javax.xml.rpc.server.ServiceLifecycle#destroy()}
* method on target bean if this bean implements