operationName = new QName(opName);
}
public void setOperation(QName portName, String opName) {
if ( service == null )
throw new JAXRPCException( Messages.getMessage("noService04") );
// Make sure we're making a fresh start.
this.setPortName( portName );
this.setOperationName( opName );
this.setTargetEndpointAddress( (URL) null );
this.setEncodingStyle( null );
this.setReturnType( null );
this.removeAllParameters();
javax.wsdl.Service wsdlService = service.getWSDLService();
// Nothing to do is the WSDL is not already set.
if(wsdlService == null)
return;
Port port = wsdlService.getPort( portName.getLocalPart() );
if ( port == null )
throw new JAXRPCException( Messages.getMessage("noPort00", "" + portName) );
Binding binding = port.getBinding();
PortType portType = binding.getPortType();
if ( portType == null )
throw new JAXRPCException( Messages.getMessage("noPortType00", "" + portName) );
List operations = portType.getOperations();
if ( operations == null )
throw new JAXRPCException( Messages.getMessage("noOperation01", opName) );
Operation op = null ;
for ( int i = 0 ; i < operations.size() ; i++, op=null ) {
op = (Operation) operations.get( i );
if ( opName.equals( op.getName() ) ) break ;
}
if ( op == null )
throw new JAXRPCException( Messages.getMessage("noOperation01", opName) );
// Get the URL
////////////////////////////////////////////////////////////////////
List list = port.getExtensibilityElements();
for ( int i = 0 ; list != null && i < list.size() ; i++ ) {
Object obj = list.get(i);
if ( obj instanceof SOAPAddress ) {
try {
SOAPAddress addr = (SOAPAddress) obj ;
URL url = new URL(addr.getLocationURI());
this.setTargetEndpointAddress(url);
}
catch(Exception exp) {
throw new JAXRPCException(
Messages.getMessage("cantSetURI00", "" + exp) );
}
}
}
// Get the SOAPAction
////////////////////////////////////////////////////////////////////
BindingOperation bop = binding.getBindingOperation(opName,
null, null);
if ( bop == null )
throw new JAXRPCException( Messages.getMessage("noOperation02",
opName ));
list = bop.getExtensibilityElements();
for ( int i = 0 ; list != null && i < list.size() ; i++ ) {
Object obj = list.get(i);
if ( obj instanceof SOAPOperation ) {
SOAPOperation sop = (SOAPOperation) obj ;
String action = sop.getSoapActionURI();
if ( action != null ) {
setUseSOAPAction(true);
setSOAPActionURI(action);
}
else {
setUseSOAPAction(false);
setSOAPActionURI(null);
}
break ;
}
}
// Get the body's namespace URI and encoding style
////////////////////////////////////////////////////////////////////
BindingInput bIn = bop.getBindingInput();
if ( bIn != null ) {
list = bIn.getExtensibilityElements();
for ( int i = 0 ; list != null && i < list.size() ; i++ ) {
Object obj = list.get(i);
if( obj instanceof javax.wsdl.extensions.mime.MIMEMultipartRelated){
javax.wsdl.extensions.mime.MIMEMultipartRelated mpr=
(javax.wsdl.extensions.mime.MIMEMultipartRelated) obj;
Object part= null;
List l= mpr.getMIMEParts();
for(int j=0; l!= null && j< l.size() && part== null; j++){
javax.wsdl.extensions.mime.MIMEPart mp
= (javax.wsdl.extensions.mime.MIMEPart)l.get(j);
List ll= mp.getExtensibilityElements();
for(int k=0; ll!= null && k< ll.size() && part== null; k++){
part= ll.get(k);
if ( !(part instanceof SOAPBody)) part = null;
}
}
if(null != part) obj= part;
}
if ( obj instanceof SOAPBody ) {
SOAPBody sBody = (SOAPBody) obj ;
list = sBody.getEncodingStyles();
if ( list != null && list.size() > 0 )
this.setEncodingStyle( (String) list.get(0) );
String ns = sBody.getNamespaceURI();
if (ns != null && !ns.equals(""))
setOperationName( new QName( ns, opName ) );
break ;
}
}
}
// Get the parameters
////////////////////////////////////////////////////////////////////
List paramOrder = op.getParameterOrdering();
Input input = op.getInput();
javax.wsdl.Message message = null ;
List parts = null ;
if ( input != null ) message = input.getMessage();
if ( message != null ) parts = message.getOrderedParts( paramOrder );
if ( parts != null ) {
for ( int i = 0 ; i < parts.size() ; i++ ) {
Part part = (Part) parts.get(i);
if ( part == null ) continue ;
String name = part.getName();
QName type = part.getTypeName();
if ( type == null ) {
type = part.getElementName();
if ( type != null )
type = new QName("java","org.w3c.dom.Element");
else
throw new JAXRPCException(
Messages.getMessage("typeNotSet00", name) );
}
QName qname = new QName(type.getNamespaceURI(),
type.getLocalPart());
ParameterMode mode = ParameterMode.IN;
this.addParameter( name, qname, mode );
}
}
// Get the return type
////////////////////////////////////////////////////////////////////
Output output = op.getOutput();
message = null ;
if ( output != null ) message = output.getMessage();
if ( message != null ) parts = message.getOrderedParts(null);
// if (null != paramTypes) // attachments may have no parameters.
if (operation != null && operation.getNumParams() > 0) // attachments may have no parameters.
this.setReturnType( XMLType.AXIS_VOID );
if ( parts != null ) {
for( int i = 0 ;i < parts.size() ; i++ ) {
Part part = (Part) parts.get( i );
if (paramOrder != null && paramOrder.contains(part.getName()))
continue ;
QName type = part.getTypeName();
if ( type == null ) {
type = part.getElementName();
if ( type != null )
type = new QName("java","org.w3c.dom.Element");
else
throw new JAXRPCException(
Messages.getMessage("typeNotSet00", "<return>") );
}
QName qname = new QName(type.getNamespaceURI(),
type.getLocalPart());
this.setReturnType( qname );