1 /*
2 * Copyright 2006-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;
18
19 import java.util.Set;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import org.springframework.core.Ordered;
25 import org.springframework.ws.context.MessageContext;
26 import org.springframework.ws.server.EndpointExceptionResolver;
27
28 /**
29 * Abstract base class for {@link EndpointExceptionResolver EndpointExceptionResolvers}.
30 * <p/>
31 * <p>Provides a set of mapped endpoints that the resolver should map.
32 *
33 * @author Arjen Poutsma
34 * @author Tareq Abed Rabbo
35 * @since 1.0.0
36 */
37 public abstract class AbstractEndpointExceptionResolver implements EndpointExceptionResolver, Ordered {
38
39 /** Shared {@link Log} for subclasses to use. */
40 protected final Log logger = LogFactory.getLog(getClass());
41
42 private int order = Integer.MAX_VALUE; // default: same as non-Ordered
43
44 private Set mappedEndpoints;
45
46 /**
47 * Specify the set of endpoints that this exception resolver should map. <p>The exception mappings and the default
48 * fault will only apply to the specified endpoints.
49 * <p/>
50 * If no endpoints are set, both the exception mappings and the default fault will apply to all handlers. This means
51 * that a specified default fault will be used as fallback for all exceptions; any further
52 * <code>EndpointExceptionResolvers</code> in the chain will be ignored in this case.
53 */
54 public void setMappedEndpoints(Set mappedEndpoints) {
55 this.mappedEndpoints = mappedEndpoints;
56 }
57
58 /**
59 * Specify the order value for this mapping.
60 * <p/>
61 * Default value is {@link Integer#MAX_VALUE}, meaning that it's non-ordered.
62 *
63 * @see org.springframework.core.Ordered#getOrder()
64 */
65 public final void setOrder(int order) {
66 this.order = order;
67 }
68
69 public final int getOrder() {
70 return order;
71 }
72
73 /**
74 * Default implementation that checks whether the given <code>endpoint</code> is in the set of {@link
75 * #setMappedEndpoints mapped endpoints}.
76 *
77 * @see #resolveExceptionInternal(MessageContext,Object,Exception)
78 */
79 public final boolean resolveException(MessageContext messageContext, Object endpoint, Exception ex) {
80 Object mappedEndpoint = endpoint instanceof MethodEndpoint ? ((MethodEndpoint) endpoint).getBean() : endpoint;
81 if (mappedEndpoints != null && !mappedEndpoints.contains(mappedEndpoint)) {
82 return false;
83 }
84 return resolveExceptionInternal(messageContext, endpoint, ex);
85 }
86
87 /**
88 * Template method for resolving exceptions that is called by {@link #resolveException}.
89 *
90 * @param messageContext current message context
91 * @param endpoint the executed endpoint, or <code>null</code> if none chosen at the time of the exception
92 * @param ex the exception that got thrown during endpoint execution
93 * @return <code>true</code> if resolved; <code>false</code> otherwise
94 * @see #resolveException(MessageContext,Object,Exception)
95 */
96 protected abstract boolean resolveExceptionInternal(MessageContext messageContext, Object endpoint, Exception ex);
97
98 }