1 20 package org.apache.beehive.wsm.wsdl; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 25 import javax.xml.namespace.QName ; 26 27 import org.xmlsoap.schemas.wsdl.TTypes; 28 29 import org.apache.xmlbeans.XmlException; 30 import org.apache.xmlbeans.XmlObject; 31 32 import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument; 33 import org.apache.xmlbeans.impl.xb.xsdschema.TopLevelComplexType; 34 import org.apache.xmlbeans.impl.xb.xsdschema.TopLevelElement; 35 import org.apache.xmlbeans.impl.xb.xsdschema.TopLevelSimpleType; 36 37 38 39 public class Schema { 40 SchemaDocument.Schema[] schemas; 41 42 47 public Schema(TTypes tt) throws IllegalAccessException , NoSuchFieldException { 48 49 schemas = Utilities.selectChildren(tt, SchemaDocument.Schema.class); 50 } 51 52 57 public Schema(InputStream stream) throws XmlException, IOException { 58 SchemaDocument schemaDoc = SchemaDocument.Factory.parse(stream); 59 schemas = new SchemaDocument.Schema[1]; 60 schemas[0] = schemaDoc.getSchema(); 61 } 62 63 public XmlObject getTypeNode(QName q) { 64 SchemaDocument.Schema schema = null; 66 for (SchemaDocument.Schema nxtSchema : schemas) { 67 if (nxtSchema.getTargetNamespace() != null 68 && nxtSchema.getTargetNamespace().equals( 69 q.getNamespaceURI())) { 70 schema = nxtSchema; 71 break; 72 } 73 } 74 if (null == schema) 75 return null; 77 78 TopLevelComplexType[] tlComplexTypes = schema.getComplexTypeArray(); 80 for( TopLevelComplexType nxtComplexType : tlComplexTypes) { 81 if( nxtComplexType.getName().equals(q.getLocalPart())) { 82 return nxtComplexType; 83 } 84 } 85 86 TopLevelSimpleType[] tlSimpleTypes = schema.getSimpleTypeArray(); 88 for( TopLevelSimpleType nxtSimpleType : tlSimpleTypes) { 89 if( nxtSimpleType.getName().equals(q.getLocalPart())) { 90 return nxtSimpleType; 91 } 92 } 93 94 TopLevelElement[] tlElementTypes = schema.getElementArray(); 96 for( TopLevelElement nxtElement : tlElementTypes) { 97 if( nxtElement.getName().equals(q.getLocalPart())) { 98 return nxtElement; 99 } 100 } 101 102 return null; } 104 105 } 106 | Popular Tags |