KickJava   Java API By Example, From Geeks To Geeks.

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


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.handler.MessageContext JavaDoc;
19 import javax.xml.rpc.server.ServiceLifecycle JavaDoc;
20 import javax.xml.rpc.server.ServletEndpointContext JavaDoc;
21 import javax.xml.rpc.ServiceException JavaDoc;
22
23 import org.apache.avalon.framework.logger.AbstractLogEnabled;
24 import org.apache.avalon.framework.logger.Logger;
25
26 import org.apache.cocoon.components.axis.SoapServer; // or use Constants ?
27

28 /**
29  * Base class for providing LogEnabled SOAP services.
30  *
31  * <p>
32  * Note, this class is intended to be used for SOAP Services that require
33  * accessing to a logging object for reporting purposes only.
34  * </p>
35  *
36  * <p>
37  * If you require full Avalon support for your SOAP Service, then consider
38  * using the AvalonProvider support built into Axis itself.
39  * </p>
40  *
41  * @author <a HREF="mailto:crafterm@apache.org">Marcus Crafter</a>
42  * @version CVS $Id: AbstractLogEnabledService.java 53741 2004-10-04 19:24:11Z vgritsenko $
43  */

44 public abstract class AbstractLogEnabledService
45         extends AbstractLogEnabled
46         implements ServiceLifecycle JavaDoc {
47
48     // servlet endpoint context reference
49
protected ServletEndpointContext JavaDoc m_endPointContext;
50
51     // message context reference
52
protected MessageContext JavaDoc m_context;
53
54     /**
55      * ServiceLifecycle <code>init</code> method. Updates an internal
56      * reference to the given context object, and enables logging for
57      * this service.
58      *
59      * @param context a javax.xml.rpc.ServiceLifecycle context
60      * <code>Object</code> instance
61      * @exception ServiceException if an error occurs
62      */

63     public void init(final Object JavaDoc context) throws ServiceException JavaDoc {
64         setContext(context);
65         setLogger();
66     }
67
68     /**
69      * Helper method to set the internal context reference for future
70      * use.
71      *
72      * @param context a javax.xml.rpc.ServiceLifecycle context
73      * <code>Object</code> instance
74      * @exception ServiceException if an error occurs
75      */

76     private void setContext(final Object JavaDoc context) throws ServiceException JavaDoc {
77         try {
78             m_endPointContext = (ServletEndpointContext JavaDoc) context;
79
80         } catch (final ClassCastException JavaDoc e) {
81             throw new ServiceException JavaDoc(
82                 "Service requires ServletEndPointContext, supplied was " + context, e
83             );
84         }
85
86         m_context = m_endPointContext.getMessageContext();
87     }
88
89     /**
90      * Helper method to obtain the Avalon <code>Logger</code> object out of
91      * the context object and enable logging for this service.
92      */

93     private void setLogger() {
94         enableLogging((Logger) m_context.getProperty(SoapServer.LOGGER));
95     }
96
97     /**
98      * Called by the JAX-RPC runtime to signal the end of this service
99      */

100     public void destroy() {
101         m_context = null;
102     }
103 }
104
Popular Tags