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.wsdl.wsdl11.provider;
18  
19  import org.w3c.dom.Element;
20  
21  import org.springframework.util.Assert;
22  
23  /**
24   * Implementation of the [email protected] MessagesProvider} interface that is based on suffixes.
25   *
26   * @author Arjen Poutsma
27   * @since 1.5.1
28   */
29  public class SuffixBasedMessagesProvider extends DefaultMessagesProvider {
30  
31      /** The default suffix used to detect request elements in the schema. */
32      public static final String DEFAULT_REQUEST_SUFFIX = "Request";
33  
34      /** The default suffix used to detect response elements in the schema. */
35      public static final String DEFAULT_RESPONSE_SUFFIX = "Response";
36  
37      /** The default suffix used to detect fault elements in the schema. */
38      public static final String DEFAULT_FAULT_SUFFIX = "Fault";
39  
40      private String requestSuffix = DEFAULT_REQUEST_SUFFIX;
41  
42      private String responseSuffix = DEFAULT_RESPONSE_SUFFIX;
43  
44      private String faultSuffix = DEFAULT_FAULT_SUFFIX;
45  
46      /**
47       * Returns the suffix used to detect request elements in the schema.
48       *
49       * @see #DEFAULT_REQUEST_SUFFIX
50       */
51      public String getRequestSuffix() {
52          return requestSuffix;
53      }
54  
55      /**
56       * Sets the suffix used to detect request elements in the schema.
57       *
58       * @see #DEFAULT_REQUEST_SUFFIX
59       */
60      public void setRequestSuffix(String requestSuffix) {
61          Assert.hasText(requestSuffix, "'requestSuffix' must not be empty");
62          this.requestSuffix = requestSuffix;
63      }
64  
65      /**
66       * Returns the suffix used to detect response elements in the schema.
67       *
68       * @see #DEFAULT_RESPONSE_SUFFIX
69       */
70      public String getResponseSuffix() {
71          return responseSuffix;
72      }
73  
74      /**
75       * Sets the suffix used to detect response elements in the schema.
76       *
77       * @see #DEFAULT_RESPONSE_SUFFIX
78       */
79      public void setResponseSuffix(String responseSuffix) {
80          Assert.hasText(responseSuffix, "'responseSuffix' must not be empty");
81          this.responseSuffix = responseSuffix;
82      }
83  
84      /**
85       * Returns the suffix used to detect fault elements in the schema.
86       *
87       * @see #DEFAULT_FAULT_SUFFIX
88       */
89      public String getFaultSuffix() {
90          return faultSuffix;
91      }
92  
93      /**
94       * Sets the suffix used to detect fault elements in the schema.
95       *
96       * @see #DEFAULT_FAULT_SUFFIX
97       */
98      public void setFaultSuffix(String faultSuffix) {
99          Assert.hasText(faultSuffix, "'faultSuffix' must not be empty");
100         this.faultSuffix = faultSuffix;
101     }
102 
103     @Override
104     protected boolean isMessageElement(Element element) {
105         if (super.isMessageElement(element)) {
106             String elementName = getElementName(element);
107             Assert.hasText(elementName, "Element has no name");
108             return elementName.endsWith(getRequestSuffix()) || elementName.endsWith(getResponseSuffix()) ||
109                     elementName.endsWith(getFaultSuffix());
110         }
111         else {
112             return false;
113         }
114     }
115 }