0001: /**
0002: * Licensed to the Apache Software Foundation (ASF) under one
0003: * or more contributor license agreements. See the NOTICE file
0004: * distributed with this work for additional information
0005: * regarding copyright ownership. The ASF licenses this file
0006: * to you under the Apache License, Version 2.0 (the
0007: * "License"); you may not use this file except in compliance
0008: * with the License. You may obtain a copy of the License at
0009: *
0010: * http://www.apache.org/licenses/LICENSE-2.0
0011: *
0012: * Unless required by applicable law or agreed to in writing,
0013: * software distributed under the License is distributed on an
0014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015: * KIND, either express or implied. See the License for the
0016: * specific language governing permissions and limitations
0017: * under the License.
0018: */package org.apache.cxf.service.factory;
0019:
0020: import java.lang.reflect.Array;
0021: import java.lang.reflect.Field;
0022: import java.lang.reflect.GenericArrayType;
0023: import java.lang.reflect.Method;
0024: import java.lang.reflect.ParameterizedType;
0025: import java.lang.reflect.Type;
0026: import java.net.URL;
0027: import java.util.ArrayList;
0028: import java.util.Arrays;
0029: import java.util.Collection;
0030: import java.util.HashMap;
0031: import java.util.Iterator;
0032: import java.util.List;
0033: import java.util.Map;
0034: import java.util.ResourceBundle;
0035: import java.util.concurrent.Executor;
0036: import java.util.logging.Logger;
0037:
0038: import javax.xml.namespace.QName;
0039: import javax.xml.ws.Holder;
0040:
0041: import org.apache.cxf.BusException;
0042: import org.apache.cxf.binding.BindingFactoryManager;
0043: import org.apache.cxf.common.i18n.BundleUtils;
0044: import org.apache.cxf.common.i18n.Message;
0045: import org.apache.cxf.endpoint.Endpoint;
0046: import org.apache.cxf.endpoint.EndpointException;
0047: import org.apache.cxf.endpoint.EndpointImpl;
0048: import org.apache.cxf.frontend.MethodDispatcher;
0049: import org.apache.cxf.frontend.SimpleMethodDispatcher;
0050: import org.apache.cxf.helpers.MethodComparator;
0051: import org.apache.cxf.interceptor.Fault;
0052: import org.apache.cxf.interceptor.FaultOutInterceptor;
0053: import org.apache.cxf.jaxb.JAXBDataBinding;
0054: import org.apache.cxf.service.Service;
0055: import org.apache.cxf.service.ServiceImpl;
0056: import org.apache.cxf.service.invoker.ApplicationScopePolicy;
0057: import org.apache.cxf.service.invoker.FactoryInvoker;
0058: import org.apache.cxf.service.invoker.Invoker;
0059: import org.apache.cxf.service.invoker.LocalFactory;
0060: import org.apache.cxf.service.model.AbstractMessageContainer;
0061: import org.apache.cxf.service.model.BindingInfo;
0062: import org.apache.cxf.service.model.BindingOperationInfo;
0063: import org.apache.cxf.service.model.EndpointInfo;
0064: import org.apache.cxf.service.model.FaultInfo;
0065: import org.apache.cxf.service.model.InterfaceInfo;
0066: import org.apache.cxf.service.model.MessageInfo;
0067: import org.apache.cxf.service.model.MessagePartInfo;
0068: import org.apache.cxf.service.model.OperationInfo;
0069: import org.apache.cxf.service.model.SchemaInfo;
0070: import org.apache.cxf.service.model.ServiceInfo;
0071: import org.apache.cxf.service.model.UnwrappedOperationInfo;
0072: import org.apache.cxf.wsdl.WSDLConstants;
0073: import org.apache.cxf.wsdl11.WSDLServiceFactory;
0074: import org.apache.ws.commons.schema.XmlSchema;
0075: import org.apache.ws.commons.schema.XmlSchemaCollection;
0076: import org.apache.ws.commons.schema.XmlSchemaComplexType;
0077: import org.apache.ws.commons.schema.XmlSchemaElement;
0078: import org.apache.ws.commons.schema.XmlSchemaForm;
0079: import org.apache.ws.commons.schema.XmlSchemaImport;
0080: import org.apache.ws.commons.schema.XmlSchemaObject;
0081: import org.apache.ws.commons.schema.XmlSchemaSequence;
0082: import org.apache.ws.commons.schema.XmlSchemaType;
0083: import org.apache.ws.commons.schema.constants.Constants;
0084: import org.apache.ws.commons.schema.utils.NamespaceMap;
0085:
0086: /**
0087: * Introspects a class and builds a {@link Service} from it. If a WSDL URL is
0088: * specified, a Service model will be directly from the WSDL and then metadata
0089: * will be filled in from the service class. If no WSDL URL is specified, the
0090: * Service will be constructed directly from the class structure.
0091: */
0092: public class ReflectionServiceFactoryBean extends
0093: AbstractServiceFactoryBean {
0094:
0095: public static final String ENDPOINT_CLASS = "endpoint.class";
0096: public static final String GENERIC_TYPE = "generic.type";
0097: public static final String MODE_OUT = "messagepart.mode.out";
0098: public static final String MODE_INOUT = "messagepart.mode.inout";
0099: public static final String HOLDER = "messagepart.isholder";
0100: public static final String HEADER = "messagepart.isheader";
0101: public static final String ELEMENT_NAME = "messagepart.elementName";
0102: public static final String METHOD = "operation.method";
0103:
0104: private static final Logger LOG = Logger
0105: .getLogger(ReflectionServiceFactoryBean.class.getName());
0106: private static final ResourceBundle BUNDLE = BundleUtils
0107: .getBundle(ReflectionServiceFactoryBean.class);
0108:
0109: protected String wsdlURL;
0110:
0111: protected Class<?> serviceClass;
0112:
0113: private List<AbstractServiceConfiguration> serviceConfigurations = new ArrayList<AbstractServiceConfiguration>();
0114: private QName serviceName;
0115: private Invoker invoker;
0116: private Executor executor;
0117: private List<String> ignoredClasses = new ArrayList<String>();
0118: private List<Method> ignoredMethods = new ArrayList<Method>();
0119: private SimpleMethodDispatcher methodDispatcher = new SimpleMethodDispatcher();
0120: private Boolean wrappedStyle;
0121: private Map<String, Object> properties;
0122: private QName endpointName;
0123: private boolean populateFromClass;
0124:
0125: public ReflectionServiceFactoryBean() {
0126: getServiceConfigurations().add(0,
0127: new DefaultServiceConfiguration());
0128:
0129: setDataBinding(new JAXBDataBinding());
0130:
0131: ignoredClasses.add("java.lang.Object");
0132: ignoredClasses.add("java.lang.Throwable");
0133: ignoredClasses.add("org.omg.CORBA_2_3.portable.ObjectImpl");
0134: ignoredClasses.add("org.omg.CORBA.portable.ObjectImpl");
0135: ignoredClasses.add("javax.ejb.EJBObject");
0136: ignoredClasses.add("javax.rmi.CORBA.Stub");
0137: }
0138:
0139: @Override
0140: public Service create() {
0141: initializeServiceConfigurations();
0142:
0143: initializeServiceModel();
0144:
0145: initializeDefaultInterceptors();
0146:
0147: if (invoker != null) {
0148: getService().setInvoker(getInvoker());
0149: } else {
0150: getService().setInvoker(createInvoker());
0151: }
0152:
0153: if (getExecutor() != null) {
0154: getService().setExecutor(getExecutor());
0155: }
0156: if (getDataBinding() != null) {
0157: getService().setDataBinding(getDataBinding());
0158: }
0159:
0160: getService().put(MethodDispatcher.class.getName(),
0161: getMethodDispatcher());
0162:
0163: createEndpoints();
0164:
0165: return getService();
0166: }
0167:
0168: protected void createEndpoints() {
0169: Service service = getService();
0170:
0171: BindingFactoryManager bfm = getBus().getExtension(
0172: BindingFactoryManager.class);
0173:
0174: for (ServiceInfo inf : service.getServiceInfos()) {
0175: for (EndpointInfo ei : inf.getEndpoints()) {
0176:
0177: try {
0178: bfm.getBindingFactory(ei.getBinding()
0179: .getBindingId());
0180: } catch (BusException e1) {
0181: continue;
0182: }
0183:
0184: try {
0185: Endpoint ep = createEndpoint(ei);
0186:
0187: service.getEndpoints().put(ei.getName(), ep);
0188: } catch (EndpointException e) {
0189: throw new ServiceConstructionException(e);
0190: }
0191: }
0192: }
0193: }
0194:
0195: public Endpoint createEndpoint(EndpointInfo ei)
0196: throws EndpointException {
0197: return new EndpointImpl(getBus(), getService(), ei);
0198: }
0199:
0200: protected void initializeServiceConfigurations() {
0201: for (AbstractServiceConfiguration c : serviceConfigurations) {
0202: c.setServiceFactory(this );
0203: }
0204: }
0205:
0206: protected void buildServiceFromWSDL(String url) {
0207: LOG.info("Creating Service " + getServiceQName()
0208: + " from WSDL: " + url);
0209: WSDLServiceFactory factory = new WSDLServiceFactory(getBus(),
0210: url, getServiceQName());
0211: setService(factory.create());
0212:
0213: if (properties != null) {
0214: getService().putAll(properties);
0215: }
0216:
0217: initializeWSDLOperations();
0218:
0219: if (getDataBinding() != null) {
0220: getDataBinding().initialize(getService());
0221: }
0222: }
0223:
0224: protected void buildServiceFromClass() {
0225: LOG.info("Creating Service " + getServiceQName()
0226: + " from class " + getServiceClass().getName());
0227: ServiceInfo serviceInfo = new ServiceInfo();
0228: ServiceImpl service = new ServiceImpl(serviceInfo);
0229:
0230: setService(service);
0231:
0232: if (properties != null) {
0233: service.putAll(properties);
0234: }
0235:
0236: service.put(MethodDispatcher.class.getName(),
0237: getMethodDispatcher());
0238:
0239: serviceInfo.setName(getServiceQName());
0240: serviceInfo.setTargetNamespace(serviceInfo.getName()
0241: .getNamespaceURI());
0242:
0243: createInterface(serviceInfo);
0244:
0245: getDataBinding().initialize(service);
0246:
0247: boolean isWrapped = isWrapped();
0248: if (isWrapped) {
0249: initializeWrappedSchema(serviceInfo);
0250: }
0251:
0252: for (OperationInfo opInfo : serviceInfo.getInterface()
0253: .getOperations()) {
0254: Method m = (Method) opInfo.getProperty(METHOD);
0255:
0256: if (!isWrapped(m) && !isRPC(m) && opInfo.getInput() != null) {
0257: createBareMessage(serviceInfo, opInfo, false);
0258:
0259: }
0260:
0261: if (!isWrapped(m) && !isRPC(m)
0262: && opInfo.getOutput() != null) {
0263: createBareMessage(serviceInfo, opInfo, true);
0264: }
0265:
0266: }
0267: }
0268:
0269: protected void initializeServiceModel() {
0270: String wsdlurl = getWsdlURL();
0271:
0272: if (!populateFromClass && wsdlurl != null) {
0273: buildServiceFromWSDL(wsdlurl);
0274: } else {
0275: buildServiceFromClass();
0276: }
0277: }
0278:
0279: public boolean isPopulateFromClass() {
0280: return populateFromClass;
0281: }
0282:
0283: public void setPopulateFromClass(boolean fomClass) {
0284: this .populateFromClass = fomClass;
0285: }
0286:
0287: protected InterfaceInfo getInterfaceInfo() {
0288: if (getEndpointInfo() != null) {
0289: return getEndpointInfo().getInterface();
0290: }
0291: QName qn = this .getInterfaceName();
0292: for (ServiceInfo si : getService().getServiceInfos()) {
0293: if (qn.equals(si.getInterface().getName())) {
0294: return si.getInterface();
0295: }
0296: }
0297: throw new ServiceConstructionException(new Message(
0298: "COULD_NOT_FIND_PORTTYPE", BUNDLE, qn));
0299: }
0300:
0301: protected void initializeWSDLOperations() {
0302: Method[] methods = serviceClass.getMethods();
0303: Arrays.sort(methods, new MethodComparator());
0304:
0305: InterfaceInfo intf = getInterfaceInfo();
0306:
0307: Map<QName, Method> validMethods = new HashMap<QName, Method>();
0308: for (Method m : methods) {
0309: if (isValidMethod(m)) {
0310: QName opName = getOperationName(intf, m);
0311: validMethods.put(opName, m);
0312: }
0313: }
0314:
0315: for (OperationInfo o : intf.getOperations()) {
0316: Method selected = null;
0317: for (Map.Entry<QName, Method> m : validMethods.entrySet()) {
0318: QName opName = m.getKey();
0319:
0320: if (o.getName().getNamespaceURI().equals(
0321: opName.getNamespaceURI())
0322: && isMatchOperation(o.getName().getLocalPart(),
0323: opName.getLocalPart())) {
0324: selected = m.getValue();
0325: break;
0326: }
0327: }
0328:
0329: if (selected == null) {
0330: throw new ServiceConstructionException(new Message(
0331: "NO_METHOD_FOR_OP", BUNDLE, o.getName()));
0332: }
0333:
0334: initializeWSDLOperation(intf, o, selected);
0335: }
0336:
0337: //Some of the operations may have switched from unwrapped to wrapped. Update the bindings.
0338: for (ServiceInfo service : getService().getServiceInfos()) {
0339: for (BindingInfo bi : service.getBindings()) {
0340: for (BindingOperationInfo binfo : bi.getOperations()) {
0341: binfo.updateUnwrappedOperation();
0342: }
0343: }
0344: }
0345: }
0346:
0347: protected void initializeWSDLOperation(InterfaceInfo intf,
0348: OperationInfo o, Method selected) {
0349: // TODO Auto-generated method stub
0350:
0351: }
0352:
0353: protected Invoker createInvoker() {
0354: return new FactoryInvoker(new LocalFactory(getServiceClass()),
0355: new ApplicationScopePolicy());
0356: }
0357:
0358: protected ServiceInfo createServiceInfo(InterfaceInfo intf) {
0359: ServiceInfo svcInfo = new ServiceInfo();
0360: svcInfo.setInterface(intf);
0361:
0362: return svcInfo;
0363: }
0364:
0365: protected InterfaceInfo createInterface(ServiceInfo serviceInfo) {
0366: QName intfName = getInterfaceName();
0367: InterfaceInfo intf = new InterfaceInfo(serviceInfo, intfName);
0368:
0369: Method[] methods = serviceClass.getMethods();
0370:
0371: // The BP profile states we can't have operations of the same name
0372: // so we have to append numbers to the name. Different JVMs sort methods
0373: // differently.
0374: // We need to keep them ordered so if we have overloaded methods, the
0375: // wsdl is generated the same every time across JVMs and across
0376: // client/servers.
0377: Arrays.sort(methods, new MethodComparator());
0378:
0379: for (Method m : methods) {
0380: if (isValidMethod(m)) {
0381: createOperation(serviceInfo, intf, m);
0382: }
0383: }
0384:
0385: return intf;
0386: }
0387:
0388: protected OperationInfo createOperation(ServiceInfo serviceInfo,
0389: InterfaceInfo intf, Method m) {
0390: OperationInfo op = intf.addOperation(getOperationName(intf, m));
0391: op.setProperty(m.getClass().getName(), m);
0392: op.setProperty("action", getAction(op, m));
0393:
0394: if (isWrapped(m)) {
0395: UnwrappedOperationInfo uOp = new UnwrappedOperationInfo(op);
0396: op.setUnwrappedOperation(uOp);
0397:
0398: createMessageParts(intf, uOp, m);
0399:
0400: if (uOp.hasInput()) {
0401: MessageInfo msg = new MessageInfo(op, uOp.getInput()
0402: .getName());
0403: op.setInput(uOp.getInputName(), msg);
0404:
0405: createInputWrappedMessageParts(uOp, m, msg);
0406:
0407: for (MessagePartInfo p : uOp.getInput()
0408: .getMessageParts()) {
0409: p.setConcreteName(p.getName());
0410: }
0411: }
0412:
0413: if (uOp.hasOutput()) {
0414:
0415: QName name = uOp.getOutput().getName();
0416: MessageInfo msg = new MessageInfo(op, name);
0417: op.setOutput(uOp.getOutputName(), msg);
0418:
0419: createOutputWrappedMessageParts(uOp, m, msg);
0420:
0421: for (MessagePartInfo p : uOp.getOutput()
0422: .getMessageParts()) {
0423: p.setConcreteName(p.getName());
0424: }
0425: }
0426: } else {
0427: createMessageParts(intf, op, m);
0428: }
0429:
0430: getMethodDispatcher().bind(op, m);
0431:
0432: return op;
0433: }
0434:
0435: protected void initializeWrappedSchema(ServiceInfo serviceInfo) {
0436: for (OperationInfo op : serviceInfo.getInterface()
0437: .getOperations()) {
0438: if (op.getUnwrappedOperation() != null) {
0439: if (op.hasInput()) {
0440: QName wraperBeanName = op.getInput()
0441: .getMessageParts().get(0).getElementQName();
0442: XmlSchemaElement e = null;
0443: for (SchemaInfo s : serviceInfo.getSchemas()) {
0444: e = s.getElementByQName(wraperBeanName);
0445: if (e != null) {
0446: op.getInput().getMessageParts().get(0)
0447: .setXmlSchema(e);
0448: break;
0449: }
0450: }
0451: if (e == null) {
0452: createWrappedSchema(serviceInfo, op.getInput(),
0453: op.getUnwrappedOperation().getInput(),
0454: wraperBeanName);
0455: }
0456:
0457: for (MessagePartInfo mpi : op.getInput()
0458: .getMessageParts()) {
0459: if (Boolean.TRUE
0460: .equals(mpi.getProperty(HEADER))) {
0461: QName qn = (QName) mpi
0462: .getProperty(ELEMENT_NAME);
0463: mpi.setElement(true);
0464: mpi.setElementQName(qn);
0465:
0466: checkForHeaderElement(serviceInfo, mpi);
0467: }
0468: }
0469:
0470: }
0471: if (op.hasOutput()) {
0472: QName wraperBeanName = op.getOutput()
0473: .getMessageParts().get(0).getElementQName();
0474: XmlSchemaElement e = null;
0475: for (SchemaInfo s : serviceInfo.getSchemas()) {
0476: e = s.getElementByQName(wraperBeanName);
0477: if (e != null) {
0478: break;
0479: }
0480: }
0481: if (e == null) {
0482: createWrappedSchema(serviceInfo,
0483: op.getOutput(), op
0484: .getUnwrappedOperation()
0485: .getOutput(), wraperBeanName);
0486: }
0487:
0488: for (MessagePartInfo mpi : op.getOutput()
0489: .getMessageParts()) {
0490: if (Boolean.TRUE
0491: .equals(mpi.getProperty(HEADER))) {
0492: QName qn = (QName) mpi
0493: .getProperty(ELEMENT_NAME);
0494: mpi.setElement(true);
0495: mpi.setElementQName(qn);
0496:
0497: checkForHeaderElement(serviceInfo, mpi);
0498: }
0499: }
0500: }
0501: }
0502: }
0503:
0504: }
0505:
0506: protected void checkForHeaderElement(ServiceInfo serviceInfo,
0507: MessagePartInfo mpi) {
0508: for (SchemaInfo s : serviceInfo.getSchemas()) {
0509: XmlSchemaElement e = s.getElementByQName(mpi
0510: .getElementQName());
0511: if (e != null) {
0512: return;
0513: }
0514: }
0515: SchemaInfo si = getOrCreateSchema(serviceInfo, mpi
0516: .getElementQName().getNamespaceURI());
0517: XmlSchema schema = si.getSchema();
0518:
0519: XmlSchemaElement el = new XmlSchemaElement();
0520: el.setQName(mpi.getElementQName());
0521: el.setName(mpi.getElementQName().getLocalPart());
0522: if (!isExistSchemaElement(schema, mpi.getElementQName())) {
0523: schema.getItems().add(el);
0524: }
0525: el.setMinOccurs(1);
0526: el.setMaxOccurs(0);
0527: el.setNillable(true);
0528:
0529: XmlSchemaType tp = (XmlSchemaType) mpi.getXmlSchema();
0530: el.setSchemaTypeName(tp.getQName());
0531: }
0532:
0533: protected boolean qualifyWrapperSchema() {
0534: return true;
0535: }
0536:
0537: protected void createWrappedSchema(ServiceInfo serviceInfo,
0538: AbstractMessageContainer wrappedMessage,
0539: AbstractMessageContainer unwrappedMessage,
0540: QName wraperBeanName) {
0541: SchemaInfo schemaInfo = getOrCreateSchema(serviceInfo,
0542: wraperBeanName.getNamespaceURI());
0543:
0544: createWrappedMessageSchema(serviceInfo, wrappedMessage,
0545: unwrappedMessage, schemaInfo.getSchema(),
0546: wraperBeanName);
0547: }
0548:
0549: protected void createBareMessage(ServiceInfo serviceInfo,
0550: OperationInfo opInfo, boolean isOut) {
0551:
0552: SchemaInfo schemaInfo = null;
0553: XmlSchema schema = null;
0554: MessageInfo message = isOut ? opInfo.getOutput() : opInfo
0555: .getInput();
0556:
0557: if (message.getMessageParts().size() == 0) {
0558: return;
0559: }
0560:
0561: Method method = (Method) opInfo.getProperty(METHOD);
0562: int paraNumber = 0;
0563: for (MessagePartInfo mpi : message.getMessageParts()) {
0564: QName qname = (QName) mpi.getProperty(ELEMENT_NAME);
0565: if (message.getMessageParts().size() == 1) {
0566: qname = qname == null && !isOut ? getInParameterName(
0567: opInfo, method, -1) : qname;
0568: qname = qname == null && isOut ? getOutParameterName(
0569: opInfo, method, -1) : qname;
0570: if (qname.getLocalPart().startsWith("arg")
0571: || qname.getLocalPart().startsWith("return")) {
0572: qname = isOut ? new QName(qname.getNamespaceURI(),
0573: method.getName() + "Response") : new QName(
0574: qname.getNamespaceURI(), method.getName());
0575: }
0576:
0577: }
0578:
0579: if (isOut && message.getMessageParts().size() > 1
0580: && qname == null) {
0581: while (!isOutParam(method, paraNumber)) {
0582: paraNumber++;
0583: }
0584: qname = getOutParameterName(opInfo, method, paraNumber);
0585: } else if (qname == null) {
0586: qname = getInParameterName(opInfo, method, paraNumber);
0587: }
0588:
0589: for (SchemaInfo s : serviceInfo.getSchemas()) {
0590: if (s.getNamespaceURI().equals(qname.getNamespaceURI())) {
0591: schemaInfo = s;
0592: break;
0593: }
0594: }
0595:
0596: if (schemaInfo == null) {
0597: schemaInfo = new SchemaInfo(serviceInfo, qname
0598: .getNamespaceURI());
0599: XmlSchemaCollection col = new XmlSchemaCollection();
0600: schema = new XmlSchema(qname.getNamespaceURI(), col);
0601: schema.setElementFormDefault(new XmlSchemaForm(
0602: XmlSchemaForm.QUALIFIED));
0603: serviceInfo.setXmlSchemaCollection(col);
0604:
0605: NamespaceMap nsMap = new NamespaceMap();
0606: nsMap.add(WSDLConstants.NP_SCHEMA_XSD,
0607: WSDLConstants.NU_SCHEMA_XSD);
0608: schema.setNamespaceContext(nsMap);
0609: serviceInfo.addSchema(schemaInfo);
0610: } else {
0611: schema = schemaInfo.getSchema();
0612: if (schema != null
0613: && schema.getElementByName(qname) != null) {
0614: mpi.setElement(true);
0615: mpi.setElementQName(qname);
0616: paraNumber++;
0617: continue;
0618: }
0619: }
0620:
0621: XmlSchemaElement el = new XmlSchemaElement();
0622: el.setQName(qname);
0623: el.setName(qname.getLocalPart());
0624:
0625: if (!isExistSchemaElement(schema, qname)) {
0626: schema.getItems().add(el);
0627: }
0628:
0629: el.setMinOccurs(1);
0630: el.setMaxOccurs(0);
0631: el.setNillable(true);
0632:
0633: if (mpi.isElement()) {
0634: continue;
0635: } else {
0636: el.setSchemaTypeName(mpi.getTypeQName());
0637: String ns = mpi.getTypeQName().getNamespaceURI();
0638: if (!ns.equals(schema.getTargetNamespace())
0639: && !ns.equals(WSDLConstants.NU_SCHEMA_XSD)) {
0640: XmlSchemaImport is = new XmlSchemaImport();
0641: is.setNamespace(ns);
0642: if (!isExistImport(schema, ns)) {
0643: schema.getItems().add(is);
0644: }
0645: }
0646: }
0647:
0648: schemaInfo.setSchema(schema);
0649:
0650: mpi.setElement(true);
0651: mpi.setElementQName(qname);
0652: paraNumber++;
0653: }
0654: }
0655:
0656: private boolean isExistImport(XmlSchema schema, String ns) {
0657: boolean isExist = false;
0658:
0659: for (Iterator ite = schema.getItems().getIterator(); ite
0660: .hasNext();) {
0661: XmlSchemaObject obj = (XmlSchemaObject) ite.next();
0662: if (obj instanceof XmlSchemaImport) {
0663: XmlSchemaImport xsImport = (XmlSchemaImport) obj;
0664: if (xsImport.getNamespace().equals(ns)) {
0665: isExist = true;
0666: break;
0667: }
0668: }
0669: }
0670: return isExist;
0671:
0672: }
0673:
0674: private boolean isExistSchemaElement(XmlSchema schema, QName qn) {
0675: boolean isExist = false;
0676: for (Iterator ite = schema.getItems().getIterator(); ite
0677: .hasNext();) {
0678: XmlSchemaObject obj = (XmlSchemaObject) ite.next();
0679: if (obj instanceof XmlSchemaElement) {
0680: XmlSchemaElement xsEle = (XmlSchemaElement) obj;
0681: if (xsEle.getQName().equals(qn)) {
0682: isExist = true;
0683: break;
0684: }
0685: }
0686: }
0687: return isExist;
0688: }
0689:
0690: private void createWrappedMessageSchema(ServiceInfo serviceInfo,
0691: AbstractMessageContainer wrappedMessage,
0692: AbstractMessageContainer unwrappedMessage,
0693: XmlSchema schema, QName wrapperName) {
0694: XmlSchemaElement el = new XmlSchemaElement();
0695: el.setQName(wrapperName);
0696: el.setName(wrapperName.getLocalPart());
0697: schema.getItems().add(el);
0698:
0699: wrappedMessage.getMessageParts().get(0).setXmlSchema(el);
0700:
0701: XmlSchemaComplexType ct = new XmlSchemaComplexType(schema);
0702: ct.setName(wrapperName.getLocalPart());
0703: el.setSchemaTypeName(wrapperName);
0704: schema.addType(ct);
0705: schema.getItems().add(ct);
0706:
0707: XmlSchemaSequence seq = new XmlSchemaSequence();
0708: ct.setParticle(seq);
0709:
0710: for (MessagePartInfo mpi : unwrappedMessage.getMessageParts()) {
0711:
0712: el = new XmlSchemaElement();
0713: el.setName(mpi.getName().getLocalPart());
0714: el.setQName(mpi.getName());
0715: if (mpi.isElement()) {
0716: el.setRefName(mpi.getElementQName());
0717: } else {
0718: el.setSchemaTypeName(mpi.getTypeQName());
0719: if (schema.getElementFormDefault().getValue().equals(
0720: XmlSchemaForm.UNQUALIFIED)) {
0721: mpi.setConcreteName(new QName(null, mpi.getName()
0722: .getLocalPart()));
0723: }
0724: }
0725: if (!Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
0726: if (!mpi.isElement()) {
0727: mpi.setXmlSchema(el);
0728: }
0729: if (mpi.getTypeClass() != null
0730: && mpi.getTypeClass().isArray()
0731: && !Byte.TYPE.equals(mpi.getTypeClass()
0732: .getComponentType())) {
0733: el.setMinOccurs(0);
0734: el.setMaxOccurs(Long.MAX_VALUE);
0735: } else if (Collection.class.isAssignableFrom(mpi
0736: .getTypeClass())
0737: && mpi.getTypeClass().isInterface()) {
0738: Type type = (Type) mpi.getProperty(GENERIC_TYPE);
0739: if (!(type instanceof java.lang.reflect.ParameterizedType)
0740: && mpi.getTypeQName() == null) {
0741: el.setMinOccurs(0);
0742: el.setMaxOccurs(Long.MAX_VALUE);
0743: el.setSchemaTypeName(Constants.XSD_ANYTYPE);
0744: }
0745:
0746: } else {
0747: el.setMaxOccurs(1);
0748: if (mpi.getTypeClass() != null
0749: && !mpi.getTypeClass().isPrimitive()) {
0750: el.setMinOccurs(0);
0751: }
0752: }
0753: seq.getItems().add(el);
0754: }
0755: if (Boolean.TRUE.equals(mpi.getProperty(HEADER))) {
0756:
0757: QName qn = (QName) mpi.getProperty(ELEMENT_NAME);
0758:
0759: el.setName(qn.getLocalPart());
0760: el.setQName(qn);
0761:
0762: SchemaInfo headerSchemaInfo = getOrCreateSchema(
0763: serviceInfo, qn.getNamespaceURI());
0764: if (!isExistSchemaElement(headerSchemaInfo.getSchema(),
0765: qn)) {
0766: headerSchemaInfo.getSchema().getItems().add(el);
0767: }
0768: }
0769: }
0770:
0771: }
0772:
0773: private SchemaInfo getOrCreateSchema(ServiceInfo serviceInfo,
0774: String namespaceURI) {
0775: for (SchemaInfo s : serviceInfo.getSchemas()) {
0776: if (s.getNamespaceURI().equals(namespaceURI)) {
0777: return s;
0778: }
0779: }
0780:
0781: SchemaInfo schemaInfo = new SchemaInfo(serviceInfo,
0782: namespaceURI);
0783: XmlSchemaCollection col = new XmlSchemaCollection();
0784: XmlSchema schema = new XmlSchema(namespaceURI, col);
0785: if (qualifyWrapperSchema()) {
0786: schema.setElementFormDefault(new XmlSchemaForm(
0787: XmlSchemaForm.QUALIFIED));
0788: }
0789: serviceInfo.setXmlSchemaCollection(col);
0790: schemaInfo.setSchema(schema);
0791:
0792: NamespaceMap nsMap = new NamespaceMap();
0793: nsMap.add(WSDLConstants.NP_SCHEMA_XSD,
0794: WSDLConstants.NU_SCHEMA_XSD);
0795: schema.setNamespaceContext(nsMap);
0796: serviceInfo.addSchema(schemaInfo);
0797: return schemaInfo;
0798: }
0799:
0800: protected void createMessageParts(InterfaceInfo intf,
0801: OperationInfo op, Method method) {
0802: final Class[] paramClasses = method.getParameterTypes();
0803: // Setup the input message
0804: op.setProperty(METHOD, method);
0805: MessageInfo inMsg = op.createMessage(this .getInputMessageName(
0806: op, method));
0807: op.setInput(inMsg.getName().getLocalPart(), inMsg);
0808: for (int j = 0; j < paramClasses.length; j++) {
0809: if (isInParam(method, j)) {
0810: final QName q = getInParameterName(op, method, j);
0811: final QName q2 = getInPartName(op, method, j);
0812: MessagePartInfo part = inMsg.addMessagePart(q2);
0813: initializeParameter(part, paramClasses[j], method
0814: .getGenericParameterTypes()[j]);
0815:
0816: if (!isWrapped(method) && !isRPC(method)) {
0817: part.setProperty(ELEMENT_NAME, q);
0818: }
0819:
0820: if (isHeader(method, j)) {
0821: part.setProperty(HEADER, Boolean.TRUE);
0822: if (isRPC(method) || !isWrapped(method)) {
0823: part.setElementQName(q);
0824: } else {
0825: part.setProperty(ELEMENT_NAME, q);
0826: }
0827: }
0828: part.setIndex(j);
0829: }
0830: }
0831:
0832: if (hasOutMessage(method)) {
0833: // Setup the output message
0834: MessageInfo outMsg = op
0835: .createMessage(createOutputMessageName(op, method));
0836: op.setOutput(outMsg.getName().getLocalPart(), outMsg);
0837: final Class<?> returnType = method.getReturnType();
0838: if (!returnType.isAssignableFrom(void.class)) {
0839: final QName q = getOutPartName(op, method, -1);
0840: final QName q2 = getOutParameterName(op, method, -1);
0841: MessagePartInfo part = outMsg.addMessagePart(q);
0842: initializeParameter(part, method.getReturnType(),
0843: method.getGenericReturnType());
0844: if (!isRPC(method) && !isWrapped(method)) {
0845: part.setProperty(ELEMENT_NAME, q2);
0846: }
0847:
0848: if (isHeader(method, -1)) {
0849: part.setProperty(HEADER, Boolean.TRUE);
0850: if (isRPC(method) || !isWrapped(method)) {
0851: part.setElementQName(q2);
0852: } else {
0853: part.setProperty(ELEMENT_NAME, q2);
0854: }
0855: }
0856:
0857: part.setIndex(0);
0858: }
0859:
0860: for (int j = 0; j < paramClasses.length; j++) {
0861: if (isOutParam(method, j)) {
0862: if (outMsg == null) {
0863: outMsg = op
0864: .createMessage(createOutputMessageName(
0865: op, method));
0866: }
0867: QName q = getOutPartName(op, method, j);
0868: QName q2 = getOutParameterName(op, method, j);
0869:
0870: if (isInParam(method, j)) {
0871: q = op.getInput().getMessagePartByIndex(j)
0872: .getName();
0873: q2 = (QName) op.getInput()
0874: .getMessagePartByIndex(j).getProperty(
0875: ELEMENT_NAME);
0876: if (q2 == null) {
0877: q2 = op.getInput().getMessagePartByIndex(j)
0878: .getElementQName();
0879: }
0880: }
0881:
0882: MessagePartInfo part = outMsg.addMessagePart(q);
0883: initializeParameter(part, paramClasses[j], method
0884: .getGenericParameterTypes()[j]);
0885: part.setIndex(j + 1);
0886:
0887: if (!isRPC(method) && !isWrapped(method)) {
0888: part.setProperty(ELEMENT_NAME, q2);
0889: }
0890:
0891: if (isInParam(method, j)) {
0892: part.setProperty(MODE_INOUT, Boolean.TRUE);
0893: }
0894: if (isHeader(method, j)) {
0895: part.setProperty(HEADER, Boolean.TRUE);
0896: if (isRPC(method) || !isWrapped(method)) {
0897: part.setElementQName(q2);
0898: } else {
0899: part.setProperty(ELEMENT_NAME, q2);
0900: }
0901: }
0902: }
0903: }
0904:
0905: }
0906:
0907: initializeFaults(intf, op, method);
0908: }
0909:
0910: protected void createInputWrappedMessageParts(OperationInfo op,
0911: Method method, MessageInfo inMsg) {
0912: MessagePartInfo part = inMsg.addMessagePart("parameters");
0913: part.setIndex(0);
0914: part.setElement(true);
0915: for (Iterator itr = serviceConfigurations.iterator(); itr
0916: .hasNext();) {
0917: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
0918: .next();
0919: QName q = c.getRequestWrapperName(op, method);
0920: if (q != null) {
0921: part.setElementQName(q);
0922: }
0923: }
0924: if (part.getElementQName() == null) {
0925: part.setElementQName(inMsg.getName());
0926: } else if (!part.getElementQName().equals(
0927: op.getInput().getName())) {
0928: op.getInput().setName(part.getElementQName());
0929: }
0930: if (getRequestWrapper(method) != null) {
0931: part.setTypeClass(this .getRequestWrapper(method));
0932: } else if (getRequestWrapperClassName(method) != null) {
0933: part.setProperty("REQUEST.WRAPPER.CLASSNAME",
0934: getRequestWrapperClassName(method));
0935: }
0936:
0937: for (MessagePartInfo mpart : op.getInput().getMessageParts()) {
0938: if (Boolean.TRUE.equals(mpart.getProperty(HEADER))) {
0939: int idx = mpart.getIndex();
0940: inMsg.addMessagePart(mpart);
0941: mpart.setIndex(idx);
0942: }
0943: }
0944: }
0945:
0946: protected void createOutputWrappedMessageParts(OperationInfo op,
0947: Method method, MessageInfo outMsg) {
0948: MessagePartInfo part = outMsg.addMessagePart("result");
0949: part.setElement(true);
0950: part.setIndex(0);
0951: for (Iterator itr = serviceConfigurations.iterator(); itr
0952: .hasNext();) {
0953: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
0954: .next();
0955: QName q = c.getResponseWrapperName(op, method);
0956: if (q != null) {
0957: part.setElementQName(q);
0958: }
0959: }
0960:
0961: if (part.getElementQName() == null) {
0962: part.setElementQName(outMsg.getName());
0963: } else if (!part.getElementQName().equals(
0964: op.getOutput().getName())) {
0965: op.getOutput().setName(part.getElementQName());
0966: }
0967:
0968: if (this .getResponseWrapper(method) != null) {
0969: part.setTypeClass(this .getResponseWrapper(method));
0970: } else if (getResponseWrapperClassName(method) != null) {
0971: part.setProperty("RESPONSE.WRAPPER.CLASSNAME",
0972: getResponseWrapperClassName(method));
0973: }
0974:
0975: for (MessagePartInfo mpart : op.getOutput().getMessageParts()) {
0976: if (Boolean.TRUE.equals(mpart.getProperty(HEADER))) {
0977: int idx = mpart.getIndex();
0978: outMsg.addMessagePart(mpart);
0979: mpart.setIndex(idx);
0980: }
0981: }
0982: }
0983:
0984: // TODO: Remove reference to JAX-WS holder if possible
0985: // We do need holder support in the simple frontend though as Aegis has its
0986: // own
0987: // holder class. I'll tackle refactoring this into a more generic way of
0988: // handling
0989: // holders in phase 2.
0990: protected void initializeParameter(MessagePartInfo part,
0991: Class rawClass, Type type) {
0992: if (rawClass.equals(Holder.class)
0993: && type instanceof ParameterizedType) {
0994: ParameterizedType paramType = (ParameterizedType) type;
0995: rawClass = getHolderClass(paramType);
0996: }
0997:
0998: part.setProperty(GENERIC_TYPE, type);
0999: part.setTypeClass(rawClass);
1000: }
1001:
1002: protected Class getHolderClass(ParameterizedType paramType) {
1003: Object rawType = paramType.getActualTypeArguments()[0];
1004: Class rawClass;
1005: if (rawType instanceof GenericArrayType) {
1006: rawClass = (Class) ((GenericArrayType) rawType)
1007: .getGenericComponentType();
1008: rawClass = Array.newInstance(rawClass, 0).getClass();
1009: } else {
1010: if (rawType instanceof ParameterizedType) {
1011: rawType = (Class) ((ParameterizedType) rawType)
1012: .getRawType();
1013: }
1014: rawClass = (Class) rawType;
1015: }
1016: return rawClass;
1017: }
1018:
1019: public QName getServiceQName() {
1020: if (serviceName == null) {
1021: serviceName = new QName(getServiceNamespace(),
1022: getServiceName());
1023: }
1024:
1025: return serviceName;
1026: }
1027:
1028: public QName getEndpointName() {
1029: if (endpointName != null) {
1030: return endpointName;
1031: }
1032:
1033: for (AbstractServiceConfiguration c : serviceConfigurations) {
1034: QName name = c.getEndpointName();
1035: if (name != null) {
1036: endpointName = name;
1037: return name;
1038: }
1039: }
1040: throw new IllegalStateException(
1041: "ServiceConfiguration must provide a value!");
1042: }
1043:
1044: public EndpointInfo getEndpointInfo() {
1045: return getService().getEndpointInfo(getEndpointName());
1046: }
1047:
1048: public void setEndpointName(QName en) {
1049: this .endpointName = en;
1050: }
1051:
1052: protected String getServiceName() {
1053: for (AbstractServiceConfiguration c : serviceConfigurations) {
1054: String name = c.getServiceName();
1055: if (name != null) {
1056: return name;
1057: }
1058: }
1059: throw new IllegalStateException(
1060: "ServiceConfiguration must provide a value!");
1061: }
1062:
1063: protected String getServiceNamespace() {
1064: if (serviceName != null) {
1065: return serviceName.getNamespaceURI();
1066: }
1067:
1068: for (AbstractServiceConfiguration c : serviceConfigurations) {
1069: String name = c.getServiceNamespace();
1070: if (name != null) {
1071: return name;
1072: }
1073: }
1074: throw new IllegalStateException(
1075: "ServiceConfiguration must provide a value!");
1076: }
1077:
1078: public QName getInterfaceName() {
1079: for (AbstractServiceConfiguration c : serviceConfigurations) {
1080: QName name = c.getInterfaceName();
1081: if (name != null) {
1082: return name;
1083: }
1084: }
1085: throw new IllegalStateException(
1086: "ServiceConfiguration must provide a value!");
1087: }
1088:
1089: protected boolean isValidMethod(final Method method) {
1090: for (AbstractServiceConfiguration c : serviceConfigurations) {
1091: Boolean b = c.isOperation(method);
1092: if (b != null) {
1093: return b.booleanValue();
1094: }
1095: }
1096: return true;
1097: }
1098:
1099: protected boolean isWrapped(final Method method) {
1100: for (AbstractServiceConfiguration c : serviceConfigurations) {
1101: Boolean b = c.isWrapped(method);
1102: if (b != null) {
1103: return b.booleanValue();
1104: }
1105: }
1106: return true;
1107: }
1108:
1109: protected boolean isMatchOperation(String methodNameInClass,
1110: String methodNameInWsdl) {
1111: // TODO: This seems wrong and not sure who put it here. Will revisit -
1112: // DBD
1113: boolean ret = false;
1114: String initOfMethodInClass = methodNameInClass.substring(0, 1);
1115: String initOfMethodInWsdl = methodNameInWsdl.substring(0, 1);
1116: if (initOfMethodInClass.equalsIgnoreCase(initOfMethodInWsdl)
1117: && methodNameInClass.substring(1,
1118: methodNameInClass.length()).equals(
1119: methodNameInWsdl.substring(1, methodNameInWsdl
1120: .length()))) {
1121: ret = true;
1122: }
1123: return ret;
1124: }
1125:
1126: protected boolean isOutParam(Method method, int j) {
1127: for (Iterator itr = serviceConfigurations.iterator(); itr
1128: .hasNext();) {
1129: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1130: .next();
1131: Boolean b = c.isOutParam(method, j);
1132: if (b != null) {
1133: return b.booleanValue();
1134: }
1135: }
1136: return true;
1137: }
1138:
1139: protected boolean isInParam(Method method, int j) {
1140: for (Iterator itr = serviceConfigurations.iterator(); itr
1141: .hasNext();) {
1142: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1143: .next();
1144: Boolean b = c.isInParam(method, j);
1145: if (b != null) {
1146: return b.booleanValue();
1147: }
1148: }
1149: return true;
1150: }
1151:
1152: protected QName getInputMessageName(final OperationInfo op,
1153: final Method method) {
1154: for (Iterator itr = serviceConfigurations.iterator(); itr
1155: .hasNext();) {
1156: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1157: .next();
1158: QName q = c.getInputMessageName(op, method);
1159: if (q != null) {
1160: return q;
1161: }
1162: }
1163: throw new IllegalStateException(
1164: "ServiceConfiguration must provide a value!");
1165: }
1166:
1167: protected QName createOutputMessageName(final OperationInfo op,
1168: final Method method) {
1169: for (Iterator itr = serviceConfigurations.iterator(); itr
1170: .hasNext();) {
1171: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1172: .next();
1173: QName q = c.getOutputMessageName(op, method);
1174: if (q != null) {
1175: return q;
1176: }
1177: }
1178: throw new IllegalStateException(
1179: "ServiceConfiguration must provide a value!");
1180: }
1181:
1182: protected boolean hasOutMessage(Method m) {
1183: for (Iterator itr = serviceConfigurations.iterator(); itr
1184: .hasNext();) {
1185: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1186: .next();
1187: Boolean b = c.hasOutMessage(m);
1188: if (b != null) {
1189: return b.booleanValue();
1190: }
1191: }
1192: return true;
1193: }
1194:
1195: protected void initializeFaults(final InterfaceInfo service,
1196: final OperationInfo op, final Method method) {
1197: // Set up the fault messages
1198: final Class[] exceptionClasses = method.getExceptionTypes();
1199: for (int i = 0; i < exceptionClasses.length; i++) {
1200: Class exClazz = exceptionClasses[i];
1201:
1202: // Ignore XFireFaults because they don't need to be declared
1203: if (exClazz.equals(Exception.class)
1204: || Fault.class.isAssignableFrom(exClazz)
1205: || exClazz.equals(RuntimeException.class)
1206: || exClazz.equals(Throwable.class)) {
1207: continue;
1208: }
1209:
1210: addFault(service, op, exClazz);
1211: }
1212: }
1213:
1214: protected void initializeDefaultInterceptors() {
1215: super .initializeDefaultInterceptors();
1216:
1217: initializeFaultInterceptors();
1218: }
1219:
1220: protected void initializeFaultInterceptors() {
1221: getService().getOutFaultInterceptors().add(
1222: new FaultOutInterceptor());
1223: }
1224:
1225: protected FaultInfo addFault(final InterfaceInfo service,
1226: final OperationInfo op, Class exClass) {
1227: Class beanClass = getBeanClass(exClass);
1228: if (beanClass == null) {
1229: return null;
1230: }
1231:
1232: QName faultName = getFaultName(service, op, exClass, beanClass);
1233: FaultInfo fi = op.addFault(new QName(op.getName()
1234: .getNamespaceURI(), exClass.getSimpleName()),
1235: new QName(op.getName().getNamespaceURI(), exClass
1236: .getSimpleName()));
1237: fi.setProperty(Class.class.getName(), exClass);
1238: fi.setProperty("elementName", faultName);
1239: MessagePartInfo mpi = fi.addMessagePart(new QName(faultName
1240: .getNamespaceURI(), "fault"));
1241: mpi.setElementQName(faultName);
1242: mpi.setTypeClass(beanClass);
1243: return fi;
1244: }
1245:
1246: protected void createFaultForException(Class<?> exClass,
1247: FaultInfo fi) {
1248: Field fields[] = exClass.getDeclaredFields();
1249: for (Field field : fields) {
1250: MessagePartInfo mpi = fi.addMessagePart(new QName(fi
1251: .getName().getNamespaceURI(), field.getName()));
1252: mpi.setProperty(Class.class.getName(), field.getType());
1253: }
1254:
1255: MessagePartInfo mpi = fi.addMessagePart(new QName(fi.getName()
1256: .getNamespaceURI(), "message"));
1257: mpi.setProperty(Class.class.getName(), String.class);
1258: }
1259:
1260: protected Class<?> getBeanClass(Class<?> exClass) {
1261: if (java.rmi.RemoteException.class.isAssignableFrom(exClass)) {
1262: return null;
1263: }
1264: return exClass;
1265: }
1266:
1267: protected QName getFaultName(InterfaceInfo service,
1268: OperationInfo o, Class exClass, Class beanClass) {
1269: for (Iterator itr = serviceConfigurations.iterator(); itr
1270: .hasNext();) {
1271: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1272: .next();
1273: QName q = c.getFaultName(service, o, exClass, beanClass);
1274: if (q != null) {
1275: return q;
1276: }
1277: }
1278: throw new IllegalStateException(
1279: "ServiceConfiguration must provide a value!");
1280: }
1281:
1282: protected String getAction(OperationInfo op, Method method) {
1283: for (Iterator itr = serviceConfigurations.iterator(); itr
1284: .hasNext();) {
1285: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1286: .next();
1287: String s = c.getAction(op, method);
1288: if (s != null) {
1289: return s;
1290: }
1291: }
1292: return "";
1293: }
1294:
1295: public boolean isHeader(Method method, int j) {
1296: for (Iterator itr = serviceConfigurations.iterator(); itr
1297: .hasNext();) {
1298: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1299: .next();
1300: Boolean b = c.isHeader(method, j);
1301: if (b != null) {
1302: return b.booleanValue();
1303: }
1304: }
1305: return true;
1306: }
1307:
1308: /**
1309: * Creates a name for the operation from the method name. If an operation
1310: * with that name already exists, a name is create by appending an integer
1311: * to the end. I.e. if there is already two methods named
1312: * <code>doSomething</code>, the first one will have an operation name of
1313: * "doSomething" and the second "doSomething1".
1314: *
1315: * @param service
1316: * @param method
1317: */
1318: protected QName getOperationName(InterfaceInfo service,
1319: Method method) {
1320: for (Iterator itr = serviceConfigurations.iterator(); itr
1321: .hasNext();) {
1322: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1323: .next();
1324: QName s = c.getOperationName(service, method);
1325: if (s != null) {
1326: return s;
1327: }
1328: }
1329: throw new IllegalStateException(
1330: "ServiceConfiguration must provide a value!");
1331: }
1332:
1333: protected boolean isAsync(final Method method) {
1334: for (Iterator itr = serviceConfigurations.iterator(); itr
1335: .hasNext();) {
1336: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1337: .next();
1338: Boolean b = c.isAsync(method);
1339: if (b != null) {
1340: return b.booleanValue();
1341: }
1342: }
1343: return true;
1344: }
1345:
1346: protected QName getInPartName(final OperationInfo op,
1347: final Method method, final int paramNumber) {
1348: if (paramNumber == -1) {
1349: return null;
1350: }
1351:
1352: if (isWrapped(method) && !isHeader(method, paramNumber)) {
1353: return getInParameterName(op, method, paramNumber);
1354: }
1355:
1356: for (Iterator itr = serviceConfigurations.iterator(); itr
1357: .hasNext();) {
1358: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1359: .next();
1360: QName q = c.getInPartName(op, method, paramNumber);
1361: if (q != null) {
1362: return q;
1363: }
1364:
1365: }
1366: throw new IllegalStateException(
1367: "ServiceConfiguration must provide a value!");
1368: }
1369:
1370: protected QName getInParameterName(final OperationInfo op,
1371: final Method method, final int paramNumber) {
1372: if (paramNumber == -1) {
1373: return null;
1374: }
1375: for (Iterator itr = serviceConfigurations.iterator(); itr
1376: .hasNext();) {
1377: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1378: .next();
1379: QName q = c.getInParameterName(op, method, paramNumber);
1380: if (q != null) {
1381: return q;
1382: }
1383: }
1384: throw new IllegalStateException(
1385: "ServiceConfiguration must provide a value!");
1386: }
1387:
1388: protected QName getOutParameterName(final OperationInfo op,
1389: final Method method, final int paramNumber) {
1390: for (Iterator itr = serviceConfigurations.iterator(); itr
1391: .hasNext();) {
1392: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1393: .next();
1394: QName q = c.getOutParameterName(op, method, paramNumber);
1395: if (q != null) {
1396: return q;
1397: }
1398: }
1399: throw new IllegalStateException(
1400: "ServiceConfiguration must provide a value!");
1401: }
1402:
1403: protected QName getOutPartName(final OperationInfo op,
1404: final Method method, final int paramNumber) {
1405: if (isWrapped(method)) {
1406: return getOutParameterName(op, method, paramNumber);
1407: }
1408:
1409: for (Iterator itr = serviceConfigurations.iterator(); itr
1410: .hasNext();) {
1411: AbstractServiceConfiguration c = (AbstractServiceConfiguration) itr
1412: .next();
1413: QName q = c.getOutPartName(op, method, paramNumber);
1414: if (q != null) {
1415: return q;
1416: }
1417: }
1418: throw new IllegalStateException(
1419: "ServiceConfiguration must provide a value!");
1420: }
1421:
1422: protected Class getResponseWrapper(Method selected) {
1423: for (AbstractServiceConfiguration c : serviceConfigurations) {
1424: Class cls = c.getResponseWrapper(selected);
1425: if (cls != null) {
1426: return cls;
1427: }
1428: }
1429: return null;
1430: }
1431:
1432: protected String getResponseWrapperClassName(Method selected) {
1433: for (AbstractServiceConfiguration c : serviceConfigurations) {
1434: String cls = c.getResponseWrapperClassName(selected);
1435: if (cls != null) {
1436: return cls;
1437: }
1438: }
1439: return null;
1440: }
1441:
1442: protected Class getRequestWrapper(Method selected) {
1443: for (AbstractServiceConfiguration c : serviceConfigurations) {
1444: Class cls = c.getRequestWrapper(selected);
1445: if (cls != null) {
1446: return cls;
1447: }
1448: }
1449: return null;
1450: }
1451:
1452: protected String getRequestWrapperClassName(Method selected) {
1453: for (AbstractServiceConfiguration c : serviceConfigurations) {
1454: String cls = c.getRequestWrapperClassName(selected);
1455: if (cls != null) {
1456: return cls;
1457: }
1458: }
1459: return null;
1460: }
1461:
1462: protected SimpleMethodDispatcher getMethodDispatcher() {
1463: return methodDispatcher;
1464: }
1465:
1466: public List<AbstractServiceConfiguration> getConfigurations() {
1467: return serviceConfigurations;
1468: }
1469:
1470: public void setConfigurations(
1471: List<AbstractServiceConfiguration> configurations) {
1472: this .serviceConfigurations = configurations;
1473: }
1474:
1475: public Class<?> getServiceClass() {
1476: return serviceClass;
1477: }
1478:
1479: public void setServiceClass(Class<?> serviceClass) {
1480: this .serviceClass = serviceClass;
1481: }
1482:
1483: public String getWsdlURL() {
1484: if (wsdlURL == null) {
1485: for (AbstractServiceConfiguration c : serviceConfigurations) {
1486: wsdlURL = c.getWsdlURL();
1487: if (wsdlURL != null) {
1488: //create a unique string so if its an interned string (like
1489: //from an annotation), caches will clear
1490: wsdlURL = new String(wsdlURL);
1491: break;
1492: }
1493: }
1494: }
1495: return wsdlURL;
1496: }
1497:
1498: public void setWsdlURL(String wsdlURL) {
1499: //create a unique string so if its an interned string (like
1500: //from an annotation), caches will clear
1501: this .wsdlURL = new String(wsdlURL);
1502: }
1503:
1504: public void setWsdlURL(URL wsdlURL) {
1505: this .wsdlURL = wsdlURL.toString();
1506: }
1507:
1508: public List<AbstractServiceConfiguration> getServiceConfigurations() {
1509: return serviceConfigurations;
1510: }
1511:
1512: public void setServiceConfigurations(
1513: List<AbstractServiceConfiguration> serviceConfigurations) {
1514: this .serviceConfigurations = serviceConfigurations;
1515: }
1516:
1517: public void setServiceName(QName serviceName) {
1518: this .serviceName = serviceName;
1519: }
1520:
1521: public Invoker getInvoker() {
1522: return invoker;
1523: }
1524:
1525: public void setInvoker(Invoker invoker) {
1526: this .invoker = invoker;
1527: }
1528:
1529: public Executor getExecutor() {
1530: return executor;
1531: }
1532:
1533: public void setExecutor(Executor executor) {
1534: this .executor = executor;
1535: }
1536:
1537: public List<String> getIgnoredClasses() {
1538: return ignoredClasses;
1539: }
1540:
1541: public void setIgnoredClasses(List<String> ignoredClasses) {
1542: this .ignoredClasses = ignoredClasses;
1543: }
1544:
1545: public boolean isWrapped() {
1546: if (this .wrappedStyle != null) {
1547: return this .wrappedStyle;
1548: }
1549: for (AbstractServiceConfiguration c : serviceConfigurations) {
1550: Boolean b = c.isWrapped();
1551: if (b != null) {
1552: return b.booleanValue();
1553: }
1554: }
1555: return true;
1556: }
1557:
1558: public String getStyle() {
1559: for (AbstractServiceConfiguration c : serviceConfigurations) {
1560: String style = c.getStyle();
1561: if (style != null) {
1562: return style;
1563: }
1564: }
1565: return "document";
1566: }
1567:
1568: public boolean isRPC(Method method) {
1569: for (AbstractServiceConfiguration c : serviceConfigurations) {
1570: Boolean b = c.isRPC(method);
1571: if (b != null) {
1572: return b.booleanValue();
1573: }
1574: }
1575: return true;
1576: }
1577:
1578: public void setWrapped(boolean style) {
1579: this .wrappedStyle = style;
1580: }
1581:
1582: /**
1583: * Returns non-null if wrapped mode was explicitely disabled or enabled.
1584: */
1585: public Boolean getWrapped() {
1586: return this .wrappedStyle;
1587: }
1588:
1589: public Map<String, Object> getProperties() {
1590: return properties;
1591: }
1592:
1593: public void setProperties(Map<String, Object> properties) {
1594: this .properties = properties;
1595: }
1596:
1597: public List<Method> getIgnoredMethods() {
1598: return ignoredMethods;
1599: }
1600:
1601: public void setIgnoredMethods(List<Method> ignoredMethods) {
1602: this.ignoredMethods = ignoredMethods;
1603: }
1604:
1605: }
|