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: */
0019: package org.apache.axis2.wsdl.codegen.emitter;
0020:
0021: import org.apache.axis2.AxisFault;
0022: import org.apache.axis2.addressing.AddressingConstants;
0023: import org.apache.axis2.description.AxisBinding;
0024: import org.apache.axis2.description.AxisBindingMessage;
0025: import org.apache.axis2.description.AxisBindingOperation;
0026: import org.apache.axis2.description.AxisEndpoint;
0027: import org.apache.axis2.description.AxisMessage;
0028: import org.apache.axis2.description.AxisOperation;
0029: import org.apache.axis2.description.AxisService;
0030: import org.apache.axis2.description.Parameter;
0031: import org.apache.axis2.description.WSDL20DefaultValueHolder;
0032: import org.apache.axis2.description.WSDL2Constants;
0033: import org.apache.axis2.util.CommandLineOptionConstants;
0034: import org.apache.axis2.util.JavaUtils;
0035: import org.apache.axis2.util.PolicyUtil;
0036: import org.apache.axis2.util.Utils;
0037: import org.apache.axis2.util.XSLTUtils;
0038: import org.apache.axis2.wsdl.HTTPHeaderMessage;
0039: import org.apache.axis2.wsdl.SOAPHeaderMessage;
0040: import org.apache.axis2.wsdl.SOAPModuleMessage;
0041: import org.apache.axis2.wsdl.WSDLConstants;
0042: import org.apache.axis2.wsdl.WSDLUtil;
0043: import org.apache.axis2.wsdl.codegen.CodeGenConfiguration;
0044: import org.apache.axis2.wsdl.codegen.CodeGenerationException;
0045: import org.apache.axis2.wsdl.codegen.writer.AntBuildWriter;
0046: import org.apache.axis2.wsdl.codegen.writer.CallbackHandlerWriter;
0047: import org.apache.axis2.wsdl.codegen.writer.FileWriter;
0048: import org.apache.axis2.wsdl.codegen.writer.ExceptionWriter;
0049: import org.apache.axis2.wsdl.codegen.writer.InterfaceImplementationWriter;
0050: import org.apache.axis2.wsdl.codegen.writer.InterfaceWriter;
0051: import org.apache.axis2.wsdl.codegen.writer.MessageReceiverWriter;
0052: import org.apache.axis2.wsdl.codegen.writer.SchemaWriter;
0053: import org.apache.axis2.wsdl.codegen.writer.ServiceXMLWriter;
0054: import org.apache.axis2.wsdl.codegen.writer.SkeletonInterfaceWriter;
0055: import org.apache.axis2.wsdl.codegen.writer.SkeletonWriter;
0056: import org.apache.axis2.wsdl.codegen.writer.TestClassWriter;
0057: import org.apache.axis2.wsdl.codegen.writer.WSDL11Writer;
0058: import org.apache.axis2.wsdl.codegen.writer.WSDL20Writer;
0059: import org.apache.axis2.wsdl.databinding.TypeMapper;
0060: import org.apache.axis2.wsdl.util.Constants;
0061: import org.apache.axis2.wsdl.util.MessagePartInformationHolder;
0062: import org.apache.axis2.wsdl.util.TypeTesterUtil;
0063: import org.apache.axis2.wsdl.util.XSLTIncludeResolver;
0064: import org.apache.commons.logging.Log;
0065: import org.apache.commons.logging.LogFactory;
0066: import org.apache.neethi.Policy;
0067: import org.apache.ws.commons.schema.XmlSchema;
0068: import org.w3c.dom.DOMException;
0069: import org.w3c.dom.Document;
0070: import org.w3c.dom.Element;
0071: import org.w3c.dom.Text;
0072:
0073: import javax.xml.namespace.QName;
0074: import javax.xml.parsers.DocumentBuilder;
0075: import javax.xml.parsers.DocumentBuilderFactory;
0076: import javax.xml.parsers.ParserConfigurationException;
0077: import javax.xml.transform.OutputKeys;
0078: import javax.xml.transform.Transformer;
0079: import javax.xml.transform.TransformerFactory;
0080: import javax.xml.transform.URIResolver;
0081: import javax.xml.transform.dom.DOMSource;
0082: import javax.xml.transform.stream.StreamResult;
0083: import java.io.File;
0084: import java.io.IOException;
0085: import java.io.StringWriter;
0086: import java.net.URI;
0087: import java.util.ArrayList;
0088: import java.util.HashMap;
0089: import java.util.HashSet;
0090: import java.util.Iterator;
0091: import java.util.List;
0092: import java.util.Map;
0093: import java.util.Set;
0094:
0095: public class AxisServiceBasedMultiLanguageEmitter implements Emitter {
0096:
0097: protected static final String CALL_BACK_HANDLER_SUFFIX = "CallbackHandler";
0098: protected static final String STUB_SUFFIX = "Stub";
0099: protected static final String TEST_SUFFIX = "Test";
0100: protected static final String SKELETON_CLASS_SUFFIX = "Skeleton";
0101: protected static final String SKELETON_CLASS_SUFFIX_BACK = "Impl";
0102: protected static final String SKELETON_INTERFACE_SUFFIX = "SkeletonInterface";
0103: // keep a seperate variable for SKELETON_INTERFACE_SUFFIX_BACK although it is
0104: // "" to accomadate any future changes easily.
0105: protected static final String SKELETON_INTERFACE_SUFFIX_BACK = "";
0106: protected static final String STUB_INTERFACE_SUFFIX_BACK = "Stub";
0107: protected static final String MESSAGE_RECEIVER_SUFFIX = "MessageReceiver";
0108: protected static final String DATABINDING_SUPPORTER_NAME_SUFFIX = "DatabindingSupporter";
0109:
0110: protected static Map mepToClassMap;
0111: protected static Map mepToSuffixMap;
0112:
0113: protected AxisBinding axisBinding;
0114: protected AxisEndpoint axisEndpoint;
0115:
0116: protected int uniqueFaultNameCounter = 0;
0117: /**
0118: * Field constructorMap
0119: */
0120: protected static HashMap constructorMap = new HashMap(50);
0121:
0122: //~--- static initializers ------------------------------------------------
0123:
0124: static {
0125:
0126: // Type maps to a valid initialization value for that type
0127: // Type var = new Type(arg)
0128: // Where "Type" is the key and "new Type(arg)" is the string stored
0129: // Used in emitting test cases and server skeletons.
0130: constructorMap.put("int", "0");
0131: constructorMap.put("float", "0");
0132: constructorMap.put("boolean", "true");
0133: constructorMap.put("double", "0");
0134: constructorMap.put("byte", "(byte)0");
0135: constructorMap.put("short", "(short)0");
0136: constructorMap.put("long", "0");
0137: constructorMap.put("java.lang.Boolean",
0138: "new java.lang.Boolean(false)");
0139: constructorMap.put("java.lang.Byte",
0140: "new java.lang.Byte((byte)0)");
0141: constructorMap.put("java.lang.Double",
0142: "new java.lang.Double(0)");
0143: constructorMap.put("java.lang.Float", "new java.lang.Float(0)");
0144: constructorMap.put("java.lang.Integer",
0145: "new java.lang.Integer(0)");
0146: constructorMap.put("java.lang.Long", "new java.lang.Long(0)");
0147: constructorMap.put("java.lang.Short",
0148: "new java.lang.Short((short)0)");
0149: constructorMap.put("java.math.BigDecimal",
0150: "new java.math.BigDecimal(0)");
0151: constructorMap.put("java.math.BigInteger",
0152: "new java.math.BigInteger(\"0\")");
0153: constructorMap
0154: .put("java.lang.Object", "new java.lang.String()");
0155: constructorMap.put("byte[]", "new byte[0]");
0156: constructorMap.put("java.util.Calendar",
0157: "java.util.Calendar.getInstance()");
0158: constructorMap
0159: .put("javax.xml.namespace.QName",
0160: "new javax.xml.namespace.QName(\"http://foo\", \"bar\")");
0161:
0162: //populate the MEP -> class map
0163: mepToClassMap = new HashMap();
0164: mepToClassMap.put(WSDL2Constants.MEP_URI_IN_ONLY,
0165: "org.apache.axis2.receivers.AbstractInMessageReceiver");
0166: mepToClassMap
0167: .put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
0168: "org.apache.axis2.receivers.AbstractRobustInMessageReceiver");
0169: mepToClassMap
0170: .put(WSDL2Constants.MEP_URI_IN_OUT,
0171: "org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver");
0172:
0173: //populate the MEP -> suffix map
0174: mepToSuffixMap = new HashMap();
0175: mepToSuffixMap.put(
0176: WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_ONLY,
0177: MESSAGE_RECEIVER_SUFFIX + "InOnly");
0178: mepToSuffixMap.put(
0179: WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_ONLY,
0180: MESSAGE_RECEIVER_SUFFIX + "InOnly");
0181: mepToSuffixMap.put(WSDL2Constants.MEP_URI_IN_ONLY,
0182: MESSAGE_RECEIVER_SUFFIX + "InOnly");
0183: mepToSuffixMap
0184: .put(
0185: WSDLConstants.WSDL20_2004_Constants.MEP_URI_ROBUST_IN_ONLY,
0186: MESSAGE_RECEIVER_SUFFIX + "RobustInOnly");
0187: mepToSuffixMap
0188: .put(
0189: WSDLConstants.WSDL20_2006Constants.MEP_URI_ROBUST_IN_ONLY,
0190: MESSAGE_RECEIVER_SUFFIX + "RobustInOnly");
0191: mepToSuffixMap.put(WSDL2Constants.MEP_URI_ROBUST_IN_ONLY,
0192: MESSAGE_RECEIVER_SUFFIX + "RobustInOnly");
0193: mepToSuffixMap.put(
0194: WSDLConstants.WSDL20_2004_Constants.MEP_URI_IN_OUT,
0195: MESSAGE_RECEIVER_SUFFIX + "InOut");
0196: mepToSuffixMap.put(
0197: WSDLConstants.WSDL20_2006Constants.MEP_URI_IN_OUT,
0198: MESSAGE_RECEIVER_SUFFIX + "InOut");
0199: mepToSuffixMap.put(WSDL2Constants.MEP_URI_IN_OUT,
0200: MESSAGE_RECEIVER_SUFFIX + "InOut");
0201: //register the other types as necessary
0202: }
0203:
0204: //~--- fields -------------------------------------------------------------
0205: protected static final Log log = LogFactory
0206: .getLog(AxisServiceBasedMultiLanguageEmitter.class);
0207: protected URIResolver resolver;
0208:
0209: // this is used to keep the current service infoHolder
0210: protected Map infoHolder;
0211: // this is used to keep infoHolders for all services
0212: protected Map allServiceInfoHolder;
0213:
0214: protected CodeGenConfiguration codeGenConfiguration;
0215:
0216: protected TypeMapper mapper;
0217:
0218: protected AxisService axisService;
0219:
0220: protected List axisServices;
0221:
0222: //a map to keep the fault classNames
0223: protected Map fullyQualifiedFaultClassNameMap = new HashMap();
0224: protected Map faultClassNameMap = new HashMap();
0225: protected Map faultElementQNameMap = new HashMap();
0226:
0227: protected Map instantiatableMessageClassNames = new HashMap();
0228:
0229: protected static final String TEST_SRC_DIR_NAME = "test";
0230:
0231: /**
0232: * default constructor - builds
0233: */
0234: public AxisServiceBasedMultiLanguageEmitter() {
0235: infoHolder = new HashMap();
0236: allServiceInfoHolder = new HashMap();
0237: }
0238:
0239: /**
0240: * Sets the relevant codegen configuration
0241: *
0242: * @param configuration
0243: * @see Emitter#setCodeGenConfiguration(org.apache.axis2.wsdl.codegen.CodeGenConfiguration)
0244: */
0245: public void setCodeGenConfiguration(
0246: CodeGenConfiguration configuration) {
0247: this .codeGenConfiguration = configuration;
0248: this .axisServices = codeGenConfiguration.getAxisServices();
0249: this .axisService = codeGenConfiguration.getAxisService();
0250: this .axisEndpoint = axisService.getEndpoint(axisService
0251: .getEndpointName());
0252: this .axisBinding = axisEndpoint.getBinding();
0253: resolver = new XSLTIncludeResolver(codeGenConfiguration);
0254: }
0255:
0256: /**
0257: * Sets the type mapper
0258: *
0259: * @param mapper
0260: * @see Emitter#setMapper(org.apache.axis2.wsdl.databinding.TypeMapper)
0261: */
0262: public void setMapper(TypeMapper mapper) {
0263: this .mapper = mapper;
0264: }
0265:
0266: private Object getBindingPropertyFromOperation(String name,
0267: QName qName) {
0268:
0269: // Get the correct AxisBindingOperation coresponding to the AxisOperation
0270: AxisBindingOperation axisBindingOperation = null;
0271: if (axisBinding != null) {
0272: axisBindingOperation = (AxisBindingOperation) axisBinding
0273: .getChild(qName);
0274: }
0275:
0276: Object property = null;
0277:
0278: if (axisBindingOperation != null) {
0279: property = axisBindingOperation.getProperty(name);
0280: }
0281:
0282: if ((property == null) && (axisBinding != null)) {
0283: property = axisBinding.getProperty(name);
0284: }
0285:
0286: if (property == null) {
0287: property = WSDL20DefaultValueHolder.getDefaultValue(name);
0288: }
0289:
0290: return property;
0291: }
0292:
0293: private Policy getBindingPolicyFromMessage(QName qName, String key) {
0294:
0295: AxisBindingOperation axisBindingOperation = null;
0296: if (axisBinding != null) {
0297: axisBindingOperation = (AxisBindingOperation) axisBinding
0298: .getChild(qName);
0299: }
0300:
0301: AxisBindingMessage axisBindingMessage = null;
0302:
0303: if (axisBindingOperation != null) {
0304:
0305: axisBindingMessage = (AxisBindingMessage) axisBindingOperation
0306: .getChild(key);
0307: if (axisBindingMessage != null) {
0308: try {
0309: return axisBindingMessage.getEffectivePolicy();
0310: } catch (RuntimeException ex) {
0311: System.out.println("ERROR: Ignoring policy - "
0312: + ex.getMessage());
0313: log.error(ex.getMessage(), ex);
0314: }
0315: }
0316: }
0317: return null;
0318: }
0319:
0320: private Object getBindingPropertyFromMessage(String name,
0321: QName qName, String key) {
0322:
0323: Object property = null;
0324: // Get the correct AxisBindingOperation coresponding to the AxisOperation
0325: AxisBindingOperation axisBindingOperation = null;
0326: if (axisBinding != null) {
0327: axisBindingOperation = (AxisBindingOperation) axisBinding
0328: .getChild(qName);
0329:
0330: }
0331:
0332: AxisBindingMessage axisBindingMessage = null;
0333: if (axisBindingOperation != null) {
0334: axisBindingMessage = (AxisBindingMessage) axisBindingOperation
0335: .getChild(key);
0336: if (axisBindingMessage != null) {
0337: property = axisBindingMessage.getProperty(name);
0338: }
0339:
0340: if (property == null) {
0341: property = axisBindingOperation.getProperty(name);
0342: }
0343: }
0344:
0345: if ((property == null) && (axisBinding != null)) {
0346: property = axisBinding.getProperty(name);
0347: }
0348:
0349: if (property == null) {
0350: property = WSDL20DefaultValueHolder.getDefaultValue(name);
0351: }
0352:
0353: return property;
0354: }
0355:
0356: private Object getBindingPropertyFromMessageFault(String name,
0357: QName qName, String key) {
0358:
0359: Object property = null;
0360: // Get the correct AxisBindingOperation coresponding to the AxisOperation
0361: AxisBindingOperation axisBindingOperation = (AxisBindingOperation) axisBinding
0362: .getChild(qName);
0363:
0364: AxisBindingMessage axisBindingMessageFault = null;
0365: AxisBindingMessage axisBindingFault = null;
0366: if (axisBindingOperation != null) {
0367: axisBindingMessageFault = (AxisBindingMessage) axisBindingOperation
0368: .getFault(key);
0369:
0370: if (axisBindingMessageFault != null) {
0371: property = axisBindingMessageFault.getProperty(name);
0372: }
0373:
0374: if (property == null) {
0375: axisBindingFault = axisBinding.getFault(key);
0376: property = axisBindingFault.getProperty(name);
0377: }
0378: }
0379:
0380: if (property == null) {
0381: property = WSDL20DefaultValueHolder.getDefaultValue(name);
0382: }
0383:
0384: return property;
0385: }
0386:
0387: /**
0388: * Update mapper for the stub
0389: */
0390: protected void updateMapperForStub() {
0391: updateMapperClassnames(getFullyQualifiedStubName());
0392: }
0393:
0394: /**
0395: * Returns the fully qualified Stub name reused in many methods
0396: *
0397: * @return classname
0398: */
0399: protected String getFullyQualifiedStubName() {
0400: String packageName = codeGenConfiguration.getPackageName();
0401: String localPart = null;
0402: if (this .axisService.getEndpoints().size() > 1) {
0403: localPart = makeJavaClassName(axisService.getName()
0404: + axisService.getEndpointName());
0405: } else {
0406: localPart = makeJavaClassName(axisService.getName());
0407: }
0408: return packageName + "." + localPart + STUB_SUFFIX;
0409: }
0410:
0411: /**
0412: * rests the fault name maps
0413: */
0414: protected void resetFaultNames() {
0415: fullyQualifiedFaultClassNameMap.clear();
0416: faultClassNameMap.clear();
0417: faultElementQNameMap.clear();
0418: }
0419:
0420: /**
0421: * Populate a map of fault class names
0422: */
0423: protected void generateAndPopulateFaultNames() {
0424: //loop through and find the faults
0425: Iterator operations = axisService.getOperations();
0426: AxisOperation operation;
0427: AxisMessage faultMessage;
0428: while (operations.hasNext()) {
0429: operation = (AxisOperation) operations.next();
0430: ArrayList faultMessages = operation.getFaultMessages();
0431: for (int i = 0; i < faultMessages.size(); i++) {
0432: faultMessage = (AxisMessage) faultMessages.get(i);
0433: //make a unique name and put that in the hashmap
0434: if (!fullyQualifiedFaultClassNameMap
0435: .containsKey(faultMessage.getName())) {
0436: //make a name
0437: String className = makeJavaClassName(faultMessage
0438: .getName());
0439: QName faultQName = new QName(codeGenConfiguration
0440: .getTargetNamespace(), faultMessage
0441: .getName());
0442: if (this .mapper.getQNameToMappingObject(faultQName) != null) {
0443: // i.e we already have an entry
0444: className = makeJavaClassName(className
0445: + "Exception"
0446: + (uniqueFaultNameCounter++));
0447: }
0448: while (fullyQualifiedFaultClassNameMap
0449: .containsValue(className)) {
0450: className = makeJavaClassName(className
0451: + (uniqueFaultNameCounter++));
0452: }
0453:
0454: fullyQualifiedFaultClassNameMap.put(faultMessage
0455: .getName(), className);
0456: //we've to keep track of the fault base names seperately
0457: faultClassNameMap.put(faultMessage.getName(),
0458: className);
0459:
0460: faultElementQNameMap.put(faultMessage.getName(),
0461: faultMessage.getElementQName());
0462:
0463: }
0464: }
0465:
0466: }
0467: }
0468:
0469: /**
0470: * Emits the stubcode with bindings.
0471: *
0472: * @throws CodeGenerationException
0473: * @see Emitter#emitStub()
0474: */
0475: public void emitStub() throws CodeGenerationException {
0476: try {
0477:
0478: //first keep a seperate copy of the original map to use in
0479: // every iteration
0480: // for every iteration qName2NameMap is changed in updateMapperForStub
0481: // method if in the packing mode
0482: Map originalTypeMap = getNewCopy(mapper.getAllMappedNames());
0483:
0484: for (Iterator axisServicesIter = this .axisServices
0485: .iterator(); axisServicesIter.hasNext();) {
0486: this .axisService = (AxisService) axisServicesIter
0487: .next();
0488: //we have to generate the code for each bininding
0489: //for the moment lets genrate the stub name with the service name and end point name
0490:
0491: if (!codeGenConfiguration.isPackClasses()) {
0492: // write the call back handlers
0493: writeCallBackHandlers();
0494: }
0495:
0496: Map endpoints = this .axisService.getEndpoints();
0497: for (Iterator endPointsIter = endpoints.values()
0498: .iterator(); endPointsIter.hasNext();) {
0499: // set the end point details.
0500: this .axisEndpoint = (AxisEndpoint) endPointsIter
0501: .next();
0502: this .axisBinding = this .axisEndpoint.getBinding();
0503: axisService.setEndpointName(this .axisEndpoint
0504: .getName());
0505: axisService.setBindingName(this .axisEndpoint
0506: .getBinding().getName().getLocalPart());
0507:
0508: // see the comment at updateMapperClassnames for details and reasons for
0509: // calling this method
0510: if (mapper.isObjectMappingPresent()) {
0511: // initialize the map to original one
0512: copyMap(originalTypeMap, mapper
0513: .getAllMappedNames());
0514: updateMapperForStub();
0515: } else {
0516: copyToFaultMap();
0517: }
0518:
0519: //generate and populate the fault names before hand. We need that for
0520: //the smooth opration of the thing
0521: //first reset the fault names and recreate it
0522: resetFaultNames();
0523: generateAndPopulateFaultNames();
0524: updateFaultPackageForStub();
0525:
0526: // write the inteface
0527: // feed the binding information also
0528: // note that we do not create this interface if the user switched on the wrap classes mode
0529: // this interface also depends on the binding
0530: if (!codeGenConfiguration.isPackClasses()) {
0531: writeInterface(false);
0532: }
0533:
0534: if (codeGenConfiguration.isPackClasses()) {
0535: // write the call back handlers
0536: writeCallBackHandlers();
0537: }
0538:
0539: // write the Exceptions
0540: writeExceptions();
0541:
0542: // write interface implementations
0543: writeInterfaceImplementation();
0544:
0545: // write the test classes
0546: writeTestClasses();
0547:
0548: }
0549:
0550: }
0551:
0552: // save back type map
0553: if (this .mapper.isObjectMappingPresent()) {
0554: copyMap(originalTypeMap, this .mapper
0555: .getAllMappedNames());
0556: }
0557:
0558: if (!codeGenConfiguration.isSkipBuildXML()) {
0559: // write an ant build file
0560: // Note that ant build is generated only once
0561: // and that has to happen here only if the
0562: // client side code is required
0563: if (!codeGenConfiguration.isGenerateAll()) {
0564: //our logic for the build xml is that it will
0565: //only be written when not flattened
0566: if (!codeGenConfiguration.isFlattenFiles()) {
0567: writeAntBuild();
0568: }
0569: }
0570: }
0571: } catch (CodeGenerationException ce) {
0572: throw ce;
0573: } catch (Exception e) {
0574: throw new CodeGenerationException(e);
0575: }
0576: }
0577:
0578: private Map getNewCopy(Map copyFormMap) {
0579: Map copyToMap = new HashMap();
0580: Object key;
0581: for (Iterator iter = copyFormMap.keySet().iterator(); iter
0582: .hasNext();) {
0583: key = iter.next();
0584: copyToMap.put(key, copyFormMap.get(key));
0585: }
0586: return copyToMap;
0587: }
0588:
0589: private void copyMap(Map copyFormMap, Map copyToMap) {
0590: Object key;
0591: for (Iterator iter = copyFormMap.keySet().iterator(); iter
0592: .hasNext();) {
0593: key = iter.next();
0594: copyToMap.put(key, copyFormMap.get(key));
0595: }
0596: }
0597:
0598: /**
0599: * Writes the Ant build.
0600: *
0601: * @throws Exception
0602: */
0603: protected void writeAntBuild() throws Exception {
0604:
0605: // Write the service xml in a folder with the
0606: Document skeletonModel = createDOMDocumentForAntBuild();
0607: debugLogDocument("Document for ant build:", skeletonModel);
0608: AntBuildWriter antBuildWriter = new AntBuildWriter(
0609: codeGenConfiguration.getOutputLocation(),
0610: codeGenConfiguration.getOutputLanguage());
0611:
0612: antBuildWriter.setDatabindingFramework(codeGenConfiguration
0613: .getDatabindingType());
0614: antBuildWriter.setOverride(codeGenConfiguration.isOverride());
0615: writeFile(skeletonModel, antBuildWriter);
0616: codeGenConfiguration.addXmlFileName(antBuildWriter
0617: .getOutputFile().getAbsolutePath());
0618: }
0619:
0620: /**
0621: * Creates the DOM tree for the Ant build. Uses the interface.
0622: */
0623: protected Document createDOMDocumentForAntBuild() {
0624: Document doc = getEmptyDocument();
0625: Element rootElement = doc.createElement("ant");
0626: String serviceName = makeJavaClassName(axisService.getName());
0627: String packageName = codeGenConfiguration.getPackageName();
0628: String[] dotSeparatedValues = packageName.split("\\.");
0629:
0630: addAttribute(doc, "package", dotSeparatedValues[0], rootElement);
0631: addAttribute(doc, "name", serviceName, rootElement);
0632: addAttribute(doc, "servicename", serviceName, rootElement);
0633: addAttribute(doc, "src", codeGenConfiguration
0634: .getSourceLocation(), rootElement);
0635: addAttribute(doc, "resource", codeGenConfiguration
0636: .getResourceLocation(), rootElement);
0637:
0638: if (codeGenConfiguration.getAxisServices().size() > 1) {
0639: addAttribute(doc, "artifactname", "Services", rootElement);
0640: } else {
0641: addAttribute(doc, "artifactname", this .axisService
0642: .getName(), rootElement);
0643: }
0644:
0645: if (!codeGenConfiguration.isWriteTestCase()) {
0646: addAttribute(doc, "testOmit", "true", rootElement);
0647: }
0648:
0649: if (codeGenConfiguration.isServerSide()) {
0650: addAttribute(doc, "isserverside", "yes", rootElement);
0651: }
0652:
0653: doc.appendChild(rootElement);
0654:
0655: //////////////////////////////////////////////////////////
0656: // System.out.println(DOM2Writer.nodeToString(rootElement));
0657: ////////////////////////////////////////////////////////////
0658:
0659: return doc;
0660: }
0661:
0662: /**
0663: * Write the test classes
0664: */
0665: protected void writeTestClasses() throws Exception {
0666: if (codeGenConfiguration.isWriteTestCase()) {
0667: Document classModel = createDOMDocumentForTestCase();
0668: debugLogDocument("Document for test case:", classModel);
0669: TestClassWriter callbackWriter = new TestClassWriter(
0670: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
0671: codeGenConfiguration.getOutputLocation(),
0672: null)
0673: : getOutputDirectory(codeGenConfiguration
0674: .getOutputLocation(),
0675: TEST_SRC_DIR_NAME),
0676: codeGenConfiguration.getOutputLanguage());
0677: callbackWriter.setOverride(codeGenConfiguration
0678: .isOverride());
0679: writeFile(classModel, callbackWriter);
0680: }
0681: }
0682:
0683: /**
0684: * Creates the XML Model for the test case
0685: *
0686: * @return DOM document
0687: */
0688: protected Document createDOMDocumentForTestCase() {
0689: String coreClassName = makeJavaClassName(axisService.getName());
0690: Document doc = getEmptyDocument();
0691: Element rootElement = doc.createElement("class");
0692:
0693: addAttribute(doc, "package", codeGenConfiguration
0694: .getPackageName(), rootElement);
0695: if (this .axisService.getEndpoints().size() > 1) {
0696: addAttribute(doc, "name", makeJavaClassName(axisService
0697: .getName()
0698: + axisService.getEndpointName())
0699: + TEST_SUFFIX, rootElement);
0700: } else {
0701: addAttribute(doc, "name", makeJavaClassName(axisService
0702: .getName())
0703: + TEST_SUFFIX, rootElement);
0704: }
0705:
0706: //todo is this right ???
0707: addAttribute(doc, "namespace",
0708: axisService.getTargetNamespace(), rootElement);
0709: addAttribute(doc, "interfaceName", coreClassName, rootElement);
0710: if (codeGenConfiguration.isPackClasses()) {
0711: if (this .axisService.getEndpoints().size() > 1) {
0712: addAttribute(doc, "callbackname",
0713: makeJavaClassName(axisService.getName()
0714: + axisService.getEndpointName())
0715: + CALL_BACK_HANDLER_SUFFIX, rootElement);
0716: } else {
0717: addAttribute(doc, "callbackname",
0718: makeJavaClassName(axisService.getName())
0719: + CALL_BACK_HANDLER_SUFFIX, rootElement);
0720: }
0721:
0722: } else {
0723: addAttribute(doc, "callbackname", coreClassName
0724: + CALL_BACK_HANDLER_SUFFIX, rootElement);
0725: }
0726: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
0727: addAttribute(doc, "stubname", makeJavaClassName(axisService
0728: .getBindingName())
0729: + STUB_SUFFIX, rootElement);
0730: } else {
0731: if (this .axisService.getEndpoints().size() > 1) {
0732: addAttribute(doc, "stubname",
0733: makeJavaClassName(axisService.getName()
0734: + axisService.getEndpointName())
0735: + STUB_SUFFIX, rootElement);
0736: } else {
0737: addAttribute(doc, "stubname",
0738: makeJavaClassName(axisService.getName())
0739: + STUB_SUFFIX, rootElement);
0740: }
0741:
0742: }
0743:
0744: //add backwordcompatibility attribute
0745: addAttribute(doc, "isbackcompatible", String
0746: .valueOf(codeGenConfiguration
0747: .isBackwordCompatibilityMode()), rootElement);
0748:
0749: fillSyncAttributes(doc, rootElement);
0750: loadOperations(doc, rootElement, null);
0751:
0752: // add the databind supporters. Now the databind supporters are completly contained inside
0753: // the stubs implementation and not visible outside
0754: rootElement.appendChild(createDOMElementforDatabinders(doc,
0755: false));
0756: doc.appendChild(rootElement);
0757: //////////////////////////////////////////////////////////
0758: // System.out.println(DOM2Writer.nodeToString(rootElement));
0759: ////////////////////////////////////////////////////////////
0760:
0761: return doc;
0762: }
0763:
0764: /**
0765: * Writes the implementations.
0766: *
0767: * @throws Exception
0768: */
0769: protected void writeInterfaceImplementation() throws Exception {
0770:
0771: // first check for the policies in this service and write them
0772: Document interfaceImplModel = createDOMDocumentForInterfaceImplementation();
0773: debugLogDocument("Document for interface implementation:",
0774: interfaceImplModel);
0775: InterfaceImplementationWriter writer = new InterfaceImplementationWriter(
0776: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
0777: codeGenConfiguration.getOutputLocation(), null)
0778: : getOutputDirectory(codeGenConfiguration
0779: .getOutputLocation(),
0780: codeGenConfiguration
0781: .getSourceLocation()),
0782: codeGenConfiguration.getOutputLanguage());
0783:
0784: writer.setOverride(codeGenConfiguration.isOverride());
0785: writeFile(interfaceImplModel, writer);
0786:
0787: }
0788:
0789: /**
0790: * Creates the DOM tree for implementations.
0791: */
0792: protected Document createDOMDocumentForInterfaceImplementation()
0793: throws Exception {
0794:
0795: String packageName = codeGenConfiguration.getPackageName();
0796: String localPart = makeJavaClassName(axisService.getName());
0797: String stubName = makeJavaClassName(axisService.getName()
0798: + axisService.getEndpointName())
0799: + STUB_SUFFIX;
0800: Document doc = getEmptyDocument();
0801: Element rootElement = doc.createElement("class");
0802:
0803: addAttribute(doc, "package", packageName, rootElement);
0804:
0805: addAttribute(doc, "servicename", localPart, rootElement);
0806: //The target nemespace is added as the namespace for this service
0807: addAttribute(doc, "namespace",
0808: axisService.getTargetNamespace(), rootElement);
0809: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
0810: addAttribute(doc, "interfaceName",
0811: makeJavaClassName(axisService.getEndpointName())
0812: + STUB_INTERFACE_SUFFIX_BACK, rootElement);
0813: addAttribute(doc, "name", makeJavaClassName(axisService
0814: .getBindingName())
0815: + STUB_SUFFIX, rootElement);
0816: } else {
0817: if (this .axisService.getEndpoints().size() > 1) {
0818: addAttribute(doc, "interfaceName",
0819: makeJavaClassName(axisService.getName()
0820: + axisService.getEndpointName()),
0821: rootElement);
0822: addAttribute(doc, "name", stubName, rootElement);
0823: } else {
0824: addAttribute(doc, "interfaceName",
0825: makeJavaClassName(axisService.getName()),
0826: rootElement);
0827: addAttribute(doc, "name", makeJavaClassName(axisService
0828: .getName())
0829: + STUB_SUFFIX, rootElement);
0830: }
0831:
0832: }
0833:
0834: if (codeGenConfiguration.isPackClasses()) {
0835: if (this .axisService.getEndpoints().size() > 1) {
0836: addAttribute(doc, "callbackname",
0837: makeJavaClassName(axisService.getName()
0838: + axisService.getEndpointName())
0839: + CALL_BACK_HANDLER_SUFFIX, rootElement);
0840: } else {
0841: addAttribute(doc, "callbackname",
0842: makeJavaClassName(axisService.getName())
0843: + CALL_BACK_HANDLER_SUFFIX, rootElement);
0844: }
0845:
0846: } else {
0847: addAttribute(doc, "callbackname", localPart
0848: + CALL_BACK_HANDLER_SUFFIX, rootElement);
0849: }
0850: //add backwordcompatibility attribute
0851: addAttribute(doc, "isbackcompatible", String
0852: .valueOf(codeGenConfiguration
0853: .isBackwordCompatibilityMode()), rootElement);
0854:
0855: // add the wrap classes flag
0856: if (codeGenConfiguration.isPackClasses()) {
0857: addAttribute(doc, "wrapped", "yes", rootElement);
0858: }
0859:
0860: // add SOAP version
0861: addSoapVersion(doc, rootElement);
0862:
0863: // add the end point
0864: addEndpoint(doc, rootElement);
0865:
0866: // set the sync/async attributes
0867: fillSyncAttributes(doc, rootElement);
0868:
0869: // ###########################################################################################
0870: // this block of code specifically applies to the integration of databinding code into the
0871: // generated classes tightly (probably as inner classes)
0872: // ###########################################################################################
0873: // check for the special models in the mapper and if they are present process them
0874: if (mapper.isObjectMappingPresent()) {
0875:
0876: // add an attribute to the root element showing that the writing has been skipped
0877: addAttribute(doc, "skip-write", "yes", rootElement);
0878:
0879: // process the mapper objects
0880: processModelObjects(mapper.getAllMappedObjects(),
0881: rootElement, doc);
0882: }
0883:
0884: // #############################################################################################
0885:
0886: // load the operations
0887: loadOperations(doc, rootElement, null);
0888:
0889: // add the databind supporters. Now the databind supporters are completly contained inside
0890: // the stubs implementation and not visible outside
0891: rootElement.appendChild(createDOMElementforDatabinders(doc,
0892: false));
0893:
0894: Object moduleCodegenPolicyExtensionElement;
0895:
0896: //if some extension has added the stub methods property, add them to the
0897: //main document
0898: if ((moduleCodegenPolicyExtensionElement = codeGenConfiguration
0899: .getProperty("module-codegen-policy-extensions")) != null) {
0900: rootElement
0901: .appendChild(doc
0902: .importNode(
0903: (Element) moduleCodegenPolicyExtensionElement,
0904: true));
0905: }
0906:
0907: //add another element to have the unique list of faults
0908: rootElement.appendChild(getUniqueListofFaults(doc));
0909:
0910: doc.appendChild(rootElement);
0911:
0912: //////////////////////////////////////////////////////////
0913: // System.out.println(DOM2Writer.nodeToString(rootElement));
0914: ////////////////////////////////////////////////////////////
0915: return doc;
0916: }
0917:
0918: /**
0919: * A util method that returns a unique list of faults
0920: *
0921: * @param doc
0922: * @return DOM element
0923: */
0924: protected Element getUniqueListofFaults(Document doc) {
0925: Element rootElement = doc.createElement("fault-list");
0926: Element faultElement;
0927: String key;
0928: Iterator iterator = fullyQualifiedFaultClassNameMap.keySet()
0929: .iterator();
0930: while (iterator.hasNext()) {
0931: faultElement = doc.createElement("fault");
0932: key = (String) iterator.next();
0933:
0934: //as for the name of a fault, we generate an exception
0935: addAttribute(doc, "name",
0936: (String) fullyQualifiedFaultClassNameMap.get(key),
0937: faultElement);
0938: addAttribute(doc, "shortName", (String) faultClassNameMap
0939: .get(key), faultElement);
0940:
0941: //the type represents the type that will be wrapped by this
0942: //name
0943: String typeMapping = this .mapper
0944: .getTypeMappingName((QName) faultElementQNameMap
0945: .get(key));
0946: addAttribute(doc, "type", (typeMapping == null) ? ""
0947: : typeMapping, faultElement);
0948: String attribValue = (String) instantiatableMessageClassNames
0949: .get(key);
0950:
0951: addAttribute(doc, "instantiatableType",
0952: attribValue == null ? "" : attribValue,
0953: faultElement);
0954:
0955: // add an extra attribute to say whether the type mapping is
0956: // the default
0957: if (mapper.getDefaultMappingName().equals(typeMapping)) {
0958: addAttribute(doc, "default", "yes", faultElement);
0959: }
0960: addAttribute(doc, "value",
0961: getParamInitializer(typeMapping), faultElement);
0962:
0963: rootElement.appendChild(faultElement);
0964: }
0965: return rootElement;
0966: }
0967:
0968: /**
0969: * add the qNames of the operation fault message names to faultMessages Mep
0970: *
0971: * @param operationFaultMessages
0972: * @param faultMessagesToMep
0973: */
0974:
0975: private void addFaultMessages(List operationFaultMessages,
0976: Set faultMessagesToMep) {
0977:
0978: AxisMessage faultMessage;
0979: for (Iterator iter = operationFaultMessages.iterator(); iter
0980: .hasNext();) {
0981: faultMessage = (AxisMessage) iter.next();
0982: faultMessagesToMep.add(faultMessage.getName());
0983: }
0984:
0985: }
0986:
0987: /**
0988: * A util method that returns a unique list of faults for a given mep
0989: *
0990: * @param doc
0991: * @return DOM element
0992: */
0993: protected Element getUniqueListofFaultsofMep(Document doc,
0994: String mep) {
0995:
0996: // list to keep fault message qnames for this mep
0997: Set faultListForMep = new HashSet();
0998:
0999: Iterator iter = this .axisService.getOperations();
1000: AxisOperation axisOperation;
1001:
1002: for (; iter.hasNext();) {
1003: axisOperation = (AxisOperation) iter.next();
1004: if (mep == null) {
1005: // add the fault messages
1006: addFaultMessages(axisOperation.getFaultMessages(),
1007: faultListForMep);
1008: } else {
1009: if (mep.equals(axisOperation
1010: .getMessageExchangePattern())) {
1011: // add the fault messages
1012: addFaultMessages(axisOperation.getFaultMessages(),
1013: faultListForMep);
1014: }
1015: }
1016: }
1017:
1018: Element rootElement = doc.createElement("fault-list");
1019: Element faultElement;
1020: String key;
1021: Iterator iterator = faultListForMep.iterator();
1022: while (iterator.hasNext()) {
1023: faultElement = doc.createElement("fault");
1024: key = (String) iterator.next();
1025:
1026: //as for the name of a fault, we generate an exception
1027: addAttribute(doc, "name",
1028: (String) fullyQualifiedFaultClassNameMap.get(key),
1029: faultElement);
1030: addAttribute(doc, "shortName", (String) faultClassNameMap
1031: .get(key), faultElement);
1032:
1033: //the type represents the type that will be wrapped by this
1034: //name
1035: String typeMapping = this .mapper
1036: .getTypeMappingName((QName) faultElementQNameMap
1037: .get(key));
1038: addAttribute(doc, "type", (typeMapping == null) ? ""
1039: : typeMapping, faultElement);
1040: String attribValue = (String) instantiatableMessageClassNames
1041: .get(key);
1042:
1043: addAttribute(doc, "instantiatableType",
1044: attribValue == null ? "" : attribValue,
1045: faultElement);
1046:
1047: String exceptionName = ((QName) faultElementQNameMap
1048: .get(key)).getLocalPart();
1049: addAttribute(doc, "localname", exceptionName == null ? ""
1050: : exceptionName, faultElement);
1051:
1052: // add an extra attribute to say whether the type mapping is
1053: // the default
1054: if (mapper.getDefaultMappingName().equals(typeMapping)) {
1055: addAttribute(doc, "default", "yes", faultElement);
1056: }
1057: addAttribute(doc, "value",
1058: getParamInitializer(typeMapping), faultElement);
1059:
1060: rootElement.appendChild(faultElement);
1061: }
1062: return rootElement;
1063: }
1064:
1065: /**
1066: * Adds the endpoint to the document.
1067: *
1068: * @param doc
1069: * @param rootElement
1070: */
1071: protected void addEndpoint(Document doc, Element rootElement)
1072: throws Exception {
1073:
1074: Element endpointElement = doc.createElement("endpoint");
1075:
1076: String endpoint = this .axisEndpoint.getEndpointURL();
1077: Text text = doc.createTextNode((endpoint != null) ? endpoint
1078: : "");
1079:
1080: endpointElement.appendChild(text);
1081: rootElement.appendChild(endpointElement);
1082: }
1083:
1084: /**
1085: * Looks for the SOAPVersion and adds it.
1086: *
1087: * @param doc
1088: * @param rootElement
1089: */
1090: protected void addSoapVersion(Document doc, Element rootElement) {
1091: // loop through the extensibility elements to get to the bindings element
1092: addAttribute(doc, "soap-version", (String) axisBinding
1093: .getProperty(WSDL2Constants.ATTR_WSOAP_VERSION),
1094: rootElement);
1095: }
1096:
1097: /**
1098: * Writes the exceptions.
1099: */
1100: protected void writeExceptions() throws Exception {
1101: Element faultElement;
1102: String key;
1103: Iterator iterator = fullyQualifiedFaultClassNameMap.keySet()
1104: .iterator();
1105: while (iterator.hasNext()) {
1106: Document doc = getEmptyDocument();
1107:
1108: faultElement = doc.createElement("fault");
1109:
1110: addAttribute(doc, "package", codeGenConfiguration
1111: .getPackageName(), faultElement);
1112:
1113: key = (String) iterator.next();
1114:
1115: //as for the name of a fault, we generate an exception
1116: addAttribute(doc, "name", (String) faultClassNameMap
1117: .get(key), faultElement);
1118: addAttribute(doc, "shortName", (String) faultClassNameMap
1119: .get(key), faultElement);
1120:
1121: //the type represents the type that will be wrapped by this
1122: //name
1123: String typeMapping = this .mapper
1124: .getTypeMappingName((QName) faultElementQNameMap
1125: .get(key));
1126: addAttribute(doc, "type", (typeMapping == null) ? ""
1127: : typeMapping, faultElement);
1128: String attribValue = (String) instantiatableMessageClassNames
1129: .get(key);
1130: addAttribute(doc, "instantiatableType",
1131: attribValue == null ? "" : attribValue,
1132: faultElement);
1133:
1134: // add an extra attribute to say whether the type mapping is
1135: // the default
1136: if (mapper.getDefaultMappingName().equals(typeMapping)) {
1137: addAttribute(doc, "default", "yes", faultElement);
1138: }
1139: addAttribute(doc, "value",
1140: getParamInitializer(typeMapping), faultElement);
1141: ExceptionWriter exceptionWriter = new ExceptionWriter(
1142: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
1143: codeGenConfiguration.getOutputLocation(),
1144: null)
1145: : getOutputDirectory(codeGenConfiguration
1146: .getOutputLocation(),
1147: codeGenConfiguration
1148: .getSourceLocation()),
1149: codeGenConfiguration.getOutputLanguage());
1150:
1151: doc.appendChild(faultElement);
1152: //////////////////////////////////////////////////////////
1153: // System.out.println(DOM2Writer.nodeToString(doc));
1154: ////////////////////////////////////////////////////////////
1155: exceptionWriter.setOverride(codeGenConfiguration
1156: .isOverride());
1157: writeFile(doc, exceptionWriter);
1158: }
1159: }
1160:
1161: /**
1162: * Generates the model for the callbacks.
1163: */
1164: protected Document createDOMDocumentForException() {
1165: Document doc = getEmptyDocument();
1166: Element rootElement = doc.createElement("callback");
1167:
1168: addAttribute(doc, "package", codeGenConfiguration
1169: .getPackageName(), rootElement);
1170: addAttribute(doc, "name", makeJavaClassName(axisService
1171: .getName())
1172: + CALL_BACK_HANDLER_SUFFIX, rootElement);
1173:
1174: // TODO JAXRPC mapping support should be considered here ??
1175: this .loadOperations(doc, rootElement, null);
1176:
1177: doc.appendChild(rootElement);
1178: return doc;
1179: }
1180:
1181: /**
1182: * Writes the callback handlers.
1183: */
1184: protected void writeCallBackHandlers() throws Exception {
1185: if (codeGenConfiguration.isAsyncOn()) {
1186: Document interfaceModel = createDOMDocumentForCallbackHandler();
1187: debugLogDocument("Document for callback handler:",
1188: interfaceModel);
1189: CallbackHandlerWriter callbackWriter = new CallbackHandlerWriter(
1190: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
1191: codeGenConfiguration.getOutputLocation(),
1192: null)
1193: : getOutputDirectory(codeGenConfiguration
1194: .getOutputLocation(),
1195: codeGenConfiguration
1196: .getSourceLocation()),
1197: codeGenConfiguration.getOutputLanguage());
1198: callbackWriter.setOverride(codeGenConfiguration
1199: .isOverride());
1200: writeFile(interfaceModel, callbackWriter);
1201: }
1202: }
1203:
1204: /**
1205: * Generates the model for the callbacks.
1206: */
1207: protected Document createDOMDocumentForCallbackHandler() {
1208: Document doc = getEmptyDocument();
1209: Element rootElement = doc.createElement("callback");
1210:
1211: addAttribute(doc, "package", codeGenConfiguration
1212: .getPackageName(), rootElement);
1213: if (codeGenConfiguration.isPackClasses()
1214: && this .axisService.getEndpoints().size() > 1) {
1215: addAttribute(doc, "name", makeJavaClassName(axisService
1216: .getName()
1217: + axisService.getEndpointName())
1218: + CALL_BACK_HANDLER_SUFFIX, rootElement);
1219: } else {
1220: addAttribute(doc, "name", makeJavaClassName(axisService
1221: .getName())
1222: + CALL_BACK_HANDLER_SUFFIX, rootElement);
1223: }
1224:
1225: // TODO JAXRPC mapping support should be considered here ??
1226: this .loadOperations(doc, rootElement, null);
1227:
1228: doc.appendChild(rootElement);
1229: return doc;
1230: }
1231:
1232: /**
1233: * Writes the interfaces.
1234: *
1235: * @throws Exception
1236: */
1237: protected void writeInterface(boolean writeDatabinders)
1238: throws Exception {
1239: Document interfaceModel = createDOMDocumentForInterface(writeDatabinders);
1240: debugLogDocument("Document for interface:", interfaceModel);
1241: InterfaceWriter interfaceWriter = new InterfaceWriter(
1242: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
1243: codeGenConfiguration.getOutputLocation(), null)
1244: : getOutputDirectory(codeGenConfiguration
1245: .getOutputLocation(),
1246: codeGenConfiguration
1247: .getSourceLocation()),
1248: this .codeGenConfiguration.getOutputLanguage());
1249: interfaceWriter.setOverride(codeGenConfiguration.isOverride());
1250: writeFile(interfaceModel, interfaceWriter);
1251: }
1252:
1253: /**
1254: * Creates the DOM tree for the interface creation. Uses the interface.
1255: */
1256: protected Document createDOMDocumentForInterface(
1257: boolean writeDatabinders) {
1258: Document doc = getEmptyDocument();
1259: Element rootElement = doc.createElement("interface");
1260: String localPart = null;
1261: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
1262: localPart = makeJavaClassName(axisService.getEndpointName()
1263: + STUB_INTERFACE_SUFFIX_BACK);
1264: } else {
1265: if (this .axisService.getEndpoints().size() > 1) {
1266: localPart = makeJavaClassName(axisService.getName()
1267: + axisService.getEndpointName());
1268: } else {
1269: localPart = makeJavaClassName(axisService.getName());
1270: }
1271: }
1272:
1273: addAttribute(doc, "package", codeGenConfiguration
1274: .getPackageName(), rootElement);
1275: addAttribute(doc, "name", localPart, rootElement);
1276:
1277: addAttribute(doc, "callbackname", makeJavaClassName(axisService
1278: .getName())
1279: + CALL_BACK_HANDLER_SUFFIX, rootElement);
1280:
1281: //add backwordcompatibility attribute
1282: addAttribute(doc, "isbackcompatible", String
1283: .valueOf(codeGenConfiguration
1284: .isBackwordCompatibilityMode()), rootElement);
1285: fillSyncAttributes(doc, rootElement);
1286: loadOperations(doc, rootElement, null);
1287:
1288: // ###########################################################################################
1289: // this block of code specifically applies to the integration of databinding code into the
1290: // generated classes tightly (probably as inner classes)
1291: // ###########################################################################################
1292: // check for the special models in the mapper and if they are present process them
1293: if (writeDatabinders) {
1294: if (mapper.isObjectMappingPresent()) {
1295:
1296: // add an attribute to the root element showing that the writing has been skipped
1297: addAttribute(doc, "skip-write", "yes", rootElement);
1298:
1299: // process the mapper objects
1300: processModelObjects(mapper.getAllMappedObjects(),
1301: rootElement, doc);
1302: }
1303: }
1304:
1305: // #############################################################################################
1306: doc.appendChild(rootElement);
1307:
1308: return doc;
1309: }
1310:
1311: /**
1312: * Update mapper for message receiver
1313: */
1314: protected void updateMapperForMessageReceiver() {
1315: updateMapperClassnames(getFullyQualifiedMessageReceiverName());
1316: }
1317:
1318: /**
1319: * @return fully qualified MR name
1320: */
1321: protected String getFullyQualifiedMessageReceiverName() {
1322: String packageName = codeGenConfiguration.getPackageName();
1323: String localPart = makeJavaClassName(axisService.getName());
1324: return packageName + "." + localPart + MESSAGE_RECEIVER_SUFFIX;
1325: }
1326:
1327: /**
1328: * @return fully qualified skeleton name
1329: */
1330: protected String getFullyQualifiedSkeletonName() {
1331: String packageName = codeGenConfiguration.getPackageName();
1332: String localPart = makeJavaClassName(axisService.getName());
1333: String skeltonName;
1334: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
1335: skeltonName = packageName + "."
1336: + makeJavaClassName(axisService.getBindingName())
1337: + SKELETON_CLASS_SUFFIX_BACK;
1338: } else {
1339: skeltonName = packageName + "." + localPart
1340: + SKELETON_CLASS_SUFFIX;
1341: }
1342: return skeltonName;
1343: }
1344:
1345: /**
1346: * @return fully qualified skeleton interface name
1347: */
1348: protected String getFullyQualifiedSkeletonInterfaceName() {
1349: String packageName = codeGenConfiguration.getPackageName();
1350: String localPart = makeJavaClassName(axisService.getName());
1351: String skeltonInterfaceName;
1352: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
1353: skeltonInterfaceName = packageName + "."
1354: + makeJavaClassName(axisService.getEndpointName())
1355: + SKELETON_INTERFACE_SUFFIX_BACK;
1356: } else {
1357: skeltonInterfaceName = packageName + "." + localPart
1358: + SKELETON_INTERFACE_SUFFIX;
1359: }
1360: return skeltonInterfaceName;
1361: }
1362:
1363: /**
1364: * Emits the skeleton
1365: *
1366: * @throws CodeGenerationException
1367: */
1368: public void emitSkeleton() throws CodeGenerationException {
1369:
1370: try {
1371:
1372: allServiceInfoHolder = new HashMap();
1373: Map originalMap = getNewCopy(this .mapper
1374: .getAllMappedNames());
1375: // we are going to generate following files seperately per service
1376: for (Iterator axisServicesIter = this .axisServices
1377: .iterator(); axisServicesIter.hasNext();) {
1378: // create a new hash map for each service
1379: this .infoHolder = new HashMap();
1380: this .axisService = (AxisService) axisServicesIter
1381: .next();
1382: this .axisBinding = axisService.getEndpoint(
1383: axisService.getEndpointName()).getBinding();
1384:
1385: // see the comment at updateMapperClassnames for details and reasons for
1386: // calling this method
1387: if (mapper.isObjectMappingPresent()) {
1388: copyMap(originalMap, this .mapper
1389: .getAllMappedNames());
1390: updateMapperForMessageReceiver();
1391: } else {
1392: copyToFaultMap();
1393: }
1394:
1395: //handle faults
1396: generateAndPopulateFaultNames();
1397:
1398: //
1399: if (codeGenConfiguration.isServerSideInterface()) {
1400: //write skeletonInterface
1401: writeSkeletonInterface();
1402: }
1403:
1404: // write skeleton only if the used has
1405: // asked for the deployment descriptor in the interface mode
1406: // else write it anyway :)
1407: if (codeGenConfiguration.isServerSideInterface()) {
1408: if (codeGenConfiguration
1409: .isGenerateDeployementDescriptor()) {
1410: writeSkeleton();
1411: }
1412: } else {
1413: writeSkeleton();
1414: }
1415:
1416: if (!codeGenConfiguration.isSkipMessageReceiver()) {
1417: // write a MessageReceiver for this particular service.
1418: writeMessageReceiver();
1419: }
1420:
1421: // write the Exceptions
1422: writeExceptions();
1423:
1424: if (!codeGenConfiguration.isSkipWriteWSDLs()) {
1425: //for the server side codegen
1426: //we need to serialize the WSDL's
1427: writeWSDLFiles();
1428: }
1429: // save the info holder with the service
1430: allServiceInfoHolder.put(this .axisService.getName(),
1431: this .infoHolder);
1432: }
1433:
1434: // save back type map
1435: if (this .mapper.isObjectMappingPresent()) {
1436: copyMap(originalMap, this .mapper.getAllMappedNames());
1437: }
1438:
1439: // write service xml
1440: // if asked
1441: if (codeGenConfiguration.isGenerateDeployementDescriptor()) {
1442: writeServiceXml();
1443: }
1444:
1445: if (!codeGenConfiguration.isSkipBuildXML()) {
1446: //write the ant build
1447: //we skip this for the flattened case
1448: if (!codeGenConfiguration.isFlattenFiles()) {
1449: writeAntBuild();
1450: }
1451: }
1452:
1453: } catch (CodeGenerationException cgExp) {
1454: throw cgExp;
1455: } catch (Exception e) {
1456: throw new CodeGenerationException(e);
1457: }
1458: }
1459:
1460: /**
1461: * Write out the WSDL files (and the schemas) writing the WSDL (and schemas) is somewhat special
1462: * so we cannot follow the usual pattern of using the class writer
1463: */
1464: protected void writeWSDLFiles() {
1465:
1466: //first modify the schema names (and locations) so that
1467: //they have unique (flattened) names and the schema locations
1468: //are adjusted to suit it
1469: axisService.setCustomSchemaNamePrefix("");//prefix with nothing
1470: axisService.setCustomSchemaNameSuffix(".xsd");//suffix with .xsd - the file name extension
1471: //force the mappings to be reconstructed
1472: axisService.setSchemaLocationsAdjusted(false);
1473: Map changedMap = axisService.populateSchemaMappings();
1474:
1475: // add these two attribute to use the user defined wsdl to use.
1476: try {
1477: axisService.addParameter(new Parameter("useOriginalwsdl",
1478: "true"));
1479: axisService.addParameter(new Parameter(
1480: "modifyUserWSDLPortAddress", "false"));
1481: } catch (AxisFault axisFault) {
1482: // there is no way to get this excpetion while in codegeneration
1483: }
1484:
1485: //now get the schema list and write it out
1486: SchemaWriter schemaWriter = new SchemaWriter(
1487: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
1488: codeGenConfiguration.getOutputLocation(), null)
1489: : getOutputDirectory(codeGenConfiguration
1490: .getOutputLocation(),
1491: codeGenConfiguration
1492: .getResourceLocation()));
1493:
1494: // first write all the schmas.
1495: // then use the changedMap got above to adjust the names.
1496: Map schemaMappings = axisService.getSchemaMappingTable();
1497: Iterator keys = schemaMappings.keySet().iterator();
1498: while (keys.hasNext()) {
1499: Object key = keys.next();
1500: schemaWriter.writeSchema((XmlSchema) schemaMappings
1501: .get(key), (String) key);
1502: }
1503:
1504: //switch between the correct writer
1505: if (CommandLineOptionConstants.WSDL2JavaConstants.WSDL_VERSION_2
1506: .equals(codeGenConfiguration.getWSDLVersion())) {
1507: // Woden cannot serialize the WSDL as yet, so lets serialize the axisService for now.
1508:
1509: WSDL20Writer wsdl20Writer = new WSDL20Writer(
1510: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
1511: codeGenConfiguration.getOutputLocation(),
1512: null)
1513: : getOutputDirectory(codeGenConfiguration
1514: .getOutputLocation(),
1515: codeGenConfiguration
1516: .getResourceLocation()));
1517: wsdl20Writer.writeWSDL(axisService);
1518:
1519: } else {
1520: // here we are going to write the wsdl and its imports
1521: // with out using the axis service.
1522:
1523: WSDL11Writer wsdl11Writer = new WSDL11Writer(
1524: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
1525: codeGenConfiguration.getOutputLocation(),
1526: null)
1527: : getOutputDirectory(codeGenConfiguration
1528: .getOutputLocation(),
1529: codeGenConfiguration
1530: .getResourceLocation()));
1531: wsdl11Writer.writeWSDL(axisService, codeGenConfiguration
1532: .getWsdlDefinition(), changedMap);
1533:
1534: }
1535: }
1536:
1537: /**
1538: * Utility method to copy the faults to the correct map
1539: */
1540: protected void copyToFaultMap() {
1541: Map classNameMap = mapper.getAllMappedNames();
1542: Iterator keys = classNameMap.keySet().iterator();
1543: while (keys.hasNext()) {
1544: Object key = keys.next();
1545: instantiatableMessageClassNames.put(key, classNameMap
1546: .get(key));
1547: }
1548: }
1549:
1550: /**
1551: * Change the fault classnames to go with the package and stub
1552: */
1553: protected void updateFaultPackageForStub() {
1554: Iterator faultClassNameKeys = fullyQualifiedFaultClassNameMap
1555: .keySet().iterator();
1556: while (faultClassNameKeys.hasNext()) {
1557: Object key = faultClassNameKeys.next();
1558: String className = (String) fullyQualifiedFaultClassNameMap
1559: .get(key);
1560: //append the skelton name
1561: String fullyQualifiedStubName = getFullyQualifiedStubName();
1562: fullyQualifiedFaultClassNameMap.put(key,
1563: codeGenConfiguration.getPackageName() + "."
1564: + className);
1565: }
1566: }
1567:
1568: /**
1569: * Writes the message receiver
1570: *
1571: * @throws Exception
1572: */
1573: protected void writeMessageReceiver() throws Exception {
1574: //loop through the meps and generate code for each mep
1575: Iterator it = mepToClassMap.keySet().iterator();
1576: while (it.hasNext()) {
1577: String mep = (String) it.next();
1578: Document classModel = createDocumentForMessageReceiver(mep,
1579: codeGenConfiguration.isServerSideInterface());
1580: debugLogDocument("Document for message receiver (mep="
1581: + mep + "):", classModel);
1582: //write the class only if any methods are found
1583: if (Boolean.TRUE.equals(infoHolder.get(mep))) {
1584: MessageReceiverWriter writer = new MessageReceiverWriter(
1585: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
1586: codeGenConfiguration
1587: .getOutputLocation(), null)
1588: : getOutputDirectory(
1589: codeGenConfiguration
1590: .getOutputLocation(),
1591: codeGenConfiguration
1592: .getSourceLocation()),
1593: codeGenConfiguration.getOutputLanguage());
1594: writer.setOverride(codeGenConfiguration.isOverride());
1595: writeFile(classModel, writer);
1596:
1597: }
1598: }
1599: }
1600:
1601: /**
1602: * Creates the XML model for the message receiver
1603: *
1604: * @param mep
1605: * @param isServerSideInterface
1606: * @return DOM Document
1607: */
1608: protected Document createDocumentForMessageReceiver(String mep,
1609: boolean isServerSideInterface) {
1610:
1611: Document doc = getEmptyDocument();
1612: Element rootElement = doc.createElement("interface");
1613:
1614: addAttribute(doc, "package", codeGenConfiguration
1615: .getPackageName(), rootElement);
1616:
1617: String localPart = makeJavaClassName(axisService.getName());
1618:
1619: addAttribute(doc, "name", localPart + mepToSuffixMap.get(mep),
1620: rootElement);
1621: //add backwordcompatibility attribute
1622: addAttribute(doc, "isbackcompatible", String
1623: .valueOf(codeGenConfiguration
1624: .isBackwordCompatibilityMode()), rootElement);
1625:
1626: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
1627: addAttribute(doc, "skeletonname",
1628: makeJavaClassName(axisService.getBindingName())
1629: + SKELETON_CLASS_SUFFIX_BACK, rootElement);
1630: if (isServerSideInterface) {
1631: addAttribute(
1632: doc,
1633: "skeletonInterfaceName",
1634: makeJavaClassName(axisService.getEndpointName())
1635: + SKELETON_INTERFACE_SUFFIX_BACK,
1636: rootElement);
1637: } else {
1638: addAttribute(doc, "skeletonInterfaceName",
1639: makeJavaClassName(axisService.getBindingName())
1640: + SKELETON_CLASS_SUFFIX_BACK,
1641: rootElement);
1642: }
1643: } else {
1644: addAttribute(doc, "skeletonname", localPart
1645: + SKELETON_CLASS_SUFFIX, rootElement);
1646: if (isServerSideInterface) {
1647: addAttribute(doc, "skeletonInterfaceName", localPart
1648: + SKELETON_INTERFACE_SUFFIX, rootElement);
1649: } else {
1650: addAttribute(doc, "skeletonInterfaceName", localPart
1651: + SKELETON_CLASS_SUFFIX, rootElement);
1652: }
1653: }
1654:
1655: addAttribute(doc, "basereceiver", (String) mepToClassMap
1656: .get(mep), rootElement);
1657:
1658: fillSyncAttributes(doc, rootElement);
1659:
1660: // ###########################################################################################
1661: // this block of code specifically applies to the integration of databinding code into the
1662: // generated classes tightly (probably as inner classes)
1663: // ###########################################################################################
1664: // check for the special models in the mapper and if they are present process them
1665: if (mapper.isObjectMappingPresent()) {
1666: // add an attribute to the root element showing that the writing has been skipped
1667: addAttribute(doc, "skip-write", "yes", rootElement);
1668: // process the mapper objects
1669: processModelObjects(mapper.getAllMappedObjects(),
1670: rootElement, doc);
1671: }
1672: // #############################################################################################
1673:
1674: boolean isOpsFound = loadOperations(doc, rootElement, mep);
1675: //put the result in the property map
1676: infoHolder.put(mep, isOpsFound ? Boolean.TRUE : Boolean.FALSE);
1677: //create the databinder element with serverside as true
1678: rootElement.appendChild(createDOMElementforDatabinders(doc,
1679: true));
1680:
1681: //attach a list of faults
1682: rootElement.appendChild(getUniqueListofFaultsofMep(doc, mep));
1683:
1684: doc.appendChild(rootElement);
1685:
1686: //////////////////////////////////////////////////////////
1687: // System.out.println(DOM2Writer.nodeToString(rootElement));
1688: ////////////////////////////////////////////////////////////
1689:
1690: return doc;
1691: }
1692:
1693: /**
1694: * create a dom element for databinders. This is called by other
1695: *
1696: * @param doc
1697: */
1698: protected Element createDOMElementforDatabinders(Document doc,
1699: boolean isServerside) {
1700:
1701: // First Iterate through the operations and find the relevant fromOM and toOM methods to be generated
1702: ArrayList parameters = new ArrayList();
1703:
1704: for (Iterator operationsIterator = axisService.getOperations(); operationsIterator
1705: .hasNext();) {
1706: AxisOperation axisOperation = (AxisOperation) operationsIterator
1707: .next();
1708:
1709: // Add the parameters to a map with their type as the key
1710: // this step is needed to remove repetitions
1711:
1712: // process the input parameters
1713: String MEP = axisOperation.getMessageExchangePattern();
1714: if (WSDLUtil.isInputPresentForMEP(MEP)) {
1715: Element[] inputParamElement = getInputParamElement(doc,
1716: axisOperation);
1717: for (int i = 0; i < inputParamElement.length; i++) {
1718: //add an attribute to the parameter saying that this is an
1719: //input
1720: addAttribute(doc, "direction", "in",
1721: inputParamElement[i]);
1722: //add the short type name
1723: parameters.add(inputParamElement[i]);
1724:
1725: }
1726: }
1727: // process output parameters
1728: if (WSDLUtil.isOutputPresentForMEP(MEP)) {
1729: Element outputParamElement = getOutputParamElement(doc,
1730: axisOperation);
1731: if (outputParamElement != null) {
1732: //set the direction as out
1733: addAttribute(doc, "direction", "out",
1734: outputParamElement);
1735: parameters.add(outputParamElement);
1736: }
1737: }
1738:
1739: //process faults
1740: Element[] faultParamElements = getFaultParamElements(doc,
1741: axisOperation);
1742: for (int i = 0; i < faultParamElements.length; i++) {
1743: //set the direction as out - all faults are out messages ?
1744: addAttribute(doc, "direction", "out",
1745: faultParamElements[i]);
1746: parameters.add(faultParamElements[i]);
1747: }
1748:
1749: // process the header parameters
1750: Element newChild;
1751: List headerParameterQNameList = new ArrayList();
1752: addHeaderOperations(headerParameterQNameList,
1753: axisOperation, true);
1754: List parameterElementList = getParameterElementList(doc,
1755: headerParameterQNameList, WSDLConstants.SOAP_HEADER);
1756:
1757: for (int i = 0; i < parameterElementList.size(); i++) {
1758: newChild = (Element) parameterElementList.get(i);
1759: parameters.add(newChild);
1760: }
1761:
1762: headerParameterQNameList.clear();
1763: parameterElementList.clear();
1764: addHeaderOperations(headerParameterQNameList,
1765: axisOperation, false);
1766: parameterElementList = getParameterElementList(doc,
1767: headerParameterQNameList, WSDLConstants.SOAP_HEADER);
1768:
1769: for (int i = 0; i < parameterElementList.size(); i++) {
1770: newChild = (Element) parameterElementList.get(i);
1771: parameters.add(newChild);
1772: }
1773: }
1774:
1775: Element rootElement = doc.createElement("databinders");
1776: //add the db type attribute - the name of the databinding type
1777: //this will be used to select the correct template
1778: addAttribute(doc, "dbtype", codeGenConfiguration
1779: .getDatabindingType(), rootElement);
1780: //add the wrapped flag state - this is used by JiBX, but may be useful
1781: //for other frameworks in the future
1782: String wrapflag = Boolean.toString(codeGenConfiguration
1783: .isParametersWrapped());
1784: addAttribute(doc, "wrapped", wrapflag, rootElement);
1785:
1786: //at this point we may need to capture the extra parameters passes to the
1787: //particular databinding framework
1788: //these parameters showup in the property map with String keys, and we
1789: //can just copy these items as attributes of the <extra> element.
1790: Element extraElement = addElement(doc, "extra", null,
1791: rootElement);
1792: Map propertiesMap = codeGenConfiguration.getProperties();
1793: for (Iterator it = propertiesMap.keySet().iterator(); it
1794: .hasNext();) {
1795: Object key = it.next();
1796: if (key instanceof String) {
1797: Object value = propertiesMap.get(key);
1798: //if the value is null set it to empty string
1799: if (value == null)
1800: value = "";
1801: //add key="value" attribute to element iff value a string
1802: if (value instanceof String) {
1803: addAttribute(doc, (String) key, (String) value,
1804: extraElement);
1805: }
1806: }
1807: }
1808:
1809: //add the server side attribute. this helps the databinding template
1810: //to determine the methods to generate
1811: if (isServerside) {
1812: addAttribute(doc, "isserverside", "yes", rootElement);
1813: }
1814: // add the names of the elements that have base 64 content
1815: // if the base64 name list is missing then this whole step is skipped
1816: rootElement.appendChild(getBase64Elements(doc));
1817:
1818: //add the method names
1819: rootElement.appendChild(getOpNames(doc));
1820:
1821: for (Iterator iterator = parameters.iterator(); iterator
1822: .hasNext();) {
1823: rootElement.appendChild((Element) iterator.next());
1824: }
1825:
1826: // finish with any extra information from service and operations
1827: Parameter details = axisService
1828: .getParameter(Constants.DATABINDING_SERVICE_DETAILS);
1829: if (details != null) {
1830: Object value = details.getValue();
1831: if (value instanceof Element) {
1832: rootElement.appendChild(doc.importNode((Element) value,
1833: true));
1834: } else if (value instanceof List) {
1835: for (Iterator iter = ((List) value).iterator(); iter
1836: .hasNext();) {
1837: rootElement.appendChild(doc.importNode(
1838: (Element) iter.next(), true));
1839: }
1840: }
1841: }
1842:
1843: for (Iterator operationsIterator = axisService.getOperations(); operationsIterator
1844: .hasNext();) {
1845: AxisOperation axisOperation = (AxisOperation) operationsIterator
1846: .next();
1847: details = axisOperation
1848: .getParameter(Constants.DATABINDING_OPERATION_DETAILS);
1849: if (details != null) {
1850: rootElement.appendChild(doc.importNode(
1851: (Element) details.getValue(), true));
1852: }
1853: }
1854:
1855: ///////////////////////////////////////////////
1856: // System.out.println("databinding root element " + DOM2Writer.nodeToString(rootElement));
1857: ////////////////////////////////////////////////
1858:
1859: return rootElement;
1860: }
1861:
1862: /**
1863: * set the short type as it is in the data binding
1864: *
1865: * @param paramElement
1866: * @param xmlName
1867: */
1868:
1869: protected void addShortType(Element paramElement, String xmlName) {
1870:
1871: if (xmlName != null) {
1872: String javaName;
1873: if (JavaUtils.isJavaKeyword(xmlName)) {
1874: javaName = JavaUtils.makeNonJavaKeyword(xmlName);
1875: } else {
1876: javaName = JavaUtils.capitalizeFirstChar(JavaUtils
1877: .xmlNameToJava(xmlName));
1878: }
1879: addAttribute(paramElement.getOwnerDocument(), "shorttype",
1880: javaName, paramElement);
1881: } else {
1882: addAttribute(paramElement.getOwnerDocument(), "shorttype",
1883: "", paramElement);
1884: }
1885: }
1886:
1887: /**
1888: * Gets an element representing the operation names
1889: *
1890: * @param doc
1891: * @return Returns Element.
1892: */
1893: protected Element getOpNames(Document doc) {
1894: Element root = doc.createElement("opnames");
1895: Element elt;
1896:
1897: for (Iterator operationsIterator = axisService.getOperations(); operationsIterator
1898: .hasNext();) {
1899: AxisOperation axisOperation = (AxisOperation) operationsIterator
1900: .next();
1901: elt = doc.createElement("name");
1902: elt.appendChild(doc.createTextNode(axisOperation.getName()
1903: .getLocalPart()));
1904:
1905: //what needs to be put here as the opertation namespace is actually the
1906: //traget namespace of the service
1907: addAttribute(doc, "opnsuri", axisService
1908: .getTargetNamespace(), elt);
1909: root.appendChild(elt);
1910: }
1911:
1912: return root;
1913: }
1914:
1915: /**
1916: * Gets the base64 types. If not available this will be empty!!!
1917: *
1918: * @param doc
1919: * @return Returns Element.
1920: */
1921: protected Element getBase64Elements(Document doc) {
1922: Element root = doc.createElement("base64Elements");
1923: Element elt;
1924: QName qname;
1925:
1926: // this is a list of QNames
1927: List list = (List) codeGenConfiguration.getProperties().get(
1928: Constants.BASE_64_PROPERTY_KEY);
1929:
1930: if ((list != null) && !list.isEmpty()) {
1931: int count = list.size();
1932:
1933: for (int i = 0; i < count; i++) {
1934: qname = (QName) list.get(i);
1935: elt = doc.createElement("name");
1936: addAttribute(doc, "ns-url", qname.getNamespaceURI(),
1937: elt);
1938: addAttribute(doc, "localName", qname.getLocalPart(),
1939: elt);
1940: root.appendChild(elt);
1941: }
1942: }
1943:
1944: return root;
1945: }
1946:
1947: /**
1948: * @param objectMappings
1949: * @param root
1950: * @param doc
1951: */
1952: protected void processModelObjects(Map objectMappings,
1953: Element root, Document doc) {
1954: Iterator objectIterator = objectMappings.values().iterator();
1955:
1956: while (objectIterator.hasNext()) {
1957: Object o = objectIterator.next();
1958:
1959: if (o instanceof Document) {
1960: //we cannot have an empty document
1961: root.appendChild(doc.importNode(((Document) o)
1962: .getDocumentElement(), true));
1963: } else {
1964:
1965: // oops we have no idea how to do this, if the model provided is not a DOM document
1966: // we are done. we might as well skip it here
1967: }
1968: }
1969: }
1970:
1971: /**
1972: * we need to modify the mapper's class name list. The issue here is that in this case we do not
1973: * expect the fully qulified class names to be present in the class names list due to the simple
1974: * reason that they've not been written yet! Hence the mappers class name list needs to be
1975: * updated to suit the expected package to be written in this case we modify the package name to
1976: * have the class a inner class of the stub, interface or the message receiver depending on the
1977: * style
1978: */
1979: protected void updateMapperClassnames(
1980: String fullyQulifiedIncludingClassNamePrefix) {
1981: Map classNameMap = mapper.getAllMappedNames();
1982: Iterator keys = classNameMap.keySet().iterator();
1983:
1984: while (keys.hasNext()) {
1985: Object key = keys.next();
1986: String className = (String) classNameMap.get(key);
1987:
1988: String realClassName = className;
1989: if (className.endsWith("[]")) {
1990: realClassName = realClassName.substring(0,
1991: realClassName.indexOf("[]"));
1992: }
1993: //this is a generated class name - update the name
1994: if (!TypeTesterUtil.hasPackage(realClassName)
1995: && !TypeTesterUtil.isPrimitive(realClassName)) {
1996: classNameMap.put(key,
1997: fullyQulifiedIncludingClassNamePrefix + "."
1998: + className);
1999: instantiatableMessageClassNames.put(key,
2000: fullyQulifiedIncludingClassNamePrefix + "$"
2001: + className);
2002: } else {
2003: //this is a fully qualified class name - just leave it as it is
2004: classNameMap.put(key, className);
2005: instantiatableMessageClassNames.put(key, className);
2006: }
2007: }
2008: }
2009:
2010: /**
2011: * Write the service XML
2012: *
2013: * @throws Exception
2014: */
2015: protected void writeServiceXml() throws Exception {
2016:
2017: // Write the service xml in a folder with the
2018: Document serviceXMLModel = createDOMDocumentForServiceXML();
2019: debugLogDocument("Document for service XML:", serviceXMLModel);
2020: FileWriter serviceXmlWriter = new ServiceXMLWriter(
2021: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
2022: codeGenConfiguration.getOutputLocation(), null)
2023: : getOutputDirectory(codeGenConfiguration
2024: .getOutputLocation(),
2025: codeGenConfiguration
2026: .getResourceLocation()),
2027: this .codeGenConfiguration.getOutputLanguage());
2028: serviceXmlWriter.setOverride(codeGenConfiguration.isOverride());
2029: writeFile(serviceXMLModel, serviceXmlWriter);
2030: codeGenConfiguration.addXmlFileName(serviceXmlWriter
2031: .getOutputFile().getAbsolutePath());
2032:
2033: }
2034:
2035: protected Document createDOMDocumentForServiceXML() {
2036: Document doc = getEmptyDocument();
2037: String className = null;
2038: String serviceName = null;
2039:
2040: Element rootElement = doc.createElement("interfaces");
2041: doc.appendChild(rootElement);
2042:
2043: for (Iterator iter = this .axisServices.iterator(); iter
2044: .hasNext();) {
2045: this .axisService = (AxisService) iter.next();
2046: this .axisBinding = axisService.getEndpoint(
2047: axisService.getEndpointName()).getBinding();
2048: serviceName = axisService.getName();
2049: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
2050: className = makeJavaClassName(axisService
2051: .getBindingName());
2052: } else {
2053: className = makeJavaClassName(serviceName);
2054: }
2055:
2056: rootElement.appendChild(getServiceElement(serviceName,
2057: className, doc));
2058: }
2059:
2060: return doc;
2061: }
2062:
2063: /**
2064: * A resusable method to return the service element for creating the service xml
2065: *
2066: * @param serviceName
2067: * @param className
2068: * @param doc
2069: * @return DOM Element
2070: */
2071: protected Element getServiceElement(String serviceName,
2072: String className, Document doc) {
2073:
2074: if (allServiceInfoHolder.get(serviceName) != null) {
2075: this .infoHolder = (Map) allServiceInfoHolder
2076: .get(serviceName);
2077: }
2078: Element rootElement = doc.createElement("interface");
2079:
2080: addAttribute(doc, "package", "", rootElement);
2081: addAttribute(doc, "classpackage", codeGenConfiguration
2082: .getPackageName(), rootElement);
2083: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
2084: addAttribute(doc, "name", className
2085: + SKELETON_CLASS_SUFFIX_BACK, rootElement);
2086: } else {
2087: addAttribute(doc, "name",
2088: className + SKELETON_CLASS_SUFFIX, rootElement);
2089: }
2090:
2091: if (!codeGenConfiguration.isWriteTestCase()) {
2092: addAttribute(doc, "testOmit", "true", rootElement);
2093: }
2094: addAttribute(doc, "servicename", serviceName, rootElement);
2095:
2096: Iterator it = mepToClassMap.keySet().iterator();
2097: while (it.hasNext()) {
2098: Object key = it.next();
2099:
2100: if (Boolean.TRUE.equals(infoHolder.get(key))) {
2101: Element elt = addElement(doc, "messagereceiver",
2102: makeJavaClassName(serviceName)
2103: + mepToSuffixMap.get(key), rootElement);
2104: addAttribute(doc, "mepURI", key.toString(), elt);
2105: }
2106:
2107: }
2108:
2109: loadOperations(doc, rootElement, null);
2110:
2111: return rootElement;
2112: }
2113:
2114: protected void writeSkeleton() throws Exception {
2115: Document skeletonModel = createDOMDocumentForSkeleton(codeGenConfiguration
2116: .isServerSideInterface());
2117: debugLogDocument("Document for skeleton:", skeletonModel);
2118: FileWriter skeletonWriter = new SkeletonWriter(
2119: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
2120: codeGenConfiguration.getOutputLocation(), null)
2121: : getOutputDirectory(codeGenConfiguration
2122: .getOutputLocation(),
2123: codeGenConfiguration
2124: .getSourceLocation()),
2125: this .codeGenConfiguration.getOutputLanguage());
2126: skeletonWriter.setOverride(codeGenConfiguration.isOverride());
2127: writeFile(skeletonModel, skeletonWriter);
2128: }
2129:
2130: /**
2131: * Write the skeletonInterface
2132: *
2133: * @throws Exception
2134: */
2135: protected void writeSkeletonInterface() throws Exception {
2136: Document skeletonModel = createDOMDocumentForSkeletonInterface();
2137: debugLogDocument("Document for skeleton Interface:",
2138: skeletonModel);
2139: FileWriter skeletonInterfaceWriter = new SkeletonInterfaceWriter(
2140: codeGenConfiguration.isFlattenFiles() ? getOutputDirectory(
2141: codeGenConfiguration.getOutputLocation(), null)
2142: : getOutputDirectory(codeGenConfiguration
2143: .getOutputLocation(),
2144: codeGenConfiguration
2145: .getSourceLocation()),
2146: this .codeGenConfiguration.getOutputLanguage());
2147: skeletonInterfaceWriter.setOverride(codeGenConfiguration
2148: .isOverride());
2149: writeFile(skeletonModel, skeletonInterfaceWriter);
2150: }
2151:
2152: /**
2153: * Creates the XMLModel for the skeleton
2154: *
2155: * @param isSkeletonInterface
2156: * @return DOM Document
2157: */
2158: protected Document createDOMDocumentForSkeleton(
2159: boolean isSkeletonInterface) {
2160: Document doc = getEmptyDocument();
2161: Element rootElement = doc.createElement("interface");
2162:
2163: String serviceName = makeJavaClassName(axisService.getName());
2164: addAttribute(doc, "package", codeGenConfiguration
2165: .getPackageName(), rootElement);
2166: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
2167: addAttribute(doc, "name", makeJavaClassName(axisService
2168: .getBindingName())
2169: + SKELETON_CLASS_SUFFIX_BACK, rootElement);
2170: } else {
2171: addAttribute(doc, "name", serviceName
2172: + SKELETON_CLASS_SUFFIX, rootElement);
2173: }
2174: addAttribute(doc, "callbackname", serviceName
2175: + CALL_BACK_HANDLER_SUFFIX, rootElement);
2176: //add backwordcompatibility attribute
2177: addAttribute(doc, "isbackcompatible", String
2178: .valueOf(codeGenConfiguration
2179: .isBackwordCompatibilityMode()), rootElement);
2180: if (isSkeletonInterface) {
2181: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
2182: addAttribute(
2183: doc,
2184: "skeletonInterfaceName",
2185: makeJavaClassName(axisService.getEndpointName())
2186: + SKELETON_INTERFACE_SUFFIX_BACK,
2187: rootElement);
2188: } else {
2189: addAttribute(doc, "skeletonInterfaceName", serviceName
2190: + SKELETON_INTERFACE_SUFFIX, rootElement);
2191: }
2192:
2193: }
2194: fillSyncAttributes(doc, rootElement);
2195: loadOperations(doc, rootElement, null);
2196:
2197: //attach a list of faults
2198: rootElement.appendChild(getUniqueListofFaults(doc));
2199:
2200: doc.appendChild(rootElement);
2201:
2202: //////////////////////////////////////////////////////////
2203: // System.out.println(DOM2Writer.nodeToString(rootElement));
2204: ////////////////////////////////////////////////////////////
2205: return doc;
2206:
2207: }
2208:
2209: /**
2210: * Creates the XML model for the skeleton interface
2211: *
2212: * @return DOM Document
2213: */
2214: protected Document createDOMDocumentForSkeletonInterface() {
2215: Document doc = getEmptyDocument();
2216: Element rootElement = doc.createElement("interface");
2217:
2218: String serviceName = makeJavaClassName(axisService.getName());
2219: addAttribute(doc, "package", codeGenConfiguration
2220: .getPackageName(), rootElement);
2221: if (this .codeGenConfiguration.isBackwordCompatibilityMode()) {
2222: addAttribute(doc, "name", makeJavaClassName(axisService
2223: .getEndpointName())
2224: + SKELETON_INTERFACE_SUFFIX_BACK, rootElement);
2225: } else {
2226: addAttribute(doc, "name", serviceName
2227: + SKELETON_INTERFACE_SUFFIX, rootElement);
2228: }
2229:
2230: addAttribute(doc, "callbackname", serviceName
2231: + CALL_BACK_HANDLER_SUFFIX, rootElement);
2232:
2233: //add backwordcompatibility attribute
2234: addAttribute(doc, "isbackcompatible", String
2235: .valueOf(codeGenConfiguration
2236: .isBackwordCompatibilityMode()), rootElement);
2237:
2238: fillSyncAttributes(doc, rootElement);
2239: loadOperations(doc, rootElement, null);
2240:
2241: //attach a list of faults
2242: rootElement.appendChild(getUniqueListofFaults(doc));
2243:
2244: doc.appendChild(rootElement);
2245: //////////////////////////////////////////////////////////
2246: // System.out.println(DOM2Writer.nodeToString(rootElement));
2247: ////////////////////////////////////////////////////////////
2248: return doc;
2249:
2250: }
2251:
2252: /**
2253: * Loads the operations
2254: *
2255: * @param doc
2256: * @param rootElement
2257: * @param mep
2258: * @return boolean
2259: */
2260: protected boolean loadOperations(Document doc, Element rootElement,
2261: String mep) {
2262: Element methodElement;
2263: String serviceName = makeJavaClassName(axisService.getName());
2264:
2265: Iterator operationNames = axisService.getOperationsNameList()
2266: .iterator();
2267: boolean opsFound = false;
2268: QName operationName;
2269: while (operationNames.hasNext()) {
2270: operationName = (QName) operationNames.next();
2271: AxisOperation axisOperation = axisService
2272: .getOperation(operationName);
2273:
2274: // populate info holder with mep information. This will used in determining which
2275: // message receiver to use, etc.,
2276:
2277: String messageExchangePattern = axisOperation
2278: .getMessageExchangePattern();
2279: if (infoHolder.get(messageExchangePattern) == null) {
2280: infoHolder.put(messageExchangePattern, Boolean.TRUE);
2281: }
2282:
2283: if (mep == null) {
2284: opsFound = true;
2285: methodElement = generateMethodElement(doc, serviceName,
2286: axisOperation);
2287: rootElement.appendChild(methodElement);
2288:
2289: } else {
2290: //mep is present - we move ahead only if the given mep matches the mep of this operation
2291:
2292: if (mep.equals(axisOperation
2293: .getMessageExchangePattern())) {
2294: //at this point we know it's true
2295: opsFound = true;
2296: methodElement = generateMethodElement(doc,
2297: serviceName, axisOperation);
2298: rootElement.appendChild(methodElement);
2299: //////////////////////
2300: }
2301: }
2302:
2303: }
2304:
2305: return opsFound;
2306: }
2307:
2308: /**
2309: * Common code to generate a <method> element from an operation.
2310: *
2311: * @param doc
2312: * @param endpointName
2313: * @param axisOperation
2314: * @return generated element
2315: * @throws DOMException
2316: */
2317: private Element generateMethodElement(Document doc,
2318: String endpointName, AxisOperation axisOperation)
2319: throws DOMException {
2320: Element methodElement;
2321: List soapHeaderInputParameterList = new ArrayList();
2322: List soapHeaderOutputParameterList = new ArrayList();
2323: methodElement = doc.createElement("method");
2324: String localPart = axisOperation.getName().getLocalPart();
2325:
2326: addAttribute(doc, "name", JavaUtils.xmlNameToJava(localPart),
2327: methodElement);
2328: addAttribute(doc, "namespace", axisOperation.getName()
2329: .getNamespaceURI(), methodElement);
2330: addAttribute(doc, "style",
2331: (String) getBindingPropertyFromOperation(
2332: WSDLConstants.WSDL_1_1_STYLE, axisOperation
2333: .getName()), methodElement);
2334: addAttribute(doc, "dbsupportname", endpointName + localPart
2335: + DATABINDING_SUPPORTER_NAME_SUFFIX, methodElement);
2336: String messageExchangePattern = axisOperation
2337: .getMessageExchangePattern();
2338: addAttribute(doc, "mep", Utils
2339: .getAxisSpecifMEPConstant(messageExchangePattern)
2340: + "", methodElement);
2341: addAttribute(doc, "mepURI", messageExchangePattern,
2342: methodElement);
2343: Parameter wsdl2StyleParameter = axisOperation
2344: .getParameter(WSDL2Constants.OPERATION_STYLE);
2345: if (wsdl2StyleParameter != null) {
2346: // provide WSDL2 styles to allow templates to take advantage of them, if desired
2347: addAttribute(doc, "wsdl2Styles",
2348: arrayToString((URI[]) wsdl2StyleParameter
2349: .getValue()), methodElement);
2350: }
2351:
2352: // check for this operation to be handled directly by databinding code generation
2353: Parameter dbmethname = axisOperation
2354: .getParameter(Constants.DATABINDING_GENERATED_RECEIVER);
2355: if (dbmethname != null) {
2356: addAttribute(doc, "usedbmethod", (String) dbmethname
2357: .getValue(), methodElement);
2358: }
2359: Parameter dbgenimpl = axisOperation
2360: .getParameter(Constants.DATABINDING_GENERATED_IMPLEMENTATION);
2361: if (dbgenimpl != null
2362: && Boolean.TRUE.equals(dbgenimpl.getValue())) {
2363: addAttribute(doc, "usdbimpl", "true", methodElement);
2364: } else {
2365: addAttribute(doc, "usdbimpl", "false", methodElement);
2366: }
2367:
2368: addSOAPAction(doc, methodElement, axisOperation.getName());
2369: addOutputAndFaultActions(doc, methodElement, axisOperation);
2370: addHeaderOperations(soapHeaderInputParameterList,
2371: axisOperation, true);
2372: // addHeaderOperations(soapHeaderOutputParameterList, axisOperation, false);
2373:
2374: if (WSDLUtil.isInputPresentForMEP(messageExchangePattern)) {
2375: methodElement.appendChild(getInputElement(doc,
2376: axisOperation, soapHeaderInputParameterList));
2377: }
2378: if (WSDLUtil.isOutputPresentForMEP(messageExchangePattern)) {
2379: methodElement.appendChild(getOutputElement(doc,
2380: axisOperation, soapHeaderOutputParameterList));
2381: }
2382: methodElement.appendChild(getFaultElement(doc, axisOperation));
2383:
2384: setTransferCoding(axisOperation, methodElement, doc);
2385:
2386: String property = (String) getBindingPropertyFromOperation(
2387: WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,
2388: axisOperation.getName());
2389: if (property != null) {
2390: methodElement
2391: .appendChild(generateOptionParamComponent(
2392: doc,
2393: "org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR",
2394: "\"" + property + "\""));
2395: }
2396:
2397: property = (String) getBindingPropertyFromOperation(
2398: WSDL2Constants.ATTR_WHTTP_LOCATION, axisOperation
2399: .getName());
2400: if (property != null) {
2401: methodElement
2402: .appendChild(generateOptionParamComponent(
2403: doc,
2404: "org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_LOCATION",
2405: "\"" + property + "\""));
2406: }
2407:
2408: String mep = (String) getBindingPropertyFromOperation(
2409: WSDL2Constants.ATTR_WSOAP_MEP, axisOperation.getName());
2410:
2411: String bindingType = null;
2412: if (axisBinding != null) {
2413: bindingType = axisBinding.getType();
2414: }
2415:
2416: if (WSDL2Constants.URI_WSOAP_MEP.equalsIgnoreCase(mep)) {
2417: methodElement
2418: .appendChild(generateOptionParamComponent(
2419: doc,
2420: "org.apache.axis2.Constants.Configuration.ENABLE_REST",
2421: "true"));
2422: methodElement
2423: .appendChild(generateOptionParamComponent(
2424: doc,
2425: "org.apache.axis2.Constants.Configuration.HTTP_METHOD",
2426: "\""
2427: + org.apache.axis2.Constants.Configuration.HTTP_METHOD_GET
2428: + "\""));
2429: methodElement
2430: .appendChild(generateOptionParamComponent(
2431: doc,
2432: "org.apache.axis2.Constants.Configuration.CONTENT_TYPE",
2433: "\""
2434: + org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_X_WWW_FORM
2435: + "\""));
2436: methodElement
2437: .appendChild(generateOptionParamComponent(
2438: doc,
2439: "org.apache.axis2.Constants.Configuration.MESSAGE_TYPE",
2440: "\""
2441: + org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_X_WWW_FORM
2442: + "\""));
2443: methodElement
2444: .appendChild(generateOptionParamComponent(
2445: doc,
2446: "org.apache.axis2.Constants.Configuration.SOAP_RESPONSE_MEP",
2447: "true"));
2448: } else if (bindingType != null
2449: && bindingType.equals(WSDL2Constants.URI_WSDL2_HTTP)) {
2450:
2451: methodElement
2452: .appendChild(generateOptionParamComponent(
2453: doc,
2454: "org.apache.axis2.Constants.Configuration.ENABLE_REST",
2455: "true"));
2456:
2457: property = (String) getBindingPropertyFromOperation(
2458: WSDL2Constants.ATTR_WHTTP_METHOD, axisOperation
2459: .getName());
2460: if (property != null) {
2461: methodElement
2462: .appendChild(generateOptionParamComponent(
2463: doc,
2464: "org.apache.axis2.Constants.Configuration.HTTP_METHOD",
2465: "\"" + property + "\""));
2466: } else if (!WSDL2Constants.URI_WSOAP_MEP
2467: .equalsIgnoreCase(mep)) {
2468: // If there is no WHTTP_METHOD defined then we better compute the default value which is get if the operation
2469: // is wsdlx:safe or post otherwise
2470: Parameter safe = axisOperation
2471: .getParameter(WSDL2Constants.ATTR_WSDLX_SAFE);
2472: if (safe != null) {
2473: if (((Boolean) safe.getValue()).booleanValue()) {
2474: methodElement
2475: .appendChild(generateOptionParamComponent(
2476: doc,
2477: "org.apache.axis2.Constants.Configuration.HTTP_METHOD",
2478: "\""
2479: + org.apache.axis2.Constants.Configuration.HTTP_METHOD_GET
2480: + "\""));
2481: } else {
2482: methodElement
2483: .appendChild(generateOptionParamComponent(
2484: doc,
2485: "org.apache.axis2.Constants.Configuration.HTTP_METHOD",
2486: "\""
2487: + org.apache.axis2.Constants.Configuration.HTTP_METHOD_POST
2488: + "\""));
2489: }
2490: }
2491: }
2492:
2493: Boolean value = (Boolean) getBindingPropertyFromOperation(
2494: WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED,
2495: axisOperation.getName());
2496: if (value != null) {
2497: methodElement
2498: .appendChild(generateOptionParamComponent(
2499: doc,
2500: "org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED",
2501: "\"" + value.booleanValue() + "\""));
2502: }
2503:
2504: property = (String) getBindingPropertyFromOperation(
2505: WSDL2Constants.ATTR_WHTTP_CODE, axisOperation
2506: .getName());
2507: if (property != null) {
2508: methodElement
2509: .appendChild(generateOptionParamComponent(
2510: doc,
2511: "org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_CODE",
2512: "\"" + property + "\""));
2513: }
2514:
2515: property = (String) getBindingPropertyFromOperation(
2516: WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION,
2517: axisOperation.getName());
2518: if (property != null) {
2519: methodElement
2520: .appendChild(generateOptionParamComponent(
2521: doc,
2522: "org.apache.axis2.Constants.Configuration.CONTENT_TYPE",
2523: "\"" + property + "\""));
2524: methodElement
2525: .appendChild(generateOptionParamComponent(
2526: doc,
2527: "org.apache.axis2.Constants.Configuration.MESSAGE_TYPE",
2528: "\"" + property + "\""));
2529: }
2530:
2531: }
2532: return methodElement;
2533: }
2534:
2535: /**
2536: * Returns a comma-separated list of the string representations of the array elements.
2537: * @param array the array to be processed
2538: * @return the empty string "" if array is null or empty, the array element if size is 1,
2539: * or a comma-separated list when size > 1.
2540: */
2541: private String arrayToString(Object[] array) {
2542: if (array == null || array.length == 0) {
2543: return "";
2544: }
2545: int size = array.length;
2546: if (size == 1) {
2547: return String.valueOf(array[0]);
2548: }
2549: StringBuffer result = new StringBuffer(String.valueOf(array[0]));
2550: for (int i = 1; i < size; i++) {
2551: result.append(",");
2552: result.append(String.valueOf(array[i]));
2553: }
2554: return result.toString();
2555: }
2556:
2557: /**
2558: * Set the transfer coding property of the input message
2559: *
2560: * @param axisOperation
2561: * @param methodElement
2562: * @param doc
2563: */
2564: private void setTransferCoding(AxisOperation axisOperation,
2565: Element methodElement, Document doc) {
2566: // Add a optionParam element which holds the value of transferCoding
2567: String transferCoding = (String) getBindingPropertyFromMessage(
2568: WSDL2Constants.ATTR_WHTTP_CONTENT_ENCODING,
2569: axisOperation.getName(),
2570: WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
2571: if (!"".equals(transferCoding)) {
2572: if ("gzip".equals(transferCoding)
2573: || "compress".equals(transferCoding)) {
2574: methodElement
2575: .appendChild(generateOptionParamComponent(
2576: doc,
2577: "org.apache.axis2.transport.http.HTTPConstants.MC_GZIP_REQUEST",
2578: "true"));
2579: }
2580: }
2581: }
2582:
2583: /**
2584: * Set thttp header properties needed for the stub
2585: *
2586: * @param axisOperation
2587: * @param methodElement
2588: * @param doc
2589: */
2590: private void setHttpHeaderOptions(AxisOperation axisOperation,
2591: Element methodElement, Document doc) {
2592: // Add a optionParam elements here
2593:
2594: }
2595:
2596: // ==================================================================
2597: // Util Methods
2598: // ==================================================================
2599:
2600: protected Document getEmptyDocument() {
2601: try {
2602: DocumentBuilder documentBuilder = DocumentBuilderFactory
2603: .newInstance().newDocumentBuilder();
2604: return documentBuilder.newDocument();
2605: } catch (ParserConfigurationException e) {
2606: throw new RuntimeException(e);
2607: }
2608: }
2609:
2610: /**
2611: * @param word
2612: * @return Returns character removed string.
2613: */
2614: protected String makeJavaClassName(String word) {
2615: if (JavaUtils.isJavaKeyword(word)) {
2616: return JavaUtils.makeNonJavaKeyword(word);
2617: } else {
2618: return JavaUtils.capitalizeFirstChar(JavaUtils
2619: .xmlNameToJava(word));
2620: }
2621: }
2622:
2623: /**
2624: * Utility method to add an attribute to a given element.
2625: *
2626: * @param document
2627: * @param AttribName
2628: * @param attribValue
2629: * @param element
2630: */
2631: protected void addAttribute(Document document, String AttribName,
2632: String attribValue, Element element) {
2633: XSLTUtils.addAttribute(document, AttribName, attribValue,
2634: element);
2635: }
2636:
2637: /**
2638: * @param doc
2639: * @param rootElement
2640: */
2641: protected void fillSyncAttributes(Document doc, Element rootElement) {
2642: addAttribute(doc, "isAsync", this .codeGenConfiguration
2643: .isAsyncOn() ? "1" : "0", rootElement);
2644: addAttribute(doc, "isSync", this .codeGenConfiguration
2645: .isSyncOn() ? "1" : "0", rootElement);
2646: }
2647:
2648: /**
2649: * debugging method - write the output to the debugger
2650: *
2651: * @param description
2652: * @param doc
2653: */
2654: protected void debugLogDocument(String description, Document doc) {
2655: if (log.isDebugEnabled()) {
2656: try {
2657: DOMSource source = new DOMSource(doc);
2658: StringWriter swrite = new StringWriter();
2659: swrite.write(description);
2660: swrite.write("\n");
2661: Transformer transformer = TransformerFactory
2662: .newInstance().newTransformer();
2663: transformer.setOutputProperty("omit-xml-declaration",
2664: "yes");
2665: transformer.setOutputProperty(OutputKeys.INDENT, "yes");
2666: transformer.transform(source, new StreamResult(swrite));
2667:
2668: log.debug(swrite.toString());
2669:
2670: } catch (Exception e) {
2671: e.printStackTrace();
2672: }
2673: }
2674: }
2675:
2676: /**
2677: * Gets the output directory for source files.
2678: *
2679: * @param outputDir
2680: * @return Returns File.
2681: */
2682: protected File getOutputDirectory(File outputDir, String dir2) {
2683: if (dir2 != null && !"".equals(dir2)) {
2684: outputDir = new File(outputDir, dir2);
2685: }
2686:
2687: if (!outputDir.exists()) {
2688: outputDir.mkdirs();
2689: }
2690:
2691: return outputDir;
2692: }
2693:
2694: /**
2695: * A resusable method for the implementation of interface and implementation writing.
2696: *
2697: * @param model
2698: * @param writer
2699: * @throws java.io.IOException
2700: * @throws Exception
2701: */
2702: protected void writeFile(Document model, FileWriter writer)
2703: throws IOException, Exception {
2704: writer.loadTemplate();
2705:
2706: String packageName = model.getDocumentElement().getAttribute(
2707: "package");
2708: String className = model.getDocumentElement().getAttribute(
2709: "name");
2710:
2711: writer.createOutFile(packageName, className);
2712:
2713: // use the global resolver
2714: writer.parse(model, resolver);
2715: }
2716:
2717: /**
2718: * Adds the soap action
2719: *
2720: * @param doc
2721: * @param rootElement
2722: * @param qName
2723: */
2724: protected void addSOAPAction(Document doc, Element rootElement,
2725: QName qName) {
2726: addAttribute(doc, "soapaction",
2727: (String) getBindingPropertyFromOperation(
2728: WSDL2Constants.ATTR_WSOAP_ACTION, qName),
2729: rootElement);
2730: }
2731:
2732: /**
2733: * Adds the output and fault actions
2734: *
2735: * @param doc
2736: * @param methodElement
2737: * @param operation
2738: */
2739: private void addOutputAndFaultActions(Document doc,
2740: Element methodElement, AxisOperation operation) {
2741: String outputAction = operation.getOutputAction();
2742: if (outputAction != null) {
2743: Element outputActionElt = doc
2744: .createElement(org.apache.axis2.Constants.OUTPUT_ACTION_MAPPING);
2745: outputActionElt.setAttribute(
2746: AddressingConstants.WSA_ACTION, outputAction);
2747: methodElement.appendChild(outputActionElt);
2748: }
2749:
2750: String[] faultActionNames = operation.getFaultActionNames();
2751: if (faultActionNames != null) {
2752: for (int i = 0; i < faultActionNames.length; i++) {
2753: Element faultActionElt = doc
2754: .createElement(org.apache.axis2.Constants.FAULT_ACTION_MAPPING);
2755: faultActionElt.setAttribute(
2756: org.apache.axis2.Constants.FAULT_ACTION_NAME,
2757: faultActionNames[i]);
2758: faultActionElt.setAttribute(
2759: AddressingConstants.WSA_ACTION, operation
2760: .getFaultAction(faultActionNames[i]));
2761: methodElement.appendChild(faultActionElt);
2762: }
2763: }
2764: }
2765:
2766: /**
2767: * populate the header parameters
2768: *
2769: * @param soapHeaderParameterQNameList
2770: * @param axisOperation
2771: * @param input
2772: */
2773: protected void addHeaderOperations(
2774: List soapHeaderParameterQNameList,
2775: AxisOperation axisOperation, boolean input) {
2776: ArrayList headerparamList = new ArrayList();
2777: String MEP = axisOperation.getMessageExchangePattern();
2778: if (input) {
2779: if (WSDLUtil.isInputPresentForMEP(MEP)) {
2780:
2781: headerparamList = (ArrayList) getBindingPropertyFromMessage(
2782: WSDL2Constants.ATTR_WSOAP_HEADER, axisOperation
2783: .getName(),
2784: WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
2785:
2786: }
2787: } else {
2788: if (WSDLUtil.isOutputPresentForMEP(MEP)) {
2789: headerparamList = (ArrayList) getBindingPropertyFromMessage(
2790: WSDL2Constants.ATTR_WSOAP_HEADER, axisOperation
2791: .getName(),
2792: WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
2793: }
2794: }
2795: if (headerparamList != null) {
2796: for (Iterator iterator = headerparamList.iterator(); iterator
2797: .hasNext();) {
2798: SOAPHeaderMessage header = (SOAPHeaderMessage) iterator
2799: .next();
2800: soapHeaderParameterQNameList.add(header);
2801: }
2802: }
2803:
2804: }
2805:
2806: /**
2807: * populate the header parameters to faults
2808: *
2809: * @param soapHeaderParameterQNameList
2810: * @param axisOperation
2811: */
2812: protected void addHeaderOperationsToFault(
2813: List soapHeaderParameterQNameList,
2814: AxisOperation axisOperation) {
2815: ArrayList headerparamList = new ArrayList();
2816: ArrayList faultMessages = axisOperation.getFaultMessages();
2817: Iterator iter = faultMessages.iterator();
2818: while (iter.hasNext()) {
2819: AxisMessage axisFaultMessage = (AxisMessage) iter.next();
2820: headerparamList
2821: .addAll((ArrayList) getBindingPropertyFromMessageFault(
2822: WSDL2Constants.ATTR_WSOAP_HEADER,
2823: axisOperation.getName(), axisFaultMessage
2824: .getName()));
2825: }
2826:
2827: if (headerparamList != null) {
2828: for (Iterator iterator = headerparamList.iterator(); iterator
2829: .hasNext();) {
2830: SOAPHeaderMessage header = (SOAPHeaderMessage) iterator
2831: .next();
2832: soapHeaderParameterQNameList.add(header.getElement());
2833: }
2834: }
2835: }
2836:
2837: /**
2838: * Get the input element
2839: *
2840: * @param doc
2841: * @param operation
2842: * @param headerParameterQNameList
2843: * @return DOM element
2844: */
2845: protected Element getInputElement(Document doc,
2846: AxisOperation operation, List headerParameterQNameList) {
2847: Element inputElt = doc.createElement("input");
2848: String mep = operation.getMessageExchangePattern();
2849:
2850: if (WSDLUtil.isInputPresentForMEP(mep)) {
2851:
2852: Element[] param = getInputParamElement(doc, operation);
2853: for (int i = 0; i < param.length; i++) {
2854: inputElt.appendChild(param[i]);
2855: }
2856:
2857: List parameterElementList = getParameterElementList(doc,
2858: headerParameterQNameList, WSDLConstants.SOAP_HEADER);
2859: parameterElementList
2860: .addAll(getParameterElementListForHttpHeader(
2861: doc,
2862: (ArrayList) getBindingPropertyFromMessage(
2863: WSDL2Constants.ATTR_WHTTP_HEADER,
2864: operation.getName(),
2865: WSDLConstants.WSDL_MESSAGE_DIRECTION_IN),
2866: WSDLConstants.HTTP_HEADER));
2867: parameterElementList
2868: .addAll(getParameterElementListForSOAPModules(
2869: doc,
2870: (ArrayList) getBindingPropertyFromMessage(
2871: WSDL2Constants.ATTR_WSOAP_MODULE,
2872: operation.getName(),
2873: WSDLConstants.WSDL_MESSAGE_DIRECTION_IN)));
2874:
2875: for (int i = 0; i < parameterElementList.size(); i++) {
2876: inputElt.appendChild((Element) parameterElementList
2877: .get(i));
2878: }
2879:
2880: /*
2881: * Setting the effective policy of input message
2882: */
2883: Policy policy = getBindingPolicyFromMessage(operation
2884: .getName(), WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
2885:
2886: if (policy != null) {
2887: try {
2888: addAttribute(doc, "policy", PolicyUtil
2889: .getSafeString(PolicyUtil
2890: .policyComponentToString(policy)),
2891: inputElt);
2892: } catch (Exception ex) {
2893: throw new RuntimeException(
2894: "can't serialize the policy ..");
2895: }
2896: }
2897:
2898: }
2899: return inputElt;
2900: }
2901:
2902: /**
2903: * Get the fault element - No header faults are supported
2904: *
2905: * @param doc
2906: * @param operation
2907: */
2908: protected Element getFaultElement(Document doc,
2909: AxisOperation operation) {
2910: Element faultElt = doc.createElement("fault");
2911: Element[] param = getFaultParamElements(doc, operation);
2912:
2913: for (int i = 0; i < param.length; i++) {
2914: faultElt.appendChild(param[i]);
2915: }
2916:
2917: return faultElt;
2918: }
2919:
2920: /**
2921: * Finds the output element.
2922: *
2923: * @param doc
2924: * @param operation
2925: * @param headerParameterQNameList
2926: */
2927: protected Element getOutputElement(Document doc,
2928: AxisOperation operation, List headerParameterQNameList) {
2929: Element outputElt = doc.createElement("output");
2930: String mep = operation.getMessageExchangePattern();
2931:
2932: if (WSDLUtil.isOutputPresentForMEP(mep)) {
2933:
2934: Element param = getOutputParamElement(doc, operation);
2935:
2936: if (param != null) {
2937: outputElt.appendChild(param);
2938: }
2939:
2940: List outputElementList = getParameterElementList(doc,
2941: headerParameterQNameList, WSDLConstants.SOAP_HEADER);
2942: outputElementList
2943: .addAll(getParameterElementListForHttpHeader(
2944: doc,
2945: (ArrayList) getBindingPropertyFromMessage(
2946: WSDL2Constants.ATTR_WHTTP_HEADER,
2947: operation.getName(),
2948: WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT),
2949: WSDLConstants.HTTP_HEADER));
2950:
2951: for (int i = 0; i < outputElementList.size(); i++) {
2952: outputElt.appendChild((Element) outputElementList
2953: .get(i));
2954: }
2955:
2956: /*
2957: * Setting the effective policy for the output message.
2958: */
2959: Policy policy = getBindingPolicyFromMessage(operation
2960: .getName(),
2961: WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
2962:
2963: if (policy != null) {
2964: try {
2965: addAttribute(doc, "policy", PolicyUtil
2966: .getSafeString(PolicyUtil
2967: .policyComponentToString(policy)),
2968: outputElt);
2969: } catch (Exception ex) {
2970: throw new RuntimeException(
2971: "can't serialize the policy ..");
2972: }
2973: }
2974: }
2975: return outputElt;
2976: }
2977:
2978: /**
2979: * @param doc
2980: * @param operation
2981: * @return Returns the parameter element.
2982: */
2983: protected Element[] getFaultParamElements(Document doc,
2984: AxisOperation operation) {
2985: ArrayList params = new ArrayList();
2986: ArrayList faultMessages = operation.getFaultMessages();
2987:
2988: if (faultMessages != null && !faultMessages.isEmpty()) {
2989: Element paramElement;
2990: AxisMessage msg;
2991: for (int i = 0; i < faultMessages.size(); i++) {
2992: paramElement = doc.createElement("param");
2993: msg = (AxisMessage) faultMessages.get(i);
2994:
2995: if (msg.getElementQName() == null) {
2996: throw new RuntimeException(
2997: "Element QName is null for "
2998: + msg.getName() + "!");
2999: }
3000:
3001: //as for the name of a fault, we generate an exception
3002: addAttribute(doc, "name",
3003: (String) fullyQualifiedFaultClassNameMap
3004: .get(msg.getName()), paramElement);
3005: addAttribute(doc, "shortName",
3006: (String) faultClassNameMap.get(msg.getName()),
3007: paramElement);
3008:
3009: // attach the namespace and the localName
3010: addAttribute(doc, "namespace", msg.getElementQName()
3011: .getNamespaceURI(), paramElement);
3012: addAttribute(doc, "localname", msg.getElementQName()
3013: .getLocalPart(), paramElement);
3014: //the type represents the type that will be wrapped by this
3015: //name
3016: String typeMapping = this .mapper.getTypeMappingName(msg
3017: .getElementQName());
3018: addAttribute(doc, "type", (typeMapping == null) ? ""
3019: : typeMapping, paramElement);
3020:
3021: //add the short name
3022: addShortType(paramElement,
3023: (msg.getElementQName() == null) ? null : msg
3024: .getElementQName().getLocalPart());
3025:
3026: String attribValue = (String) instantiatableMessageClassNames
3027: .get(msg.getElementQName());
3028: addAttribute(doc, "instantiatableType",
3029: attribValue == null ? "" : attribValue,
3030: paramElement);
3031:
3032: // add an extra attribute to say whether the type mapping is
3033: // the default
3034: if (mapper.getDefaultMappingName().equals(typeMapping)) {
3035: addAttribute(doc, "default", "yes", paramElement);
3036: }
3037: addAttribute(doc, "value",
3038: getParamInitializer(typeMapping), paramElement);
3039:
3040: Iterator iter = msg.getExtensibilityAttributes()
3041: .iterator();
3042: while (iter.hasNext()) {
3043: // process extensibility attributes
3044: }
3045: params.add(paramElement);
3046: }
3047:
3048: return (Element[]) params
3049: .toArray(new Element[params.size()]);
3050: } else {
3051: return new Element[] {};//return empty array
3052: }
3053:
3054: }
3055:
3056: /**
3057: * @param doc
3058: * @param operation
3059: * @return Returns the parameter element.
3060: */
3061: protected Element[] getInputParamElement(Document doc,
3062: AxisOperation operation) {
3063:
3064: AxisMessage inputMessage = operation
3065: .getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
3066: List paramElementList = new ArrayList();
3067: if (inputMessage != null) {
3068:
3069: // This is the wrapped component - add the type mapping
3070: Element mainParameter = generateParamComponent(doc,
3071: this .mapper.getParameterName(inputMessage
3072: .getElementQName()), this .mapper
3073: .getTypeMappingName(inputMessage
3074: .getElementQName()), operation
3075: .getName(), inputMessage.getElementQName());
3076:
3077: paramElementList.add(mainParameter);
3078:
3079: //if the unwrapping or backWordCompatibility flag is on then we have to
3080: //put the element complex type if it exits
3081: if (this .codeGenConfiguration.isBackwordCompatibilityMode()
3082: || !this .codeGenConfiguration.isParametersWrapped()) {
3083: if (inputMessage.getParameter(Constants.COMPLEX_TYPE) != null) {
3084: Parameter parameter = inputMessage
3085: .getParameter(Constants.COMPLEX_TYPE);
3086: addAttribute(doc, "complextype", (String) parameter
3087: .getValue(), mainParameter);
3088: }
3089: }
3090:
3091: // this message has been unwrapped - find the correct references of the
3092: // the message by looking at the unwrapped details object and attach the
3093: // needed parameters inside main parameter element
3094: if (inputMessage.getParameter(Constants.UNWRAPPED_KEY) != null) {
3095:
3096: //we have this unwrapped earlier. get the info holder
3097: //and then look at the parameters
3098: Parameter detailsParameter = inputMessage
3099: .getParameter(Constants.UNWRAPPED_DETAILS);
3100: MessagePartInformationHolder infoHolder = (MessagePartInformationHolder) detailsParameter
3101: .getValue();
3102: List partsList = infoHolder.getPartsList();
3103:
3104: //populate the parts list - this list is needed to generate multiple
3105: //parameters in the signatures
3106: for (int i = 0; i < partsList.size(); i++) {
3107: QName qName = (QName) partsList.get(i);
3108: mainParameter
3109: .appendChild(generateParamComponent(
3110: doc,
3111: this .mapper.getParameterName(qName),
3112: this .mapper
3113: .getTypeMappingName(qName),
3114: operation.getName(),
3115: qName,
3116: qName.getLocalPart(),
3117: (this .mapper
3118: .getTypeMappingStatus(qName) != null),
3119: Constants.ARRAY_TYPE
3120: .equals(this .mapper
3121: .getTypeMappingStatus(qName))));
3122: }
3123:
3124: }
3125:
3126: }
3127:
3128: return (Element[]) paramElementList
3129: .toArray(new Element[paramElementList.size()]);
3130: }
3131:
3132: /**
3133: * A convenient method for the generating the parameter element
3134: *
3135: * @param doc
3136: * @param paramName
3137: * @param paramType
3138: * @return DOM Element
3139: */
3140: protected Element generateParamComponent(Document doc,
3141: String paramName, String paramType, QName operationName,
3142: QName paramQName) {
3143: return generateParamComponent(doc, paramName, paramType,
3144: operationName, paramQName, null, false, false);
3145: }
3146:
3147: /**
3148: * A convenient method for the generating the parameter element
3149: *
3150: * @param doc
3151: * @param paramName
3152: * @param paramType
3153: * @return DOM Element
3154: */
3155: protected Element generateParamComponent(Document doc,
3156: String paramName, String paramType, QName paramQName) {
3157: return generateParamComponent(doc, paramName, paramType, null,
3158: paramQName, null, false, false);
3159: }
3160:
3161: /**
3162: * A convenient method for the generating optionParam components
3163: *
3164: * @param doc
3165: * @param name
3166: * @param value
3167: * @return Element
3168: */
3169: protected Element generateOptionParamComponent(Document doc,
3170: String name, String value) {
3171:
3172: Element optionParamElement = doc.createElement("optionParam");
3173: addAttribute(doc, "name", name, optionParamElement);
3174: addAttribute(doc, "value", value, optionParamElement);
3175: return optionParamElement;
3176: }
3177:
3178: /**
3179: * A convenient method for the generating the parameter element
3180: *
3181: * @param doc
3182: * @param paramName
3183: * @param paramType
3184: * @param opName
3185: * @param paramName
3186: */
3187: protected Element generateParamComponent(Document doc,
3188: String paramName, String paramType, QName opName,
3189: QName paramQName, String partName, boolean isPrimitive,
3190: boolean isArray) {
3191: Element paramElement = doc.createElement("param");
3192: addAttribute(doc, "name", paramName, paramElement);
3193:
3194: addAttribute(doc, "type", (paramType == null) ? "" : paramType,
3195: paramElement);
3196:
3197: //adds the short type
3198: addShortType(paramElement, (paramQName == null) ? null
3199: : paramQName.getLocalPart());
3200:
3201: // add an extra attribute to say whether the type mapping is the default
3202: if (mapper.getDefaultMappingName().equals(paramType)) {
3203: addAttribute(doc, "default", "yes", paramElement);
3204: }
3205: addAttribute(doc, "value", getParamInitializer(paramType),
3206: paramElement);
3207: // add this as a body parameter
3208: addAttribute(doc, "location", "body", paramElement);
3209:
3210: //if the opName and partName are present , add them
3211: if (opName != null) {
3212: addAttribute(doc, "opname", opName.getLocalPart(),
3213: paramElement);
3214: }
3215:
3216: if (paramQName != null) {
3217: Element qNameElement = doc.createElement("qname");
3218: addAttribute(doc, "nsuri", paramQName.getNamespaceURI(),
3219: qNameElement);
3220: addAttribute(doc, "localname", paramQName.getLocalPart(),
3221: qNameElement);
3222: paramElement.appendChild(qNameElement);
3223: }
3224: if (partName != null) {
3225: String javaName = null;
3226: if (JavaUtils.isJavaKeyword(partName)) {
3227: javaName = JavaUtils.makeNonJavaKeyword(partName);
3228: } else {
3229: javaName = JavaUtils.capitalizeFirstChar(JavaUtils
3230: .xmlNameToJava(partName));
3231: }
3232: addAttribute(doc, "partname", javaName, paramElement);
3233: }
3234:
3235: if (isPrimitive) {
3236: addAttribute(doc, "primitive", "yes", paramElement);
3237: }
3238:
3239: if (isArray) {
3240: addAttribute(doc, "array", "yes", paramElement);
3241: }
3242:
3243: return paramElement;
3244: }
3245:
3246: /**
3247: * @param doc
3248: * @param operation
3249: * @return Returns Element.
3250: */
3251: protected Element getOutputParamElement(Document doc,
3252: AxisOperation operation) {
3253: Element paramElement = doc.createElement("param");
3254: AxisMessage outputMessage = operation
3255: .getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
3256: String typeMappingStr;
3257: String parameterName;
3258:
3259: if (outputMessage != null) {
3260: parameterName = this .mapper.getParameterName(outputMessage
3261: .getElementQName());
3262: String typeMapping = this .mapper
3263: .getTypeMappingName(outputMessage.getElementQName());
3264: typeMappingStr = (typeMapping == null) ? "" : typeMapping;
3265: } else {
3266: parameterName = "";
3267: typeMappingStr = "";
3268: }
3269:
3270: addAttribute(doc, "name", parameterName, paramElement);
3271: addAttribute(doc, "type", typeMappingStr, paramElement);
3272:
3273: //adds the short type
3274: addShortType(paramElement,
3275: (outputMessage.getElementQName() == null) ? null
3276: : outputMessage.getElementQName()
3277: .getLocalPart());
3278:
3279: // add an extra attribute to say whether the type mapping is the default
3280: if (mapper.getDefaultMappingName().equals(typeMappingStr)) {
3281: addAttribute(doc, "default", "yes", paramElement);
3282: }
3283:
3284: // add this as a body parameter
3285: addAttribute(doc, "location", "body", paramElement);
3286: addAttribute(doc, "opname", operation.getName().getLocalPart(),
3287: paramElement);
3288:
3289: //if the unwrapping or backWordCompatibility flag is on then we have to
3290: //put the element complex type if it exits
3291: if (this .codeGenConfiguration.isBackwordCompatibilityMode()
3292: || !this .codeGenConfiguration.isParametersWrapped()) {
3293: if (outputMessage.getParameter(Constants.COMPLEX_TYPE) != null) {
3294: Parameter parameter = outputMessage
3295: .getParameter(Constants.COMPLEX_TYPE);
3296: addAttribute(doc, "complextype", (String) parameter
3297: .getValue(), paramElement);
3298: }
3299: }
3300:
3301: // this message has been unwrapped - find the correct references of the
3302: // the message by looking at the unwrapped details object and attach the
3303: // needed parameters inside main parameter element
3304: if (outputMessage.getParameter(Constants.UNWRAPPED_KEY) != null) {
3305:
3306: //we have this unwrapped earlier. get the info holder
3307: //and then look at the parameters
3308: Parameter detailsParameter = outputMessage
3309: .getParameter(Constants.UNWRAPPED_DETAILS);
3310: MessagePartInformationHolder infoHolder = (MessagePartInformationHolder) detailsParameter
3311: .getValue();
3312: List partsList = infoHolder.getPartsList();
3313:
3314: //populate the parts list - this list is needed to generate multiple
3315: //parameters in the signatures
3316: // in out put params we only intersted if there is only one parameter
3317: // otherwise we can not unwrap it.
3318: if (partsList.size() == 1) {
3319: QName qName = (QName) partsList.get(0);
3320: paramElement.appendChild(generateParamComponent(doc,
3321: this .mapper.getParameterName(qName),
3322: this .mapper.getTypeMappingName(qName),
3323: operation.getName(), qName, qName
3324: .getLocalPart(), (this .mapper
3325: .getTypeMappingStatus(qName) != null),
3326: Constants.ARRAY_TYPE.equals(this .mapper
3327: .getTypeMappingStatus(qName))));
3328: }
3329:
3330: }
3331:
3332: QName paramQName = outputMessage.getElementQName();
3333: if (paramQName != null) {
3334: Element qNameElement = doc.createElement("qname");
3335: addAttribute(doc, "nsuri", paramQName.getNamespaceURI(),
3336: qNameElement);
3337: addAttribute(doc, "localname", paramQName.getLocalPart(),
3338: qNameElement);
3339: paramElement.appendChild(qNameElement);
3340: }
3341:
3342: return paramElement;
3343: }
3344:
3345: /**
3346: * @param paramType
3347: */
3348: protected String getParamInitializer(String paramType) {
3349:
3350: // Look up paramType in the table
3351: String out = (String) constructorMap.get(paramType);
3352:
3353: if (out == null) {
3354: out = "null";
3355: }
3356:
3357: return out;
3358: }
3359:
3360: /**
3361: * @param doc
3362: * @param parameters
3363: * @param location
3364: */
3365: protected List getParameterElementList(Document doc,
3366: List parameters, String location) {
3367: List parameterElementList = new ArrayList();
3368:
3369: if ((parameters != null) && !parameters.isEmpty()) {
3370: int count = parameters.size();
3371:
3372: for (int i = 0; i < count; i++) {
3373: Element param = doc.createElement("param");
3374: SOAPHeaderMessage header = (SOAPHeaderMessage) parameters
3375: .get(i);
3376: QName name = header.getElement();
3377:
3378: addAttribute(doc, "name", this .mapper
3379: .getParameterName(name), param);
3380:
3381: String typeMapping = this .mapper
3382: .getTypeMappingName(name);
3383: String typeMappingStr = (typeMapping == null) ? ""
3384: : typeMapping;
3385:
3386: addAttribute(doc, "type", typeMappingStr, param);
3387: addAttribute(doc, "location", location, param);
3388: if (header.isMustUnderstand()) {
3389: addAttribute(doc, "mustUnderstand", "true", param);
3390: }
3391: parameterElementList.add(param);
3392: }
3393: }
3394:
3395: return parameterElementList;
3396: }
3397:
3398: protected List getParameterElementListForHttpHeader(Document doc,
3399: List parameters, String location) {
3400:
3401: List parameterElementList = new ArrayList();
3402:
3403: if ((parameters != null) && !parameters.isEmpty()) {
3404: int count = parameters.size();
3405:
3406: for (int i = 0; i < count; i++) {
3407: Element param = doc.createElement("param");
3408: HTTPHeaderMessage httpHeaderMessage = (HTTPHeaderMessage) parameters
3409: .get(i);
3410: QName qName = httpHeaderMessage.getqName();
3411: String name = httpHeaderMessage.getName();
3412:
3413: // use name as the name attribute of the parameter
3414: addAttribute(doc, "name", JavaUtils
3415: .xmlNameToJavaIdentifier(name), param);
3416: // header name is to set the header value
3417: addAttribute(doc, "headername", name, param);
3418:
3419: String typeMapping = this .mapper
3420: .getTypeMappingName(qName);
3421: String typeMappingStr = (typeMapping == null) ? ""
3422: : typeMapping;
3423:
3424: addAttribute(doc, "type", typeMappingStr, param);
3425: addAttribute(doc, "location", location, param);
3426: parameterElementList.add(param);
3427: }
3428: }
3429:
3430: return parameterElementList;
3431: }
3432:
3433: protected List getParameterElementListForSOAPModules(Document doc,
3434: List parameters) {
3435:
3436: List parameterElementList = new ArrayList();
3437:
3438: if ((parameters != null) && !parameters.isEmpty()) {
3439: int count = parameters.size();
3440:
3441: for (int i = 0; i < count; i++) {
3442: Element param = doc.createElement("param");
3443: SOAPModuleMessage soapModuleMessage = (SOAPModuleMessage) parameters
3444: .get(i);
3445:
3446: // header name is to set the header value
3447: addAttribute(doc, "uri", soapModuleMessage.getUri(),
3448: param);
3449:
3450: addAttribute(doc, "location", "wsoap_module", param);
3451: parameterElementList.add(param);
3452: }
3453: }
3454:
3455: return parameterElementList;
3456: }
3457:
3458: /**
3459: * Utility method to add an attribute to a given element.
3460: *
3461: * @param document
3462: * @param eltName
3463: * @param eltValue
3464: * @param element
3465: */
3466: protected Element addElement(Document document, String eltName,
3467: String eltValue, Element element) {
3468: Element elt = XSLTUtils.addChildElement(document, eltName,
3469: element);
3470: if (eltValue != null) {
3471: elt.appendChild(document.createTextNode(eltValue));
3472: }
3473: return elt;
3474: }
3475:
3476: }
|