You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2011/10/31 07:04:41 UTC
svn commit: r1195343 [1/2] - in
/incubator/airavata/trunk/modules/commons/gfac-schema: ./ schemas/
src/main/java/org/apache/airavata/commons/gfac/wsdl/
Author: smarru
Date: Mon Oct 31 06:04:40 2011
New Revision: 1195343
URL: http://svn.apache.org/viewvc?rev=1195343&view=rev
Log:
Adding WSDL generation utilities to address AIRAVATA-163
Added:
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacSchemaConstants.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacWSDLException.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/RoundTrip.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/TypesGenerator.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLConstants.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGenerator.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGeneratorUtil.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLMessageBean.java
incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSPolicyGenerator.java
Modified:
incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml
incubator/airavata/trunk/modules/commons/gfac-schema/schemas/ServiceDescription.xsd
Modified: incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml?rev=1195343&r1=1195342&r2=1195343&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml (original)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/pom.xml Mon Oct 31 06:04:40 2011
@@ -1,57 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--Licensed to the Apache Software Foundation (ASF) under one or more contributor
- license agreements. See the NOTICE file distributed with this work for additional
- information regarding copyright ownership. The ASF licenses this file to
- you 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. -->
+<!--Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.apache.airavata</groupId>
- <artifactId>commons</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.apache.airavata</groupId>
- <artifactId>gfac-schema-utils</artifactId>
- <packaging>jar</packaging>
- <name>Airavata GFac Schema Utilities</name>
- <url>http://incubator.apache.org/airavata/</url>
-
- <dependencies>
- <dependency>
- <groupId>javax.jcr</groupId>
- <artifactId>jcr</artifactId>
- </dependency>
- <dependency>
- <groupId>xmlbeans</groupId>
- <artifactId>xbean</artifactId>
- </dependency>
- <dependency>
- <groupId>xerces</groupId>
- <artifactId>xercesImpl</artifactId>
- </dependency>
- <dependency>
- <groupId>wsdl4j</groupId>
- <artifactId>wsdl4j</artifactId>
- <version>1.6.2</version>
- </dependency>
- <dependency>
- <groupId>commons-configuration</groupId>
- <artifactId>commons-configuration</artifactId>
- <version>1.6</version>
- </dependency>
- <dependency>
+ <parent>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>commons</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.airavata</groupId>
+ <artifactId>gfac-schema-utils</artifactId>
+ <packaging>jar</packaging>
+ <name>Airavata GFac Schema Utilities</name>
+ <url>http://incubator.apache.org/airavata/</url>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>xmlbeans</groupId>
+ <artifactId>xbean</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>wsdl4j</groupId>
+ <artifactId>wsdl4j</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
<version>1.1.4c</version>
@@ -61,81 +58,87 @@
<artifactId>xsul</artifactId>
<version>2.10.5_d</version>
</dependency>
-
- <!-- Testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-jcr-rmi</artifactId>
- </dependency>
- </dependencies>
- <build>
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
-
-
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.7</version>
- <executions>
- <execution>
- <id>add-source</id>
- <phase>generate-sources</phase>
- <goals>
- <goal>add-source</goal>
- </goals>
- <configuration>
- <sources>
- <source>${basedir}/target/generated-sources/xmlbeans</source>
- </sources>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>xmlbeans-maven-plugin</artifactId>
- <version>2.3.3</version>
- <executions>
- <execution>
- <goals>
- <goal>xmlbeans</goal>
- </goals>
- </execution>
- </executions>
- <inherited>true</inherited>
- <configuration>
- <schemaDirectory>schemas</schemaDirectory>
- <xmlConfigs>
- <xmlConfig implementation="java.io.File">schemas/gfac-schemas.xsdconfig</xmlConfig>
- </xmlConfigs>
- <outputJar>target/generated/${project.artifactId}-${project.version}.jar</outputJar>
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-rmi</artifactId>
+ </dependency>
+ </dependencies>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+
+
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.7</version>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${basedir}/target/generated-sources/xmlbeans</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>xmlbeans-maven-plugin</artifactId>
+ <version>2.3.3</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>xmlbeans</goal>
+ </goals>
+ </execution>
+ </executions>
+ <inherited>true</inherited>
+ <configuration>
+ <schemaDirectory>schemas</schemaDirectory>
+ <xmlConfigs>
+ <xmlConfig implementation="java.io.File">schemas/gfac-schemas.xsdconfig</xmlConfig>
+ </xmlConfigs>
+ <outputJar>target/generated/${project.artifactId}-${project.version}.jar</outputJar>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: incubator/airavata/trunk/modules/commons/gfac-schema/schemas/ServiceDescription.xsd
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/schemas/ServiceDescription.xsd?rev=1195343&r1=1195342&r2=1195343&view=diff
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/schemas/ServiceDescription.xsd (original)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/schemas/ServiceDescription.xsd Mon Oct 31 06:04:40 2011
@@ -19,10 +19,12 @@
<element name="name" type="xsd:string" minOccurs="0" />
<element name="description" type="xsd:string" minOccurs="0" maxOccurs="1" />
<element name="service" type="gfac:serviceType" minOccurs="1" maxOccurs="1" />
+ <element name="portType" type="gfac:portTypeType" minOccurs="1" maxOccurs="1" />
<element name="authorInfo" type="gfac:authorInfoType" minOccurs="0" maxOccurs="unbounded" />
<element name="documentInfo" type="gfac:documentInfoType" minOccurs="0" maxOccurs="1" />
<element name="inputParameters" type="gfac:inputParameterType" minOccurs="0" maxOccurs="unbounded" nillable="true" />
- <element name="outputParameters" type="gfac:outputParameterType" minOccurs="0" maxOccurs="unbounded" nillable="true" />
+ <element name="outputParameters" type="gfac:outputParameterType" minOccurs="0" maxOccurs="unbounded"
+ nillable="true" />
</sequence>
</complexType>
@@ -46,6 +48,7 @@
<sequence>
<element name="parameterName" type="xsd:string" minOccurs="1" maxOccurs="1" />
<element name="parameterDescription" type="xsd:string" minOccurs="0" maxOccurs="1" />
+ <element name="parameterType" type="gfac:ParameterType" minOccurs="1" maxOccurs="1" />
<element ref="gfac:anyMetadata" minOccurs="0" maxOccurs="1" />
</sequence>
</complexType>
@@ -54,7 +57,7 @@
<complexContent>
<extension base="gfac:parameter">
<sequence>
- <element name="parameterType" type="gfac:ParameterType" minOccurs="1" maxOccurs="1" />
+ <element name="parameterValue" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</sequence>
</extension>
</complexContent>
@@ -64,10 +67,28 @@
<complexContent>
<extension base="gfac:parameter">
<sequence>
- <element name="parameterType" type="gfac:ParameterType" minOccurs="1" maxOccurs="1" />
<element name="stdOutRegExp" type="xsd:string" minOccurs="0" maxOccurs="1" />
</sequence>
</extension>
</complexContent>
- </complexType>
+ </complexType>
+
+ <complexType name="portTypeType">
+ <sequence>
+ <element name="portName" type="xsd:QName" minOccurs="0" maxOccurs="1" />
+ <element name="portDescription" type="xsd:string" minOccurs="0" maxOccurs="1" />
+ <!-- Only supporting one operation per wsdl. This is a gfac limitation, not a wsdl one -->
+ <element name="method" type="gfac:methodType" minOccurs="1" maxOccurs="1" />
+ <element ref="gfac:anyMetadata" minOccurs="0" maxOccurs="unbounded" />
+ </sequence>
+ </complexType>
+
+ <complexType name="methodType">
+ <sequence>
+ <element name="methodName" type="xsd:string" minOccurs="1" maxOccurs="1" />
+ <element name="methodDescription" type="xsd:string" minOccurs="0" maxOccurs="1" />
+ <element ref="gfac:anyMetadata" minOccurs="0" maxOccurs="unbounded" />
+ </sequence>
+ </complexType>
+
</schema>
\ No newline at end of file
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacSchemaConstants.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacSchemaConstants.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacSchemaConstants.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacSchemaConstants.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,119 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+public class GFacSchemaConstants {
+
+ public static final String SHUTDOWN = "Shutdown";
+
+ public static final String PING = "Ping";
+
+ public static final String KILL = "Kill";
+
+ public static final String ARRAY_VALUE = "value";
+
+ public static final String _127_0_0_1 = "127.0.0.1";
+
+ public static final String GFAC_NAMESPACE = "http://schemas.airavata.apache.org/gfac/type";
+
+ public static final String TRANSPORT_LEVEL = "TransportLevel";
+
+ public static final String MESSAGE_SIGNATURE = "MessageSignature";
+
+ // Specific to application service
+ public static final String SERVICE_URI = "SERVICE_URI";
+
+ public static final String METHOD_NAME = "METHOD_NAME";
+
+ public static final String SERVICE_NAME = "SERVICE_NAME";
+
+ public static final String APP_SERVICE_STRING_PARAM = "AFAC_STRING_PARAM";
+
+ public static final String SERVICE_RESP_MSG_SUFFIX = "_ResponseMessage";
+
+ public static final String SERVICE_INPUT_PARAMS_TYPE_SUFFIX = "_InputParamsType";
+
+ public static final String SERVICE_OUTPUT_PARAMS_TYPE_SUFFIX = "_OutputParamsType";
+
+ public static final String SERVICE_REQ_MSG_SUFFIX = "_RequestMessage";
+
+ public static final String SERVICE_IN_PARAMS_SUFFIX = "_InputParams";
+
+ public static final String SERVICE_OUT_PARAMS_SUFFIX = "_OutputParams";
+
+ public static final String SERVICE_TMP_DIR = "AFAC_TMP_DIR";
+
+ public static final String SERVICE_INPUT_MESSAGE_NAME = "AFAC_INPUT_MESSAGE_NAME";
+
+ public static final String HOST = "host";
+
+ public static final String UTF8 = "UTF-8";
+
+ public static final String LOCALHOST = "localhost";
+
+ public static interface InbuitOperations {
+ public static final String OP_KILL = "Kill";
+
+ public static final String OP_PING = "Ping";
+
+ public static final String OP_SHUTDOWN = "Shutdown";
+ }
+
+ public static class Types {
+ public static final String TYPE_STRING = "String";
+
+ public static final String TYPE_INT = "Integer";
+
+ public static final String TYPE_FLOAT = "Float";
+
+ public static final String TYPE_DOUBLE = "Double";
+
+ public static final String TYPE_BOOLEAN = "Boolean";
+
+ public static final String TYPE_QNAME = "QName";
+
+ public static final String TYPE_URI = "URI";
+
+ public static final String TYPE_STRING_ARRAY = "StringArray";
+
+ public static final String TYPE_INT_ARRAY = "IntegerArray";
+
+ public static final String TYPE_FLAOT_ARRAY = "FloatArray";
+
+ public static final String TYPE_DOUBLE_ARRAY = "DoubleArray";
+
+ public static final String TYPE_BOOLEAN_ARRAY = "BooleanArray";
+
+ public static final String TYPE_QNAME_ARRAY = "QNameArray";
+
+ public static final String TYPE_URI_ARRAY = "URIArray";
+
+ public static final String TYPE_STDOUT = "StdOut";
+
+ public static final String TYPE_STDERRORs = "StdErr";
+
+ public static final String TYPE_DATAID = "DataID";
+
+ public static final String TYPE_DATAID_ARRAY = "DataIDArray";
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacWSDLException.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacWSDLException.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacWSDLException.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/GFacWSDLException.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,43 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+public class GFacWSDLException extends Exception {
+
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 3146697337237463348L;
+
+ public GFacWSDLException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public GFacWSDLException(String message) {
+ super(message);
+ }
+
+ public GFacWSDLException(Throwable cause) {
+ super(cause);
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/RoundTrip.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/RoundTrip.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/RoundTrip.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/RoundTrip.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,141 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlPullParserFactory;
+import org.xmlpull.v1.XmlSerializer;
+
+/**
+ * This sample demonstrates how to roundtrip XML document (roundtrip is not exact but infoset level)
+ */
+
+public class RoundTrip {
+ private final static String PROPERTY_XMLDECL_STANDALONE = "http://xmlpull.org/v1/doc/features.html#xmldecl-standalone";
+ private final static String PROPERTY_SERIALIZER_INDENTATION = "http://xmlpull.org/v1/doc/properties.html#serializer-indentation";
+ private XmlPullParser parser;
+ private XmlSerializer serializer;
+
+ private RoundTrip(XmlPullParser parser, XmlSerializer serializer) {
+ this.parser = parser;
+ this.serializer = serializer;
+ }
+
+ private void writeStartTag() throws XmlPullParserException, IOException {
+ // check for case when feature xml roundtrip is supported
+ // if (parser.getFeature (FEATURE_XML_ROUNDTRIP)) {
+ if (!parser.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES)) {
+ for (int i = parser.getNamespaceCount(parser.getDepth() - 1); i <= parser.getNamespaceCount(parser
+ .getDepth()) - 1; i++) {
+ serializer.setPrefix(parser.getNamespacePrefix(i), parser.getNamespaceUri(i));
+ }
+ }
+ serializer.startTag(parser.getNamespace(), parser.getName());
+ for (int i = 0; i < parser.getAttributeCount(); i++) {
+ serializer.attribute(parser.getAttributeNamespace(i), parser.getAttributeName(i),
+ parser.getAttributeValue(i));
+ }
+ // serializer.closeStartTag();
+ }
+
+ private void writeToken(int eventType) throws XmlPullParserException, IOException {
+ switch (eventType) {
+ case XmlPullParser.START_DOCUMENT:
+ // use Boolean.TRUE to make it standalone
+ Boolean standalone = (Boolean) parser.getProperty(PROPERTY_XMLDECL_STANDALONE);
+ serializer.startDocument(parser.getInputEncoding(), standalone);
+ break;
+ case XmlPullParser.END_DOCUMENT:
+ serializer.endDocument();
+ break;
+ case XmlPullParser.START_TAG:
+ writeStartTag();
+ break;
+ case XmlPullParser.END_TAG:
+ serializer.endTag(parser.getNamespace(), parser.getName());
+ break;
+ case XmlPullParser.IGNORABLE_WHITESPACE:
+ // comment it to remove ignorable whtespaces from XML infoset
+ String s = parser.getText();
+ serializer.ignorableWhitespace(s);
+ break;
+ case XmlPullParser.TEXT:
+ serializer.text(parser.getText());
+ break;
+ case XmlPullParser.ENTITY_REF:
+ serializer.entityRef(parser.getName());
+ break;
+ case XmlPullParser.CDSECT:
+ serializer.cdsect(parser.getText());
+ break;
+ case XmlPullParser.PROCESSING_INSTRUCTION:
+ serializer.processingInstruction(parser.getText());
+ break;
+ case XmlPullParser.COMMENT:
+ serializer.comment(parser.getText());
+ break;
+ case XmlPullParser.DOCDECL:
+ serializer.docdecl(parser.getText());
+ break;
+ }
+ }
+
+ private void roundTrip() throws XmlPullParserException, IOException {
+ parser.nextToken(); // read first token
+ writeToken(XmlPullParser.START_DOCUMENT); // write optional XMLDecl if
+ // present
+ while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
+ writeToken(parser.getEventType());
+ parser.nextToken();
+ }
+ writeToken(XmlPullParser.END_DOCUMENT);
+ }
+
+ public static void roundTrip(Reader reader, Writer writer, String indent) throws XmlPullParserException,
+ IOException {
+ XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
+ factory.setNamespaceAware(true);
+ XmlPullParser pp = factory.newPullParser();
+ pp.setInput(reader);
+ XmlSerializer serializer = factory.newSerializer();
+ serializer.setOutput(writer);
+ if (indent != null) {
+ serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
+ }
+ (new RoundTrip(pp, serializer)).roundTrip();
+ }
+
+ public static void main(String[] args) throws Exception {
+ String XML = "<test><foo>fdf</foo></test>";
+ Reader r = new StringReader(XML);
+ Writer w = new StringWriter();
+ roundTrip(r, w, " ");
+ System.out.println("indented XML=" + w);
+ }
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/TypesGenerator.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/TypesGenerator.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/TypesGenerator.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/TypesGenerator.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,395 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Vector;
+
+import javax.wsdl.Definition;
+import javax.wsdl.Types;
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.schemas.gfac.InputParameterType;
+import org.apache.airavata.schemas.gfac.OutputParameterType;
+import org.apache.airavata.schemas.gfac.ServiceDescriptionType;
+import org.apache.derby.iapi.sql.ParameterValueSet;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import com.ibm.wsdl.extensions.schema.SchemaImpl;
+
+public class TypesGenerator implements WSDLConstants {
+ private static final String ENDPOINT_REFERENCE_TYPE = "EndpointReferenceType";
+
+ public static Types addTypes(Definition def, DOMImplementation dImpl, ServiceDescriptionType serviceDesc,
+ String typens, String globalTypens) {
+ ArrayList<Element> schemaTable = new ArrayList<Element>();
+ Vector complexTypes = new Vector();
+ HashMap<String, String> knownTypes = new HashMap<String, String>();
+
+ Element documentation = null;
+
+ Document doc = dImpl.createDocument(typens, SCHEMA, null);
+
+ Element schema = doc.createElementNS(XSD_NAMESPACE, "schema");
+ // Element schema = doc.getDocumentElement();
+ schema.setAttribute(TARGET_NAMESPACE, typens);
+ schema.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.w3.org/2001/XMLSchema");
+ // schema.setAttribute(XMLNS,
+ // XSD_NAMESPACE);
+ schema.setAttribute(ELEMENT_FORM_DEFAULT, UNQUALIFIED);
+
+ Element globalSchema = doc.createElementNS(XSD_NAMESPACE, "schema");
+ // Element globalSchema = doc.getDocumentElement();
+ globalSchema.setAttribute(TARGET_NAMESPACE, globalTypens);
+ globalSchema.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.w3.org/2001/XMLSchema");
+ // globalSchema.setAttribute(XMLNS,
+ // XSD_NAMESPACE);
+ globalSchema.setAttribute(ELEMENT_FORM_DEFAULT, UNQUALIFIED);
+
+ Types types = def.createTypes();
+
+ InputParameterType[] inputParams = serviceDesc.getInputParametersArray();
+ Vector inParamNames = new Vector();
+ Vector inParamDesc = new Vector();
+ Vector inParamTypes = new Vector();
+
+ for (int k = 0; k < inputParams.length; ++k) {
+ inParamNames.add(inputParams[k].getParameterName());
+ inParamDesc.add(inputParams[k].getParameterDescription());
+ inParamTypes.add(inputParams[k].getParameterType().getType().toString());
+ inputParams[k].getParameterValueArray();
+ }
+
+ OutputParameterType[] outputParams = serviceDesc.getOutputParametersArray();
+ Vector outParamNames = new Vector();
+ Vector outParamDesc = new Vector();
+ Vector outParamTypes = new Vector();
+
+ for (int k = 0; k < outputParams.length; ++k) {
+ outParamNames.add(outputParams[k].getParameterName());
+ outParamDesc.add(outputParams[k].getParameterDescription());
+ outParamTypes.add(outputParams[k].getParameterType().getType().toString());
+ }
+
+ String methodName = serviceDesc.getPortType().getMethod().getMethodName();
+ WSDLMessageBean wsdlMsgBean = new WSDLMessageBean();
+ wsdlMsgBean.setNamespace(typens);
+ // Set the method name in the message object
+ wsdlMsgBean.setMethodName(methodName);
+
+ // === write all the input parameters ========
+ // Input message name
+ String inputMessageName = methodName + GFacSchemaConstants.SERVICE_IN_PARAMS_SUFFIX;
+
+ // Set the input message name in the message object
+ wsdlMsgBean.setInElementName(inputMessageName);
+
+ // local data types
+ Element wsdlInputParams = doc.createElement("element");
+ String inputElementName = methodName + GFacSchemaConstants.SERVICE_IN_PARAMS_SUFFIX;
+ String inputParametersType = methodName + GFacSchemaConstants.SERVICE_INPUT_PARAMS_TYPE_SUFFIX;
+
+ wsdlInputParams.setAttribute("name", inputElementName);
+ wsdlInputParams.setAttribute("type", TYPENS + ":" + inputParametersType);
+
+ schema.appendChild(wsdlInputParams);
+ // local data types
+
+ wsdlMsgBean.setInMsgParamNames(inParamNames);
+ wsdlMsgBean.setInMsgParamTypes(inParamTypes);
+
+ Element first = doc.createElement(COMPLEX_TYPE);
+ first.setAttribute("name", inputParametersType);
+
+ Element sequence = doc.createElement("sequence");
+
+ for (int j = 0; j < inParamNames.size(); ++j) {
+ Element elem = doc.createElement("element");
+ String paramName = (String) inParamNames.get(j);
+ paramName = paramName.replaceAll(HYPHEN, HYPHEN_REPLACEMENT);
+ elem.setAttribute("name", paramName);
+ String dataType = (String) inParamTypes.get(j);
+
+ if (dataType.equals("String")) {
+ elem.setAttribute("type", XSD_STRING_TYPE);
+ } else if (dataType.equals("Integer")) {
+ elem.setAttribute("type", "xsd:int");
+ } else if (dataType.equals("Float")) {
+ elem.setAttribute("type", "xsd:float");
+ } else if (dataType.equals("Double")) {
+ elem.setAttribute("type", "xsd:double");
+ } else if (dataType.equals("Boolean")) {
+ elem.setAttribute("type", "xsd:boolean");
+ } else if (dataType.equals("QName")) {
+ elem.setAttribute("type", "xsd:QName");
+ } else if (dataType.equals("URI")) {
+ elem.setAttribute("type", "xsd:anyURI");
+ }
+ // schemas for complex types will be written later
+ else if (dataType.equals("StringArray") || dataType.equals("IntegerArray") || dataType.equals("FloatArray")
+ || dataType.equals("DoubleArray") || dataType.equals("BooleanArray")
+ || dataType.equals("QNameArray") || dataType.equals("HostName")
+ || dataType.equals(GFacSchemaConstants.Types.TYPE_URI_ARRAY)
+ || dataType.equals(GFacSchemaConstants.Types.TYPE_DATAID)) {
+ elem.setAttribute("type", GLOBAL_TYPENS + ":" + dataType + "Type");
+ if (!complexTypes.contains(dataType)) {
+ complexTypes.add(dataType);
+ }
+ } else if (dataType.equals(GFacSchemaConstants.Types.TYPE_DATAID_ARRAY)) {
+ elem.setAttribute("type", GLOBAL_TYPENS + ":" + dataType + "Type");
+ if (!complexTypes.contains(GFacSchemaConstants.Types.TYPE_DATAID_ARRAY)) {
+ complexTypes.add(GFacSchemaConstants.Types.TYPE_DATAID_ARRAY);
+ }
+ if (!complexTypes.contains(GFacSchemaConstants.Types.TYPE_DATAID)) {
+ complexTypes.add(GFacSchemaConstants.Types.TYPE_DATAID);
+ }
+ } else if (dataType.equals("StringEnum") || dataType.equals("IntegerEnum") || dataType.equals("FloatEnum")
+ || dataType.equals("DoubleEnum")) {
+ elem.setAttribute("type", TYPENS + ":" + methodName + "_" + paramName + "_" + dataType + "Type");
+ } else if (dataType.equals(ENDPOINT_REFERENCE_TYPE)) {
+ if (!knownTypes.containsKey(ENDPOINT_REFERENCE_TYPE)) {
+ schemaTable.add(createAddressingSchema(doc));
+ knownTypes.put(ENDPOINT_REFERENCE_TYPE, ENDPOINT_REFERENCE_TYPE);
+ }
+ elem.setAttribute("type", WSDLGenerator.WSA_PREFIX + ":" + ENDPOINT_REFERENCE_TYPE);
+ }
+
+ Element annotation = doc.createElement(ANNOTATION);
+
+ // TODO create Metadata
+
+ WSDLGenerator.createMetadata(inputParams[j], doc, annotation);
+
+ documentation = doc.createElement(DOCUMENTATION);
+ documentation.appendChild(doc.createTextNode((String) inParamDesc.get(j)));
+ annotation.appendChild(documentation);
+ elem.appendChild(annotation);
+ sequence.appendChild(elem);
+ } // end for inParams
+
+ first.appendChild(sequence);
+ schema.appendChild(first);
+
+ // write the enumeration types
+ for (int j = 0; j < inParamNames.size(); ++j) {
+ String dataType = (String) inParamTypes.get(j);
+ if (dataType.equals("StringEnum") || dataType.equals("IntegerEnum") || dataType.equals("FloatEnum")
+ || dataType.equals("DoubleEnum")) {
+ String paramName = (String) inParamNames.get(j);
+ String[] paramValues = serviceDesc.getInputParametersArray(j).getParameterValueArray();
+ if (paramValues == null)
+ continue;
+ Element elem = doc.createElement(SIMPLE_TYPE);
+ elem.setAttribute("name", methodName + "_" + paramName + "_" + dataType + "Type");
+
+ for (int k = 0; k < paramValues.length; ++k) {
+ documentation = doc.createElement(DOCUMENTATION);
+ // documentation.setAttribute(XML_LANG,
+ // ENGLISH);
+
+ Element value = doc.createElement("value");
+ value.appendChild(doc.createTextNode(paramValues[k]));
+ documentation.appendChild(value);
+ elem.appendChild(documentation);
+ }
+
+ Element restriction = doc.createElement("restriction");
+ if (dataType.equals("StringEnum")) {
+ restriction.setAttribute("base", "xsd:string");
+ } else if (dataType.equals("IntegerEnum")) {
+ restriction.setAttribute("base", "xsd:int");
+ } else if (dataType.equals("FloatEnum")) {
+ restriction.setAttribute("base", "xsd:float");
+ } else if (dataType.equals("DoubleEnum")) {
+ restriction.setAttribute("base", "xsd:double");
+ }
+ for (int k = 0; k < paramValues.length; ++k) {
+ Element enumeration = doc.createElement("enumeration");
+ enumeration.setAttribute("value", paramValues[k]);
+ restriction.appendChild(enumeration);
+ }
+ elem.appendChild(restriction);
+ schema.appendChild(elem);
+ }
+ }
+
+ // ====== write the output parameters ==============
+ // Output message name
+ if (outputParams.length > 0) {
+ String outputMessageName = methodName + GFacSchemaConstants.SERVICE_OUT_PARAMS_SUFFIX;
+ // Set the output message name in the message object
+ wsdlMsgBean.setOutElementName(outputMessageName);
+ Element wsdlOutputParams = doc.createElement("element");
+ String outputElementName = methodName + GFacSchemaConstants.SERVICE_OUT_PARAMS_SUFFIX;
+ String outputParametersType = methodName + GFacSchemaConstants.SERVICE_OUTPUT_PARAMS_TYPE_SUFFIX;
+ wsdlOutputParams.setAttribute("name", outputElementName);
+ wsdlOutputParams.setAttribute("type", TYPENS + ":" + outputParametersType);
+ schema.appendChild(wsdlOutputParams);
+ wsdlMsgBean.setOutMsgParamNames(outParamNames);
+ wsdlMsgBean.setOutMsgParamTypes(outParamTypes);
+
+ // Now add the output parameters
+ first = doc.createElement(COMPLEX_TYPE);
+ first.setAttribute("name", outputParametersType);
+ sequence = doc.createElement("sequence");
+
+ for (int j = 0; j < outParamNames.size(); ++j) {
+ Element elem = doc.createElement("element");
+ elem.setAttribute("name", (String) outParamNames.get(j));
+ String dataType = (String) outParamTypes.get(j);
+
+ if (dataType.equals("String") || dataType.equals("StdOut") || dataType.equals("StdErr")) {
+ elem.setAttribute("type", XSD_STRING_TYPE);
+ } else if (dataType.equals("Integer")) {
+ elem.setAttribute("type", "xsd:int");
+ } else if (dataType.equals("Float")) {
+ elem.setAttribute("type", "xsd:float");
+ } else if (dataType.equals("Double")) {
+ elem.setAttribute("type", "xsd:double");
+ } else if (dataType.equals("Boolean")) {
+ elem.setAttribute("type", "xsd:boolean");
+ } else if (dataType.equals("URI")) {
+ elem.setAttribute("type", "xsd:anyURI");
+ } else if (dataType.equals("QName")) {
+ elem.setAttribute("type", "xsd:QName");
+ } else if (dataType.equals("StringArray") || dataType.equals("IntegerArray")
+ || dataType.equals("FloatArray") || dataType.equals("DoubleArray")
+ || dataType.equals("BooleanArray") || dataType.equals("QNameArray")
+ || dataType.equals("LEADFileID") || dataType.equals("LEADFileIDArray")
+ || dataType.equals(GFacSchemaConstants.Types.TYPE_DATAID)
+ || dataType.equals(GFacSchemaConstants.Types.TYPE_URI_ARRAY)) {
+ elem.setAttribute("type", GLOBAL_TYPENS + ":" + dataType + "Type");
+ if (!complexTypes.contains(dataType)) {
+ complexTypes.add(dataType);
+ }
+ } else if (dataType.equals(GFacSchemaConstants.Types.TYPE_DATAID_ARRAY)) {
+ elem.setAttribute("type", GLOBAL_TYPENS + ":" + dataType + "Type");
+ if (!complexTypes.contains(GFacSchemaConstants.Types.TYPE_DATAID_ARRAY)) {
+ complexTypes.add(GFacSchemaConstants.Types.TYPE_DATAID_ARRAY);
+ }
+ if (!complexTypes.contains(GFacSchemaConstants.Types.TYPE_DATAID)) {
+ complexTypes.add(GFacSchemaConstants.Types.TYPE_DATAID);
+ }
+ }
+
+ // Create an annotation
+ Element annotation = doc.createElement(ANNOTATION);
+ WSDLGenerator.createMetadata(serviceDesc.getOutputParametersArray(j), doc, annotation);
+ documentation = doc.createElement(DOCUMENTATION);
+ documentation.appendChild(doc.createTextNode((String) outParamDesc.get(j)));
+ annotation.appendChild(documentation);
+ elem.appendChild(annotation);
+ sequence.appendChild(elem);
+
+ } // end for outParamNames.size()
+ }
+
+ first.appendChild(sequence);
+ schema.appendChild(first);
+
+ // write the schemas for the complex types in the input and output
+ // parameters
+
+ for (int i = 0; i < complexTypes.size(); ++i) {
+ Element wsdlFirstElement = doc.createElement(COMPLEX_TYPE);
+ String dataType = (String) complexTypes.get(i);
+ first.setAttribute("name", dataType + "Type");
+ Element wsdlSequence = doc.createElement("sequence");
+ Element elem = doc.createElement("element");
+ elem.setAttribute("name", GFacSchemaConstants.ARRAY_VALUE);
+
+ if (dataType.equals("StringArray")) {
+ elem.setAttribute("type", "xsd:string");
+ } else if (dataType.equals("IntegerArray")) {
+ elem.setAttribute("type", "xsd:int");
+ } else if (dataType.equals("FloatArray")) {
+ elem.setAttribute("type", "xsd:float");
+ } else if (dataType.equals("DoubleArray")) {
+ elem.setAttribute("type", "xsd:double");
+ } else if (dataType.equals("BooleanArray")) {
+ elem.setAttribute("type", "xsd:boolean");
+ } else if (dataType.equals("QNameArray")) {
+ elem.setAttribute("type", "xsd:anyQName");
+ } else {
+ continue;
+ }
+
+ elem.setAttribute("minOccurs", "0");
+ elem.setAttribute("maxOccurs", "unbounded");
+ wsdlSequence.appendChild(elem);
+ first.appendChild(wsdlSequence);
+ globalSchema.appendChild(first);
+ }
+
+ // types.setDocumentationElement(schema);
+ SchemaImpl schemaImpl = new SchemaImpl();
+ // SchemaImportImpl schemaimport = new SchemaImportImpl();
+ // schemaimport.setNamespaceURI("http://www.extreme.indiana.edu/lead/xsd");
+ // schemaimport.setSchemaLocationURI("http://www.extreme.indiana.edu/gfac/gfac-simple-types.xsd");
+ // schemaImpl.addImport(schemaimport);
+
+ Element importEle = doc.createElement("import");
+ importEle.setAttribute("namespace", "http://www.extreme.indiana.edu/lead/xsd");
+ importEle.setAttribute("schemaLocation", "http://www.extreme.indiana.edu/gfac/gfac-simple-types.xsd");
+ schema.insertBefore(importEle, schema.getFirstChild());
+
+ // schema.appendChild();
+
+ schemaImpl.setElement(schema);
+ schemaImpl.setElementType(new QName("http://www.w3.org/2001/XMLSchema", "schema"));
+
+ SchemaImpl globalSchemaImpl = new SchemaImpl();
+ globalSchemaImpl.setElement(globalSchema);
+ globalSchemaImpl.setElementType(new QName("http://www.w3.org/2001/XMLSchema", "schema"));
+ globalSchemaImpl.getElement().setAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
+
+ types.addExtensibilityElement(schemaImpl);
+
+ return types;
+ }
+
+ public static Element createAddressingSchema(Document doc) {
+ Element wsAddressing = doc.createElementNS(XSD_NAMESPACE, "schema");
+ // Element globalSchema = doc.getDocumentElement();
+ wsAddressing.setAttribute(TARGET_NAMESPACE, "http://www.w3.org/2005/08/addressing");
+ wsAddressing.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.w3.org/2001/XMLSchema");
+ wsAddressing.setAttribute("attributeFormDefault", "unqualified");
+ wsAddressing.setAttribute(ELEMENT_FORM_DEFAULT, "qualified");
+
+ Element type = doc.createElement("complexType");
+ type.setAttribute("name", ENDPOINT_REFERENCE_TYPE);
+
+ Element sequence = doc.createElement("sequence");
+ Element any = doc.createElement("any");
+ any.setAttribute("namespace", "##any");
+ any.setAttribute("minOccurs", "0");
+
+ sequence.appendChild(any);
+ type.appendChild(sequence);
+ wsAddressing.appendChild(type);
+
+ return wsAddressing;
+ }
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLConstants.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLConstants.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLConstants.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLConstants.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,104 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+public interface WSDLConstants {
+ // For wsdl generation
+ public final static String TYPENS = "typens";
+
+ public final static String GLOBAL_TYPENS = "globalTypens";
+
+ public final static String WSDLNS = "wsdlns";
+
+ public final static String SOAP = "soap";
+
+ public final static String XSD = "xsd";
+
+ public final static String XMLNS = "xmlns";
+
+ public final static String TARGET_NAMESPACE = "targetNamespace";
+
+ public final static String SCHEMA = "schema";
+
+ public final static String ELEMENT_FORM_DEFAULT = "elementFormDefault";
+
+ public final static String UNQUALIFIED = "unqualified";
+
+ public final static String ANNOTATION = "annotation";
+
+ public final static String WSDL_DOCUMENTATION = "wsdl:documentation";
+
+ public final static String DOCUMENTATION = "documentation";
+
+ public static final String SERVICE_QNAME = "SERVICE_QNAME";
+
+ public final static String AWSDL = "AWSDL";
+
+ public static final String WSDL_PORT_SUFFIX = "_Port";
+
+ public static final String WSDL_SOAP_BINDING_SUFFIX = "_SoapBinding";
+
+ public static final String LITERAL = "literal";
+
+ public static final String DOCUMENT = "document";
+
+ public static final String XSD_STRING_TYPE = "xsd:string";
+
+ public static final String COMPLEX_TYPE = "complexType";
+
+ public static final String SIMPLE_TYPE = "simpleType";
+
+ public static final String PART_NAME = "parameters";
+
+ public final static String WSDL = "WSDL";
+
+ public final static String WSDL_QNAME = "WSDL_QNAME";
+
+ public static final String XSD_NAMESPACE = "http://www.w3.org/2001/XMLSchema";
+
+ public static final String WSDL_NAMEPSPACE = "http://schemas.xmlsoap.org/wsdl/";
+
+ public static final String SOAP_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/soap/";
+
+ public static final String SOAP_HTTP_NAMESPACE = "http://schemas.xmlsoap.org/soap/http";
+
+ public static final String WSP_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+
+ public static final String WSPE_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy/encoding";
+
+ public static final String WSA_NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
+
+ public static final String WSU_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
+
+ public static final String SP_NAMESPACE = "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";
+
+ public static final String WSS10_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
+
+ public static final String WST_NAMESPACE = "http://schemas.xmlsoap.org/ws/2005/02/trust";
+
+ public static final String SERVICE_LOCATION = "ServiceLocation";
+
+ public static final String HYPHEN_REPLACEMENT = "GFAC_MINUS_REPLACEMENT";
+
+ public static final String HYPHEN = "-";
+
+}
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGenerator.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGenerator.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGenerator.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGenerator.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,586 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Random;
+import java.util.UUID;
+import java.util.Vector;
+
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Definition;
+import javax.wsdl.OperationType;
+import javax.wsdl.Types;
+import javax.wsdl.WSDLException;
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+import javax.wsdl.extensions.soap.SOAPOperation;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLWriter;
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.schemas.gfac.InputParameterType;
+import org.apache.airavata.schemas.gfac.MethodType;
+import org.apache.airavata.schemas.gfac.OutputParameterType;
+import org.apache.airavata.schemas.gfac.PortTypeType;
+import org.apache.airavata.schemas.gfac.ServiceDescriptionType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Comment;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.builder.XmlInfosetBuilder;
+
+import xsul.XmlConstants;
+
+import com.ibm.wsdl.BindingInputImpl;
+import com.ibm.wsdl.BindingOutputImpl;
+import com.ibm.wsdl.InputImpl;
+import com.ibm.wsdl.MessageImpl;
+import com.ibm.wsdl.OperationImpl;
+import com.ibm.wsdl.OutputImpl;
+import com.ibm.wsdl.PartImpl;
+import com.ibm.wsdl.PortImpl;
+import com.ibm.wsdl.PortTypeImpl;
+import com.ibm.wsdl.ServiceImpl;
+import com.ibm.wsdl.extensions.soap.SOAPAddressImpl;
+import com.ibm.wsdl.extensions.soap.SOAPBindingImpl;
+import com.ibm.wsdl.extensions.soap.SOAPBodyImpl;
+import com.ibm.wsdl.extensions.soap.SOAPOperationImpl;
+
+public class WSDLGenerator implements WSDLConstants {
+ public static final String WSA_PREFIX = "wsa";
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ public Hashtable generateWSDL(String serviceLocation, QName wsdlQName_, String security,
+ ServiceDescriptionType serviceDesc, boolean abstractWSDL) throws GFacWSDLException {
+ Hashtable table = new Hashtable();
+ QName wsdlQName = null;
+ String wsdlString = null;
+ String serviceName = serviceDesc.getService().getServiceName().getStringValue();
+ String nameSpaceURI = serviceDesc.getService().getServiceName().getTargetNamespace();
+ QName serviceQName = new QName(nameSpaceURI, serviceName);
+
+ if (wsdlQName_ != null && !abstractWSDL) {
+ wsdlQName = wsdlQName_;
+ } else if (wsdlQName_ == null && !abstractWSDL) {
+ String date = (new Date()).toString();
+ date = date.replaceAll(" ", "_");
+ date = date.replaceAll(":", "_");
+ Random rand = new Random();
+ int rdint = rand.nextInt(1000000);
+ wsdlQName = new QName(nameSpaceURI, serviceName + "_" + date + "_" + rdint);
+ }
+
+ PortTypeType portType = serviceDesc.getPortType();
+ MethodType method = portType.getMethod();
+ QName portTypeName = serviceQName;
+
+ String portName = portTypeName.getLocalPart();
+
+ try {
+ WSDLFactory fac = WSDLFactory.newInstance();
+ WSDLWriter wsWriter = fac.newWSDLWriter();
+
+ // =========== start of wsdl definition ===========
+ Definition def = fac.newDefinition();
+
+ String typens = nameSpaceURI + "/" + portName + "/" + "xsd";
+ String globalTypens = nameSpaceURI + "/" + "xsd";
+
+ if (abstractWSDL) {
+ def.setQName(serviceQName);
+ log.info("Service QName set to = " + serviceQName);
+ } else {
+ def.setQName(wsdlQName);
+ log.info("WSDL QName set to = " + wsdlQName);
+ }
+
+ // namespaces ===========
+ def.setTargetNamespace(nameSpaceURI);
+ def.addNamespace(WSDLNS, nameSpaceURI);
+ def.addNamespace(TYPENS, typens);
+ def.addNamespace(GLOBAL_TYPENS, globalTypens);
+ def.addNamespace(SOAP, SOAP_NAMESPACE);
+ def.addNamespace(XSD, XSD_NAMESPACE);
+ def.addNamespace(WSA_PREFIX, "http://www.w3.org/2005/08/addressing");
+
+ if (GFacSchemaConstants.TRANSPORT_LEVEL.equals(security)
+ || GFacSchemaConstants.MESSAGE_SIGNATURE.equals(security)) {
+ def.addNamespace(WSA_PREFIX, WSA_NAMESPACE);
+ def.addNamespace("wsp", WSP_NAMESPACE);
+ def.addNamespace("wsu", WSU_NAMESPACE);
+ def.addNamespace("wspe", WSPE_NAMESPACE);
+ def.addNamespace("sp", SP_NAMESPACE);
+ def.addNamespace("wss10", WSS10_NAMESPACE);
+
+ def.addNamespace("sp", SP_NAMESPACE);
+ def.addNamespace("wst", WST_NAMESPACE);
+ }
+ // =========== end of wsdl namespaces ===========
+
+ javax.xml.parsers.DocumentBuilderFactory domfactory = javax.xml.parsers.DocumentBuilderFactory
+ .newInstance();
+ javax.xml.parsers.DocumentBuilder builder = null;
+
+ try {
+ builder = domfactory.newDocumentBuilder();
+ } catch (javax.xml.parsers.ParserConfigurationException e) {
+ throw new GFacWSDLException("Parser configuration exception: " + e.getMessage());
+ }
+
+ DOMImplementation dImpl = builder.getDOMImplementation();
+
+ String policyID = portName + "_Policy";
+ String inputPolicyID = portName + "_operationPolicy";
+
+ UnknownExtensibilityElement serviceLevelPolicRef = null;
+ UnknownExtensibilityElement opLevelPolicRef = null;
+
+ String namespace = GFacSchemaConstants.GFAC_NAMESPACE;
+ Document doc = dImpl.createDocument(namespace, "factoryServices", null);
+
+ String description = serviceDesc.getService().getServiceDescription();
+ if (description != null) {
+ Element documentation = doc.createElementNS("http://schemas.xmlsoap.org/wsdl/", "wsdl:documentation");
+ documentation.appendChild(doc.createTextNode(description));
+ def.setDocumentationElement(documentation);
+ }
+
+ if (GFacSchemaConstants.TRANSPORT_LEVEL.equals(security)) {
+ def.addExtensibilityElement(createTransportLevelPolicy(dImpl, policyID));
+ serviceLevelPolicRef = createWSPolicyRef(dImpl, policyID);
+ } else if (GFacSchemaConstants.MESSAGE_SIGNATURE.equals(security)) {
+ def.addExtensibilityElement(WSPolicyGenerator.createServiceLevelPolicy(dImpl, policyID));
+ serviceLevelPolicRef = createWSPolicyRef(dImpl, policyID);
+ opLevelPolicRef = createWSPolicyRef(dImpl, inputPolicyID);
+ }
+
+ // Create types
+ Types types = ((TypesGenerator) TypesGenerator.addTypes(def, dImpl, serviceDesc, typens, globalTypens))
+ .addTypes(def, dImpl, serviceDesc, typens, globalTypens);
+ def.setTypes(types);
+
+ // if(!abstractWSDL)
+ // {
+ // table = createMessageTable(serviceDesc, typens, operation);
+ // }
+
+ // Create port types (only first port type)
+ PortTypeImpl wsdlPortType = addPortTypes(def, dImpl, portType, serviceQName);
+ Binding binding = addBinding(def, nameSpaceURI, wsdlPortType, serviceLevelPolicRef, dImpl);
+
+ String methodDesc = serviceDesc.getPortType().getMethod().getMethodDescription();
+ String methodName = serviceDesc.getPortType().getMethod().getMethodName();
+ OutputParameterType[] outputParams = serviceDesc.getOutputParametersArray();
+
+ OperationImpl operation = addOperation(def, dImpl, methodName, methodDesc, typens, outputParams);
+ wsdlPortType.addOperation(operation);
+
+ if (!abstractWSDL) {
+ UnknownExtensibilityElement wsInPolicyRef = null;
+ UnknownExtensibilityElement wsOutPolicyRef = null;
+
+ BindingInputImpl bindingInput = addBindingInput(def, methodName, wsInPolicyRef);
+ BindingOutputImpl bindingOutput = addBindingOutput(def, methodName, outputParams, wsOutPolicyRef);
+ BindingOperation bindingOperation = addBindingOperation(def, operation, dImpl);
+ bindingOperation.setBindingInput(bindingInput);
+ bindingOperation.setBindingOutput(bindingOutput);
+ binding.addBindingOperation(bindingOperation);
+
+ if (opLevelPolicRef != null) {
+ binding.addExtensibilityElement(opLevelPolicRef);
+ }
+
+ }
+ def.addPortType(wsdlPortType);
+
+ // =========== end of wsdl binding ===========
+
+ // FIXME: This is done as factory information is not needed
+ // if(abstractWSDL)
+ // {
+ //
+ //
+ // Element factoryServices = doc.createElement("n:factoryServices");
+ // factoryServices.setAttribute("xmlns:n", namespace);
+ // Element factoryService = doc.createElement("n:factoryService");
+ // factoryService.setAttribute("location",
+ // "http://rainier.extreme.indiana.edu:12345");
+ // factoryService.setAttribute("portType", "n:GenericFactory");
+ // factoryService.setAttribute("operation", "n:CreateService");
+ // factoryServices.appendChild(factoryService);
+ // UnknownExtensibilityElement elem = new
+ // UnknownExtensibilityElement();
+ // elem.setElement(factoryServices);
+ // def.addExtensibilityElement(elem);
+ // }
+
+ if (!abstractWSDL) {
+ def.addBinding(binding);
+ ServiceImpl service = (ServiceImpl) def.createService();
+ service.setQName(wsdlQName);
+
+ PortImpl port = (PortImpl) def.createPort();
+ port.setName(wsdlQName.getLocalPart() + WSDL_PORT_SUFFIX);
+ port.setBinding(binding);
+ service.addPort(port);
+
+ SOAPAddressImpl soapAddress = new SOAPAddressImpl();
+ soapAddress.setLocationURI(serviceLocation);
+ port.addExtensibilityElement(soapAddress);
+ def.addService(service);
+ }
+
+ if (!abstractWSDL) {
+ table.put(WSDL_QNAME, wsdlQName);
+ }
+
+ table.put(SERVICE_QNAME, serviceQName);
+
+ ByteArrayOutputStream bs = new ByteArrayOutputStream();
+ wsWriter.writeWSDL(def, bs);
+ wsdlString = bs.toString();
+ } catch (WSDLException e) {
+ throw new GFacWSDLException("Error generating WSDL: " + e.getMessage());
+ }
+
+ Reader reader = new StringReader(wsdlString);
+ Writer writer = new StringWriter();
+ try {
+ RoundTrip.roundTrip(reader, writer, " ");
+ } catch (XmlPullParserException e) {
+ throw new GFacWSDLException(e);
+ } catch (IOException e) {
+ throw new GFacWSDLException(e);
+ }
+ wsdlString = writer.toString();
+
+ if (abstractWSDL) {
+ table.put(AWSDL, wsdlString);
+ } else {
+ table.put(WSDL, wsdlString);
+ }
+ return table;
+ }
+
+ private UnknownExtensibilityElement createWSPolicyRef(DOMImplementation dImpl, String id) {
+ Document doc = dImpl.createDocument(WSP_NAMESPACE, "wsp:PolicyReference", null);
+ Element policyRef = doc.getDocumentElement();
+ policyRef.setAttribute("URI", "#" + id);
+ UnknownExtensibilityElement elem = new UnknownExtensibilityElement();
+ elem.setElement(policyRef);
+ elem.setElementType(new QName(WSP_NAMESPACE, "PolicyReference"));
+ return elem;
+ }
+
+ private UnknownExtensibilityElement createTransportLevelPolicy(DOMImplementation dImpl, String policyID) {
+ Document doc = dImpl.createDocument(WSP_NAMESPACE, "wsp:Policy", null);
+
+ Element policy = doc.getDocumentElement();
+ policy.setAttribute("wsu:Id", policyID);
+ Element exactlyOne = doc.createElement("wsp:ExactlyOne");
+ Element all = doc.createElement("wsp:All");
+
+ Element transportBinding = doc.createElement("sp:TransportBinding");
+ transportBinding.setAttribute("xmlns:sp", SP_NAMESPACE);
+ Element policy1 = doc.createElement("wsp:Policy");
+
+ Element transportToken = doc.createElement("sp:TransportToken");
+ Element policy2 = doc.createElement("wsp:Policy");
+ Element httpsToken = doc.createElement("sp:HttpsToken");
+ httpsToken.setAttribute("RequireClientCertificate", "true");
+ policy2.appendChild(httpsToken);
+ transportToken.appendChild(policy2);
+ policy1.appendChild(transportToken);
+
+ /*
+ * Element algorithmSuite = doc.createElement("sp:AlgorithmSuite"); Element policy3 =
+ * doc.createElement("wsp:Policy"); Element base256 = doc.createElement("sp:Base256");
+ * policy3.appendChild(base256); algorithmSuite.appendChild(policy3); policy1.appendChild(algorithmSuite);
+ *
+ *
+ * Element layout = doc.createElement("sp:Layout"); Element policy4 = doc.createElement("wsp:Policy"); Element
+ * lax = doc.createElement("sp:Lax"); policy4.appendChild(lax); layout.appendChild(policy4);
+ * policy1.appendChild(layout);
+ *
+ * Element includeTimestamp = doc.createElement("sp:includeTimestamp"); policy1.appendChild(includeTimestamp);
+ */
+
+ /*
+ * Element signedSupportingTokens = doc.createElement("sp:SignedSupportingTokens"); policy2 =
+ * doc.createElement("wsp:Policy"); Element usernameToken = doc.createElement("sp:UsernameToken");
+ * usernameToken.setAttribute("sp:IncludeToken",
+ * "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" );
+ * policy2.appendChild(usernameToken); signedSupportingTokens.appendChild(policy2);
+ * policy1.appendChild(signedSupportingTokens);
+ */
+
+ Element signedEndorsingSupportingTokens = doc.createElement("sp:SignedEndorsingSupportingTokens");
+ policy2 = doc.createElement("wsp:Policy");
+ Element x509V3Token = doc.createElement("sp:X509V3Token");
+ // x509V3Token.setAttribute("sp:IncludeToken",
+ // "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Once");
+ policy2.appendChild(x509V3Token);
+ signedEndorsingSupportingTokens.appendChild(policy2);
+ policy1.appendChild(signedEndorsingSupportingTokens);
+
+ transportBinding.appendChild(policy1);
+ all.appendChild(transportBinding);
+
+ /*
+ * Element wss10 = doc.createElement("sp:wss10"); Element requireSignatureConfirmation =
+ * doc.createElement("sp:RequireSignatureConfirmation"); wss10.appendChild(requireSignatureConfirmation);
+ * all.appendChild(wss10);
+ */
+
+ exactlyOne.appendChild(all);
+ policy.appendChild(exactlyOne);
+
+ UnknownExtensibilityElement elem = new UnknownExtensibilityElement();
+ elem.setElement(policy);
+ elem.setElementType(new QName(WSP_NAMESPACE, "wsp:Policy"));
+ return elem;
+ }
+
+ private PortTypeImpl addPortTypes(Definition def, DOMImplementation dImpl, PortTypeType portType, QName serviceQName) {
+ // create port type
+ PortTypeImpl wsdlPortType = (PortTypeImpl) def.createPortType();
+ wsdlPortType.setQName(serviceQName);
+ wsdlPortType.setUndefined(false);
+
+ // create documentation for this port type
+ Document doc = dImpl.createDocument(WSDL_NAMEPSPACE, WSDL_DOCUMENTATION, null);
+ Element documentation = doc.getDocumentElement();
+ documentation.appendChild(doc.createTextNode(portType.getPortDescription()));
+ wsdlPortType.setDocumentationElement(documentation);
+ return wsdlPortType;
+ }
+
+ private OperationImpl addOperation(Definition def, DOMImplementation dImpl, String methodName, String methodDesc,
+ String typens, OutputParameterType[] outputParameterTypes) {
+ OperationImpl operation = (OperationImpl) def.createOperation();
+ operation.setUndefined(false);
+ operation.setName(methodName);
+ if (outputParameterTypes.length == 0) {
+ operation.setStyle(OperationType.ONE_WAY);
+ } else {
+ operation.setStyle(OperationType.REQUEST_RESPONSE);
+ }
+
+ Document doc = dImpl.createDocument(WSDL_NAMEPSPACE, WSDL_DOCUMENTATION, null);
+ Element documentation = doc.createElement(WSDL_DOCUMENTATION);
+ documentation.appendChild(doc.createTextNode(methodDesc));
+ operation.setDocumentationElement(documentation);
+
+ MessageImpl inputMessage = (MessageImpl) def.createMessage();
+ String inputMessageName = methodName + GFacSchemaConstants.SERVICE_REQ_MSG_SUFFIX + "_" + UUID.randomUUID();
+
+ inputMessage.setQName(new QName(def.getTargetNamespace(), inputMessageName));
+ inputMessage.setUndefined(false);
+
+ PartImpl inPart = (PartImpl) def.createPart();
+ inPart.setName(PART_NAME);
+ String inputElementName = methodName + GFacSchemaConstants.SERVICE_IN_PARAMS_SUFFIX;
+ inPart.setElementName(new QName(typens, inputElementName));
+ inputMessage.addPart(inPart);
+
+ def.addMessage(inputMessage);
+ InputImpl ip = (InputImpl) def.createInput();
+ ip.setName(inputMessageName);
+ ip.setMessage(inputMessage);
+
+ operation.setInput(ip);
+
+ if (outputParameterTypes.length > 0) {
+ MessageImpl outputMessage = (MessageImpl) def.createMessage();
+ String outputMessageName = methodName + GFacSchemaConstants.SERVICE_RESP_MSG_SUFFIX + "_"
+ + UUID.randomUUID();
+ outputMessage.setQName(new QName(def.getTargetNamespace(), outputMessageName));
+ outputMessage.setUndefined(false);
+
+ PartImpl part = (PartImpl) def.createPart();
+ part.setName(PART_NAME);
+ String outputElementName = methodName + GFacSchemaConstants.SERVICE_OUT_PARAMS_SUFFIX;
+
+ part.setElementName(new QName(typens, outputElementName));
+ outputMessage.addPart(part);
+ def.addMessage(outputMessage);
+
+ OutputImpl op = (OutputImpl) def.createOutput();
+ op.setName(outputMessageName);
+ op.setMessage(outputMessage);
+ operation.setOutput(op);
+ }
+ return operation;
+ }
+
+ private BindingInputImpl addBindingInput(Definition def, String methodName, UnknownExtensibilityElement wsPolicyRef) {
+
+ BindingInputImpl bindingInput = (BindingInputImpl) def.createBindingInput();
+ bindingInput.setName(methodName + GFacSchemaConstants.SERVICE_REQ_MSG_SUFFIX);
+ if (wsPolicyRef != null) {
+ log.info("policy info is not null");
+ bindingInput.addExtensibilityElement(wsPolicyRef);
+ }
+ SOAPBodyImpl inputExtension = new SOAPBodyImpl();
+ inputExtension.setUse(LITERAL);
+ bindingInput.addExtensibilityElement(inputExtension);
+ return bindingInput;
+ }
+
+ private BindingOutputImpl addBindingOutput(Definition def, String methodName, OutputParameterType[] outputParams,
+ UnknownExtensibilityElement wsPolicyRef) {
+ // specify output only if there are output parameters
+ BindingOutputImpl bindingOutput = null;
+ if (outputParams.length > 0) {
+ bindingOutput = (BindingOutputImpl) def.createBindingOutput();
+ bindingOutput.setName(methodName + GFacSchemaConstants.SERVICE_RESP_MSG_SUFFIX);
+ if (wsPolicyRef != null) {
+ log.info("policy info is not null");
+ bindingOutput.addExtensibilityElement(wsPolicyRef);
+ }
+ SOAPBodyImpl outputExtension = new SOAPBodyImpl();
+ outputExtension.setUse(LITERAL);
+ bindingOutput.addExtensibilityElement(outputExtension);
+ }
+ return bindingOutput;
+ }
+
+ private BindingOperation addBindingOperation(Definition def, OperationImpl operation, DOMImplementation dImpl) {
+ BindingOperation bindingOperation = def.createBindingOperation();
+ bindingOperation.setName(operation.getName());
+ SOAPOperation soapOperation = new SOAPOperationImpl();
+ bindingOperation.addExtensibilityElement(soapOperation);
+ bindingOperation.setOperation(operation);
+
+ Document doc = dImpl.createDocument(WSP_NAMESPACE, "Misc", null);
+
+ UnknownExtensibilityElement exEle = new UnknownExtensibilityElement();
+ Element anonymousEle = doc.createElementNS("http://www.w3.org/2006/05/addressing/wsdl", "wsaw:Anonymous");
+ anonymousEle.appendChild(doc.createTextNode("optional"));
+ exEle.setElement(anonymousEle);
+ exEle.setElementType(new QName("http://www.w3.org/2006/05/addressing/wsdl", "wsaw:Anonymous"));
+ bindingOperation.addExtensibilityElement(exEle);
+ return bindingOperation;
+ }
+
+ private Binding addBinding(Definition def, String nameSpaceURI, PortTypeImpl portType,
+ UnknownExtensibilityElement wsPolicyRef, DOMImplementation dImpl) {
+ String portName = portType.getQName().getLocalPart();
+
+ Binding binding = def.createBinding();
+ binding.setQName(new QName(nameSpaceURI, portName + WSDL_SOAP_BINDING_SUFFIX));
+ binding.setUndefined(false);
+ binding.setPortType(portType);
+
+ SOAPBindingImpl soapBindingImpl = new SOAPBindingImpl();
+ soapBindingImpl.setStyle(DOCUMENT);
+ soapBindingImpl.setTransportURI(SOAP_HTTP_NAMESPACE);
+ binding.addExtensibilityElement(soapBindingImpl);
+ if (wsPolicyRef != null) {
+ log.info("policy info is not null");
+ binding.addExtensibilityElement(wsPolicyRef);
+ }
+
+ Document doc = dImpl.createDocument(WSP_NAMESPACE, "Misc", null);
+
+ UnknownExtensibilityElement exEle = new UnknownExtensibilityElement();
+ exEle.setElement(doc.createElementNS("http://www.w3.org/2006/05/addressing/wsdl", "wsaw:UsingAddressing"));
+ exEle.setElementType(new QName("http://www.w3.org/2006/05/addressing/wsdl", "wsaw:UsingAddressing"));
+ binding.addExtensibilityElement(exEle);
+
+ return binding;
+ }
+
+ public static void createMetadata(InputParameterType inparam, Document doc, Element annotation) {
+ if (inparam.getAnyMetadata() != null) {
+ unwrapMetadata(doc, annotation, (Element) inparam.getAnyMetadata());
+ }
+ }
+
+ public static void createMetadata(OutputParameterType outparam, Document doc, Element annotation) {
+ if (outparam.getAnyMetadata() != null) {
+ // GfacUtils.writeDOM((Element)outparam.getMetadata());
+ unwrapMetadata(doc, annotation, (Element) outparam.getAnyMetadata());
+ }
+ }
+
+ private static void unwrapMetadata(Document doc, Element annotation, Element base) {
+ Element appInfo = doc.createElementNS(XSD_NAMESPACE, "appinfo");
+ annotation.appendChild(appInfo);
+
+ NodeList childs = base.getChildNodes();
+ for (int i = 0; i < childs.getLength(); i++) {
+ if (childs.item(i) instanceof Element) {
+ appInfo.appendChild(cloneElement(doc, (Element) childs.item(i)));
+ }
+ }
+ }
+
+ private static Element cloneElement(Document doc, Element base) {
+ // Element copy = doc.createElementNS(tagretNamespace,prefix+ ":" +
+ // base.getLocalName());
+ Element copy = doc.createElementNS(base.getNamespaceURI(), base.getTagName());
+
+ NodeList nodes = base.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ switch (node.getNodeType()) {
+ case Node.COMMENT_NODE:
+ Comment comment = (Comment) node;
+ copy.appendChild(doc.createComment(comment.getData()));
+ break;
+ case Node.ELEMENT_NODE:
+ copy.appendChild(cloneElement(doc, (Element) node));
+ break;
+ case Node.ATTRIBUTE_NODE:
+ Attr attr = (Attr) node;
+ Attr attrCopy = doc.createAttributeNS(attr.getNamespaceURI(), attr.getPrefix() + ":" + attr.getName());
+ attrCopy.setValue(attr.getValue());
+ copy.appendChild(attrCopy);
+ break;
+ case Node.TEXT_NODE:
+ copy.appendChild(doc.createTextNode(((Text) node).getNodeValue()));
+ break;
+ default:
+ break;
+ }
+ }
+ return copy;
+
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGeneratorUtil.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGeneratorUtil.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGeneratorUtil.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLGeneratorUtil.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,53 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+import org.apache.airavata.schemas.gfac.InputParameterType;
+import org.apache.airavata.schemas.gfac.MethodType;
+import org.apache.airavata.schemas.gfac.PortTypeType;
+import org.apache.airavata.schemas.gfac.ServiceDescriptionType;
+
+public class WSDLGeneratorUtil {
+
+ public static MethodType findOperationFromServiceDesc(String methodName, ServiceDescriptionType serviceDescType)
+ throws GFacWSDLException {
+ PortTypeType portType = serviceDescType.getPortType();
+ if (serviceDescType.getPortType().getMethod().getMethodName().equals(methodName)) {
+ serviceDescType.getPortType().getMethod();
+ }
+
+ if (isInbuiltOperation(methodName)) {
+ MethodType builtInOperationType = portType.addNewMethod();
+ builtInOperationType.setMethodName(methodName);
+ return builtInOperationType;
+ }
+
+ throw new GFacWSDLException("Method name " + methodName + " not found");
+ }
+
+ public static boolean isInbuiltOperation(String name) {
+ return GFacSchemaConstants.InbuitOperations.OP_KILL.equals(name)
+ || GFacSchemaConstants.InbuitOperations.OP_PING.equals(name)
+ || GFacSchemaConstants.InbuitOperations.OP_SHUTDOWN.equals(name);
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLMessageBean.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLMessageBean.java?rev=1195343&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLMessageBean.java (added)
+++ incubator/airavata/trunk/modules/commons/gfac-schema/src/main/java/org/apache/airavata/commons/gfac/wsdl/WSDLMessageBean.java Mon Oct 31 06:04:40 2011
@@ -0,0 +1,211 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.airavata.commons.gfac.wsdl;
+
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+
+public class WSDLMessageBean {
+ private QName portType;
+ private String methodName;
+ private String namespace = null;
+
+ private String inElementName;
+ private Vector inMsgParamNames;
+ private Vector inMsgParamTypes;
+
+ private String outElementName;
+ private Vector outMsgParamNames;
+ private Vector outMsgParamTypes;
+
+ /**
+ * Sets OutMsgParamTypes
+ *
+ * @param OutMsgParamTypes
+ * a Vector
+ */
+ public void setOutMsgParamTypes(Vector outMsgParamTypes) {
+ this.outMsgParamTypes = outMsgParamTypes;
+ }
+
+ /**
+ * Returns OutMsgParamTypes
+ *
+ * @return a Vector
+ */
+ public Vector getOutMsgParamTypes() {
+ return outMsgParamTypes;
+ }
+
+ /**
+ * Sets Namespace
+ *
+ * @param Namespace
+ * a String
+ */
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ /**
+ * Returns Namespace
+ *
+ * @return a String
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * Sets InMsgParamTypes
+ *
+ * @param InMsgParamTypes
+ * a Vector
+ */
+ public void setInMsgParamTypes(Vector inMsgParamTypes) {
+ this.inMsgParamTypes = inMsgParamTypes;
+ }
+
+ /**
+ * Returns InMsgParamTypes
+ *
+ * @return a Vector
+ */
+ public Vector getInMsgParamTypes() {
+ return inMsgParamTypes;
+ }
+
+ /**
+ * Sets PortType
+ *
+ * @param PortType
+ * a QName
+ */
+ public void setPortType(QName portType) {
+ this.portType = portType;
+ }
+
+ /**
+ * Returns PortType
+ *
+ * @return a QName
+ */
+ public QName getPortType() {
+ return portType;
+ }
+
+ /**
+ * Sets OutputMessageParamNames
+ *
+ * @param OutputMessageParamNamesa
+ * Vector
+ */
+ public void setOutMsgParamNames(Vector outputMessageParamNames) {
+ this.outMsgParamNames = outputMessageParamNames;
+ }
+
+ /**
+ * Returns OutputMessageParamNames
+ *
+ * @return a Vector
+ */
+ public Vector getOutMsgParamNames() {
+ return outMsgParamNames;
+ }
+
+ /**
+ * Sets InputMessagePartNames
+ *
+ * @param InputMessagePartNamesa
+ * Vector
+ */
+ public void setInMsgParamNames(Vector inputMessagePartNames) {
+ this.inMsgParamNames = inputMessagePartNames;
+ }
+
+ /**
+ * Returns InputMessagePartNames
+ *
+ * @return a Vector
+ */
+ public Vector getInMsgParamNames() {
+ return inMsgParamNames;
+ }
+
+ /**
+ * Sets MethodName
+ *
+ * @param MethodName
+ * a String
+ */
+ public void setMethodName(String methodName) {
+ this.methodName = methodName;
+ }
+
+ /**
+ * Returns MethodName
+ *
+ * @return a String
+ */
+ public String getMethodName() {
+ return methodName;
+ }
+
+ /**
+ * Sets OutputMessageName
+ *
+ * @param OutputMessageName
+ * a String
+ */
+ public void setOutElementName(String outputMessageName) {
+ this.outElementName = outputMessageName;
+ }
+
+ /**
+ * Returns OutputMessageName
+ *
+ * @return a String
+ */
+ public String getOutElementName() {
+ return outElementName;
+ }
+
+ /**
+ * Sets InputMessageName
+ *
+ * @param InputMessageName
+ * a String
+ */
+ public void setInElementName(String inputMessageName) {
+ this.inElementName = inputMessageName;
+ }
+
+ /**
+ * Returns InputMessageName
+ *
+ * @return a String
+ */
+ public String getInElementName() {
+ return inElementName;
+ }
+}
\ No newline at end of file