01: /*
02: * Copyright 2006-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: import org.springframework.core.Ordered;
24: import org.springframework.ws.context.MessageContext;
25: import org.springframework.ws.server.EndpointExceptionResolver;
26:
27: /**
28: * Abstract base class for {@link EndpointExceptionResolver EndpointExceptionResolvers}.
29: * <p/>
30: * <p>Provides a set of mapped endpoints that the resolver should map.
31: *
32: * @author Arjen Poutsma
33: * @since 1.0.0
34: */
35: public abstract class AbstractEndpointExceptionResolver implements
36: EndpointExceptionResolver, Ordered {
37:
38: /** Shared {@link Log} for subclasses to use. */
39: protected final Log logger = LogFactory.getLog(getClass());
40:
41: private int order = Integer.MAX_VALUE; // default: same as non-Ordered
42:
43: private Set mappedEndpoints;
44:
45: /**
46: * Specify the set of endpoints that this exception resolver should map. <p>The exception mappings and the default
47: * fault will only apply to the specified endpoints.
48: * <p/>
49: * If no endpoints are set, both the exception mappings and the default fault will apply to all handlers. This means
50: * that a specified default fault will be used as fallback for all exceptions; any further
51: * <code>EndpointExceptionResolvers</code> in the chain will be ignored in this case.
52: */
53: public void setMappedEndpoints(Set mappedEndpoints) {
54: this .mappedEndpoints = mappedEndpoints;
55: }
56:
57: /**
58: * Specify the order value for this mapping.
59: * <p/>
60: * Default value is {@link Integer#MAX_VALUE}, meaning that it's non-ordered.
61: *
62: * @see org.springframework.core.Ordered#getOrder()
63: */
64: public final void setOrder(int order) {
65: this .order = order;
66: }
67:
68: public final int getOrder() {
69: return order;
70: }
71:
72: /**
73: * Default implementation that checks whether the given <code>endpoint</code> is in the set of {@link
74: * #setMappedEndpoints mapped endpoints}.
75: *
76: * @see #resolveExceptionInternal(org.springframework.ws.context.MessageContext,Object,Exception)
77: */
78: public final boolean resolveException(
79: MessageContext messageContext, Object endpoint, Exception ex) {
80: if (mappedEndpoints != null
81: && !mappedEndpoints.contains(endpoint)) {
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(org.springframework.ws.context.MessageContext,Object,Exception)
95: */
96: protected abstract boolean resolveExceptionInternal(
97: MessageContext messageContext, Object endpoint, Exception ex);
98:
99: }
|