package org.jboss.axis.providers;
import org.jboss.axis.AxisFault;
import org.jboss.axis.MessageContext;
import org.jboss.axis.description.ServiceDesc;
import org.jboss.axis.encoding.TypeMapping;
import org.jboss.axis.handlers.BasicHandler;
import org.jboss.axis.handlers.soap.SOAPService;
import org.jboss.axis.utils.Messages;
import org.jboss.axis.wsdl.fromJava.Emitter;
import org.jboss.logging.Logger;
import org.w3c.dom.Document;
import javax.xml.namespace.QName;
import java.util.Hashtable;
public abstract class BasicProvider extends BasicHandler
{
public static final String OPTION_WSDL_PORTTYPE = "wsdlPortType";
public static final String OPTION_WSDL_SERVICEELEMENT = "wsdlServiceElement";
public static final String OPTION_WSDL_SERVICEPORT = "wsdlServicePort";
public static final String OPTION_WSDL_TARGETNAMESPACE = "wsdlTargetNamespace";
public static final String OPTION_WSDL_INPUTSCHEMA = "wsdlInputSchema";
private static Logger log = Logger.getLogger(BasicProvider.class.getName());
public abstract void initServiceDesc(SOAPService service,
MessageContext msgContext)
throws AxisFault;
public void addOperation(String name, QName qname)
{
Hashtable operations = (Hashtable)getOption("Operations");
if (operations == null)
{
operations = new Hashtable();
setOption("Operations", operations);
}
operations.put(qname, name);
}
public String getOperationName(QName qname)
{
Hashtable operations = (Hashtable)getOption("Operations");
if (operations == null) return null;
return (String)operations.get(qname);
}
public QName[] getOperationQNames()
{
Hashtable operations = (Hashtable)getOption("Operations");
if (operations == null) return null;
Object[] keys = operations.keySet().toArray();
QName[] qnames = new QName[keys.length];
System.arraycopy(keys, 0, qnames, 0, keys.length);
return qnames;
}
public String[] getOperationNames()
{
Hashtable operations = (Hashtable)getOption("Operations");
if (operations == null) return null;
Object[] values = operations.values().toArray();
String[] names = new String[values.length];
System.arraycopy(values, 0, names, 0, values.length);
return names;
}
public void generateWSDL(MessageContext msgContext) throws AxisFault
{
if (log.isDebugEnabled())
log.debug("Enter: BSFProvider::generateWSDL (" + this + ")");
SOAPService service = msgContext.getService();
ServiceDesc serviceDesc = service.getInitializedServiceDesc(msgContext);
try
{
String locationUrl =
msgContext.getStrProp(MessageContext.WSDLGEN_SERV_LOC_URL);
if (locationUrl == null)
{
locationUrl = serviceDesc.getEndpointURL();
}
if (locationUrl == null)
{
locationUrl = msgContext.getStrProp(MessageContext.TRANS_URL);
}
String interfaceNamespace =
msgContext.getStrProp(MessageContext.WSDLGEN_INTFNAMESPACE);
if (interfaceNamespace == null)
{
interfaceNamespace = serviceDesc.getDefaultNamespace();
}
if (interfaceNamespace == null)
{
interfaceNamespace = locationUrl;
}
Emitter emitter = new Emitter();
emitter.setServiceElementName(serviceDesc.getName());
String alias = (String)service.getOption("alias");
if (alias != null) emitter.setServiceElementName(alias);
emitter.setStyle(serviceDesc.getStyle());
emitter.setUse(serviceDesc.getUse());
emitter.setClsSmart(serviceDesc.getImplClass(), locationUrl);
String targetNamespace = (String)service.getOption(OPTION_WSDL_TARGETNAMESPACE);
if (targetNamespace == null ||
targetNamespace.length() == 0)
{
targetNamespace = interfaceNamespace;
}
emitter.setIntfNamespace(targetNamespace);
emitter.setLocationUrl(locationUrl);
emitter.setServiceDesc(serviceDesc);
emitter.setTypeMapping((TypeMapping)msgContext.getTypeMappingRegistry()
.getTypeMapping(serviceDesc.getUse().getEncoding()));
emitter.setDefaultTypeMapping((TypeMapping)msgContext.getTypeMappingRegistry().
getDefaultTypeMapping());
String wsdlPortType = (String)service.getOption(OPTION_WSDL_PORTTYPE);
String wsdlServiceElement = (String)service.getOption(OPTION_WSDL_SERVICEELEMENT);
String wsdlServicePort = (String)service.getOption(OPTION_WSDL_SERVICEPORT);
if (wsdlPortType != null && wsdlPortType.length() > 0)
{
emitter.setPortTypeName(wsdlPortType);
}
if (wsdlServiceElement != null && wsdlServiceElement.length() > 0)
{
emitter.setServiceElementName(wsdlServiceElement);
}
if (wsdlServicePort != null && wsdlServicePort.length() > 0)
{
emitter.setServicePortName(wsdlServicePort);
}
String wsdlInputSchema = (String)
service.getOption(OPTION_WSDL_INPUTSCHEMA);
if (null != wsdlInputSchema && wsdlInputSchema.length() > 0)
{
emitter.setInputSchema(wsdlInputSchema);
}
Document doc = emitter.emit(Emitter.MODE_ALL);
msgContext.setProperty("WSDL", doc);
}
catch (NoClassDefFoundError e)
{
log.info(Messages.getMessage("toAxisFault00"), e);
throw new AxisFault(e.toString(), e);
}
catch (Exception e)
{
log.info(Messages.getMessage("toAxisFault00"), e);
throw AxisFault.makeFault(e);
}
if (log.isDebugEnabled())
log.debug("Exit: JavaProvider::generateWSDL (" + this + ")");
}
}