1 16 17 package org.apache.axis.providers; 18 19 import java.util.Hashtable ; 20 21 import javax.xml.namespace.QName ; 22 23 import org.apache.axis.AxisFault; 24 import org.apache.axis.Constants; 25 import org.apache.axis.MessageContext; 26 import org.apache.axis.AxisEngine; 27 import org.apache.axis.components.logger.LogFactory; 28 import org.apache.axis.description.ServiceDesc; 29 import org.apache.axis.description.JavaServiceDesc; 30 import org.apache.axis.encoding.TypeMapping; 31 import org.apache.axis.handlers.BasicHandler; 32 import org.apache.axis.handlers.soap.SOAPService; 33 import org.apache.axis.utils.Messages; 34 import org.apache.axis.wsdl.fromJava.Emitter; 35 import org.apache.commons.logging.Log; 36 import org.w3c.dom.Document ; 37 38 43 public abstract class BasicProvider extends BasicHandler { 44 45 public static final String OPTION_WSDL_PORTTYPE = "wsdlPortType"; 46 public static final String OPTION_WSDL_SERVICEELEMENT = "wsdlServiceElement"; 47 public static final String OPTION_WSDL_SERVICEPORT = "wsdlServicePort"; 48 public static final String OPTION_WSDL_TARGETNAMESPACE = "wsdlTargetNamespace"; 49 public static final String OPTION_WSDL_INPUTSCHEMA = "wsdlInputSchema"; 50 public static final String OPTION_WSDL_SOAPACTION_MODE = "wsdlSoapActionMode"; 51 public static final String OPTION_EXTRACLASSES = "extraClasses"; 52 53 protected static Log log = 54 LogFactory.getLog(BasicProvider.class.getName()); 55 56 protected static Log entLog = 60 LogFactory.getLog(Constants.ENTERPRISE_LOG_CATEGORY); 61 62 66 public abstract void initServiceDesc(SOAPService service, 67 MessageContext msgContext) 68 throws AxisFault; 69 70 public void addOperation(String name, QName qname) { 71 Hashtable operations = (Hashtable )getOption("Operations"); 72 if (operations == null) { 73 operations = new Hashtable (); 74 setOption("Operations", operations); 75 } 76 operations.put(qname, name); 77 } 78 79 public String getOperationName(QName qname) { 80 Hashtable operations = (Hashtable )getOption("Operations"); 81 if (operations == null) return null; 82 return (String )operations.get(qname); 83 } 84 85 public QName [] getOperationQNames() { 86 Hashtable operations = (Hashtable )getOption("Operations"); 87 if (operations == null) return null; 88 Object [] keys = operations.keySet().toArray(); 89 QName [] qnames = new QName [keys.length]; 90 System.arraycopy(keys,0,qnames,0,keys.length); 91 return qnames; 92 } 93 94 public String [] getOperationNames() { 95 Hashtable operations = (Hashtable )getOption("Operations"); 96 if (operations == null) return null; 97 Object [] values = operations.values().toArray(); 98 String [] names = new String [values.length]; 99 System.arraycopy(values,0,names,0,values.length); 100 return names; 101 } 102 103 109 public void generateWSDL(MessageContext msgContext) throws AxisFault { 110 if (log.isDebugEnabled()) 111 log.debug("Enter: BasicProvider::generateWSDL (" + this +")"); 112 113 114 115 SOAPService service = msgContext.getService(); 116 117 ServiceDesc serviceDesc = service.getInitializedServiceDesc(msgContext); 118 119 129 try { 130 String locationUrl = msgContext.getStrProp(MessageContext.WSDLGEN_SERV_LOC_URL); 132 133 if (locationUrl == null) { 134 locationUrl = serviceDesc.getEndpointURL(); 136 } 137 138 if (locationUrl == null) { 139 locationUrl = msgContext.getStrProp(MessageContext.TRANS_URL); 141 } 142 143 String interfaceNamespace = msgContext.getStrProp(MessageContext.WSDLGEN_INTFNAMESPACE); 145 146 if (interfaceNamespace == null) { 147 interfaceNamespace = serviceDesc.getDefaultNamespace(); 149 } 150 151 if (interfaceNamespace == null) { 152 interfaceNamespace = locationUrl; 154 } 155 156 176 Emitter emitter = new Emitter(); 177 178 184 String alias = (String ) service.getOption("alias"); 187 if (alias != null) 188 emitter.setServiceElementName(alias); 189 190 emitter.setStyle(serviceDesc.getStyle()); 192 emitter.setUse(serviceDesc.getUse()); 193 194 if (serviceDesc instanceof JavaServiceDesc) { 195 emitter.setClsSmart(((JavaServiceDesc)serviceDesc).getImplClass(), 196 locationUrl); 197 } 198 199 String targetNamespace = (String ) service.getOption(OPTION_WSDL_TARGETNAMESPACE); 202 if (targetNamespace == null || targetNamespace.length() == 0) { 203 targetNamespace = interfaceNamespace; 204 } 205 emitter.setIntfNamespace(targetNamespace); 206 207 emitter.setLocationUrl(locationUrl); 208 emitter.setServiceDesc(serviceDesc); 209 emitter.setTypeMappingRegistry(msgContext.getTypeMappingRegistry()); 210 211 String wsdlPortType = (String ) service.getOption(OPTION_WSDL_PORTTYPE); 212 String wsdlServiceElement = (String ) service.getOption(OPTION_WSDL_SERVICEELEMENT); 213 String wsdlServicePort = (String ) service.getOption(OPTION_WSDL_SERVICEPORT); 214 String wsdlInputSchema = (String ) service.getOption(OPTION_WSDL_INPUTSCHEMA); 215 String wsdlSoapActinMode = (String ) service.getOption(OPTION_WSDL_SOAPACTION_MODE); 216 String extraClasses = (String ) service.getOption(OPTION_EXTRACLASSES); 217 218 if (wsdlPortType != null && wsdlPortType.length() > 0) { 219 emitter.setPortTypeName(wsdlPortType); 220 } 221 if (wsdlServiceElement != null && wsdlServiceElement.length() > 0) { 222 emitter.setServiceElementName(wsdlServiceElement); 223 } 224 if (wsdlServicePort != null && wsdlServicePort.length() > 0) { 225 emitter.setServicePortName(wsdlServicePort); 226 } 227 if (wsdlInputSchema != null && wsdlInputSchema.length() > 0) { 228 emitter.setInputSchema(wsdlInputSchema); 229 } 230 if (wsdlSoapActinMode != null && wsdlSoapActinMode.length() > 0) { 231 emitter.setSoapAction(wsdlSoapActinMode); 232 } 233 234 if (extraClasses != null && extraClasses.length() > 0) { 235 emitter.setExtraClasses(extraClasses); 236 } 237 238 if (msgContext.isPropertyTrue(AxisEngine.PROP_EMIT_ALL_TYPES)) { 239 emitter.setEmitAllTypes(true); 240 } 241 242 Document doc = emitter.emit(Emitter.MODE_ALL); 243 244 msgContext.setProperty("WSDL", doc); 245 } catch (NoClassDefFoundError e) { 246 entLog.info(Messages.getMessage("toAxisFault00"), e); 247 throw new AxisFault(e.toString(), e); 248 } catch (Exception e) { 249 entLog.info(Messages.getMessage("toAxisFault00"), e); 250 throw AxisFault.makeFault(e); 251 } 252 253 if (log.isDebugEnabled()) 254 log.debug("Exit: BasicProvider::generateWSDL (" + this +")"); 255 } 256 } 257 | Popular Tags |