This document provides a quick overview of how to use the SAWSDL4J object model. This includes code samples showing how to kickstart the usage of SAWSDL4J
This object model is built based on the WSDL4J object model from sourceforge. The interfaces are mostly extended (rather than replicated) so that the exisitng WSDL4J model is loosely coupled to this implementation. This gives us the flexibility to easily integrate the changes in WSDL4J implementation.
The following jar files are needed in the classpath in order to use SAWSDL4J
System.setProperty("javax.wsdl.factory.WSDLFactory",
"edu.uga.cs.lsdis.sawsdl.impl.factory.WSDLFactoryImpl");
WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
String wsdlURI = new File(WSDLFileName).toURI().toString();
Definition def = (Definiton)wsdlReader.readWSDL(wsdlURI);
Note the variable WSDLFileName holds the full path of the WSDL file.
The most important line of code in this segment is the setting of the system property in the first line
.This is how the WSDL4J libraries take the SAWSDL factory. The other important fact to notice is
that a casting is needed to actually get the edu.uga.cs.lsdis.sawsdl.Definition object since the
standard factory interface returns and object of type javax.wsdl.Definition.
System.setProperty("javax.wsdl.factory.WSDLFactory",
"edu.uga.cs.lsdis.sawsdl.impl.factory.WSDLFactoryImpl");
Definition def =
edu.uga.cs.lsdis.sawsdl.util.SAWSDLUtility.getDefinitionFromFile(new File(WSDLFileName));
If there is a requirement not to change the root factory using the system property setting
then one can pass the fully qualified factory class name to the newInstance()
method
attrExtensions
has been handled underneath to handle the model reference correctly.
Definition sawsdlDefinition = getDefinition();
PortType sawsdlPortType =
sawsdlDefinition.getSemanticPortType(new QName(TARGET_NS,PORTTYPE_NAME));
ModelReference modelReference = sawsdlPortType.getModelReference();
String concept = modelReference.getConcept();
The getDefinition()
method returns a modified Definition object. The same
prinicipal applies to the other modified objects where the getSemanticxxx methods are available.
Definition sawsdlDefinition = getDefinition();
Types types = sawsdlDefinition.getTypes();
List < Schema > schemaList = SchemaUtils.getSchemas(types);
Schema s = schemaList.get(0);
try {
Set < ModelReference> modelReferences =
s.getModelReferences(s.getElement(), "//xsd:schema/xsd:element[@name=\"OrderRequest\"]", sawsdlDefinition);
// do something with the model references
} catch (WSDLSException e) {
e.printStackTrace();
}
Definition sawsdlDefinition = getDefinition();
Binding binding =
sawsdlDefinition.getBinding(new QName(TARGET_NS,BINDING_NAME));
List < String > modelRefURIs = (List <String >)
binding.getExtensionAttribute(edu.uga.cs.lsdis.sawsdl.impl.Constants.Q_ATTR_MODELREF);