01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.webservices;
18:
19: import javax.xml.rpc.ServiceException;
20:
21: import org.apache.avalon.framework.component.ComponentException;
22: import org.apache.avalon.framework.component.ComponentManager;
23: import org.apache.avalon.framework.component.Composable;
24: import org.apache.cocoon.components.axis.providers.AvalonProvider;
25:
26: /**
27: * Base class for providing Composable SOAP services.
28: *
29: * <p>
30: * Note, this class is intended to be used in SOAP Services that require
31: * references to Component's provided by the Cocoon Component Manager.
32: * </p>
33: *
34: * <p>
35: * If you require full Avalon support in your SOAP Service, consider using
36: * the AvalonProvider support built into Axis itself.
37: * </p>
38: *
39: * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
40: * @version CVS $Id: AbstractComposableService.java 433543 2006-08-22 06:22:54Z crossley $
41: */
42: public abstract class AbstractComposableService extends
43: AbstractLogEnabledService 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 context) throws ServiceException {
58: super .init(context);
59:
60: try {
61: setComponentManager();
62:
63: } catch (ComponentException e) {
64: throw new ServiceException("ComponentException generated",
65: e);
66: }
67: }
68:
69: /**
70: * Compose this service.
71: *
72: * @param manager a <code>ComponentManager</code> instance
73: * @exception ComponentException if an error occurs
74: */
75: public void compose(final ComponentManager manager)
76: throws ComponentException {
77: m_manager = manager;
78: }
79:
80: /**
81: * Helper method to extract the ComponentManager reference
82: * from the context.
83: * @exception ComponentException if an error occurs
84: */
85: private void setComponentManager() throws ComponentException {
86: compose((ComponentManager) m_context
87: .getProperty(AvalonProvider.COMPONENT_MANAGER));
88: }
89:
90: /**
91: * Called by the JAX-RPC runtime to signal the end of this service
92: */
93: public void destroy() {
94: super.destroy();
95:
96: m_manager = null;
97: }
98: }
|