KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > webservices > AbstractComposableService


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.webservices;
17
18 import javax.xml.rpc.ServiceException JavaDoc;
19
20 import org.apache.avalon.framework.component.ComponentException;
21 import org.apache.avalon.framework.component.ComponentManager;
22 import org.apache.avalon.framework.component.Composable;
23 import org.apache.cocoon.components.axis.providers.AvalonProvider;
24
25 /**
26  * Base class for providing Composable SOAP services.
27  *
28  * <p>
29  * Note, this class is intended to be used in SOAP Services that require
30  * references to Component's provided by the Cocoon Component Manager.
31  * </p>
32  *
33  * <p>
34  * If you require full Avalon support in your SOAP Service, consider using
35  * the AvalonProvider support built into Axis itself.
36  * </p>
37  *
38  * @author <a HREF="mailto:crafterm@apache.org">Marcus Crafter</a>
39  * @version CVS $Id: AbstractComposableService.java 53741 2004-10-04 19:24:11Z vgritsenko $
40  */

41 public abstract class AbstractComposableService
42         extends AbstractLogEnabledService
43         implements Composable {
44     
45     // component manager reference
46
protected ComponentManager m_manager;
47
48     /**
49      * ServiceLifecycle <code>init</code> method. Updates an internal
50      * reference to the given context object, and enables logging for
51      * this service.
52      *
53      * @param context a javax.xml.rpc.ServiceLifecycle context
54      * <code>Object</code> instance
55      * @exception ServiceException if an error occurs
56      */

57     public void init(final Object JavaDoc context) throws ServiceException JavaDoc {
58         super.init(context);
59
60         try {
61             setComponentManager();
62
63         } catch (ComponentException e) {
64             throw new ServiceException JavaDoc("ComponentException generated", e);
65         }
66     }
67
68     /**
69      * Compose this service.
70      *
71      * @param manager a <code>ComponentManager</code> instance
72      * @exception ComponentException if an error occurs
73      */

74     public void compose(final ComponentManager manager) throws ComponentException {
75         m_manager = manager;
76     }
77
78     /**
79      * Helper method to extract the ComponentManager reference
80      * from the context.
81      * @exception ComponentException if an error occurs
82      */

83     private void setComponentManager() throws ComponentException {
84         compose(
85             (ComponentManager) m_context.getProperty(
86                 AvalonProvider.COMPONENT_MANAGER
87             )
88         );
89     }
90
91     /**
92      * Called by the JAX-RPC runtime to signal the end of this service
93      */

94     public void destroy() {
95         super.destroy();
96
97         m_manager = null;
98     }
99 }
100
Popular Tags