1 55 56 package org.jboss.axis.providers; 57 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.MessageContext; 60 import org.jboss.axis.description.ServiceDesc; 61 import org.jboss.axis.encoding.TypeMapping; 62 import org.jboss.axis.handlers.BasicHandler; 63 import org.jboss.axis.handlers.soap.SOAPService; 64 import org.jboss.axis.utils.Messages; 65 import org.jboss.axis.wsdl.fromJava.Emitter; 66 import org.jboss.logging.Logger; 67 import org.w3c.dom.Document ; 68 69 import javax.xml.namespace.QName ; 70 import java.util.Hashtable ; 71 72 77 public abstract class BasicProvider extends BasicHandler 78 { 79 80 public static final String OPTION_WSDL_PORTTYPE = "wsdlPortType"; 81 public static final String OPTION_WSDL_SERVICEELEMENT = "wsdlServiceElement"; 82 public static final String OPTION_WSDL_SERVICEPORT = "wsdlServicePort"; 83 public static final String OPTION_WSDL_TARGETNAMESPACE = "wsdlTargetNamespace"; 84 public static final String OPTION_WSDL_INPUTSCHEMA = "wsdlInputSchema"; 85 86 private static Logger log = Logger.getLogger(BasicProvider.class.getName()); 87 88 92 public abstract void initServiceDesc(SOAPService service, 93 MessageContext msgContext) 94 throws AxisFault; 95 96 public void addOperation(String name, QName qname) 97 { 98 Hashtable operations = (Hashtable )getOption("Operations"); 99 if (operations == null) 100 { 101 operations = new Hashtable (); 102 setOption("Operations", operations); 103 } 104 operations.put(qname, name); 105 } 106 107 public String getOperationName(QName qname) 108 { 109 Hashtable operations = (Hashtable )getOption("Operations"); 110 if (operations == null) return null; 111 return (String )operations.get(qname); 112 } 113 114 public QName [] getOperationQNames() 115 { 116 Hashtable operations = (Hashtable )getOption("Operations"); 117 if (operations == null) return null; 118 Object [] keys = operations.keySet().toArray(); 119 QName [] qnames = new QName [keys.length]; 120 System.arraycopy(keys, 0, qnames, 0, keys.length); 121 return qnames; 122 } 123 124 public String [] getOperationNames() 125 { 126 Hashtable operations = (Hashtable )getOption("Operations"); 127 if (operations == null) return null; 128 Object [] values = operations.values().toArray(); 129 String [] names = new String [values.length]; 130 System.arraycopy(values, 0, names, 0, values.length); 131 return names; 132 } 133 134 140 public void generateWSDL(MessageContext msgContext) throws AxisFault 141 { 142 if (log.isDebugEnabled()) 143 log.debug("Enter: BSFProvider::generateWSDL (" + this + ")"); 144 145 146 147 SOAPService service = msgContext.getService(); 148 ServiceDesc serviceDesc = service.getInitializedServiceDesc(msgContext); 149 150 160 try 161 { 162 String locationUrl = 164 msgContext.getStrProp(MessageContext.WSDLGEN_SERV_LOC_URL); 165 166 if (locationUrl == null) 167 { 168 locationUrl = serviceDesc.getEndpointURL(); 170 } 171 172 if (locationUrl == null) 173 { 174 locationUrl = msgContext.getStrProp(MessageContext.TRANS_URL); 176 } 177 178 String interfaceNamespace = 180 msgContext.getStrProp(MessageContext.WSDLGEN_INTFNAMESPACE); 181 182 if (interfaceNamespace == null) 183 { 184 interfaceNamespace = serviceDesc.getDefaultNamespace(); 186 } 187 188 if (interfaceNamespace == null) 189 { 190 interfaceNamespace = locationUrl; 192 } 193 194 214 Emitter emitter = new Emitter(); 215 216 emitter.setServiceElementName(serviceDesc.getName()); 218 219 String alias = (String )service.getOption("alias"); 222 if (alias != null) emitter.setServiceElementName(alias); 223 224 emitter.setStyle(serviceDesc.getStyle()); 226 emitter.setUse(serviceDesc.getUse()); 227 228 emitter.setClsSmart(serviceDesc.getImplClass(), locationUrl); 229 230 String targetNamespace = (String )service.getOption(OPTION_WSDL_TARGETNAMESPACE); 233 if (targetNamespace == null || 234 targetNamespace.length() == 0) 235 { 236 targetNamespace = interfaceNamespace; 237 } 238 emitter.setIntfNamespace(targetNamespace); 239 240 emitter.setLocationUrl(locationUrl); 241 emitter.setServiceDesc(serviceDesc); 242 emitter.setTypeMapping((TypeMapping)msgContext.getTypeMappingRegistry() 243 .getTypeMapping(serviceDesc.getUse().getEncoding())); 244 emitter.setDefaultTypeMapping((TypeMapping)msgContext.getTypeMappingRegistry(). 245 getDefaultTypeMapping()); 246 247 String wsdlPortType = (String )service.getOption(OPTION_WSDL_PORTTYPE); 248 String wsdlServiceElement = (String )service.getOption(OPTION_WSDL_SERVICEELEMENT); 249 String wsdlServicePort = (String )service.getOption(OPTION_WSDL_SERVICEPORT); 250 251 if (wsdlPortType != null && wsdlPortType.length() > 0) 252 { 253 emitter.setPortTypeName(wsdlPortType); 254 } 255 if (wsdlServiceElement != null && wsdlServiceElement.length() > 0) 256 { 257 emitter.setServiceElementName(wsdlServiceElement); 258 } 259 if (wsdlServicePort != null && wsdlServicePort.length() > 0) 260 { 261 emitter.setServicePortName(wsdlServicePort); 262 } 263 264 String wsdlInputSchema = (String ) 265 service.getOption(OPTION_WSDL_INPUTSCHEMA); 266 if (null != wsdlInputSchema && wsdlInputSchema.length() > 0) 267 { 268 emitter.setInputSchema(wsdlInputSchema); 269 } 270 271 Document doc = emitter.emit(Emitter.MODE_ALL); 272 273 msgContext.setProperty("WSDL", doc); 274 } 275 catch (NoClassDefFoundError e) 276 { 277 log.info(Messages.getMessage("toAxisFault00"), e); 278 throw new AxisFault(e.toString(), e); 279 } 280 catch (Exception e) 281 { 282 log.info(Messages.getMessage("toAxisFault00"), e); 283 throw AxisFault.makeFault(e); 284 } 285 286 if (log.isDebugEnabled()) 287 log.debug("Exit: JavaProvider::generateWSDL (" + this + ")"); 288 } 289 } 290 | Popular Tags |