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 javax.wsdl.Message;
20
21 import org.springframework.util.Assert;
22
23 /**
24 * Implementation of the {@link PortTypesProvider} interface that is based on suffixes.
25 *
26 * @author Arjen Poutsma
27 * @since 1.5.0
28 */
29 public class SuffixBasedPortTypesProvider extends AbstractPortTypesProvider {
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 String getOperationName(Message message) {
105 String messageName = getMessageName(message);
106 if (messageName != null) {
107 if (messageName.endsWith(getRequestSuffix())) {
108 return messageName.substring(0, messageName.length() - getRequestSuffix().length());
109 }
110 else if (messageName.endsWith(getResponseSuffix())) {
111 return messageName.substring(0, messageName.length() - getResponseSuffix().length());
112 }
113 else if (messageName.endsWith(getFaultSuffix())) {
114 return messageName.substring(0, messageName.length() - getFaultSuffix().length());
115 }
116 }
117 return null;
118 }
119
120 /**
121 * Indicates whether the given name name should be included as {@link javax.wsdl.Input} message in the definition.
122 * <p/>
123 * This implementation checks whether the message name ends with the {@link #setRequestSuffix(String)
124 * requestSuffix}.
125 *
126 * @param message the message
127 * @return <code>true</code> if to be included as input; <code>false</code> otherwise
128 */
129 @Override
130 protected boolean isInputMessage(Message message) {
131 String messageName = getMessageName(message);
132 return messageName != null && messageName.endsWith(getRequestSuffix());
133 }
134
135 /**
136 * Indicates whether the given name name should be included as {@link javax.wsdl.Output} message in the definition.
137 * <p/>
138 * This implementation checks whether the message name ends with the {@link #setResponseSuffix(String)
139 * responseSuffix}.
140 *
141 * @param message the message
142 * @return <code>true</code> if to be included as output; <code>false</code> otherwise
143 */
144 @Override
145 protected boolean isOutputMessage(Message message) {
146 String messageName = getMessageName(message);
147 return messageName != null && messageName.endsWith(getResponseSuffix());
148 }
149
150 /**
151 * Indicates whether the given name name should be included as {@link javax.wsdl.Fault} message in the definition.
152 * <p/>
153 * This implementation checks whether the message name ends with the {@link #setFaultSuffix(String) faultSuffix}.
154 *
155 * @param message the message
156 * @return <code>true</code> if to be included as fault; <code>false</code> otherwise
157 */
158 @Override
159 protected boolean isFaultMessage(Message message) {
160 String messageName = getMessageName(message);
161 return messageName != null && messageName.endsWith(getFaultSuffix());
162 }
163
164 private String getMessageName(Message message) {
165 return message.getQName().getLocalPart();
166 }
167 }