Author: richard.opalka(a)jboss.com
Date: 2009-08-10 09:46:55 -0400 (Mon, 10 Aug 2009)
New Revision: 10511
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java
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/InvocationHandlerJAXWS.java
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java
Log:
[JBWS-2332] refactoring + javadoc
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java 2009-08-10
10:40:17 UTC (rev 10510)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandler.java 2009-08-10
13:46:55 UTC (rev 10511)
@@ -23,7 +23,6 @@
import java.lang.reflect.Method;
-import org.jboss.wsf.common.JavaUtils;
import org.jboss.wsf.spi.deployment.Endpoint;
import org.jboss.wsf.spi.invocation.Invocation;
import org.jboss.wsf.spi.invocation.InvocationHandler;
@@ -36,30 +35,39 @@
*/
abstract class AbstractInvocationHandler extends InvocationHandler
{
-
+
+ /**
+ * Creates invocation.
+ *
+ * @return invocation instance
+ */
public final Invocation createInvocation()
{
return new Invocation();
}
- public void init(Endpoint ep)
+ /**
+ * Initialization method.
+ *
+ * @param endpoint endpoint
+ */
+ public void init(final Endpoint endpoint)
{
+ // does nothing
}
- protected Method getImplMethod(Class<?> implClass, Method seiMethod) throws
ClassNotFoundException, NoSuchMethodException
+ /**
+ * Returns implementation method that will be used for invocation.
+ *
+ * @param implClass implementation endpoint class
+ * @param seiMethod SEI interface method used for method finding algorithm
+ * @return implementation method
+ * @throws NoSuchMethodException if implementation method wasn't found
+ */
+ protected final Method getImplMethod(final Class<?> implClass, final Method
seiMethod) throws NoSuchMethodException
{
- String methodName = seiMethod.getName();
- Class<?>[] paramTypes = seiMethod.getParameterTypes();
- for (int i = 0; i < paramTypes.length; i++)
- {
- Class<?> paramType = paramTypes[i];
- if (JavaUtils.isPrimitive(paramType) == false)
- {
- String paramTypeName = paramType.getName();
- paramType = JavaUtils.loadJavaType(paramTypeName);
- paramTypes[i] = paramType;
- }
- }
+ final String methodName = seiMethod.getName();
+ final Class<?>[] paramTypes = seiMethod.getParameterTypes();
return implClass.getMethod(methodName, paramTypes);
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java 2009-08-10
10:40:17 UTC (rev 10510)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/AbstractInvocationHandlerJSE.java 2009-08-10
13:46:55 UTC (rev 10511)
@@ -36,71 +36,142 @@
abstract class AbstractInvocationHandlerJSE extends AbstractInvocationHandler
{
+ /**
+ * Constructor.
+ */
AbstractInvocationHandlerJSE()
{
super();
}
- protected Object getTargetBean(Endpoint ep, Invocation epInv) throws Exception
+ /**
+ * Retrieves endpoint implementation bean that will be used in invocation process.
+ *
+ * This method does the following steps:
+ *
+ * <ul>
+ * <li>tries to retrieve endpoint instance from invocation
context,</li>
+ * <li>if endpoint instance is not found it's created and instantiated
(lazy initialization)</li>
+ * <li>
+ * if endpoint instance was created all subclasses will be notified about this
event
+ * (using {@link #onEndpointInstantiated(Endpoint, Invocation)} template method).
+ * </li>
+ * </ul>
+ *
+ * @param endpoint to lookup implementation instance for
+ * @param invocation current invocation
+ * @return endpoint implementation
+ * @throws Exception if any error occurs
+ */
+ protected Object getTargetBean(final Endpoint endpoint, final Invocation invocation)
throws Exception
{
- InvocationContext invCtx = epInv.getInvocationContext();
- Object targetBean = invCtx.getTargetBean();
+ final InvocationContext invocationContext = invocation.getInvocationContext();
+ Object targetBean = invocationContext.getTargetBean();
+
if (targetBean == null)
{
try
{
- Class<?> epImpl = ep.getTargetBeanClass();
- targetBean = epImpl.newInstance();
- invCtx.setTargetBean(targetBean);
- this.onEndpointInstantiated(ep, epInv);
+ // create endpoint instance
+ final Class<?> endpointImplClass = endpoint.getTargetBeanClass();
+ targetBean = endpointImplClass.newInstance();
+ invocationContext.setTargetBean(targetBean);
+
+ // notify subclasses
+ this.onEndpointInstantiated(endpoint, invocation);
}
catch (Exception ex)
{
- throw new IllegalStateException("Cannot get target bean instance",
ex);
+ throw new IllegalStateException("Cannot create endpoint instance:
", ex);
}
}
return targetBean;
}
- public void invoke(Endpoint ep, Invocation epInv) throws Exception
+ /**
+ * Invokes method on endpoint implementation.
+ *
+ * This method does the following steps:
+ *
+ * <ul>
+ * <li>lookups endpoint implementation method to be invoked,</li>
+ * <li>
+ * notifies all subclasses about endpoint method is going to be
invoked<br/>
+ * (using {@link #onBeforeInvocation(Invocation)} template method),
+ * </li>
+ * <li>endpoint implementation method is invoked,</li>
+ * <li>
+ * notifies all subclasses about endpoint method invocation was
completed<br/>
+ * (using {@link #onAfterInvocation(Invocation)} template method).
+ * </li>
+ * </ul>
+ *
+ * @param endpoint which method is going to be invoked
+ * @param invocation current invocation
+ * @throws Exception if any error occurs
+ */
+ public void invoke(final Endpoint endpoint, final Invocation invocation) throws
Exception
{
- Object targetBean = null;
try
{
- targetBean = this.getTargetBean(ep, epInv);
+ // prepare for invocation
+ final Object targetBean = this.getTargetBean(endpoint, invocation);
+ final Class<?> implClass = targetBean.getClass();
+ final Method seiMethod = invocation.getJavaMethod();
+ final Method implMethod = this.getImplMethod(implClass, seiMethod);
+ final Object[] args = invocation.getArgs();
- Class<?> implClass = targetBean.getClass();
- Method seiMethod = epInv.getJavaMethod();
- Method implMethod = getImplMethod(implClass, seiMethod);
+ // notify subclasses
+ this.onBeforeInvocation(invocation);
- Object[] args = epInv.getArgs();
- this.onBeforeInvocation(epInv);
- Object retObj = implMethod.invoke(targetBean, args);
- epInv.setReturnValue(retObj);
+ // invoke implementation method
+ final Object retObj = implMethod.invoke(targetBean, args);
+
+ // set invocation result
+ invocation.setReturnValue(retObj);
}
catch (Exception e)
{
- handleInvocationException(e);
+ // propagate exception
+ this.handleInvocationException(e);
}
finally
{
- this.onAfterInvocation(epInv);
+ // notify subclasses
+ this.onAfterInvocation(invocation);
}
}
-
- // TODO: document these template methods
- protected void onEndpointInstantiated(Endpoint endpoint, final Invocation invocation)
throws Exception
+ /**
+ * Template method for notifying subclasses that endpoint instance have been
instantiated.
+ *
+ * @param endpoint instantiated endpoint
+ * @param invocation current invocation
+ * @throws Exception subclasses have to throw exception on any failure
+ */
+ protected void onEndpointInstantiated(final Endpoint endpoint, final Invocation
invocation) throws Exception
{
// does nothing
}
-
+
+ /**
+ * Template method for notifying subclasses that endpoint method is going to be
invoked.
+ *
+ * @param invocation current invocation
+ * @throws Exception subclasses have to throw exception on any failure
+ */
protected void onBeforeInvocation(final Invocation invocation) throws Exception
{
// does nothing
}
-
+
+ /**
+ * Template method for notifying subclasses that endpoint method invocation was
completed.
+ *
+ * @param invocation current invocation
+ * @throws Exception subclasses have to throw exception on any failure
+ */
protected void onAfterInvocation(final Invocation invocation) throws Exception
{
// does nothing
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-10
10:40:17 UTC (rev 10510)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXRPC.java 2009-08-10
13:46:55 UTC (rev 10511)
@@ -37,21 +37,33 @@
*/
final class InvocationHandlerJAXRPC extends AbstractInvocationHandlerJSE
{
-
+
+ /**
+ * Constructor.
+ */
InvocationHandlerJAXRPC()
{
super();
}
-
+
+ /**
+ * Calls {@link javax.xml.rpc.server.ServiceLifecycle#init(Object)}
+ * method on target bean and registers it for predestroy phase if
+ * target bean implements {@link javax.xml.rpc.server.ServiceLifecycle} interface.
+ *
+ * @param endpoint used for predestroy phase registration process
+ * @param invocation current invocation
+ * @throws Exception if any error occurs
+ */
protected void onEndpointInstantiated(final Endpoint endpoint, final Invocation
invocation) throws Exception
{
final InvocationContext invocationContext = invocation.getInvocationContext();
final Object targetBean = invocationContext.getTargetBean();
final boolean isJaxrpcLifecycleBean = targetBean instanceof ServiceLifecycle;
-
+
if (isJaxrpcLifecycleBean)
{
- ServletEndpointContext sepContext =
invocationContext.getAttachment(ServletEndpointContext.class);
+ final ServletEndpointContext sepContext =
invocationContext.getAttachment(ServletEndpointContext.class);
((ServiceLifecycle)targetBean).init(sepContext);
endpoint.addAttachment(PreDestroyHolder.class, new
PreDestroyHolder(targetBean));
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXWS.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXWS.java 2009-08-10
10:40:17 UTC (rev 10510)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerJAXWS.java 2009-08-10
13:46:55 UTC (rev 10511)
@@ -42,51 +42,98 @@
*/
final class InvocationHandlerJAXWS extends AbstractInvocationHandlerJSE
{
-
+
+ /** WebServiceContext injector. */
private final ResourceInjector wsContextInjector;
+ /**
+ * Constructor.
+ */
InvocationHandlerJAXWS()
{
super();
final SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
final ResourceInjectorFactory resourceInjectorFactory =
spiProvider.getSPI(ResourceInjectorFactory.class);
- wsContextInjector = resourceInjectorFactory.newResourceInjector();
+ this.wsContextInjector = resourceInjectorFactory.newResourceInjector();
}
+ /**
+ * Injects resources on target bean and calls post construct method.
+ * Finally it registers target bean for predestroy phase.
+ *
+ * @param endpoint used for predestroy phase registration process
+ * @param invocation current invocation
+ */
protected void onEndpointInstantiated(final Endpoint endpoint, final Invocation
invocation)
{
- final InvocationContext invocationContext = invocation.getInvocationContext();
- final Object targetBean = invocationContext.getTargetBean();
final InjectionsMetaData injectionsMD =
endpoint.getAttachment(InjectionsMetaData.class);
-
+ final Object targetBean = this.getTargetBean(invocation);
+
InjectionHelper.injectResources(targetBean, injectionsMD);
InjectionHelper.callPostConstructMethod(targetBean);
+
endpoint.addAttachment(PreDestroyHolder.class, new PreDestroyHolder(targetBean));
}
+ /**
+ * Injects webservice context on target bean.
+ *
+ * @param invocation current invocation
+ */
protected void onBeforeInvocation(final Invocation invocation)
{
- final InvocationContext invocationContext = invocation.getInvocationContext();
- final WebServiceContext wsContext =
invocationContext.getAttachment(WebServiceContext.class);
- final Object targetBean = invocationContext.getTargetBean();
+ final WebServiceContext wsContext = this.getWebServiceContext(invocation);
if (wsContext != null)
{
+ final Object targetBean = this.getTargetBean(invocation);
+
this.wsContextInjector.inject(targetBean, wsContext);
}
}
+ /**
+ * Cleanups injected webservice context on target bean.
+ *
+ * @param invocation current invocation
+ */
protected void onAfterInvocation(final Invocation invocation)
{
- final InvocationContext invocationContext = invocation.getInvocationContext();
- final WebServiceContext wsContext =
invocationContext.getAttachment(WebServiceContext.class);
- final Object targetBean = invocationContext.getTargetBean();
+ final WebServiceContext wsContext = this.getWebServiceContext(invocation);
if (wsContext != null)
{
+ final Object targetBean = this.getTargetBean(invocation);
+
this.wsContextInjector.inject(targetBean, null);
}
}
-
+
+ /**
+ * Returns WebServiceContext associated with this invocation.
+ *
+ * @param invocation current invocation
+ * @return web service context or null if not available
+ */
+ private WebServiceContext getWebServiceContext(final Invocation invocation)
+ {
+ final InvocationContext invocationContext = invocation.getInvocationContext();
+
+ return invocationContext.getAttachment(WebServiceContext.class);
+ }
+
+ /**
+ * Returns endpoint instance associated with current invocation.
+ *
+ * @param invocation current invocation
+ * @return target bean in invocation
+ */
+ private Object getTargetBean(final Invocation invocation)
+ {
+ final InvocationContext invocationContext = invocation.getInvocationContext();
+
+ return invocationContext.getTargetBean();
+ }
+
}
Modified:
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java
===================================================================
---
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java 2009-08-10
10:40:17 UTC (rev 10510)
+++
container/jboss50/branches/ropalka-jboss510/src/main/java/org/jboss/webservices/integration/invocation/InvocationHandlerMDB21.java 2009-08-10
13:46:55 UTC (rev 10511)
@@ -29,7 +29,7 @@
*/
final class InvocationHandlerMDB21 extends AbstractInvocationHandlerJSE
{
-
+
/**
* Constructor.
*/