Index: lib/.cvsignore =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/lib/.cvsignore,v retrieving revision 1.5 diff -u -3 -p -u -r1.5 .cvsignore --- lib/.cvsignore 4 May 2005 14:30:27 -0000 1.5 +++ lib/.cvsignore 9 May 2005 19:54:33 -0000 @@ -9,6 +9,7 @@ rdf.jar commons.jar xml.jar services.jar +soap.jar deps.sh gen-classlist.sh mkdep.pl Index: lib/Makefile.am =================================================================== RCS file: /cvsroot/cashew-s-editor/cashews/lib/Makefile.am,v retrieving revision 1.8 diff -u -3 -p -u -r1.8 Makefile.am --- lib/Makefile.am 9 May 2005 02:36:56 -0000 1.8 +++ lib/Makefile.am 9 May 2005 19:54:33 -0000 @@ -52,13 +52,13 @@ JAVAH = $(USER_JAVAH) -jni -classpath .: if INSTALL_GLIBJ_ZIP if FOUND_ECLIPSE -pkgdata_DATA = commons.jar xml.jar rdf.jar owls.jar cashews.jar services.jar soap.jar eclipse.jar +pkgdata_DATA = commons.jar xml.jar rdf.jar owls.jar cashews.jar services.jar soap.jar wsdl.jar eclipse.jar install-data-local: genclasses compile-classes eclipse.jar if [ ! -e $(INSTALLDIR) ]; then mkdir $(INSTALLDIR); fi cp eclipse.jar $(INSTALLDIR) cp $(top_srcdir)/resource/plugin.xml $(INSTALLDIR) else -pkgdata_DATA = commons.jar xml.jar rdf.jar cashews.jar owls.jar soap.jar services.jar +pkgdata_DATA = commons.jar xml.jar rdf.jar cashews.jar owls.jar soap.jar wsdl.jar services.jar endif endif # INSTALL_GLIBJ_ZIP @@ -121,6 +121,12 @@ if FOUND_GCJ $(GCJ) -shared -fjni -findirect-dispatch -o soap.jar.so soap.jar endif +wsdl.jar: classes compile-classes # resources + if test "$(JAR)" != ""; then rm wsdl.jar; $(JAR) cf wsdl.jar `find nongnu -path '*wsdl*' -name '*class'` > /dev/null; fi +if FOUND_GCJ +$(GCJ) -shared -fjni -findirect-dispatch -o wsdl.jar.so wsdl.jar +endif + if FOUND_ECLIPSE eclipse.jar: classes compile-classes # resources Index: src/nongnu/cashews/wsdl/WsdlHandler.java =================================================================== RCS file: src/nongnu/cashews/wsdl/WsdlHandler.java diff -N src/nongnu/cashews/wsdl/WsdlHandler.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/nongnu/cashews/wsdl/WsdlHandler.java 9 May 2005 19:54:33 -0000 @@ -0,0 +1,155 @@ +/* WsdlHandler.java -- Handler for WSDL. + Copyright (C) 2005 The University of Sheffield. + + This file is part of the CASheW-s editor. + + The CASheW-s editor is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The CASheW-s editor is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The CASheW-s editor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. +*/ + +package nongnu.cashews.wsdl; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Handler; +import java.util.logging.Logger; + +import nongnu.cashews.language.grounding.SoapOperation; + +import nongnu.cashews.xml.XmlBaseHandler; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +/** + * This class deals with the parsing of WSDL, as defined by the WSDL 1.1 standard. It turns an XML-based + * representation of a WSDL service into a list of + * SoapOperation objects. + * + * @author Andrew John Hughes (address@hidden) + * @see nongnu.cashews.langauge.grounding.SoapOperation + */ +public class WsdlHandler + extends XmlBaseHandler +{ + + /** + * The WSDL namespace. + */ + public static final String + WSDL_NAMESPACE = ""; + + /** + * The resulting list of operations. + * + * @serial the operations described in the WSDL file. + */ + private List operations; + + /** + * A Logger instance to log events generated by the + * parsing process. + */ + private Logger wsdlLogger; + + /** + * Constructs a new WSDLHandler, using the specified + * handler for log messages. + * + * @param handler the handler to use for log messages. + */ + public WsdlHandler(Handler handler) + { + super(handler); + wsdlLogger = Logger.getLogger("nongnu.cashews.wsdl.WsdlHandler"); + wsdlLogger.addHandler(handler); + wsdlLogger.setLevel(handler.getLevel()); + } + + /** + * Captures the start of the document and sets up the initial + * state. + */ + public void startDocument() + { + super.startDocument(); + operations = new ArrayList(); + } + + /** + * Captures the start of an XML element. + * + * @param uri the namespace URI. + * @param localName the local name of the element inside the namespace. + * @param qName the local name qualified with the namespace URI. This + * may or may not be provided, as we don't ask for namespace + * prefixes. + * @param attributes the attributes of this element. + * @throws SAXException if some error occurs in parsing. + */ + public void startElement(String uri, String localName, + String qName, Attributes attributes) + throws SAXException + { + super.startElement(uri, localName, qName, attributes); + } + + /** + * Captures characters within an XML element. + * + * @param ch the array of characters. + * @param start the start index of the characters to use. + * @param length the number of characters to use from the start index on. + * @throws SAXException if some error occurs in parsing. + */ + public void characters(char[] ch, int start, int length) + throws SAXException + { + super.characters(ch, start, length); + String value = new String(ch, start, length).trim(); + if (value.length() == 0) + return; + wsdlLogger.finer("Characters: " + value); + } + + /** + * Captures the end of an XML element. + * + * @param uri the namespace URI. + * @param localName the local name of the element inside the namespace. + * @param qName the local name qualified with the namespace URI. This + * may or may not be provided, as we don't ask for namespace + * prefixes. + * @throws SAXException if some error occurs in parsing. + */ + public void endElement(String uri, String localName, + String qName) + throws SAXException + { + super.endElement(uri, localName, qName); + } + + /** + * Retrieves the graph created by the parsing process. + * + * @return the graph resulting from the parse. + */ + public List getOperations() + { + return operations; + } + +} Index: src/nongnu/cashews/wsdl/WsdlParser.java =================================================================== RCS file: src/nongnu/cashews/wsdl/WsdlParser.java diff -N src/nongnu/cashews/wsdl/WsdlParser.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/nongnu/cashews/wsdl/WsdlParser.java 9 May 2005 19:54:33 -0000 @@ -0,0 +1,89 @@ +/* Parser.java -- Parser for WSDL. + Copyright (C) 2005 The University of Sheffield. + + This file is part of the CASheW-s editor. + + The CASheW-s editor is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + The CASheW-s editor is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with The CASheW-s editor; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. +*/ + +package nongnu.cashews.wsdl; + +import java.io.IOException; +import java.util.logging.ConsoleHandler; +import java.util.logging.Handler; +import java.util.logging.Level; + +import nongnu.cashews.xml.Parser; + +import org.xml.sax.SAXException; + +/** + * This class is simply a wrapper around the existing parser to enable + * WSDL parsing. + * + * @author Andrew John Hughes (address@hidden) + */ +public class WsdlParser + extends Parser +{ + + /** + * Constructs a new WSDL-based parser, using the specified handler + * for messages. + * + * @param logHandler the handler to use for log messages. + * @throws SAXException if the parser fails to obtain an + * XMLReader instance. + */ + public WsdlParser(Handler handler) + throws SAXException + { + super(handler, new WsdlHandler(handler)); + } + + /** + * Retrieves the WSDL handler used by the parser. + * + * @return the WSDL XML event handler. + */ + public WsdlHandler getWsdlHandler() + { + return (WsdlHandler) getHandler(); + } + + /** + * A simple test harness to parse the WSDL files supplied on the command + * line. + * + * @param args the command line arguments. + * @throws SAXException if a XMLReader can't be obtained + * or an error occurs during parsing. + * @throws IOException if an error occurs in the underlying input. + */ + public static void main(String[] args) + throws SAXException, IOException + { + Handler handler = new ConsoleHandler(); + handler.setLevel(Level.FINEST); + WsdlParser parser = new WsdlParser(handler); + for (int a = 0; a < args.length; ++a) + { + parser.parse(args[a]); + System.out.println(parser.getWsdlHandler().getOperations()); + } + } + +}