1 /* 2 * Copyright 2007 the original author or authors. 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 17 package org.springframework.ws.server.endpoint.adapter; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.springframework.ws.context.MessageContext; 22 import org.springframework.ws.server.EndpointAdapter; 23 import org.springframework.ws.server.endpoint.MethodEndpoint; 24 import org.springframework.xml.transform.TransformerObjectSupport; 25 26 /** 27 * Abstract base class for {@link EndpointAdapter} implementations that support {@link MethodEndpoint}s. Contains 28 * template methods for handling these method endpoints. 29 * 30 * @author Arjen Poutsma 31 * @since 1.0.0 32 */ 33 public abstract class AbstractMethodEndpointAdapter extends TransformerObjectSupport implements EndpointAdapter { 34 35 /** Logger available to subclasses. */ 36 protected final Log logger = LogFactory.getLog(getClass()); 37 38 /** 39 * Delegates to {@link #supportsInternal(org.springframework.ws.server.endpoint.MethodEndpoint)}. 40 * 41 * @param endpoint endpoint object to check 42 * @return whether or not this adapter can adapt the given endpoint 43 */ 44 public final boolean supports(Object endpoint) { 45 return endpoint instanceof MethodEndpoint && supportsInternal((MethodEndpoint) endpoint); 46 } 47 48 /** 49 * Delegates to {@link #invokeInternal(org.springframework.ws.context.MessageContext,MethodEndpoint)}. 50 * 51 * @param messageContext the current message context 52 * @param endpoint the endpoint to use. This object must have previously been passed to the 53 * <code>supportsInternal</code> method of this interface, which must have returned 54 * <code>true</code> 55 * @throws Exception in case of errors 56 */ 57 public final void invoke(MessageContext messageContext, Object endpoint) throws Exception { 58 invokeInternal(messageContext, (MethodEndpoint) endpoint); 59 } 60 61 /** 62 * Given a method endpoint, return whether or not this adapter can support it. 63 * 64 * @param methodEndpoint method endpoint to check 65 * @return whether or not this adapter can adapt the given method 66 */ 67 protected abstract boolean supportsInternal(MethodEndpoint methodEndpoint); 68 69 /** 70 * Use the given method endpoint to handle the request. 71 * 72 * @param messageContext the current message context 73 * @param methodEndpoint the method endpoint to use 74 * @throws Exception in case of errors 75 */ 76 protected abstract void invokeInternal(MessageContext messageContext, MethodEndpoint methodEndpoint) 77 throws Exception; 78 79 }