KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployment > SubDeployerInterceptorSupport


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 package org.jboss.deployment;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.mx.server.Invocation;
26 import org.jboss.system.InterceptorServiceMBeanSupport;
27
28 /**
29  * Base class that can be used for writing services
30  * that dynamically hook to other interceptable deployers
31  * in order to add functionality in the deployment cycle.
32  *
33  * We override attach() to install a different interceptor
34  * from that of the base class that understands SubDeployer
35  * calls. Note that the baseclass invoke(Invocation) won't be
36  * called, so no need to override it.
37  *
38  * Simply call attach()/detach() from createService()/destroyService()
39  * or startService()/stopService() pair methods to attach/detach the
40  * interceptor to the configured Interceptable SubDeployer(s).
41  * Then override any of the init/create/start/stop/destroy methods to
42  * apply the extra interception functionality. Inside those methods
43  * don't forget to forward the call using invokeNext().
44  *
45  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
46  * @version $Revision: 57108 $
47  */

48 public abstract class SubDeployerInterceptorSupport extends InterceptorServiceMBeanSupport
49    implements SubDeployerInterceptorMBean
50 {
51
52    // Constructors -------------------------------------------------
53

54    /**
55     * Constructs an <tt>SubDeployerInterceptorSupport</tt>.
56     */

57    public SubDeployerInterceptorSupport()
58    {
59         super();
60    }
61
62    /**
63     * Constructs an <tt>SubDeployerInterceptorSupport</tt>.
64     *
65     * Pass-through to InterceptorServiceMBeanSupport.
66     *
67     * @param type The class type to determine Logger name from.
68     */

69    public SubDeployerInterceptorSupport(final Class JavaDoc type)
70    {
71       super(type);
72    }
73    
74    /**
75     * Constructs an <tt>SubDeployerInterceptorSupport</tt>.
76     *
77     * Pass-through to InterceptorServiceMBeanSupport.
78     *
79     * @param category The logger category name.
80     */

81    public SubDeployerInterceptorSupport(final String JavaDoc category)
82    {
83       super(category);
84    }
85
86    /**
87     * Constructs an <tt>SubDeployerInterceptorSupport</tt>.
88     *
89     * Pass-through to InterceptorServiceMBeanSupport.
90     *
91     * @param log The logger to use.
92     */

93    public SubDeployerInterceptorSupport(final Logger log)
94    {
95       super(log);
96    }
97     
98    // Protected API -------------------------------------------------
99

100    /**
101     * We override attach() from InterceptorServiceMBeanSupport
102     * to attach a different interceptor that knows how to switch
103     * init/create/start/stop/destroy SubDeployer calls.
104     *
105     * @throws Exception thrown on any interceptor registration error
106     */

107    protected void attach() throws Exception JavaDoc
108    {
109       super.attach(new XMBeanInterceptor());
110    }
111    
112    // Override ------------------------------------------------------
113

114    /**
115     * Override
116     */

117    protected Object JavaDoc init(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
118    {
119       return invokeNext(invocation);
120    }
121
122    /**
123     * Override
124     */

125    protected Object JavaDoc create(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
126    {
127       return invokeNext(invocation);
128    }
129
130    /**
131     * Override
132     */

133    protected Object JavaDoc start(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
134    {
135       return invokeNext(invocation);
136    }
137
138    /**
139     * Override
140     */

141    protected Object JavaDoc stop(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
142    {
143       return invokeNext(invocation);
144    }
145
146    /**
147     * Override
148     */

149    protected Object JavaDoc destroy(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
150    {
151       return invokeNext(invocation);
152    }
153
154    // Private Inner Class -------------------------------------------
155

156    /**
157     * Simple SubDeployerInterceptor delegating to
158     * the SubDeployerInterceptorSupport callbacks
159     */

160    private class XMBeanInterceptor extends SubDeployerInterceptor
161    {
162       public XMBeanInterceptor()
163       {
164          super("XMBeanInterceptor('" + SubDeployerInterceptorSupport.this.getServiceName() + "')");
165       }
166       
167       protected Object JavaDoc init(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
168       {
169          logSubDeployerInvocation(invocation, di);
170          
171          // delegate
172
return SubDeployerInterceptorSupport.this.init(invocation, di);
173       }
174       
175       protected Object JavaDoc create(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
176       {
177          logSubDeployerInvocation(invocation, di);
178          
179          // delegate
180
return SubDeployerInterceptorSupport.this.create(invocation, di);
181       }
182       
183       protected Object JavaDoc start(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
184       {
185          logSubDeployerInvocation(invocation, di);
186
187          // delegate
188
return SubDeployerInterceptorSupport.this.start(invocation, di);
189       }
190       
191       protected Object JavaDoc stop(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
192       {
193          logSubDeployerInvocation(invocation, di);
194
195          // delegate
196
return SubDeployerInterceptorSupport.this.stop(invocation, di);
197       }
198       
199       protected Object JavaDoc destroy(Invocation invocation, DeploymentInfo di) throws Throwable JavaDoc
200       {
201          logSubDeployerInvocation(invocation, di);
202
203          // delegate
204
return SubDeployerInterceptorSupport.this.destroy(invocation, di);
205       }
206       
207       protected void logSubDeployerInvocation(Invocation invocation, DeploymentInfo di)
208       {
209          if (SubDeployerInterceptorSupport.this.log.isTraceEnabled())
210          {
211             StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
212             sbuf.append("intercepting ").append(invocation.getName())
213                .append("(), url=").append(di.url.toString())
214                .append(", state=").append(di.state.toString());
215             
216             SubDeployerInterceptorSupport.this.log.trace(sbuf.toString());
217          }
218       }
219    }
220 }
221
Popular Tags