KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aspects > asynchronous > aspects > jboss > AsynchronousInvokeTask


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22
23 package org.jboss.aspects.asynchronous.aspects.jboss;
24
25 import org.jboss.aop.joinpoint.MethodInvocation;
26 import org.jboss.aspects.asynchronous.AsynchronousConstants;
27 import org.jboss.aspects.asynchronous.AsynchronousParameters;
28 import org.jboss.aspects.asynchronous.AsynchronousResponse;
29 import org.jboss.aspects.asynchronous.AsynchronousUserTask;
30 import org.jboss.aspects.asynchronous.common.AsynchronousResponseImpl;
31
32 import java.lang.reflect.Method JavaDoc;
33
34 /**
35  * @author <a HREF="mailto:chussenet@yahoo.com">{Claude Hussenet Independent Consultant}</a>.
36  * @version <tt>$Revision: 37406 $</tt>
37  */

38
39 public class AsynchronousInvokeTask
40
41 implements AsynchronousUserTask, AsynchronousConstants
42 {
43
44    protected AsynchronousInvokeTask()
45    {
46
47       super();
48
49    }
50
51    public AsynchronousResponse process(AsynchronousParameters jp)
52    {
53
54       try
55       {
56
57          InvokeTaskInputParameters ijp = (InvokeTaskInputParameters) jp;
58
59          MethodInvocation invocation = ijp.invocation;
60
61          Object JavaDoc res = invocation.invokeNext();
62
63          return new AsynchronousResponseImpl(OK, res);
64
65       }
66       catch (Throwable JavaDoc e)
67       {
68
69          return new AsynchronousResponseImpl(EXCEPTIONCAUGHT, e);
70
71       }
72
73    }
74
75    private boolean invoke(Object JavaDoc targetedObject,
76
77                           Class JavaDoc[] paramemeterTypes,
78
79                           Object JavaDoc[] parameterObjects,
80
81                           Class JavaDoc stringName)
82    {
83
84       try
85       {
86
87          Class JavaDoc aClass = null;
88
89          if (targetedObject == null)
90
91             aClass = stringName;
92
93          else
94
95             aClass = targetedObject.getClass();
96
97          Method JavaDoc method = aClass.getMethod("cleanup", paramemeterTypes);
98
99          method.invoke(targetedObject, parameterObjects);
100
101       }
102       catch (Exception JavaDoc e)
103       {
104
105          return false;
106
107       }
108
109       return true;
110
111    }
112
113    public void cleanup(AsynchronousParameters jp)
114    {
115
116       try
117       {
118
119          InvokeTaskInputParameters ijp = (InvokeTaskInputParameters) jp;
120
121          MethodInvocation invocation = ijp.invocation;
122
123          Object JavaDoc targetedClass = invocation.getTargetObject();
124
125          if (!invoke(targetedClass,
126
127          invocation.getActualMethod().getParameterTypes(),
128
129          invocation.getArguments(),
130
131          invocation.getActualMethod().getDeclaringClass()))
132
133             invoke(targetedClass,
134
135             null,
136
137             null,
138
139             invocation.getActualMethod().getDeclaringClass());
140
141       }
142       catch (Exception JavaDoc e)
143       {
144
145
146       }
147
148    }
149
150 }
151
152
Popular Tags