View Javadoc

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