Index: src/nongnu/cashews/language/grounding/SoapOperation.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/language/grounding/SoapOperation.java,v retrieving revision 1.4 diff -u -3 -p -u -r1.4 SoapOperation.java --- src/nongnu/cashews/language/grounding/SoapOperation.java 9 May 2005 02:36:56 -0000 1.4 +++ src/nongnu/cashews/language/grounding/SoapOperation.java 10 May 2005 23:05:57 -0000 @@ -84,6 +84,13 @@ public class SoapOperation private SoapMessage outputMessage; /** + * Constructs a new empty operation. + */ + public SoapOperation() + { + } + + /** * Constructs a new operation using the specified endpoint. * The endpoint is also used as the namespace of the operation. * Index: src/nongnu/cashews/soap/SoapClient.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/soap/SoapClient.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 SoapClient.java --- src/nongnu/cashews/soap/SoapClient.java 9 May 2005 02:36:56 -0000 1.1 +++ src/nongnu/cashews/soap/SoapClient.java 10 May 2005 23:05:57 -0000 @@ -89,6 +89,7 @@ public class SoapClient OutputStream ostream = connection.getOutputStream(); Serializer.serializeToStream(document, ostream); connection.connect(); + /* System.out.println(connection.getContent()); InputStream istream = connection.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(istream)); @@ -99,6 +100,11 @@ public class SoapClient line = reader.readLine(); } return null; + */ + if (connection.getResponseCode() == 200) + return new Boolean(true); + else + return new Boolean(false); } /** Index: src/nongnu/cashews/wsdl/WsdlHandler.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/wsdl/WsdlHandler.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 WsdlHandler.java --- src/nongnu/cashews/wsdl/WsdlHandler.java 9 May 2005 20:01:06 -0000 1.1 +++ src/nongnu/cashews/wsdl/WsdlHandler.java 10 May 2005 23:05:57 -0000 @@ -21,11 +21,22 @@ package nongnu.cashews.wsdl; +import java.net.URISyntaxException; + import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.logging.Handler; import java.util.logging.Logger; +import javax.xml.namespace.QName; + +import nongnu.cashews.commons.PairMap; + +import nongnu.cashews.language.grounding.MessagePart; +import nongnu.cashews.language.grounding.SoapMessage; import nongnu.cashews.language.grounding.SoapOperation; import nongnu.cashews.xml.XmlBaseHandler; @@ -50,7 +61,13 @@ public class WsdlHandler * The WSDL namespace. */ public static final String - WSDL_NAMESPACE = ""; + WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/"; + + /** + * The WSDL SOAP namespace. + */ + public static final String + WSDL_SOAP_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/soap/"; /** * The resulting list of operations. @@ -64,7 +81,42 @@ public class WsdlHandler * parsing process. */ private Logger wsdlLogger; - + + /** + * The current SOAP message being created. + */ + private SoapMessage currentMessage; + + /** + * A map of parsed SOAP messages. + */ + private Map messages; + + /** + * A map of parsed port types. + */ + private Map> portTypeMap; + + /** + * A map of parsed SOAP operations. + */ + private PairMap operationMap; + + /** + * The current port type name. + */ + private String currentPortTypeName; + + /** + * The current operation name. + */ + private String currentOperationName; + + /** + * The current SOAP operation. + */ + private SoapOperation currentOperation; + /** * Constructs a new WSDLHandler, using the specified * handler for log messages. @@ -87,6 +139,13 @@ public class WsdlHandler { super.startDocument(); operations = new ArrayList(); + currentMessage = null; + messages = new HashMap(); + operationMap = new PairMap(); + portTypeMap = new HashMap>(); + currentPortTypeName = null; + currentOperationName = null; + currentOperation = null; } /** @@ -105,6 +164,146 @@ public class WsdlHandler throws SAXException { super.startElement(uri, localName, qName, attributes); + if (uri.equals(WSDL_NAMESPACE)) + { + if (localName.equals("message")) + { + String name = attributes.getValue("","name"); + if (name == null) + wsdlLogger.severe("Required message name not found."); + else + { + currentMessage = new SoapMessage(null, name); + messages.put(name, currentMessage); + } + } + else if (localName.equals("part")) + { + String name = attributes.getValue("","name"); + String type = attributes.getValue("","type"); + if (name == null) + wsdlLogger.severe("Required part name not found."); + else + { + try + { + MessagePart part = + new MessagePart(name); + part.setName(null, name); + if (type != null) + part.setType(parseQName(type)); + currentMessage.addPart(part); + wsdlLogger.fine("Added part: " + part); + } + catch (URISyntaxException e) + { + wsdlLogger.severe("Couldn't interprete name " + name + + " as URI."); + } + } + } + else if (localName.equals("portType")) + { + String value = attributes.getValue("","name"); + if (value == null) + wsdlLogger.severe("Required port type name not found."); + else + { + currentPortTypeName = value; + portTypeMap.put(currentPortTypeName, + new LinkedList()); + wsdlLogger.fine("Port type found: " + currentPortTypeName); + } + } + else if (localName.equals("operation") && currentPortTypeName != null) + { + String value = attributes.getValue("","name"); + if (value == null) + wsdlLogger.severe("Required port type operation name " + + "not found."); + else + { + currentOperationName = value; + currentOperation = new SoapOperation(); + operationMap.put(currentPortTypeName, currentOperationName, + currentOperation); + List operationList = + portTypeMap.get(currentPortTypeName); + if (operationList == null) + wsdlLogger.severe("Current port type name is not in the " + + "parsed port types map."); + else + operationList.add(currentOperation); + wsdlLogger.fine("Port type operation found: " + + currentOperationName); + } + } + else if (localName.equals("input") && currentOperationName != null) + { + QName message = parseQName(attributes.getValue("", "message")); + SoapMessage input = messages.get(message.getLocalPart()); + if (input == null) + wsdlLogger.severe("Operation " + currentOperationName + + " references non-existant message as input."); + else + currentOperation.setInputMessage(input); + } + else if (localName.equals("output") && currentOperationName != null) + { + QName message = parseQName(attributes.getValue("", "message")); + SoapMessage output = messages.get(message.getLocalPart()); + if (output == null) + wsdlLogger.severe("Operation " + currentOperationName + + " references non-existant message as output."); + else + currentOperation.setOutputMessage(output); + } + else if (localName.equals("port")) + { + String name = attributes.getValue("","name"); + if (name == null) + wsdlLogger.severe("No port name specified in the service."); + else + { + currentPortTypeName = name; + wsdlLogger.fine("Port " + name + + " encountered in the service."); + } + } + } + else if (uri.equals(WSDL_SOAP_NAMESPACE)) + { + if (localName.equals("address")) + { + String location = attributes.getValue("","location"); + if (location == null) + wsdlLogger.severe("No location specified."); + else + { + List operationList = + portTypeMap.get(currentPortTypeName); + if (operationList == null) + wsdlLogger.severe("Current port type name, " + + currentPortTypeName + + ", is not in the " + + "parsed port types map."); + else + for (SoapOperation op : operationList) + { + try + { + op.setEndpoint(location); + op.setNamespace(location); + } + catch (URISyntaxException e) + { + wsdlLogger.severe("Location URL, " + location + + ", is invalid."); + } + } + } + } + } } /** @@ -140,6 +339,18 @@ public class WsdlHandler throws SAXException { super.endElement(uri, localName, qName); + if (uri.equals(WSDL_NAMESPACE)) + { + if (localName.equals("message")) + wsdlLogger.fine("Created SOAP message: " + currentMessage); + else if (localName.equals("portType")) + currentPortTypeName = null; + else if (localName.equals("operation") && currentOperationName != null) + { + currentOperationName = null; + wsdlLogger.fine("Created SOAP operation: " + currentOperation); + } + } } /** @@ -152,4 +363,27 @@ public class WsdlHandler return operations; } + /** + * Parses a QName from a string. + * + * @param qname the qualified name in String form to parse. + * @return the parsed QName. + */ + private QName parseQName(String qname) + { + String[] parts = qname.split(":"); + /* FIXME: Add namespace lookup */ + return new QName(null,parts[1],parts[0]); + } + + /** + * Captures the end of the document and sets up the final + * state. + */ + public void endDocument() + { + for (SoapOperation op : operationMap.values()) + operations.add(op); + } + } Index: src/nongnu/cashews/wsdl/WsdlParser.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/wsdl/WsdlParser.java,v retrieving revision 1.1 diff -u -3 -p -u -r1.1 WsdlParser.java --- src/nongnu/cashews/wsdl/WsdlParser.java 9 May 2005 20:01:06 -0000 1.1 +++ src/nongnu/cashews/wsdl/WsdlParser.java 10 May 2005 23:05:57 -0000 @@ -77,7 +77,7 @@ public class WsdlParser throws SAXException, IOException { Handler handler = new ConsoleHandler(); - handler.setLevel(Level.FINEST); + handler.setLevel(Level.FINE); WsdlParser parser = new WsdlParser(handler); for (int a = 0; a < args.length; ++a) { Index: src/nongnu/cashews/xml/Parser.java =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/src/nongnu/cashews/xml/Parser.java,v retrieving revision 1.2 diff -u -3 -p -u -r1.2 Parser.java --- src/nongnu/cashews/xml/Parser.java 18 Apr 2005 00:54:30 -0000 1.2 +++ src/nongnu/cashews/xml/Parser.java 10 May 2005 23:05:57 -0000 @@ -83,6 +83,8 @@ public class Parser throws SAXException { reader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); + reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); + System.out.println(reader.getFeature("http://xml.org/sax/features/namespace-prefixes")); reader.setContentHandler(xmlHandler); this.xmlHandler = xmlHandler; }