in axis-codegen/src/main/java/org/apache/axis/wsdl/toJava/JavaServiceImplWriter.java [91:268]
protected void writeFileBody(PrintWriter pw) throws IOException {
Service service = sEntry.getService();
// output comments
writeComment(pw, service.getDocumentationElement(), false);
// Used to construct the getPort(Class) method.
Vector getPortIfaces = new Vector();
Vector getPortStubClasses = new Vector();
Vector getPortPortNames = new Vector();
Vector getPortPortXmlNames = new Vector();
boolean printGetPortNotice = false;
// get ports
Map portMap = service.getPorts();
Iterator portIterator = portMap.values().iterator();
//Write the constructor for <servicename>Locator
writeConstructors(pw);
// write a get method for each of the ports with a SOAP binding
while (portIterator.hasNext()) {
Port p = (Port) portIterator.next();
Binding binding = p.getBinding();
if (binding == null) {
throw new IOException(Messages.getMessage("emitFailNoBinding01",
new String[]{
p.getName()}));
}
BindingEntry bEntry =
symbolTable.getBindingEntry(binding.getQName());
if (bEntry == null) {
throw new IOException(
Messages.getMessage(
"emitFailNoBindingEntry01",
new String[]{binding.getQName().toString()}));
}
PortTypeEntry ptEntry =
symbolTable.getPortTypeEntry(binding.getPortType().getQName());
if (ptEntry == null) {
throw new IOException(
Messages.getMessage(
"emitFailNoPortType01",
new String[]{
binding.getPortType().getQName().toString()}));
}
// If this isn't an SOAP binding, skip it
if (bEntry.getBindingType() != BindingEntry.TYPE_SOAP) {
continue;
}
// JSR 101 indicates that the name of the port used
// in the java code is the name of the wsdl:port. It
// does not indicate what should occur if the
// wsdl:port name is not a java identifier. The
// TCK depends on the case-sensitivity being preserved,
// and the interop tests have port names that are not
// valid java identifiers. Thus the following code.
// java port <--> wsdl port mapping
String portXmlName = p.getName();
String portName = (String) bEntry.getDynamicVar(JavaServiceWriter.PORT_NAME + ":" + p.getName());
if (portName == null) {
portName = p.getName();
}
if (!JavaUtils.isJavaId(portName)) {
portName = Utils.xmlNameToJavaClass(portName);
}
String stubClass = bEntry.getName() + "Stub";
String bindingType =
(String) bEntry.getDynamicVar(JavaBindingWriter.INTERFACE_NAME);
// getPort(Class) must return a stub for an interface. Collect all
// the port interfaces so the getPort(Class) method can be constructed.
if (getPortIfaces.contains(bindingType)) {
printGetPortNotice = true;
}
getPortIfaces.add(bindingType);
getPortPortXmlNames.add(portXmlName);
getPortStubClasses.add(stubClass);
getPortPortNames.add(portName);
// Get endpoint address and validate it
String address = WSDLUtils.getAddressFromPort(p);
if (address == null) {
// now what?
throw new IOException(Messages.getMessage("emitFail02",
portName, className));
}
try {
new java.net.URL(address);
} catch (MalformedURLException e) {
// this exception may be due to an unrecognized protocol
// so try to instantiate the protocol handler directly
// and use that to create the URL
java.net.URL url = null;
java.net.URLStreamHandler handler = null;
String handlerPkgs =
System.getProperty("java.protocol.handler.pkgs");
if (handlerPkgs != null) {
int protIndex = address.indexOf(":");
if (protIndex > 0) {
String protocol = address.substring(0,
protIndex);
StringTokenizer st =
new StringTokenizer(handlerPkgs, "|");
while (st.hasMoreTokens()) {
String pkg = st.nextToken();
String handlerClass = pkg + "." + protocol
+ ".Handler";
try {
Class c = Class.forName(handlerClass);
handler =
(java.net.URLStreamHandler) c.newInstance();
url = new java.net.URL(null, address,
handler);
break;
} catch (Exception e2) {
url = null;
}
}
}
}
if (url == null) {
if (emitter.isAllowInvalidURL()) {
// Unchecked URL mode
System.err.println(Messages.getMessage("emitWarnInvalidURL01", new String[] {portName, className, address}));
} else {
// Checked URL mode :
// URL invalid -> Exception
throw new IOException(Messages.getMessage("emitFail03",
new String[]{
portName,
className,
address}));
}
}
}
writeAddressInfo(pw, portName, address, p);
String wsddServiceName = portName + "WSDDServiceName";
writeWSDDServiceNameInfo(pw, wsddServiceName, portName, portXmlName);
writeGetPortName(pw, bindingType, portName);
writeGetPortNameURL(pw, bindingType, portName, stubClass,
wsddServiceName);
writeSetPortEndpointAddress(pw, portName);
}
writeGetPortClass(pw, getPortIfaces, getPortStubClasses,
getPortPortNames, printGetPortNotice);
writeGetPortQNameClass(pw, getPortPortNames, getPortPortXmlNames);
writeGetServiceName(pw, sEntry.getQName());
writeGetPorts(pw, sEntry.getQName().getNamespaceURI(), getPortPortXmlNames);
writeSetEndpointAddress(pw, getPortPortNames);
} // writeFileBody