You are viewing a plain text version of this content. The canonical link for it is here.
Posted to woden-dev@ws.apache.org by ry...@apache.org on 2006/02/28 10:44:13 UTC
svn commit: r381611 -
/incubator/woden/java/src/org/apache/woden/ant/ValidateWSDL20.java
Author: ryman
Date: Tue Feb 28 01:44:12 2006
New Revision: 381611
URL: http://svn.apache.org/viewcvs?rev=381611&view=rev
Log:
Initial commit of ValidateWSDL20 Ant Task
Added:
incubator/woden/java/src/org/apache/woden/ant/ValidateWSDL20.java
Added: incubator/woden/java/src/org/apache/woden/ant/ValidateWSDL20.java
URL: http://svn.apache.org/viewcvs/incubator/woden/java/src/org/apache/woden/ant/ValidateWSDL20.java?rev=381611&view=auto
==============================================================================
--- incubator/woden/java/src/org/apache/woden/ant/ValidateWSDL20.java (added)
+++ incubator/woden/java/src/org/apache/woden/ant/ValidateWSDL20.java Tue Feb 28 01:44:12 2006
@@ -0,0 +1,199 @@
+package org.apache.woden.ant;
+
+import java.io.File;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.woden.WSDLException;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.internal.ReaderFeatures;
+import org.apache.woden.wsdl20.Binding;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.ElementDeclaration;
+import org.apache.woden.wsdl20.Interface;
+import org.apache.woden.wsdl20.Service;
+import org.apache.woden.wsdl20.TypeDefinition;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+
+/**
+ * This is an Ant task to validate WSDL 2.0 files.
+ *
+ * Parameters: The <code>dir</code> attribute is a file directory for the
+ * fileset of WSDL 2.0 files to validate. You specify files in include and
+ * exclude using the usual Ant attributes and elements.
+ *
+ * The <code>failonerror</code> attribute is a boolean flag with the usual
+ * meaning.
+ *
+ * The <code>verbose</code> attribute is a boolean flag that enables verbose
+ * output.
+ *
+ * @author Arthur Ryman, ryman@ca.ibm.com
+ *
+ */
+
+public class ValidateWSDL20 extends MatchingTask {
+
+ // directory for fileset
+ private File dir;
+
+ // flag to enable failonerror
+ private boolean failOnError = false;
+
+ // flag to enable verbose output
+ private boolean verbose = false;
+
+ public File getDir() {
+ return this.dir;
+ }
+
+ public void setDir(File dir) {
+ this.dir = dir;
+ }
+
+ public void setFailOnError(boolean failOnError) {
+ this.failOnError = failOnError;
+ }
+
+ public boolean isFailOnError() {
+ return failOnError;
+ }
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public boolean isVerbose() {
+ return verbose;
+ }
+
+public void execute() throws BuildException {
+
+ WSDLReader reader = null;
+
+ // create a reader
+ try {
+
+ WSDLFactory factory = WSDLFactory.newInstance();
+ reader = factory.newWSDLReader();
+
+ } catch (WSDLException e) {
+
+ // fail if unable to create a reader
+ throw new BuildException(e);
+ }
+
+ // set the features but continue even if they are not supported yet
+ try {
+ // always enable WSDL 2.0 validation since this is a validation task
+ reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
+
+ // enable verbose output
+ reader.setFeature(WSDLReader.FEATURE_VERBOSE, isVerbose());
+
+ // enable continue on error (opposite of fail on error)
+ reader.setFeature(WSDLReader.FEATURE_CONTINUE_ON_ERROR,
+ !isFailOnError());
+ } catch (IllegalArgumentException e) {
+ System.out.println("warning: " + e.getMessage());
+ }
+
+ if (isVerbose()) {
+ System.out.println("File dir = " + dir.getAbsolutePath());
+
+ Project project = getProject();
+ File baseDir = project.getBaseDir();
+ System.out.println("File baseDir = " + baseDir.getAbsolutePath());
+ }
+
+ DirectoryScanner directoryScanner = getDirectoryScanner(dir);
+ String[] files = directoryScanner.getIncludedFiles();
+
+ // use the same reader for all the WSDL files
+ for (int i = 0; i < files.length; i++) {
+
+ File file = new File(dir, files[i]);
+
+ // make a URL for the file
+ String wsdlLoc = file.getAbsolutePath();
+ wsdlLoc = wsdlLoc.replace('\\', '/');
+ wsdlLoc = "file:///" + wsdlLoc;
+ System.out.println("validating " + wsdlLoc);
+
+ try {
+ // <-- the <description> element
+ DescriptionElement desc = reader.readWSDL(wsdlLoc);
+
+ // <-- the Description component
+ Description descComp = desc.toComponent();
+
+ if (isVerbose()) {
+
+ ElementDeclaration elementDeclarations[] = descComp
+ .getElementDeclarations();
+ System.out.println("There are "
+ + elementDeclarations.length
+ + " ElementDeclaration components.");
+
+ for (int j = 0; j < elementDeclarations.length; j++) {
+
+ ElementDeclaration elementDeclaration = elementDeclarations[j];
+
+ QName name = elementDeclaration.getName();
+ System.out.println("ElementDeclaration[" + j
+ + "] : name = " + name);
+ }
+
+ TypeDefinition typeDefinitions[] = descComp
+ .getTypeDefinitions();
+ System.out.println("There are " + typeDefinitions.length + " TypeDefinition components.");
+
+ for (int j = 0; j < typeDefinitions.length; j++) {
+ TypeDefinition typeDefinition = typeDefinitions[j];
+
+ QName name= typeDefinition.getName();
+ System.out.println("TypeDefinition[" + j + "] : name = " + name);
+ }
+
+ Interface interfaces[] = descComp.getInterfaces();
+ System.out.println("There are " + interfaces.length
+ + " Interface components.");
+
+ for (int j = 0; j < interfaces.length; j++) {
+
+ System.out.println("Interface[" + j + "] : name = "
+ + interfaces[j].getName());
+ }
+
+ Binding bindings[] = descComp.getBindings();
+ System.out.println("There are " + bindings.length
+ + " Binding components.");
+
+ for (int j = 0; j < bindings.length; j++) {
+
+ System.out.println("Binding[" + j + "] : name = "
+ + bindings[j].getName());
+ }
+
+ Service services[] = descComp.getServices();
+ System.out.println("There are " + services.length
+ + " Service components.");
+
+ for (int j = 0; j < services.length; j++) {
+
+ System.out.println("Service[" + j + "] : name = "
+ + services[j].getName());
+ }
+ }
+
+ } catch (WSDLException e) {
+
+ throw new BuildException(e);
+ }
+ }
+ }}
---------------------------------------------------------------------
To unsubscribe, e-mail: woden-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: woden-dev-help@ws.apache.org