001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.service.factory;
019:
020: import java.lang.reflect.Method;
021: import java.lang.reflect.Modifier;
022: import java.util.Arrays;
023:
024: import javax.xml.namespace.QName;
025:
026: import org.apache.cxf.common.util.ParamReader;
027: import org.apache.cxf.helpers.ServiceUtils;
028: import org.apache.cxf.message.Exchange;
029: import org.apache.cxf.service.model.InterfaceInfo;
030: import org.apache.cxf.service.model.OperationInfo;
031:
032: public class DefaultServiceConfiguration extends
033: AbstractServiceConfiguration {
034:
035: @Override
036: public QName getOperationName(InterfaceInfo service, Method method) {
037: String ns = service.getName().getNamespaceURI();
038: String local = method.getName();
039:
040: QName name = new QName(ns, local);
041: if (service.getOperation(name) == null) {
042: return name;
043: }
044:
045: int i = 1;
046: while (true) {
047: name = new QName(ns, local + i);
048: if (service.getOperation(name) == null) {
049: return name;
050: } else {
051: i++;
052: }
053: }
054: }
055:
056: @Override
057: public QName getFaultName(InterfaceInfo service, OperationInfo o,
058: Class<?> exClass, Class<?> beanClass) {
059: String name = ServiceUtils
060: .makeServiceNameFromClassName(beanClass);
061: return new QName(service.getName().getNamespaceURI(), name);
062: }
063:
064: @Override
065: public QName getInPartName(OperationInfo op, Method method,
066: int paramNumber) {
067: return getInParameterName(op, method, paramNumber);
068: }
069:
070: @Override
071: public QName getOutPartName(OperationInfo op, Method method,
072: int paramNumber) {
073: return getOutParameterName(op, method, paramNumber);
074: }
075:
076: @Override
077: public QName getInParameterName(OperationInfo op, Method method,
078: int paramNumber) {
079: return new QName(op.getName().getNamespaceURI(),
080: getDefaultLocalName(op, method, paramNumber, "arg"));
081: }
082:
083: @Override
084: public QName getInputMessageName(OperationInfo op, Method method) {
085: return new QName(op.getName().getNamespaceURI(), op.getName()
086: .getLocalPart());
087: }
088:
089: @Override
090: public QName getOutParameterName(OperationInfo op, Method method,
091: int paramNumber) {
092: return new QName(op.getName().getNamespaceURI(),
093: getDefaultLocalName(op, method, paramNumber, "return"));
094: }
095:
096: private String getDefaultLocalName(OperationInfo op, Method method,
097: int paramNumber, String prefix) {
098: Class<?> impl = getServiceFactory().getServiceClass();
099: // try to grab the implementation class so we can read the debug symbols from it
100: if (impl == null) {
101: try {
102: method = impl.getMethod(method.getName(), method
103: .getParameterTypes());
104: } catch (Exception e) {
105: throw new ServiceConstructionException(e);
106: }
107: }
108:
109: return DefaultServiceConfiguration.createName(method,
110: paramNumber, op.getInput().getMessageParts().size(),
111: false, prefix);
112: }
113:
114: public static String createName(final Method method,
115: final int paramNumber, final int currentSize,
116: boolean addMethodName, final String flow) {
117: String paramName = "";
118:
119: if (paramNumber != -1) {
120: String[] names = ParamReader
121: .getParameterNamesFromDebugInfo(method);
122:
123: // get the specific parameter name from the parameter Number
124: if (names != null && names[paramNumber] != null) {
125: paramName = names[paramNumber];
126: addMethodName = false;
127: } else {
128: paramName = flow + currentSize;
129: }
130: } else {
131: paramName = flow;
132: }
133:
134: paramName = addMethodName ? method.getName() + paramName
135: : paramName;
136:
137: return paramName;
138: }
139:
140: @Override
141: public QName getOutputMessageName(OperationInfo op, Method method) {
142: return new QName(op.getName().getNamespaceURI(), op.getName()
143: .getLocalPart()
144: + "Response");
145: }
146:
147: @Override
148: public QName getInterfaceName() {
149: return new QName(getServiceFactory().getServiceNamespace(),
150: getServiceName() + "PortType");
151: }
152:
153: @Override
154: public QName getEndpointName() {
155: return new QName(getServiceFactory().getServiceNamespace(),
156: getServiceName() + "Port");
157: }
158:
159: @Override
160: public String getServiceName() {
161: return getServiceFactory().getServiceClass().getSimpleName();
162: }
163:
164: @Override
165: public String getServiceNamespace() {
166: return ServiceUtils
167: .makeNamespaceFromClassName(getServiceFactory()
168: .getServiceClass().getName(), "http");
169: }
170:
171: @Override
172: public Boolean hasOutMessage(Method m) {
173: if (m.getReturnType().getClass().equals(void.class)
174: && m.getExceptionTypes().length == 0) {
175: return false;
176: }
177: return true;
178: }
179:
180: @Override
181: public Boolean isAsync(Method method) {
182: return Boolean.FALSE;
183: }
184:
185: @Override
186: public Boolean isHeader(Method method, int j) {
187: return Boolean.FALSE;
188: }
189:
190: @Override
191: public Boolean isInParam(Method method, int j) {
192: if (j >= 0) {
193: Class c = method.getParameterTypes()[j];
194: if (Exchange.class.equals(c)) {
195: return false;
196: }
197: return true;
198: }
199: return false;
200: }
201:
202: @Override
203: public Boolean isOperation(Method method) {
204: if (getServiceFactory().getIgnoredClasses().contains(
205: method.getDeclaringClass().getName())) {
206: return Boolean.FALSE;
207: }
208:
209: // Don't do m.equals(method)
210: for (Method m : getServiceFactory().getIgnoredMethods()) {
211: if (m.getName().equals(method.getName())
212: && Arrays.equals(method.getParameterTypes(), m
213: .getParameterTypes())
214: && m.getReturnType() == method.getReturnType()) {
215: return Boolean.FALSE;
216: }
217: }
218:
219: final int modifiers = method.getModifiers();
220:
221: if (Modifier.isPublic(modifiers)
222: && !Modifier.isStatic(modifiers)) {
223: return Boolean.TRUE;
224: }
225: return Boolean.FALSE;
226: }
227:
228: @Override
229: public Boolean isOutParam(Method method, int j) {
230: return j < 0;
231: }
232:
233: @Override
234: public Boolean isWrapped(Method m) {
235: return getServiceFactory().isWrapped();
236: }
237: }
|