001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.webservices;
018:
019: import javax.xml.rpc.handler.MessageContext;
020: import javax.xml.rpc.server.ServiceLifecycle;
021: import javax.xml.rpc.server.ServletEndpointContext;
022: import javax.xml.rpc.ServiceException;
023:
024: import org.apache.avalon.framework.logger.AbstractLogEnabled;
025: import org.apache.avalon.framework.logger.Logger;
026:
027: import org.apache.cocoon.components.axis.SoapServer; // or use Constants ?
028:
029: /**
030: * Base class for providing LogEnabled SOAP services.
031: *
032: * <p>
033: * Note, this class is intended to be used for SOAP Services that require
034: * accessing to a logging object for reporting purposes only.
035: * </p>
036: *
037: * <p>
038: * If you require full Avalon support for your SOAP Service, then consider
039: * using the AvalonProvider support built into Axis itself.
040: * </p>
041: *
042: * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
043: * @version CVS $Id: AbstractLogEnabledService.java 433543 2006-08-22 06:22:54Z crossley $
044: */
045: public abstract class AbstractLogEnabledService extends
046: AbstractLogEnabled implements ServiceLifecycle {
047:
048: // servlet endpoint context reference
049: protected ServletEndpointContext m_endPointContext;
050:
051: // message context reference
052: protected MessageContext m_context;
053:
054: /**
055: * ServiceLifecycle <code>init</code> method. Updates an internal
056: * reference to the given context object, and enables logging for
057: * this service.
058: *
059: * @param context a javax.xml.rpc.ServiceLifecycle context
060: * <code>Object</code> instance
061: * @exception ServiceException if an error occurs
062: */
063: public void init(final Object context) throws ServiceException {
064: setContext(context);
065: setLogger();
066: }
067:
068: /**
069: * Helper method to set the internal context reference for future
070: * use.
071: *
072: * @param context a javax.xml.rpc.ServiceLifecycle context
073: * <code>Object</code> instance
074: * @exception ServiceException if an error occurs
075: */
076: private void setContext(final Object context)
077: throws ServiceException {
078: try {
079: m_endPointContext = (ServletEndpointContext) context;
080:
081: } catch (final ClassCastException e) {
082: throw new ServiceException(
083: "Service requires ServletEndPointContext, supplied was "
084: + context, e);
085: }
086:
087: m_context = m_endPointContext.getMessageContext();
088: }
089:
090: /**
091: * Helper method to obtain the Avalon <code>Logger</code> object out of
092: * the context object and enable logging for this service.
093: */
094: private void setLogger() {
095: enableLogging((Logger) m_context.getProperty(SoapServer.LOGGER));
096: }
097:
098: /**
099: * Called by the JAX-RPC runtime to signal the end of this service
100: */
101: public void destroy() {
102: m_context = null;
103: }
104: }
|