Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 67760 invoked by uid 500); 3 Sep 2001 20:01:21 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 67751 invoked by uid 500); 3 Sep 2001 20:01:21 -0000 Delivered-To: apmail-xml-axis-cvs@apache.org Received: (qmail 67746 invoked from network); 3 Sep 2001 20:01:21 -0000 Received: from icarus.apache.org (64.125.133.21) by daedalus.apache.org with SMTP; 3 Sep 2001 20:01:21 -0000 Received: (qmail 89327 invoked by uid 1144); 3 Sep 2001 19:59:13 -0000 Date: 3 Sep 2001 19:59:13 -0000 Message-ID: <20010903195913.89326.qmail@icarus.apache.org> From: gdaniels@apache.org To: xml-axis-cvs@apache.org Subject: cvs commit: xml-axis/java/src/org/apache/axis/wsdl Emitter.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N gdaniels 01/09/03 12:59:13 Modified: java/src/org/apache/axis/wsdl Emitter.java Log: Bunch of improvements from Steve Graham (sggraham@us.ibm.com): - changed return type of the skeleton operation signature to be the returntype of the operation - added the Axis MessageContext parm as first parm to the skeleton signature - added output messages to indicate which files were being generated - added generation of server side signature - spit out deploy.xml and undeploy.xml Revision Changes Path 1.4 +277 -11 xml-axis/java/src/org/apache/axis/wsdl/Emitter.java Index: Emitter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/Emitter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Emitter.java 2001/08/31 14:44:57 1.3 +++ Emitter.java 2001/09/03 19:59:13 1.4 @@ -82,12 +82,19 @@ import javax.wsdl.WSDLException; import org.w3c.dom.*; +import org.apache.xml.serialize.XMLSerializer; +import org.apache.xml.serialize.OutputFormat; + +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + import org.apache.axis.utils.XMLUtils; import com.ibm.wsdl.xml.WSDLReader; import com.ibm.wsdl.extensions.soap.SOAPAddress; import com.ibm.wsdl.extensions.soap.SOAPOperation; import com.ibm.wsdl.extensions.soap.SOAPBody; +import com.ibm.wsdl.extensions.soap.SOAPBinding; /** * This class produces java files for stubs, skeletons, and types from a @@ -95,6 +102,7 @@ * * @author Russell Butek (butek@us.ibm.com) * @author Tom Jordahl (tjordahl@macromedia.com) + * @author Steve Graham (sggraham@us.ibm.com) */ public class Emitter { private Document doc = null; @@ -131,6 +139,8 @@ writeTypes (); HashMap portTypesInfo = writePortTypes (); writeBindings (portTypesInfo); + if(bEmitSkeleton) + writeDeploymentXML(); } catch (WSDLException e) { e.printStackTrace (); @@ -244,6 +254,8 @@ while (i.hasNext ()) { PortType portType = (PortType) i.next (); HashMap portTypeInfo = writePortType (portType); + if(bEmitSkeleton) + writeAxisPortType(portType); portTypesInfo.put (portType, portTypeInfo); } @@ -251,12 +263,13 @@ } // writePortTypes /** - * Generate the bindings (interface, stub, skeleton) for the given port type. + * Generate the interface for the given port type. */ private HashMap writePortType(PortType portType) throws IOException { String nameValue = portType.getQName ().getLocalPart (); PrintWriter interfacePW = new PrintWriter ( new FileWriter (nameValue + ".java")); + System.out.println("Generating PortType interface: " + nameValue + ".java"); interfacePW.println ("public interface " + nameValue + " extends java.rmi.Remote"); interfacePW.println ("{"); @@ -278,6 +291,32 @@ } // writePortType /** + * Generate the server-side (Axis) interface for the given port type. + */ + private void writeAxisPortType(PortType portType) throws IOException { + String nameValue = portType.getQName ().getLocalPart () + "Axis"; + PrintWriter interfacePW = new PrintWriter ( + new FileWriter (nameValue + ".java")); + System.out.println("Generating server-side PortType interface: " + nameValue + ".java"); + + interfacePW.println ("import org.apache.axis.MessageContext;"); + interfacePW.println ("public interface " + nameValue + " extends java.rmi.Remote"); + interfacePW.println ("{"); + + List operations = portType.getOperations (); + + for (int i = 0; i < operations.size (); ++i) { + Operation operation = (Operation) operations.get (i); + Parameters operationInfo = writeOperationSkelSignatures (operation, interfacePW); + } + + interfacePW.println ("}"); + interfacePW.close (); + + return; + } // writeAxisPortType + + /** * This class simply collects */ private static class Parameter { @@ -469,8 +508,11 @@ if (allOuts == 0) skelSig = " public void " + name + "("; else - skelSig = " public Object " + name + "("; + skelSig = " public " + parms.returnType + " " + name + " ("; + skelSig = skelSig + "MessageContext ctx"; + if (parms.list.size() > 0) + skelSig = skelSig + ", "; boolean needComma = false; for (int i = 0; i < parms.list.size (); ++i) { @@ -482,7 +524,7 @@ skelSig = skelSig + ", "; } else - needComma = true; + needComma = true; if (p.mode == Parameter.IN) { signature = signature + p.type + " " + p.name; skelSig = skelSig + p.type + " " + p.name; @@ -522,7 +564,7 @@ } // partStrings /** - * This method generates the interface, stub, and skeleton info for the given operation. + * This method generates the interface signatures for the given operation. */ private Parameters writeOperation(Operation operation, PrintWriter interfacePW) throws IOException { String name = operation.getName (); @@ -532,7 +574,19 @@ return parms; } // writeOperation + + /** + * This method generates the skeleton interface signatures operation. + */ + private Parameters writeOperationSkelSignatures(Operation operation, PrintWriter interfacePW) throws IOException { + String name = operation.getName (); + Parameters parms = parameters (operation); + + interfacePW.println (parms.skelSignature + ";"); + return parms; + } // writeOperation + /** * This generates an exception class for the given fault and returns the capitalized name of * the fault. @@ -604,6 +658,7 @@ String stubName = name + "Stub"; PrintWriter stubPW = new PrintWriter (new FileWriter (stubName + ".java")); + System.out.println("Generating client-side stub: " + stubName + ".java"); // get the soap:address // This is a temporary hack till the service class is coded to @@ -702,10 +757,12 @@ { String skelName = name + "Skeleton"; skelPW = new PrintWriter (new FileWriter (skelName + ".java")); + System.out.println("Generating server-side skeleton: " + skelName + ".java"); - skelPW.println ("public class " + skelName); + skelPW.println ("import org.apache.axis.MessageContext;"); + skelPW.println ("public class " + skelName); skelPW.println ("{"); - skelPW.println (" private " + portTypeName + " impl;"); + skelPW.println (" private " + portTypeName + "Axis impl;"); skelPW.println (); // RJB WARNING! - is this OK? skelPW.println (" public " + skelName + "()"); @@ -713,7 +770,7 @@ skelPW.println (" this.impl = new " + name + "Impl ();"); skelPW.println (" }"); skelPW.println (); - skelPW.println (" public " + skelName + " (" + portTypeName + " impl)"); + skelPW.println (" public " + skelName + " (" + portTypeName + "Axis impl)"); skelPW.println (" {"); skelPW.println (" this.impl = impl;"); skelPW.println (" }"); @@ -901,7 +958,10 @@ if (parms.outputs == 0) pw.print (" impl." + name + "("); else - pw.print (" Object o = impl." + name + "("); + pw.print (" " + parms.returnType + " ret = impl." + name + "("); + pw.print("ctx"); + if(parms.list.size() > 0) + pw.print(", "); boolean needComma = false; for (int i = 0; i < parms.list.size (); ++i) { if (needComma) @@ -921,7 +981,7 @@ if (parms.inouts + parms.outputs > 0) { if (parms.inouts == 0 && parms.outputs == 1) // The only output is a single return value; simply pass it through. - pw.println (" return o;"); + pw.println (" return ret;"); else if (parms.outputs == 0 && parms.inouts == 1) { // There is only one inout parameter. Find it in the parms list and write // its return @@ -935,7 +995,7 @@ // There are more than 1 output parts, so create a Vector to put them into. pw.println (" java.util.Vector v = new java.util.Vector ();"); if (parms.outputs > 0) - pw.println (" v.add (o);"); + pw.println (" v.add (ret);"); for (int i = 0; i < parms.list.size (); ++i) { Parameter p = (Parameter) parms.list.get (i); @@ -948,7 +1008,199 @@ pw.println (" }"); pw.println (); } // writeSkeletonOperation + + /** + * Generate the deployment descriptor and undeployment descriptor + * for the current WSDL file + */ + private void writeDeploymentXML(){ + try{ + PrintWriter dpw = new PrintWriter (new FileWriter ("deploy.xml")); + System.out.println("Generating deployment document: deploy.xml"); + XMLSerializer deploy = initializeDeploymentDoc(dpw, "deploy"); + + PrintWriter upw = new PrintWriter (new FileWriter ("undeploy.xml")); + System.out.println("Generating deployment document: undeploy.xml"); + XMLSerializer undeploy = initializeDeploymentDoc(upw, "undeploy"); + + writeDeployServices(deploy, undeploy); + writeDeployTypes(deploy); + + deploy.endElement("AdminService", "deploy", "m:deploy"); + dpw.close(); + + undeploy.endElement("AdminService", "undeploy", "m:undeploy"); + upw.close(); + }catch (Exception e){ + System.err.println("Failed to write deployment documents"); + e.printStackTrace(); + } + + } // writeDeploymentXML + + /** + * Initialize the deployment document + */ + private XMLSerializer initializeDeploymentDoc(PrintWriter w, String deploymentOpName) throws Exception{ + OutputFormat of = new OutputFormat(); + of.setIndenting(true); + of.setIndent(3); + of.setOmitXMLDeclaration(true); + + XMLSerializer ser = new XMLSerializer(w, of); + + ser.comment( + " "); + ser.comment( + "Use this file to undeploy some handlers/chains and services "); + ser.comment( + "Two ways to do this: "); + ser.comment( + " java org.apache.axis.utils.Admin undeploy.xml "); + ser.comment( + " from the same dir that the Axis engine runs "); + ser.comment( + "or "); + ser.comment( + " java org.apache.axis.client.AdminClient undeploy.xml "); + ser.comment( + " after the axis server is running "); + ser.comment( + "This file will be replaced by WSDD once it's ready "); + ser.comment( + " "); + + ser.startDocument(); + + AttributesImpl attrs = new AttributesImpl(); + attrs.addAttribute("","xmlns:m","", "", "AdminService"); + ser.startElement("AdminService", deploymentOpName, "m:"+ deploymentOpName, attrs); + + return ser; + } // initializeDeploymentDoc + + /** + * Write out bean mappings for each type + */ + private void writeDeployTypes(XMLSerializer deploy) throws org.xml.sax.SAXException{ + Vector types = findChildNodesByName (doc, "complexType"); + + if(types.isEmpty()) return; + newLine(deploy); + newLine(deploy); + + //assumes all complex type elements are under one parent + Node type = (Node)types.get(0); + Element parent = (Element)type.getParentNode(); + String namespaceURI = parent.getAttribute("targetNamespace"); + + //grab the namespace prefix from the attributes of the root (if it is there) + String namespacePrefix="ns"; + NamedNodeMap docAttrs = doc.getDocumentElement().getAttributes(); + for(int i = 0; i