You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ews-dev@ws.apache.org by gu...@apache.org on 2005/08/08 14:28:41 UTC
svn commit: r230790 [4/9] - in /webservices/ews/trunk/mapper: ./ src/
src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/ws/
src/java/org/apache/ws/ews/ src/java/org/apache/ws/ews/context/
src/java/org/apache/ws/ews/context/webservices/ s...
Added: webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeStubWriter.java
URL: http://svn.apache.org/viewcvs/webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeStubWriter.java?rev=230790&view=auto
==============================================================================
--- webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeStubWriter.java (added)
+++ webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeStubWriter.java Mon Aug 8 05:28:03 2005
@@ -0,0 +1,894 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.ews.mapper;
+
+import org.apache.axis.Constants;
+import org.apache.axis.constants.Style;
+import org.apache.axis.constants.Use;
+import org.apache.axis.utils.JavaUtils;
+import org.apache.axis.utils.Messages;
+import org.apache.axis.wsdl.symbolTable.BindingEntry;
+import org.apache.axis.wsdl.symbolTable.DefinedType;
+import org.apache.axis.wsdl.symbolTable.FaultInfo;
+import org.apache.axis.wsdl.symbolTable.MimeInfo;
+import org.apache.axis.wsdl.symbolTable.Parameter;
+import org.apache.axis.wsdl.symbolTable.Parameters;
+import org.apache.axis.wsdl.symbolTable.SymbolTable;
+import org.apache.axis.wsdl.symbolTable.TypeEntry;
+import org.apache.axis.wsdl.toJava.JavaClassWriter;
+import org.apache.axis.wsdl.toJava.Utils;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Fault;
+import javax.wsdl.Message;
+import javax.wsdl.Operation;
+import javax.wsdl.OperationType;
+import javax.wsdl.Part;
+import javax.wsdl.PortType;
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPBinding;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.xml.namespace.QName;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+/**
+ * This is Wsdl2java's stub writer. It writes the <BindingName>Stub.java
+ * file which contains the <bindingName>Stub class.
+ *
+ * @author Ias (iasandcb@tmax.co.kr)
+ */
+public class J2eeStubWriter extends JavaClassWriter {
+ private BindingEntry bEntry;
+ private Binding binding;
+ private SymbolTable symbolTable;
+
+ static String[] modeStrings = new String[]{"",
+ "org.apache.axis.description.ParameterDesc.IN",
+ "org.apache.axis.description.ParameterDesc.OUT",
+ "org.apache.axis.description.ParameterDesc.INOUT"};
+ static HashMap styles = new HashMap();
+ static HashMap uses = new HashMap();
+
+ static {
+ styles.put(Style.DOCUMENT, "org.apache.axis.constants.Style.DOCUMENT");
+ styles.put(Style.RPC, "org.apache.axis.constants.Style.RPC");
+ styles.put(Style.MESSAGE, "org.apache.axis.constants.Style.MESSAGE");
+ styles.put(Style.WRAPPED, "org.apache.axis.constants.Style.WRAPPED");
+ uses.put(Use.ENCODED, "org.apache.axis.constants.Use.ENCODED");
+ uses.put(Use.LITERAL, "org.apache.axis.constants.Use.LITERAL");
+ }
+
+ static int OPERDESC_PER_BLOCK = 10;
+
+ /**
+ * Constructor.
+ */
+ protected J2eeStubWriter(J2eeEmitter emitter,
+ BindingEntry bEntry,
+ SymbolTable symbolTable) {
+ super(emitter, bEntry.getName() + "Stub", "stub");
+ this.bEntry = bEntry;
+ this.binding = bEntry.getBinding();
+ this.symbolTable = symbolTable;
+ } // ctor
+
+ /**
+ * Returns "extends org.apache.axis.client.Stub ".
+ */
+ protected String getExtendsText() {
+ return "extends org.apache.axis.client.Stub ";
+ } // getExtendsText
+
+ /**
+ * Returns "implements <SEI> ".
+ */
+ protected String getImplementsText() {
+ return "implements " + bEntry.getDynamicVar(J2eeBindingWriter.INTERFACE_NAME) + " ";
+ } // getImplementsText
+
+ /**
+ * Write the body of the binding's stub file.
+ */
+ protected void writeFileBody(PrintWriter pw) throws IOException {
+ PortType portType = binding.getPortType();
+ HashSet types = getTypesInPortType(portType);
+ boolean hasMIME = Utils.hasMIME(bEntry);
+ if (types.size() > 0 || hasMIME) {
+ pw.println(" private java.util.Vector cachedSerClasses = new java.util.Vector();");
+ pw.println(" private java.util.Vector cachedSerQNames = new java.util.Vector();");
+ pw.println(" private java.util.Vector cachedSerFactories = new java.util.Vector();");
+ pw.println(" private java.util.Vector cachedDeserFactories = new java.util.Vector();");
+ }
+ pw.println();
+ pw.println(" static org.apache.axis.description.OperationDesc [] _operations;");
+ pw.println();
+ writeOperationMap(pw);
+ pw.println();
+ pw.println(" public " + className + "() throws org.apache.axis.AxisFault {");
+ pw.println(" this(null);");
+ pw.println(" }");
+ pw.println();
+ pw.println(" public " + className + "(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
+ pw.println(" this(service);");
+ pw.println(" super.cachedEndpoint = endpointURL;");
+ pw.println(" }");
+ pw.println();
+ pw.println(" public " + className + "(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {");
+ pw.println(" if (service == null) {");
+ pw.println(" super.service = new org.apache.axis.client.Service();");
+ pw.println(" } else {");
+ pw.println(" super.service = service;");
+ pw.println(" }");
+ pw
+ .println(" ((org.apache.axis.client.Service)super.service).setTypeMappingVersion(\""
+ + emitter.getTypeMappingVersion() + "\");");
+ List deferredBindings = new ArrayList();
+ // keep track of how many type mappings we write out
+ int typeMappingCount = 0;
+ if (types.size() > 0) {
+ Iterator it = types.iterator();
+ while (it.hasNext()) {
+ TypeEntry type = (TypeEntry) it.next();
+ // Note this same check is repeated in JavaDeployWriter.
+ if (!Utils.shouldEmit(type)) {
+ continue;
+ }
+
+ // Write out serializer declarations
+ if (typeMappingCount == 0) {
+ writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI());
+ }
+
+ // write the type mapping for this type
+ writeSerializationInit(pw, type);
+
+ // increase the number of type mappings count
+ typeMappingCount++;
+ }
+ }
+ // We need to write out the MIME mapping, even if we don't have
+ // any type mappings
+ if (typeMappingCount == 0 && hasMIME) {
+ writeSerializationDecls(pw, hasMIME, binding.getQName().getNamespaceURI());
+ typeMappingCount++;
+ }
+ pw.println(" }");
+ pw.println();
+ pw.println(" private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {");
+ pw.println(" try {");
+ pw.println(" org.apache.axis.client.Call _call =");
+ pw.println(" (org.apache.axis.client.Call) super.service.createCall();");
+ pw.println(" if (super.maintainSessionSet) {");
+ pw.println(" _call.setMaintainSession(super.maintainSession);");
+ pw.println(" }");
+ pw.println(" if (super.cachedUsername != null) {");
+ pw.println(" _call.setUsername(super.cachedUsername);");
+ pw.println(" }");
+ pw.println(" if (super.cachedPassword != null) {");
+ pw.println(" _call.setPassword(super.cachedPassword);");
+ pw.println(" }");
+ pw.println(" if (super.cachedEndpoint != null) {");
+ pw.println(" _call.setTargetEndpointAddress(super.cachedEndpoint);");
+ pw.println(" }");
+ pw.println(" if (super.cachedTimeout != null) {");
+ pw.println(" _call.setTimeout(super.cachedTimeout);");
+ pw.println(" }");
+ pw.println(" if (super.cachedPortName != null) {");
+ pw.println(" _call.setPortName(super.cachedPortName);");
+ pw.println(" }");
+ pw.println(" java.util.Enumeration keys = super.cachedProperties.keys();");
+ pw.println(" while (keys.hasMoreElements()) {");
+ pw.println(" java.lang.String key = (java.lang.String) keys.nextElement();");
+ pw.println(" _call.setProperty(key, super.cachedProperties.get(key));");
+ pw.println(" }");
+ if (typeMappingCount > 0) {
+ pw.println(" // " + Messages.getMessage("typeMap00"));
+ pw.println(" // " + Messages.getMessage("typeMap01"));
+ pw.println(" // " + Messages.getMessage("typeMap02"));
+ pw.println(" // " + Messages.getMessage("typeMap03"));
+ pw.println(" // " + Messages.getMessage("typeMap04"));
+ pw.println(" synchronized (this) {");
+ pw.println(" if (firstCall()) {");
+
+ // Hack alert - we need to establish the encoding style before we register type mappings due
+ // to the fact that TypeMappings key off of encoding style
+ pw.println(" // "
+ + Messages.getMessage("mustSetStyle"));
+ if (bEntry.hasLiteral()) {
+ pw.println(" _call.setEncodingStyle(null);");
+ } else {
+ Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();
+ while (iterator.hasNext()) {
+ Object obj = iterator.next();
+ if (obj instanceof SOAPBinding) {
+ pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
+ pw.println(" _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);");
+ } else if (obj instanceof UnknownExtensibilityElement) {
+ //TODO: After WSDL4J supports soap12, change this code
+ UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
+ QName name = unkElement.getElementType();
+ if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
+ name.getLocalPart().equals("binding")) {
+ pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
+ pw.println(" _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP12_ENC);");
+ }
+ }
+ }
+ }
+ pw.println(" for (int i = 0; i < cachedSerFactories.size(); ++i) {");
+ pw.println(" java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);");
+ pw.println(" javax.xml.namespace.QName qName =");
+ pw.println(" (javax.xml.namespace.QName) cachedSerQNames.get(i);");
+ pw.println(" java.lang.Class sf = (java.lang.Class)");
+ pw.println(" cachedSerFactories.get(i);");
+ pw.println(" java.lang.Class df = (java.lang.Class)");
+ pw.println(" cachedDeserFactories.get(i);");
+ pw.println(" _call.registerTypeMapping(cls, qName, sf, df, false);");
+ pw.println(" }");
+ pw.println(" }");
+ pw.println(" }");
+ }
+ pw.println(" return _call;");
+ pw.println(" }");
+ pw.println(" catch (java.lang.Throwable t) {");
+ pw.println(" throw new org.apache.axis.AxisFault(\""
+ + Messages.getMessage("badCall01") + "\", t);");
+ pw.println(" }");
+ pw.println(" }");
+ pw.println();
+ List operations = binding.getBindingOperations();
+ for (int i = 0; i < operations.size(); ++i) {
+ BindingOperation operation = (BindingOperation) operations.get(i);
+ Parameters parameters =
+ bEntry.getParameters(operation.getOperation());
+
+ // Get the soapAction from the <soap:operation>
+ String soapAction = "";
+ String opStyle = null;
+ Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator();
+ for (; operationExtensibilityIterator.hasNext();) {
+ Object obj = operationExtensibilityIterator.next();
+ if (obj instanceof SOAPOperation) {
+ soapAction = ((SOAPOperation) obj).getSoapActionURI();
+ opStyle = ((SOAPOperation) obj).getStyle();
+ break;
+ } else if (obj instanceof UnknownExtensibilityElement) {
+ //TODO: After WSDL4J supports soap12, change this code
+ UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
+ QName name = unkElement.getElementType();
+ if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
+ name.getLocalPart().equals("operation")) {
+ if (unkElement.getElement().getAttribute("soapAction") != null) {
+ soapAction = unkElement.getElement().getAttribute("soapAction");
+ }
+ opStyle = unkElement.getElement().getAttribute("style");
+ }
+ }
+ }
+ Operation ptOperation = operation.getOperation();
+ OperationType type = ptOperation.getStyle();
+
+ // These operation types are not supported. The signature
+ // will be a string stating that fact.
+ if (type == OperationType.NOTIFICATION
+ || type == OperationType.SOLICIT_RESPONSE) {
+ pw.println(parameters.signature);
+ pw.println();
+ } else {
+ writeOperation(pw, operation, parameters, soapAction, opStyle,
+ type == OperationType.ONE_WAY, i);
+ }
+ }
+ } // writeFileBody
+
+ private void writeOperationMap(PrintWriter pw) {
+ List operations = binding.getBindingOperations();
+ pw.println(" static {");
+ pw.println(" _operations = new org.apache.axis.description.OperationDesc[" +
+ operations.size() + "];");
+ for (int j = 0, k = 0; j < operations.size(); ++j) {
+ if ((j % OPERDESC_PER_BLOCK) == 0) {
+ k++;
+ pw.println(" _initOperationDesc" + k + "();");
+ }
+ }
+ for (int i = 0, k = 0; i < operations.size(); ++i) {
+ if ((i % OPERDESC_PER_BLOCK) == 0) {
+ k++;
+ pw.println(" }\n");
+ pw.println(" private static void _initOperationDesc" + k + "(){");
+ pw.println(" org.apache.axis.description.OperationDesc oper;");
+ }
+ BindingOperation operation = (BindingOperation) operations.get(i);
+ Parameters parameters =
+ bEntry.getParameters(operation.getOperation());
+
+ // Get the soapAction from the <soap:operation>
+ String opStyle = null;
+ Iterator operationExtensibilityIterator = operation.getExtensibilityElements().iterator();
+ for (; operationExtensibilityIterator.hasNext();) {
+ Object obj = operationExtensibilityIterator.next();
+ if (obj instanceof SOAPOperation) {
+ opStyle = ((SOAPOperation) obj).getStyle();
+ break;
+ } else if (obj instanceof UnknownExtensibilityElement) {
+ //TODO: After WSDL4J supports soap12, change this code
+ UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
+ QName name = unkElement.getElementType();
+ if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
+ name.getLocalPart().equals("operation")) {
+ opStyle = unkElement.getElement().getAttribute("style");
+ }
+ }
+ }
+ Operation ptOperation = operation.getOperation();
+ OperationType type = ptOperation.getStyle();
+
+ // These operation types are not supported. The signature
+ // will be a string stating that fact.
+ if (type == OperationType.NOTIFICATION
+ || type == OperationType.SOLICIT_RESPONSE) {
+ pw.println(parameters.signature);
+ pw.println();
+ }
+ String operName = operation.getName();
+ String indent = " ";
+ pw.println(indent + "oper = new org.apache.axis.description.OperationDesc();");
+ pw.println(indent + "oper.setName(\"" + operName + "\");");
+
+ // loop over paramters and set up in/out params
+ for (int j = 0; j < parameters.list.size(); ++j) {
+ Parameter p = (Parameter) parameters.list.get(j);
+
+ // Get the QName representing the parameter type
+ QName paramType = Utils.getXSIType(p);
+
+ // Set the javaType to the name of the type
+ String javaType = null;
+ if (p.getMIMEInfo() != null) {
+ MimeInfo mimeInfo = p.getMIMEInfo();
+ javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions() + ".class, ";
+ } else {
+ javaType = p.getType().getName();
+ if (javaType != null) {
+ javaType += ".class, ";
+ } else {
+ javaType = "null, ";
+ }
+ }
+
+ // Get the text representing newing a QName for the name and type
+ String paramNameText = Utils.getNewQName(p.getQName());
+ String paramTypeText = Utils.getNewQName(paramType);
+
+ // Generate the addParameter call with the
+ // name qname, typeQName, optional javaType, and mode
+ boolean isInHeader = p.isInHeader();
+ boolean isOutHeader = p.isOutHeader();
+ pw.println(" oper.addParameter(" + paramNameText
+ + ", " + paramTypeText + ", "
+ + javaType + modeStrings[p.getMode()]
+ + ", " + isInHeader + ", " + isOutHeader + ");");
+ }
+ // set output type
+ if (parameters.returnParam != null) {
+ // Get the QName for the return Type
+ QName returnType = Utils.getXSIType(parameters.returnParam);
+
+ // Get the javaType
+ String javaType = null;
+ if (parameters.returnParam.getMIMEInfo() != null) {
+ MimeInfo mimeInfo = parameters.returnParam.getMIMEInfo();
+ javaType = JavaUtils.mimeToJava(mimeInfo.getType()) + mimeInfo.getDimensions();
+ } else {
+ javaType = parameters.returnParam.getType().getName();
+ }
+ if (javaType == null) {
+ javaType = "";
+ } else {
+ javaType = javaType + ".class";
+ }
+ pw.println(" oper.setReturnType(" +
+ Utils.getNewQName(returnType) + ");");
+ pw.println(" oper.setReturnClass("
+ + javaType + ");");
+ QName returnQName = parameters.returnParam.getQName();
+ if (returnQName != null) {
+ pw.println(" oper.setReturnQName(" +
+ Utils.getNewQName(returnQName) + ");");
+ }
+ if (parameters.returnParam.isOutHeader()) {
+ pw.println(" oper.setReturnHeader(true);");
+ }
+ } else {
+ pw.println(" oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);");
+ }
+ boolean hasMIME = Utils.hasMIME(bEntry, operation);
+ Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
+ Use use = bEntry.getInputBodyType(operation.getOperation());
+ if (style == Style.DOCUMENT && symbolTable.isWrapped()) {
+ style = Style.WRAPPED;
+ }
+ if (!hasMIME) {
+ pw.println(" oper.setStyle(" + styles.get(style) + ");");
+ pw.println(" oper.setUse(" + uses.get(use) + ");");
+ }
+
+ // Register fault/exception information for this operation
+ writeFaultInfo(pw, operation);
+ pw.println(indent + "_operations[" + i + "] = oper;");
+ pw.println("");
+ }
+ pw.println(" }");
+ }
+
+ /**
+ * This method returns a set of all the TypeEntry in a given PortType.
+ * The elements of the returned HashSet are Types.
+ */
+ private HashSet getTypesInPortType(PortType portType) {
+ HashSet types = new HashSet();
+ HashSet firstPassTypes = new HashSet();
+
+ // Get all the types from all the operations
+ List operations = portType.getOperations();
+ for (int i = 0; i < operations.size(); ++i) {
+ Operation op = (Operation) operations.get(i);
+ firstPassTypes.addAll(getTypesInOperation(op));
+ }
+
+ // Add all the types nested and derived from the types
+ // in the first pass.
+ Iterator i = firstPassTypes.iterator();
+ while (i.hasNext()) {
+ TypeEntry type = (TypeEntry) i.next();
+ if (!types.contains(type)) {
+ types.add(type);
+ types.addAll(type.getNestedTypes(symbolTable, true));
+ }
+ }
+ if (emitter.isAllWanted()) {
+ HashMap rawSymbolTable = symbolTable.getHashMap();
+ for (Iterator j = rawSymbolTable.values().iterator(); j.hasNext();) {
+ Vector typeVector = (Vector) j.next();
+ for (Iterator k = typeVector.iterator(); k.hasNext();) {
+ Object symbol = k.next();
+ if (symbol instanceof DefinedType) {
+ TypeEntry type = (TypeEntry) symbol;
+ if (!types.contains(type)) {
+ types.add(type);
+ }
+ }
+ }
+ }
+ }
+ return types;
+ } // getTypesInPortType
+
+ /**
+ * This method returns a set of all the TypeEntry in a given Operation.
+ * The elements of the returned HashSet are TypeEntry.
+ */
+ private HashSet getTypesInOperation(Operation operation) {
+ HashSet types = new HashSet();
+ Vector v = new Vector();
+ Parameters params = bEntry.getParameters(operation);
+
+ // Loop over parameter types for this operation
+ for (int i = 0; i < params.list.size(); i++) {
+ Parameter p = (Parameter) params.list.get(i);
+ v.add(p.getType());
+ }
+
+ // Add the return type
+ if (params.returnParam != null)
+ v.add(params.returnParam.getType());
+
+ // Collect all the types in faults
+ Map faults = operation.getFaults();
+ if (faults != null) {
+ Iterator i = faults.values().iterator();
+ while (i.hasNext()) {
+ Fault f = (Fault) i.next();
+ partTypes(v,
+ f.getMessage().getOrderedParts(null));
+ }
+ }
+ // Put all these types into a set. This operation eliminates all duplicates.
+ for (int i = 0; i < v.size(); i++)
+ types.add(v.get(i));
+ return types;
+ } // getTypesInOperation
+
+ /**
+ * This method returns a vector of TypeEntry for the parts.
+ */
+ private void partTypes(Vector v, Collection parts) {
+ Iterator i = parts.iterator();
+ while (i.hasNext()) {
+ Part part = (Part) i.next();
+ QName qType = part.getTypeName();
+ if (qType != null) {
+ v.add(symbolTable.getType(qType));
+ } else {
+ qType = part.getElementName();
+ if (qType != null) {
+ v.add(symbolTable.getElement(qType));
+ }
+ }
+ } // while
+ } // partTypes
+
+ /**
+ * This function writes the regsiterFaultInfo API calls
+ */
+ private void writeFaultInfo(PrintWriter pw, BindingOperation bindOp) {
+ Map faultMap = bEntry.getFaults();
+ // Get the list of faults for this operation
+ ArrayList faults = (ArrayList) faultMap.get(bindOp);
+
+ // check for no faults
+ if (faults == null) {
+ return;
+ }
+ // For each fault, register its information
+ for (Iterator faultIt = faults.iterator(); faultIt.hasNext();) {
+ FaultInfo info = (FaultInfo) faultIt.next();
+ QName qname = info.getQName();
+ Message message = info.getMessage();
+
+ // if no parts in fault, skip it!
+ if (qname == null) {
+ continue;
+ }
+
+ // Get the Exception class name
+ String className = Utils.getFullExceptionName(message, symbolTable);
+
+ // output the registration API call
+ pw.println(" oper.addFault(new org.apache.axis.description.FaultDesc(");
+ pw.println(" " + Utils.getNewQName(qname) + ",");
+ pw.println(" \"" + className + "\",");
+ pw.println(" " + Utils.getNewQName(info.getXMLType()) + ", ");
+ pw.println(" " + Utils.isFaultComplex(message, symbolTable));
+ pw.println(" ));");
+ }
+ }
+
+ /**
+ * In the stub constructor, write the serializer code for the complex types.
+ */
+ private void writeSerializationDecls(PrintWriter pw, boolean hasMIME,
+ String namespace) {
+ pw.println(" java.lang.Class cls;");
+ pw.println(" javax.xml.namespace.QName qName;");
+ pw.println(" java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;");
+ pw.println(" java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;");
+ pw.println(" java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;");
+ pw.println(" java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;");
+ pw.println(" java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;");
+ pw.println(" java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;");
+ pw.println(" java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;");
+ pw.println(" java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;");
+ if (hasMIME) {
+ pw.println(" java.lang.Class mimesf = org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class;");
+ pw.println(" java.lang.Class mimedf = org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class;");
+ pw.println();
+ QName qname = new QName(namespace, "DataHandler");
+ pw.println(" qName = new javax.xml.namespace.QName(\""
+ + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart()
+ + "\");");
+ pw.println(" cachedSerQNames.add(qName);");
+ pw.println(" cls = javax.activation.DataHandler.class;");
+ pw.println(" cachedSerClasses.add(cls);");
+ pw.println(" cachedSerFactories.add(mimesf);");
+ pw.println(" cachedDeserFactories.add(mimedf);");
+ pw.println();
+ }
+ } // writeSerializationDecls
+
+ private void writeSerializationInit(PrintWriter pw, TypeEntry type) {
+ QName qname = type.getQName();
+ pw.println(" qName = new javax.xml.namespace.QName(\""
+ + qname.getNamespaceURI() + "\", \"" + qname.getLocalPart()
+ + "\");");
+ pw.println(" cachedSerQNames.add(qName);");
+ pw.println(" cls = " + type.getName() + ".class;");
+ pw.println(" cachedSerClasses.add(cls);");
+ if (type.getName().endsWith("[]")) {
+ pw.println(" cachedSerFactories.add(arraysf);");
+ pw.println(" cachedDeserFactories.add(arraydf);");
+ } else if (type.getNode() != null &&
+ Utils.getEnumerationBaseAndValues(type.getNode(), symbolTable) != null) {
+ pw.println(" cachedSerFactories.add(enumsf);");
+ pw.println(" cachedDeserFactories.add(enumdf);");
+ } else if (type.isSimpleType()) {
+ pw.println(" cachedSerFactories.add(simplesf);");
+ pw.println(" cachedDeserFactories.add(simpledf);");
+ } else if (type.getBaseType() != null) {
+ // serializers are not required for types derived from base types
+ // java type to qname mapping is anyway established by default
+ // note that we have to add null to the serfactories vector to
+ // keep the order of other entries, this is not going to screw
+ // up because if type mapping returns null for a serialization
+ // factory, it is assumed to be not-defined and the delegate
+ // will be checked, the end delegate is DefaultTypeMappingImpl
+ // that'll get it right with the base type name
+ pw.println(" cachedSerFactories.add(null);");
+ pw.println(" cachedDeserFactories.add(simpledf);");
+ } else {
+ pw.println(" cachedSerFactories.add(beansf);");
+ pw.println(" cachedDeserFactories.add(beandf);");
+ }
+ pw.println();
+ } // writeSerializationInit
+
+ /**
+ * Write the stub code for the given operation.
+ */
+ private void writeOperation(PrintWriter pw,
+ BindingOperation operation,
+ Parameters parms,
+ String soapAction,
+ String opStyle,
+ boolean oneway,
+ int opIndex) {
+ writeComment(pw, operation.getDocumentationElement(), true);
+ pw.println(parms.signature + " {");
+ pw.println(" if (super.cachedEndpoint == null) {");
+ pw.println(" throw new org.apache.axis.NoEndPointException();");
+ pw.println(" }");
+ pw.println(" org.apache.axis.client.Call _call = createCall();");
+ pw.println(" _call.setOperation(_operations[" + opIndex + "]);");
+
+ // SoapAction
+ if (soapAction != null) {
+ pw.println(" _call.setUseSOAPAction(true);");
+ pw.println(" _call.setSOAPActionURI(\"" + soapAction + "\");");
+ }
+ boolean hasMIME = Utils.hasMIME(bEntry, operation);
+
+ // Encoding: literal or encoded use.
+ Use use = bEntry.getInputBodyType(operation.getOperation());
+ if (use == Use.LITERAL) {
+ // Turn off encoding
+ pw.println(" _call.setEncodingStyle(null);");
+ // turn off XSI types
+ pw.println(" _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);");
+ }
+ if (hasMIME || use == Use.LITERAL) {
+ // If it is literal, turn off multirefs.
+ //
+ // If there are any MIME types, turn off multirefs.
+ // I don't know enough about the guts to know why
+ // attachments don't work with multirefs, but they don't.
+ pw.println(" _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);");
+ }
+ Style style = Style.getStyle(opStyle, bEntry.getBindingStyle());
+ if (style == Style.DOCUMENT && symbolTable.isWrapped()) {
+ style = Style.WRAPPED;
+ }
+ Iterator iterator = bEntry.getBinding().getExtensibilityElements().iterator();
+ while (iterator.hasNext()) {
+ Object obj = iterator.next();
+ if (obj instanceof SOAPBinding) {
+ pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);");
+ } else if (obj instanceof UnknownExtensibilityElement) {
+ //TODO: After WSDL4J supports soap12, change this code
+ UnknownExtensibilityElement unkElement = (UnknownExtensibilityElement) obj;
+ QName name = unkElement.getElementType();
+ if (name.getNamespaceURI().equals(Constants.URI_WSDL12_SOAP) &&
+ name.getLocalPart().equals("binding")) {
+ pw.println(" _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP12_CONSTANTS);");
+ }
+ }
+ }
+
+ // Operation name
+ if (style == Style.WRAPPED) {
+ // We need to make sure the operation name, which is what we
+ // wrap the elements in, matches the Qname of the parameter
+ // element.
+ Map partsMap = operation.getOperation().getInput().getMessage().getParts();
+ Part p = (Part) partsMap.values().iterator().next();
+ QName q = p.getElementName();
+ pw.println(" _call.setOperationName(" + Utils.getNewQName(q) + ");");
+ } else {
+ QName elementQName =
+ Utils.getOperationQName(operation, bEntry, symbolTable);
+ if (elementQName != null) {
+ pw.println(" _call.setOperationName(" +
+ Utils.getNewQName(elementQName) + ");");
+ }
+ }
+ pw.println();
+
+ // Set the headers
+ pw.println(" setRequestHeaders(_call);");
+
+ // Set the attachments
+ pw.println(" setAttachments(_call);");
+
+ // Set DIME flag if needed
+ if (bEntry.isOperationDIME(operation.getOperation().getName())) {
+ pw.println(" _call.setProperty(_call.ATTACHMENT_ENCAPSULATION_FORMAT, _call.ATTACHMENT_ENCAPSULATION_FORMAT_DIME);");
+ }
+
+ // Invoke the operation
+ if (oneway) {
+ pw.print(" _call.invokeOneWay(");
+ } else {
+ pw.print(" try {");
+ pw.print(" java.lang.Object _resp = _call.invoke(");
+ }
+ pw.print("new java.lang.Object[] {");
+ writeParameters(pw, parms);
+ pw.println("});");
+ pw.println();
+ if (!oneway) {
+ writeResponseHandling(pw, parms);
+ }
+ pw.println(" }");
+ pw.println();
+ } // writeOperation
+
+ private void writeParameters(PrintWriter pw, Parameters parms) {
+ // Write the input and inout parameter list
+ boolean needComma = false;
+ for (int i = 0; i < parms.list.size(); ++i) {
+ Parameter p = (Parameter) parms.list.get(i);
+ if (p.getMode() != Parameter.OUT) {
+ if (needComma) {
+ pw.print(", ");
+ } else {
+ needComma = true;
+ }
+ String javifiedName = Utils.xmlNameToJava(p.getName());
+ if (p.getMode() != Parameter.IN) {
+ javifiedName += ".value";
+ }
+ if (p.getMIMEInfo() == null) {
+ javifiedName = Utils.wrapPrimitiveType(p.getType(), javifiedName);
+ }
+ pw.print(javifiedName);
+ }
+ }
+ } // writeParamters
+
+ private void writeResponseHandling(PrintWriter pw, Parameters parms) {
+ pw.println(" if (_resp instanceof java.rmi.RemoteException) {");
+ pw.println(" throw (java.rmi.RemoteException)_resp;");
+ pw.println(" }");
+ int allOuts = parms.outputs + parms.inouts;
+ if (allOuts > 0) {
+ pw.println(" else {");
+ pw.println(" extractAttachments(_call);");
+ if (allOuts == 1) {
+ if (parms.returnParam != null) {
+ writeOutputAssign(pw, "return ", parms.returnParam, "_resp");
+ } else {
+ // The resp object must go into a holder
+ int i = 0;
+ Parameter p = (Parameter) parms.list.get(i);
+ while (p.getMode() == Parameter.IN) {
+ p = (Parameter) parms.list.get(++i);
+ }
+ String javifiedName = Utils.xmlNameToJava(p.getName());
+ String qnameName = Utils.getNewQName(p.getQName());
+ pw.println(" java.util.Map _output;");
+ pw.println(" _output = _call.getOutputParams();");
+ writeOutputAssign(pw, javifiedName + ".value = ",
+ p,
+ "_output.get(" + qnameName + ")");
+ }
+ } else {
+ // There is more than 1 output. Get the outputs from getOutputParams.
+ pw.println(" java.util.Map _output;");
+ pw.println(" _output = _call.getOutputParams();");
+ for (int i = 0; i < parms.list.size(); ++i) {
+ Parameter p = (Parameter) parms.list.get(i);
+ String javifiedName = Utils.xmlNameToJava(p.getName());
+ String qnameName = Utils.getNewQName(p.getQName());
+ if (p.getMode() != Parameter.IN) {
+ writeOutputAssign(pw, javifiedName + ".value = ",
+ p,
+ "_output.get(" + qnameName + ")");
+ }
+ }
+ if (parms.returnParam != null) {
+ writeOutputAssign(pw, "return ", parms.returnParam, "_resp");
+ }
+ }
+ pw.println(" }");
+ } else {
+ pw.println(" extractAttachments(_call);");
+ }
+ // End catch
+ // Get faults
+ Map faults = parms.faults;
+ // Get fauls of signature
+ String[] throwsSig = parms.signature.split("throws");
+ List exceptionsThrowsList = new ArrayList();
+ if (throwsSig != null && throwsSig.length > 1) {
+ String[] thrExcep = throwsSig[1].split(",");
+ for (int i = 0; i < thrExcep.length; i++) {
+ exceptionsThrowsList.add(thrExcep[i]);
+ }
+ }
+ pw
+ .println(" } catch (org.apache.axis.AxisFault axisFaultException) {");
+ if (faults != null && faults.size() > 0) {
+ pw.println(" if (axisFaultException.detail != null) {");
+ for (Iterator faultIt = exceptionsThrowsList.iterator(); faultIt
+ .hasNext();) {
+ String exceptionFullName = (String) faultIt.next();
+ pw.println(" if (axisFaultException.detail instanceof "
+ + exceptionFullName + ") {");
+ pw.println(" throw (" + exceptionFullName
+ + ") axisFaultException.detail;");
+ pw.println(" }");
+ }
+ pw.println(" }");
+ }
+ pw.println(" throw axisFaultException;");
+ pw.println("}");
+ } // writeResponseHandling
+
+ /**
+ * writeOutputAssign
+ *
+ * @param target (either "return" or "something ="
+ * @param type (source TypeEntry)
+ * @param source (source String)
+ */
+ private void writeOutputAssign(PrintWriter pw, String target,
+ Parameter param,
+ String source) {
+ TypeEntry type = param.getType();
+ if ((type != null) && (type.getName() != null)) {
+ String typeName = type.getName();
+ if (param.isOmittable()) {
+ typeName = Utils.getWrapperType(type.getName());
+ }
+
+ // Try casting the output to the expected output.
+ // If that fails, use JavaUtils.convert()
+ pw.println(" try {");
+ pw.println(" " + target
+ + Utils.getResponseString(param, source));
+ pw.println(" } catch (java.lang.Exception _exception) {");
+ pw.println(" " + target
+ + Utils.getResponseString(param,
+ "org.apache.axis.utils.JavaUtils.convert(" +
+ source + ", " + typeName + ".class)"));
+ pw.println(" }");
+ } else {
+ pw.println(" " + target
+ + Utils.getResponseString(param, source));
+ }
+ }
+
+}
Added: webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeUtils.java
URL: http://svn.apache.org/viewcvs/webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeUtils.java?rev=230790&view=auto
==============================================================================
--- webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeUtils.java (added)
+++ webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/J2eeUtils.java Mon Aug 8 05:28:03 2005
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.ews.mapper;
+
+/**
+ * @author Ias (iasandcb@tmax.co.kr)
+ */
+public class J2eeUtils {
+ public static String jni2javaName(String returnType) {
+ if (returnType == null)
+ return null;
+ if (!returnType.startsWith("[")) {
+ return returnType;
+ } else {
+ returnType = returnType.substring(1);
+ }
+ String end = "[]";
+ while (returnType.startsWith("[")) {
+ end = end + "[]";
+ returnType = returnType.substring(1);
+ }
+ if (returnType.startsWith("B")) {
+ returnType = "byte";
+ } else if (returnType.startsWith("I")) {
+ returnType = "int";
+ } else if (returnType.startsWith("D")) {
+ returnType = "double";
+ } else if (returnType.startsWith("J")) {
+ returnType = "long";
+ } else if (returnType.startsWith("Z")) {
+ returnType = "boolean";
+ } else if (returnType.startsWith("F")) {
+ returnType = "float";
+ } else if (returnType.startsWith("S")) {
+ returnType = "short";
+ } else if (returnType.startsWith("L")) {
+ int index = returnType.indexOf(";@");
+ returnType.substring(1, index);
+ }
+ return returnType + end;
+ }
+
+}
Added: webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/MapperFault.java
URL: http://svn.apache.org/viewcvs/webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/MapperFault.java?rev=230790&view=auto
==============================================================================
--- webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/MapperFault.java (added)
+++ webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/MapperFault.java Mon Aug 8 05:28:03 2005
@@ -0,0 +1,37 @@
+package org.apache.ws.ews.mapper;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: sauthieg
+ * Date: Aug 4, 2005
+ * Time: 2:04:27 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class MapperFault extends Exception {
+
+ private MapperFault(Exception e) {
+ super(e);
+ }
+
+ public MapperFault(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a <code>Exception</code> with the specified
+ * detail message and nested exception.
+ *
+ * @param s the detail message
+ * @param ex the nested exception
+ */
+ public MapperFault(String s, Throwable ex) {
+ super(s, ex);
+ }
+
+ public static MapperFault createMapperFault(Exception e) {
+ if (e instanceof MapperFault) {
+ return (MapperFault) e;
+ } else
+ return new MapperFault(e);
+ }
+}
Added: webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/WsdlToJ2ee.java
URL: http://svn.apache.org/viewcvs/webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/WsdlToJ2ee.java?rev=230790&view=auto
==============================================================================
--- webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/WsdlToJ2ee.java (added)
+++ webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/WsdlToJ2ee.java Mon Aug 8 05:28:03 2005
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.ews.mapper;
+
+import org.apache.axis.constants.Scope;
+import org.apache.axis.utils.CLArgsParser;
+import org.apache.axis.utils.CLOption;
+import org.apache.axis.utils.CLOptionDescriptor;
+import org.apache.axis.utils.JavaUtils;
+import org.apache.axis.utils.Messages;
+import org.apache.axis.wsdl.gen.Parser;
+import org.apache.axis.wsdl.gen.WSDL2;
+
+import java.util.List;
+
+/**
+ * @author Ias (iasandcb@tmax.co.kr)
+ */
+public class WsdlToJ2ee extends WSDL2 {
+
+ protected static final int MAPPING_OPT = 'm';
+
+ // Define our short one-letter option identifiers.
+ protected static final int SERVER_OPT = 's';
+ protected static final int SKELETON_DEPLOY_OPT = 'S';
+ protected static final int NAMESPACE_OPT = 'N';
+ protected static final int NAMESPACE_FILE_OPT = 'f';
+ protected static final int OUTPUT_OPT = 'o';
+ protected static final int SCOPE_OPT = 'd';
+ protected static final int TEST_OPT = 't';
+ protected static final int PACKAGE_OPT = 'p';
+ protected static final int ALL_OPT = 'a';
+ protected static final int TYPEMAPPING_OPT = 'T';
+ protected static final int FACTORY_CLASS_OPT = 'F';
+ protected static final int HELPER_CLASS_OPT = 'H';
+ protected static final int USERNAME_OPT = 'U';
+ protected static final int PASSWORD_OPT = 'P';
+
+ protected boolean bPackageOpt = false;
+ private J2eeEmitter emitter;
+
+ /**
+ * Define the understood options. Each CLOptionDescriptor contains:
+ * - The "long" version of the option. Eg, "help" means that "--help" will
+ * be recognised.
+ * - The option flags, governing the option's argument(s).
+ * - The "short" version of the option. Eg, 'h' means that "-h" will be
+ * recognised.
+ * - A description of the option for the usage message
+ */
+ protected static final CLOptionDescriptor[] options = new CLOptionDescriptor[]{
+ new CLOptionDescriptor("server-side",
+ CLOptionDescriptor.ARGUMENT_DISALLOWED,
+ SERVER_OPT,
+ Messages.getMessage("optionSkel00")),
+ new CLOptionDescriptor("skeletonDeploy",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ SKELETON_DEPLOY_OPT,
+ Messages.getMessage("optionSkeletonDeploy00")),
+ new CLOptionDescriptor("NStoPkg",
+ CLOptionDescriptor.DUPLICATES_ALLOWED + CLOptionDescriptor.ARGUMENTS_REQUIRED_2,
+ NAMESPACE_OPT,
+ Messages.getMessage("optionNStoPkg00")),
+ new CLOptionDescriptor("fileNStoPkg",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ NAMESPACE_FILE_OPT,
+ Messages.getMessage("optionFileNStoPkg00")),
+ new CLOptionDescriptor("package",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ PACKAGE_OPT,
+ Messages.getMessage("optionPackage00")),
+ new CLOptionDescriptor("output",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ OUTPUT_OPT,
+ Messages.getMessage("optionOutput00")),
+ new CLOptionDescriptor("deployScope",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ SCOPE_OPT,
+ Messages.getMessage("optionScope00")),
+ new CLOptionDescriptor("testCase",
+ CLOptionDescriptor.ARGUMENT_DISALLOWED,
+ TEST_OPT,
+ Messages.getMessage("optionTest00")),
+ new CLOptionDescriptor("all",
+ CLOptionDescriptor.ARGUMENT_DISALLOWED,
+ ALL_OPT,
+ Messages.getMessage("optionAll00")),
+ new CLOptionDescriptor("typeMappingVersion",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ TYPEMAPPING_OPT,
+ Messages.getMessage("optionTypeMapping00")),
+ new CLOptionDescriptor("factory",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ FACTORY_CLASS_OPT,
+ Messages.getMessage("optionFactory00")),
+ new CLOptionDescriptor("helperGen",
+ CLOptionDescriptor.ARGUMENT_DISALLOWED,
+ HELPER_CLASS_OPT,
+ Messages.getMessage("optionHelper00")),
+ new CLOptionDescriptor("user",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ USERNAME_OPT,
+ Messages.getMessage("optionUsername")),
+ new CLOptionDescriptor("password",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ PASSWORD_OPT,
+ Messages.getMessage("optionPassword")),
+ new CLOptionDescriptor("mapping-file-path",
+ CLOptionDescriptor.ARGUMENT_REQUIRED,
+ MAPPING_OPT,
+ "Choose a mapping file path for J2EE JAX-RPC mapping")
+ };
+
+ public WsdlToJ2ee() {
+ emitter = (J2eeEmitter) parser;
+ addOptions(options);
+ } // ctor
+
+ protected Parser createParser() {
+ return new J2eeEmitter();
+ } // createParser
+
+ protected void parseOption(CLOption option) {
+ switch (option.getId()) {
+ case FACTORY_CLASS_OPT:
+ emitter.setFactory(option.getArgument());
+ break;
+ case HELPER_CLASS_OPT:
+ emitter.setHelperWanted(true);
+ break;
+ case SKELETON_DEPLOY_OPT:
+ emitter.setSkeletonWanted(JavaUtils.isTrueExplicitly(option.getArgument(0)));
+ // --skeletonDeploy assumes --server-side, so fall thru
+
+ case SERVER_OPT:
+ emitter.setServerSide(true);
+ break;
+ case NAMESPACE_OPT:
+ String namespace = option.getArgument(0);
+ String packageName = option.getArgument(1);
+ emitter.getNamespaceMap().put(namespace, packageName);
+ break;
+ case NAMESPACE_FILE_OPT:
+ emitter.setNStoPkg(option.getArgument());
+ break;
+ case PACKAGE_OPT:
+ bPackageOpt = true;
+ emitter.setPackageName(option.getArgument());
+ break;
+ case OUTPUT_OPT:
+ emitter.setOutputDir(option.getArgument());
+ break;
+ case SCOPE_OPT:
+ String arg = option.getArgument();
+
+ // Provide 'null' default, prevents logging internal error.
+ // we have something different to report here.
+ Scope scope = Scope.getScope(arg, null);
+ if (scope != null) {
+ emitter.setScope(scope);
+ } else {
+ System.err.println(Messages.getMessage("badScope00", arg));
+ }
+ break;
+ case TEST_OPT:
+ emitter.setTestCaseWanted(true);
+ break;
+ case ALL_OPT:
+ emitter.setAllWanted(true);
+ break;
+ case TYPEMAPPING_OPT:
+ String tmValue = option.getArgument();
+ if (tmValue.equals("1.1")) {
+ emitter.setTypeMappingVersion("1.1");
+ } else if (tmValue.equals("1.2")) {
+ emitter.setTypeMappingVersion("1.2");
+ } else {
+ System.out.println(Messages.getMessage("badTypeMappingOption00"));
+ }
+ break;
+ case USERNAME_OPT:
+ emitter.setUsername(option.getArgument());
+ break;
+ case PASSWORD_OPT:
+ emitter.setPassword(option.getArgument());
+ break;
+ case MAPPING_OPT:
+ emitter.setMappingFilePath(option.getArgument());
+ break;
+ default:
+ super.parseOption(option);
+ }
+ } // parseOption
+
+ /**
+ * validateOptions
+ * This method is invoked after the options are set to validate
+ * the option settings.
+ */
+ protected void validateOptions() {
+ super.validateOptions();
+
+ // validate argument combinations
+ if (emitter.isSkeletonWanted() && !emitter.isServerSide()) {
+ System.out.println(Messages.getMessage("badSkeleton00"));
+ printUsage();
+ }
+ if (!emitter.getNamespaceMap().isEmpty() && bPackageOpt) {
+ System.out.println(Messages.getMessage("badpackage00"));
+ printUsage();
+ }
+ } // validateOptions
+
+ /**
+ * run
+ * checkes the command-line arguments and runs the tool.
+ *
+ * @param args String[] command-line arguments.
+ */
+ protected void run(String[] args) {
+ // Parse the arguments
+ CLArgsParser argsParser = new CLArgsParser(args, options);
+
+ // Print parser errors, if any
+ if (null != argsParser.getErrorString()) {
+ System.err.println(Messages.getMessage("error01", argsParser.getErrorString()));
+ printUsage();
+ }
+
+ // Get a list of parsed options
+ List clOptions = argsParser.getArguments();
+ int size = clOptions.size();
+
+ // Parse the options and configure the emitter as appropriate.
+ for (int i = 0; i < size; i++) {
+ parseOption((CLOption) clOptions.get(i));
+ }
+
+ // validate argument combinations
+ //
+ validateOptions();
+ try {
+ parser.run(wsdlURI);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(-1);
+ }
+ } // run
+
+ /**
+ * Main
+ */
+ public static void main(String args[]) {
+ WsdlToJ2ee j2ee = new WsdlToJ2ee();
+ j2ee.run(args);
+ } // main
+}
Added: webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/context/JAXRPCMapperContext.java
URL: http://svn.apache.org/viewcvs/webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/context/JAXRPCMapperContext.java?rev=230790&view=auto
==============================================================================
--- webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/context/JAXRPCMapperContext.java (added)
+++ webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/context/JAXRPCMapperContext.java Mon Aug 8 05:28:03 2005
@@ -0,0 +1,55 @@
+package org.apache.ws.ews.mapper.context;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ws.ews.context.webservices.client.ServiceReferenceContext;
+import org.apache.ws.ews.context.webservices.server.WSCFContext;
+
+/**
+ * <p>This interface has all the information about the J2EE webservice that is
+ * going to be genarated. from this interface onward all the codes are
+ * ws4j2ee. If we using any class from the geronimo deployment we should
+ * wrap them. This is a Code whith runing once. It is worth keeping the
+ * code independent.<p>
+ * <p>This interface and related interfaces has both getter and setter methods
+ * but who ever implements this interface might not need the both.
+ * e.g. there can be two concreate implementations for this class
+ * for the cases
+ * <ol>
+ * <li>have WSDL</li>
+ * <li>do not have WSDL</li>
+ * </ol>
+ * if some method is not requried please throw java.lang.UnsupportedOperationException</p>
+ *
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+
+public interface JAXRPCMapperContext {
+ /**
+ * Information about the webservices.xml file
+ *
+ * @return
+ */
+ public WSCFContext getWSCFContext();
+
+ public void setWSCFContext(WSCFContext wscfcontext);
+
+ public ServiceReferenceContext getServiceReferenceContext(int index);
+
+ public void addServiceReferenceContext(ServiceReferenceContext context);
+
+ public int getServiceReferenceContextCount();
+}
Added: webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/JaxRpcMapper.java
URL: http://svn.apache.org/viewcvs/webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/JaxRpcMapper.java?rev=230790&view=auto
==============================================================================
--- webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/JaxRpcMapper.java (added)
+++ webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/JaxRpcMapper.java Mon Aug 8 05:28:03 2005
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2003,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.ews.mapper.jaxrpc;
+
+import org.apache.ws.ews.mapper.MapperFault;
+
+import javax.xml.namespace.QName;
+import java.io.InputStream;
+
+/**
+ * @author Srinath Perera(hemapani@opensource.lk)
+ */
+public interface JaxRpcMapper {
+ public void loadMappingFromInputStream(InputStream is) throws MapperFault;
+
+ public void loadMappingFromDir(String path) throws MapperFault;
+
+ /**
+ * @return Returns the mapping.
+ */
+ public int getPackageMappingCount();
+
+ public String getPackageMappingClassName(int index);
+
+ public String getPackageMappingURI(int index);
+
+ public abstract String getJavaType(QName typeQName);
+
+ public abstract String getExceptionType(QName messageQName);
+
+ public abstract String getPortName(String portName);
+
+ public abstract String getServiceInterfaceName(QName entry);
+
+ public abstract String getServiceEndpointInterfaceName(QName portTypeQName,
+ QName bindingQName);
+
+ /**
+ * @param bindingQName
+ * @param portTypeQName
+ * @param operationName
+ * @return
+ */
+ public abstract String getJavaMethodParamType(QName bindingQName,
+ QName portTypeQName, String operationName,
+ int position);
+
+ /**
+ * @param bindingQName
+ * @param portTypeQName
+ * @param operationName
+ * @return
+ */
+ public abstract String getJavaMethodReturnType(QName bindingQName,
+ QName portTypeQName, String operationName);
+
+ /**
+ * @param bindingQName
+ * @param portTypeQName
+ * @param operationName
+ * @return
+ */
+ public abstract String getJavaMethodName(QName bindingQName,
+ QName portTypeQName, String operationName);
+
+ public abstract boolean hasWrappedElement();
+}
Added: webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/XMLBeansJaxRpcMapper.java
URL: http://svn.apache.org/viewcvs/webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/XMLBeansJaxRpcMapper.java?rev=230790&view=auto
==============================================================================
--- webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/XMLBeansJaxRpcMapper.java (added)
+++ webservices/ews/trunk/mapper/src/java/org/apache/ws/ews/mapper/jaxrpc/XMLBeansJaxRpcMapper.java Mon Aug 8 05:28:03 2005
@@ -0,0 +1,315 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.ews.mapper.jaxrpc;
+
+import com.sun.java.xml.ns.j2Ee.ExceptionMappingType;
+import com.sun.java.xml.ns.j2Ee.JavaWsdlMappingDocument;
+import com.sun.java.xml.ns.j2Ee.JavaWsdlMappingType;
+import com.sun.java.xml.ns.j2Ee.JavaXmlTypeMappingType;
+import com.sun.java.xml.ns.j2Ee.MethodParamPartsMappingType;
+import com.sun.java.xml.ns.j2Ee.PackageMappingType;
+import com.sun.java.xml.ns.j2Ee.PortMappingType;
+import com.sun.java.xml.ns.j2Ee.ServiceEndpointInterfaceMappingType;
+import com.sun.java.xml.ns.j2Ee.ServiceEndpointMethodMappingType;
+import com.sun.java.xml.ns.j2Ee.ServiceInterfaceMappingType;
+import com.sun.java.xml.ns.j2Ee.WsdlReturnValueMappingType;
+import com.sun.java.xml.ns.j2Ee.XsdQNameType;
+import org.apache.xmlbeans.XmlException;
+import org.apache.ws.ews.mapper.MapperFault;
+import org.apache.ws.ews.mapper.J2eeUtils;
+
+import javax.xml.namespace.QName;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Ias (iasandcb@tmax.co.kr)
+ */
+public class XMLBeansJaxRpcMapper implements JaxRpcMapper {
+
+ private JavaWsdlMappingType mapping;
+
+ private boolean wrappedElement = false;
+
+ public void loadMappingFromInputStream(InputStream is) throws MapperFault {
+ try {
+ JavaWsdlMappingDocument mappingdoc = JavaWsdlMappingDocument.Factory.parse(is);
+ mapping = mappingdoc.getJavaWsdlMapping();
+ } catch (XmlException e) {
+ e.printStackTrace();
+ throw MapperFault.createMapperFault(e);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw MapperFault.createMapperFault(e);
+ }
+ wrappedElement = checkWrappedElemente();
+ }
+
+ public void loadMappingFromDir(String path) throws MapperFault {
+ try {
+ java.io.InputStream fis = new FileInputStream(path);
+ JavaWsdlMappingDocument mappingdoc = JavaWsdlMappingDocument.Factory.parse(fis);
+ mapping = mappingdoc.getJavaWsdlMapping();
+ } catch (FileNotFoundException e2) {
+ e2.printStackTrace();
+ throw MapperFault.createMapperFault(e2);
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw MapperFault.createMapperFault(e);
+ } catch (XmlException e2) {
+ e2.printStackTrace();
+ throw MapperFault.createMapperFault(e2);
+ }
+ wrappedElement = checkWrappedElemente();
+ }
+
+ public int getPackageMappingCount() {
+ PackageMappingType[] packagemapping = mapping.getPackageMappingArray();
+ return packagemapping.length;
+ }
+
+ public String getPackageMappingClassName(int index) {
+ PackageMappingType[] packagemapping = mapping.getPackageMappingArray();
+ return packagemapping[index].getPackageType().getStringValue();
+ }
+
+ public String getPackageMappingURI(int index) {
+ PackageMappingType[] packagemapping = mapping.getPackageMappingArray();
+ return packagemapping[index].getNamespaceURI().getStringValue();
+ }
+
+ /**
+ * @return Returns the mapping.
+ */
+ public JavaWsdlMappingType getMapping() {
+ return mapping;
+ }
+
+ public String getJavaType(QName typeQName) {
+ if (mapping == null) {
+ return null;
+ }
+ JavaXmlTypeMappingType[] typeList = mapping.getJavaXmlTypeMappingArray();
+ for (int i = 0; i < typeList.length; i++) {
+ JavaXmlTypeMappingType typeMapping = typeList[i];
+ XsdQNameType rootType = typeMapping.getRootTypeQname();
+ if (rootType == null) {
+ String mappedAnonymousTypeName = typeMapping.getAnonymousTypeQname().getStringValue();
+ String localPart = typeQName.getLocalPart();
+ String revisitedTypeQName = typeQName.getNamespaceURI() + ":" + localPart;
+ if (mappedAnonymousTypeName.equals(revisitedTypeQName)) {
+ //TODO this is a quick fix there should be a better way to do this
+ return J2eeUtils.jni2javaName(typeMapping.getJavaType().getStringValue());
+ }
+ } else {
+ QName typeName = rootType.getQNameValue();
+ if (typeQName.equals(typeName)) {
+ String className = typeMapping.getJavaType().getStringValue();
+ //TODO this is a quick fix there should be a better way to do this
+ return J2eeUtils.jni2javaName(className);
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getExceptionType(QName messageQName) {
+ if (mapping == null) {
+ return null;
+ }
+ ExceptionMappingType[] exceptionMappingList = mapping.getExceptionMappingArray();
+ for (int j = 0; j < exceptionMappingList.length; j++) {
+ ExceptionMappingType exceptionMapping = exceptionMappingList[j];
+ QName name = exceptionMapping.getWsdlMessage().getQNameValue();
+ if (messageQName.equals(name)) {
+ return exceptionMapping.getExceptionType().getStringValue();
+ }
+ }
+ return null;
+ }
+
+ public String getPortName(String portName) {
+ if (mapping == null) {
+ return null;
+ }
+ ServiceInterfaceMappingType[] serviceList = mapping.getServiceInterfaceMappingArray();
+ for (int i = 0; i < serviceList.length; i++) {
+ PortMappingType[] portList = serviceList[i].getPortMappingArray();
+ for (int j = 0; j < portList.length; j++) {
+ PortMappingType portMapping = portList[j];
+ String mappedPortName = portMapping.getPortName().getStringValue();
+ if (portName.equals(mappedPortName)) {
+ return portMapping.getJavaPortName().getStringValue();
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getServiceInterfaceName(QName entry) {
+ if (mapping == null) {
+ return null;
+ }
+ ServiceInterfaceMappingType[] serviceList = mapping.getServiceInterfaceMappingArray();
+ for (int i = 0; i < serviceList.length; i++) {
+ QName wsdlServiceName = serviceList[i].getWsdlServiceName().getQNameValue();
+ if (entry.equals(wsdlServiceName)) {
+ String serviceInterfaceName = serviceList[i].getServiceInterface().getStringValue();
+ return serviceInterfaceName;
+ }
+ }
+ return null;
+ }
+
+ public String getServiceEndpointInterfaceName(QName portTypeQName, QName bindingQName) {
+ if (mapping == null) {
+ return null;
+ }
+ ServiceEndpointInterfaceMappingType[] serviceList = mapping.getServiceEndpointInterfaceMappingArray();
+ for (int i = 0; i < serviceList.length; i++) {
+ QName wsdlBinging = serviceList[i].getWsdlBinding().getQNameValue();
+ QName wsdlPortType = serviceList[i].getWsdlPortType().getQNameValue();
+ if ((bindingQName.equals(wsdlBinging)) && (portTypeQName.equals(wsdlPortType))) {
+ String endpointServiceName =
+ serviceList[i].getServiceEndpointInterface().getStringValue();
+ return endpointServiceName;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @param bindingQName
+ * @param portTypeQName
+ * @param operationName
+ * @return
+ */
+ public String getJavaMethodParamType(QName bindingQName, QName portTypeQName, String operationName, int position) {
+ if (mapping == null) {
+ return null;
+ }
+ ServiceEndpointInterfaceMappingType[] serviceList = mapping.getServiceEndpointInterfaceMappingArray();
+ for (int i = 0; i < serviceList.length; i++) {
+ QName wsdlBinging = serviceList[i].getWsdlBinding().getQNameValue();
+ QName wsdlPortType = serviceList[i].getWsdlPortType().getQNameValue();
+ if ((bindingQName.equals(wsdlBinging)) && (portTypeQName.equals(wsdlPortType))) {
+ ServiceEndpointMethodMappingType[] methodList = serviceList[i].getServiceEndpointMethodMappingArray();
+ for (int k = 0; k < methodList.length; k++) {
+ ServiceEndpointMethodMappingType methodMapping = methodList[k];
+ String mappedOperationName = methodMapping.getWsdlOperation().getStringValue();
+ if (operationName.equals(mappedOperationName)) {
+ MethodParamPartsMappingType[] paramList = methodMapping.getMethodParamPartsMappingArray();
+ for (int m = 0; m < paramList.length; m++) {
+ MethodParamPartsMappingType paramPart = paramList[m];
+ if (paramPart.getParamPosition().getBigIntegerValue().intValue() == position) {
+ //TODO this is a quick fix there should be a better way to do this
+ return J2eeUtils.jni2javaName(paramPart.getParamType().getStringValue());
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public boolean checkWrappedElemente() {
+ if (mapping == null) {
+ return false;
+ }
+ ServiceEndpointInterfaceMappingType[] serviceList = mapping.getServiceEndpointInterfaceMappingArray();
+ for (int i = 0; i < serviceList.length; i++) {
+ ServiceEndpointMethodMappingType[] methodList = serviceList[i].getServiceEndpointMethodMappingArray();
+ for (int k = 0; k < methodList.length; k++) {
+ ServiceEndpointMethodMappingType methodMapping = methodList[k];
+ if (methodMapping.getWrappedElement() != null) {
+ // do use wrapped style
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ /**
+ * @param bindingQName
+ * @param portTypeQName
+ * @param operationName
+ * @return
+ */
+ public String getJavaMethodReturnType(QName bindingQName, QName portTypeQName, String operationName) {
+ if (mapping == null) {
+ return null;
+ }
+ ServiceEndpointInterfaceMappingType[] serviceList = mapping.getServiceEndpointInterfaceMappingArray();
+ for (int i = 0; i < serviceList.length; i++) {
+ QName wsdlBinging = serviceList[i].getWsdlBinding().getQNameValue();
+ QName wsdlPortType = serviceList[i].getWsdlPortType().getQNameValue();
+ if ((bindingQName.equals(wsdlBinging)) && (portTypeQName.equals(wsdlPortType))) {
+ ServiceEndpointMethodMappingType[] methodList = serviceList[i].getServiceEndpointMethodMappingArray();
+ for (int k = 0; k < methodList.length; k++) {
+ ServiceEndpointMethodMappingType methodMapping = methodList[k];
+ String mappedOperationName = methodMapping.getWsdlOperation().getStringValue();
+ if (operationName.equals(mappedOperationName)) {
+ WsdlReturnValueMappingType returnValueMapping =
+ methodMapping.getWsdlReturnValueMapping();
+ if (returnValueMapping != null) {
+ //TODO this is a quick fix there should be a better way to do this
+ return J2eeUtils.jni2javaName(returnValueMapping.getMethodReturnValue().getStringValue());
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @param bindingQName
+ * @param portTypeQName
+ * @param operationName
+ * @return
+ */
+ public String getJavaMethodName(QName bindingQName, QName portTypeQName, String operationName) {
+ if (mapping == null) {
+ return null;
+ }
+ ServiceEndpointInterfaceMappingType[] serviceList = mapping.getServiceEndpointInterfaceMappingArray();
+ for (int i = 0; i < serviceList.length; i++) {
+ QName wsdlBinging = serviceList[i].getWsdlBinding().getQNameValue();
+ QName wsdlPortType = serviceList[i].getWsdlPortType().getQNameValue();
+ if ((bindingQName.equals(wsdlBinging)) && (portTypeQName.equals(wsdlPortType))) {
+ ServiceEndpointMethodMappingType[] methodList = serviceList[i].getServiceEndpointMethodMappingArray();
+ for (int k = 0; k < methodList.length; k++) {
+ ServiceEndpointMethodMappingType methodMapping = methodList[k];
+ String mappedOperationName = methodMapping.getWsdlOperation().getStringValue();
+ if (operationName.equals(mappedOperationName)) {
+ return methodMapping.getJavaMethodName().getStringValue();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ws.ews.mapper.jaxrpc.JaxRpcMapper#hasWrappedElement()
+ */
+ public boolean hasWrappedElement() {
+ return wrappedElement;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: ews-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: ews-dev-help@ws.apache.org