throws WSIException
{
// ADD: check for null document?
WSDLElement wsdlElement = serviceReference.getWSDLElement();
this.wsdlDocument = wsdlDocument;
/*
* Generalised fields independent of wsdlElement:
*/
// ADD: check whether these need to be either expanded or filtered down.
// Assume WSDL4J pulls int the full tree at the root document for now
//this.imports = wsdlDocument.getImports();
// ... or if only down to first level....
this.imports =
(Import[]) getAllImports(
wsdlDocument.getDefinitions()).toArray(new Import[] {
});
/* Definitions.
* Note that the the first array element is for the root doc
* which contains all WSDL elements in scope via <import> declarations,
* as well as the root document itself. Therefore the second definitions
* array element and above are redundant, but *may* prove useful to the assertion
* code.
*/
this.definitions = new Definition[imports.length + 1];
// allow room for root doc
this.definitions[0] = wsdlDocument.getDefinitions(); // root document
// Allocate array for types elements
Types[] tempTypes = new Types[definitions.length];
int typesCount = 0;
if (definitions[0].getTypes() != null)
{
tempTypes[0] = this.definitions[0].getTypes(); // root document
typesCount++;
}
// Definitions from other (imported) wsdls correlating to the candidate
// Only one level down for now
for (int i = 0; i < imports.length; i++)
{
if (((definitions[i + 1] = imports[i].getDefinition()) != null)
&& (definitions[i + 1].getTypes() != null))
{
tempTypes[typesCount] = definitions[i + 1].getTypes();
typesCount++;
}
}
if (typesCount > 0)
{
this.types = new Types[typesCount];
for (int i = 0; i < typesCount; i++)
this.types[i] = tempTypes[i];
}
/*
* Populate element hierachy:
* Port
* Binding
* PortType
* operation(s)
* message(s)
*/
if (wsdlElement.isPort())
{
Port port = null;
// Use parentElementName to qualify the port within a service.
QName serviceName = wsdlElement.getParentElementQName();
Service[] s = wsdlDocument.getServices();
String portName = wsdlElement.getName();
for (int i = 0; i < s.length && port == null; i++)
{
if (s[i].getQName().equals(serviceName))
{
port = s[i].getPort(portName);
}
}
if (port == null)
{
throw new WSIException(
"WSDL Port \'"
+ portName
+ "\' for Service \'"
+ serviceName
+ "\' not found in service description");
}
else
{
this.ports = new Port[] { port };
// ADD: do serviceLocation check for soapbind:address?
descendents(port);
}
// ADD: the following could be instantiated here instead to refine context info
// definitions
// imports
// types
}
else if (wsdlElement.isBinding())
{
if (wsdlElement.getQName() != null
&& wsdlElement.getQName().getLocalPart() != null
&& wsdlElement.getQName().getLocalPart().length() > 0)
{
Binding binding =
wsdlDocument.getDefinitions().getBinding(wsdlElement.getQName());
if (binding == null)
{
throw new WSIException(
"WSDL Binding named \'"
+ wsdlElement.getQName()
+ "\' not found in service description");
}
else
{
this.bindings = new Binding[] { binding };
// the rest ... below binding:
// portTypes from binding
// operations from portTypes
// messages from operations
descendents(binding);
// above binding:
// ports
// definitions, imports, types (future?)
// ancestors(bindings);
}
}
}
else if (wsdlElement.isPortType())
{
PortType portType =
wsdlDocument.getDefinitions().getPortType(wsdlElement.getQName());
this.portTypes = new PortType[] { portType };
if (portType == null)
{
throw new WSIException(
"WSDL PortType named \'"
+ wsdlElement.getQName()
+ "\' not found in service description");
}
else
{
this.portTypes = new PortType[] { portType };
// the rest ... below portType:
descendents(portType);
// above portType:
// ports
// definitions, imports, types (future) ?
//ancestors(portTypes);
}
}
else if (wsdlElement.isOperation())
{
Operation operation = null;
String configOpName = wsdlElement.getName();
// Use parentElementName to qualify the operation within a portType.
QName portTypeName = wsdlElement.getParentElementQName();
PortType[] p = wsdlDocument.getPortTypes();
for (int i = 0; i < p.length && operation == null; i++)
{
if (p[i].getQName().equals(portTypeName))
{
// wsdl4j available method call below implies that only
// name+inputname+outputname uniquely defines operation!
// Since we do not have <input> & <output> name information
// available in the config, use this instead for now: -
// Get the first operation we find:
Iterator opIt = p[i].getOperations().iterator();
Operation op = null;
while (opIt.hasNext() && operation == null)
{
op = (Operation) opIt.next();
if (configOpName.equals(op.getName()))
{
operation = op;
}
}
}
}
if (operation == null)
{
throw new WSIException(
"No WSDL Operation named \'"
+ wsdlElement.getQName()
+ "\' found in service description");
}
else
{
this.operations = new Operation[] { operation };
descendents(operation);
//ancestors(operations);
}
}
else if (wsdlElement.isMessage())
{
Message message =
wsdlDocument.getDefinitions().getMessage(wsdlElement.getQName());
if (message == null)
{
throw new WSIException(
"No WSDL Message named \'"
+ wsdlElement.getQName()
+ "\' found in service description");
}
else
{
this.messages = new Message[] { message };
//ancestors(messages);
}
}
else
{
throw new WSIException(
"Unrecognised <WSDLElement type> in config: " + wsdlElement.getType());
}
// get info about the effective service location (s)
//this.endPoints = deriveEndpoints(analyzerConfig, this.ports, this.definitions);
this.endPoints =