Thanks Michael for fixing this. It is all working like charm now. :) Julie
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, February 11, 2005 1:17 PM To: [EMAIL PROTECTED] Subject: svn commit: r153454 - in incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl: ./ Schema.java Utilities.java WSDLParser.java Author: mmerz Date: Fri Feb 11 12:17:15 2005 New Revision: 153454 URL: http://svn.apache.org/viewcvs?view=rev&rev=153454 Log: added new classes to deal with WSDL Contributor: Daryoush Mehrtash Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Sche ma.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Util ities.java incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/WSDL Parser.java Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Sche ma.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/or g/apache/beehive/wsm/wsdl/Schema.java?view=auto&rev=153454 ======================================================================== ====== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Sche ma.java (added) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Sche ma.java Fri Feb 11 12:17:15 2005 @@ -0,0 +1,102 @@ +/* + * + * Copyright 2001-2004 The Apache Software Foundation. + * + * + * Licensed 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.beehive.wsm.wsdl; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.namespace.QName; + +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.w3.x2001.xmlSchema.SchemaDocument; +import org.w3.x2001.xmlSchema.TopLevelComplexType; +import org.w3.x2001.xmlSchema.TopLevelElement; +import org.w3.x2001.xmlSchema.TopLevelSimpleType; +import org.xmlsoap.schemas.wsdl.TTypes; + + +public class Schema { + SchemaDocument.Schema[] schemas; + + /** + * @param tt + * @throws NoSuchFieldException + * @throws IllegalAccessException + */ + public Schema(TTypes tt) throws IllegalAccessException, NoSuchFieldException { + + schemas = Utilities.selectChildren(tt, SchemaDocument.Schema.class); + } + + /** + * @param stream + * @throws IOException + * @throws XmlException + */ + public Schema(InputStream stream) throws XmlException, IOException { + SchemaDocument schemaDoc = SchemaDocument.Factory.parse(stream); + schemas = new SchemaDocument.Schema[1]; + schemas[0] = schemaDoc.getSchema(); + } + + public XmlObject getTypeNode(QName q) { + // first find the schema with matching namespace + SchemaDocument.Schema schema = null; + for (SchemaDocument.Schema nxtSchema : schemas) { + if (nxtSchema.getTargetNamespace() != null + && nxtSchema.getTargetNamespace().equals( + q.getNamespaceURI())) { + schema = nxtSchema; + break; + } + } + if (null == schema) + return null; // namespace is not found in this schema. + + + // look in complex types + TopLevelComplexType[] tlComplexTypes = schema.getComplexTypeArray(); + for( TopLevelComplexType nxtComplexType : tlComplexTypes) { + if( nxtComplexType.getName().equals(q.getLocalPart())) { + return nxtComplexType; + } + } + + // look in simple types + TopLevelSimpleType[] tlSimpleTypes = schema.getSimpleTypeArray(); + for( TopLevelSimpleType nxtSimpleType : tlSimpleTypes) { + if( nxtSimpleType.getName().equals(q.getLocalPart())) { + return nxtSimpleType; + } + } + + // look in element types + TopLevelElement[] tlElementTypes = schema.getElementArray(); + for( TopLevelElement nxtElement : tlElementTypes) { + if( nxtElement.getName().equals(q.getLocalPart())) { + return nxtElement; + } + } + + return null; // it is not in comlex or simple types! + } + +} Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Util ities.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/or g/apache/beehive/wsm/wsdl/Utilities.java?view=auto&rev=153454 ======================================================================== ====== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Util ities.java (added) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/Util ities.java Fri Feb 11 12:17:15 2005 @@ -0,0 +1,82 @@ +/* + * + * Copyright 2001-2004 The Apache Software Foundation. + * + * + * Licensed 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.beehive.wsm.wsdl; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Array; +import java.util.HashMap; +import java.util.Map; + +import org.apache.xmlbeans.SchemaType; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; + +public class Utilities { + + public static <T extends XmlObject> T[] selectChildren(XmlObject parent, + Class<T> childClass) throws IllegalAccessException, + NoSuchFieldException { + // retrieve the SchemaType from the static type field + SchemaType st = (SchemaType) childClass.getField("type").get(null); + XmlObject[] kids = parent.selectChildren(st.getDocumentElementName()); + T[] castKids = (T[]) Array.newInstance(childClass, kids.length); + for (int j = 0; j < castKids.length; j++) { + castKids[j] = childClass.cast(kids[j]); + } + return castKids; + } + + /** + * @param docType + * @return + * @throws XmlException + * @throws IOException + * @throws IllegalAccessException + * @throws NoSuchFieldException + */ + + // Keep a cache of schemas that have been read. + static Map<String, Schema> schemaCache = new HashMap<String, Schema>(); + public static Schema findtSchemaDocument(SchemaType docType) + throws XmlException, IOException, IllegalAccessException, + NoSuchFieldException { + Schema mySchema = null; + if (null != (mySchema = schemaCache.get(docType.getName() + .getNamespaceURI()))) { + return mySchema; + } + String schemaSrc = docType.getSourceName(); + InputStream stream = docType.getTypeSystem().getSourceAsStream( + schemaSrc); + + if (null == stream) { + throw new RuntimeException("WSDL file not found: " + schemaSrc); + } + if (schemaSrc.endsWith(".wsdl") || schemaSrc.endsWith(".WSDL")) { + mySchema = new WSDLParser(stream).getSchema(); + } else { + mySchema = new Schema(stream); + } + schemaCache.put(docType.getName().getNamespaceURI(), mySchema); + return mySchema; + } + +} Added: incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/WSDL Parser.java URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/wsm/src/runtime/or g/apache/beehive/wsm/wsdl/WSDLParser.java?view=auto&rev=153454 ======================================================================== ====== --- incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/WSDL Parser.java (added) +++ incubator/beehive/trunk/wsm/src/runtime/org/apache/beehive/wsm/wsdl/WSDL Parser.java Fri Feb 11 12:17:15 2005 @@ -0,0 +1,70 @@ +/* + * + * Copyright 2001-2004 The Apache Software Foundation. + * + * + * Licensed 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.beehive.wsm.wsdl; + + + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Array; + +import javax.xml.namespace.QName; + +import org.apache.xmlbeans.SchemaType; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.w3.x2001.xmlSchema.SchemaDocument; +import org.w3.x2001.xmlSchema.TopLevelComplexType; +import org.w3.x2001.xmlSchema.TopLevelElement; +import org.w3.x2001.xmlSchema.TopLevelSimpleType; +import org.xmlsoap.schemas.wsdl.DefinitionsDocument; +import org.xmlsoap.schemas.wsdl.TTypes; + +public class WSDLParser { + + + InputStream stream; + DefinitionsDocument defDoc; + TTypes tt; + Schema schema; + + /** + * @param stream + * @throws IOException + * @throws XmlException + * @throws NoSuchFieldException + * @throws IllegalAccessException + */ + public WSDLParser(InputStream stream) throws XmlException, IOException, IllegalAccessException, NoSuchFieldException { + super(); + this.stream = stream; + + defDoc = DefinitionsDocument.Factory.parse(stream); + tt = defDoc.getDefinitions().getTypesArray(0); + schema = new Schema(tt); + } + /** + * @return Returns the schema. + */ + public Schema getSchema() { + return schema; + } + +}
