1 20 package org.apache.beehive.wsm.wsdl; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.lang.reflect.Array ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 import org.apache.xmlbeans.SchemaType; 29 import org.apache.xmlbeans.XmlException; 30 import org.apache.xmlbeans.XmlObject; 31 32 public class Utilities { 33 34 public static <T extends XmlObject> T[] selectChildren(XmlObject parent, 35 Class <T> childClass) throws IllegalAccessException , 36 NoSuchFieldException { 37 SchemaType st = (SchemaType) childClass.getField("type").get(null); 39 XmlObject[] kids = parent.selectChildren(st.getDocumentElementName()); 40 T[] castKids = (T[]) Array.newInstance(childClass, kids.length); 41 for (int j = 0; j < castKids.length; j++) { 42 castKids[j] = childClass.cast(kids[j]); 43 } 44 return castKids; 45 } 46 47 55 56 static Map <String , Schema> schemaCache = new HashMap <String , Schema>(); 58 public static Schema findtSchemaDocument(SchemaType docType) 59 throws XmlException, IOException , IllegalAccessException , 60 NoSuchFieldException { 61 Schema mySchema = null; 62 if (null != (mySchema = schemaCache.get(docType.getName() 63 .getNamespaceURI()))) { 64 return mySchema; 65 } 66 String schemaSrc = docType.getSourceName(); 67 InputStream stream = docType.getTypeSystem().getSourceAsStream( 68 schemaSrc); 69 70 if (null == stream) { 71 throw new RuntimeException ("WSDL file not found: " + schemaSrc); 72 } 73 if (schemaSrc.endsWith(".wsdl") || schemaSrc.endsWith(".WSDL")) { 74 mySchema = new WSDLParser(stream).getSchema(); 75 } else { 76 mySchema = new Schema(stream); 77 } 78 schemaCache.put(docType.getName().getNamespaceURI(), mySchema); 79 return mySchema; 80 } 81 82 } 83 | Popular Tags |