1 29 30 package com.caucho.soap.reflect; 31 32 import com.caucho.jaxb.JAXBContextImpl; 33 import com.caucho.jaxb.JAXBUtil; 34 import com.caucho.soap.skeleton.DirectSkeleton; 35 import com.caucho.soap.skeleton.AbstractAction; 36 import com.caucho.util.L10N; 37 38 import org.w3c.dom.Node ; 39 40 import javax.jws.WebMethod; 41 import javax.jws.WebService; 42 import javax.xml.bind.JAXBException; 43 import javax.xml.bind.Marshaller; 44 import javax.xml.bind.Unmarshaller; 45 import javax.xml.stream.XMLOutputFactory; 46 import javax.xml.stream.XMLStreamException; 47 import javax.xml.stream.XMLStreamWriter; 48 import javax.xml.transform.dom.DOMResult ; 49 import java.lang.reflect.Method ; 50 import java.lang.reflect.Modifier ; 51 import java.util.HashSet ; 52 import java.util.LinkedHashMap ; 53 54 57 public class WebServiceIntrospector { 58 private static XMLOutputFactory _outputFactory = null; 59 60 public static final L10N L = new L10N(WebServiceIntrospector.class); 61 64 public DirectSkeleton introspect(Class type) 65 throws JAXBException 67 { 68 return introspect(type, "REPLACE_WITH_ACTUAL_URL"); 70 } 71 72 75 public DirectSkeleton introspect(Class type, String wsdlLocation) 76 throws JAXBException 78 { 79 85 86 boolean isInterface = type.isInterface(); 87 88 WebService webService = (WebService) type.getAnnotation(WebService.class); 89 90 HashSet <Class > jaxbClasses = new HashSet <Class >(); 92 JAXBUtil.introspectClass(type, jaxbClasses); 93 Class [] jaxbClassArray = new Class [jaxbClasses.size()]; 94 jaxbClasses.toArray(jaxbClassArray); 95 96 JAXBContextImpl jaxbContext = new JAXBContextImpl(jaxbClassArray, null); 97 Marshaller marshaller = jaxbContext.createMarshaller(); 98 Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); 99 100 DirectSkeleton skel = new DirectSkeleton(type, wsdlLocation); 101 String namespace = skel.getNamespace(); 102 103 Method[] methods = type.getMethods(); 104 105 for (int i = 0; i < methods.length; i++) { 106 if ((methods[i].getModifiers() & Modifier.PUBLIC) == 0) 107 continue; 108 109 WebMethod webMethod = methods[i].getAnnotation(WebMethod.class); 110 111 if (webService == null && webMethod == null && ! isInterface) 112 continue; 113 114 if (webMethod == null && methods[i].getDeclaringClass() != type) 115 continue; 116 117 if (webMethod != null && webMethod.exclude()) 118 continue; 119 120 AbstractAction action = 121 AbstractAction.createAction(methods[i], jaxbContext, namespace, 122 marshaller, unmarshaller); 123 124 String name = webMethod == null ? "" : webMethod.operationName(); 125 126 if (name.equals("")) 127 name = methods[i].getName(); 128 129 skel.addAction(name, action); 130 } 131 132 144 145 return skel; 146 } 147 148 private static XMLStreamWriter getStreamWriter(DOMResult result) 149 throws XMLStreamException 150 { 151 if (_outputFactory == null) 152 _outputFactory = XMLOutputFactory.newInstance(); 153 154 return _outputFactory.createXMLStreamWriter(result); 155 } 156 } 157 | Popular Tags |