1 10 11 package org.mule.providers.soap; 12 13 import org.apache.commons.lang.StringUtils; 14 import org.mule.config.converters.QNameConverter; 15 import org.mule.util.ClassUtils; 16 17 import javax.xml.namespace.QName ; 18 import javax.xml.rpc.ParameterMode ; 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.StringTokenizer ; 23 24 30 public class SoapMethod 31 { 32 33 private QName name; 34 private List namedParameters = new ArrayList (); 35 private QName returnType; 36 private Class returnClass = Object .class; 37 private static QNameConverter converter = new QNameConverter(); 38 39 public SoapMethod(String methodName, String paramsString) throws ClassNotFoundException 40 { 41 this((QName )converter.convert(QName .class, methodName), paramsString); 42 } 43 44 51 public SoapMethod(String methodName, List params) throws ClassNotFoundException 52 { 53 this((QName )converter.convert(QName .class, methodName), params); 54 } 55 56 public SoapMethod(QName methodName, String paramsString) throws ClassNotFoundException 57 { 58 name = methodName; 59 List params = new ArrayList (); 60 for (StringTokenizer stringTokenizer = new StringTokenizer (paramsString, ","); stringTokenizer.hasMoreTokens();) 61 { 62 params.add(stringTokenizer.nextToken().trim()); 63 } 64 initParams(params); 65 } 66 67 public SoapMethod(QName methodName, List params) throws ClassNotFoundException 68 { 69 name = methodName; 70 initParams(params); 71 } 72 73 private void initParams(List params) throws ClassNotFoundException 74 { 75 76 NamedParameter param; 77 for (Iterator iterator = params.iterator(); iterator.hasNext();) 78 { 79 String s = (String )iterator.next(); 80 81 for (StringTokenizer tokenizer = new StringTokenizer (s, ";"); tokenizer.hasMoreTokens();) 82 { 83 String name = tokenizer.nextToken(); 84 String type = tokenizer.nextToken(); 85 if (name.equalsIgnoreCase("return")) 86 { 87 if (type.startsWith("qname{")) 88 { 89 returnType = (QName )converter.convert(QName .class, type); 90 } 91 else 92 { 93 returnType = NamedParameter.createQName(type); 94 } 95 } 96 else if (name.equalsIgnoreCase("returnClass")) 97 { 98 returnClass = ClassUtils.loadClass(type, getClass()); 99 } 100 else 101 { 102 String mode = tokenizer.nextToken(); 103 QName paramName = null; 104 if (name.startsWith("qname{")) 105 { 106 paramName = (QName )converter.convert(QName .class, name); 107 } 108 else 109 { 110 paramName = new QName (getName().getNamespaceURI(), name, getName().getPrefix()); 111 } 112 QName qtype = null; 113 if (type.startsWith("qname{")) 114 { 115 qtype = (QName )converter.convert(QName .class, type); 116 } 117 else 118 { 119 qtype = NamedParameter.createQName(type); 120 } 121 param = new NamedParameter(paramName, qtype, mode); 122 addNamedParameter(param); 123 } 124 } 125 } 126 } 127 128 public SoapMethod(QName name) 129 { 130 this.name = name; 131 this.returnType = null; 132 } 133 134 public SoapMethod(QName name, QName returnType) 135 { 136 this.name = name; 137 this.returnType = returnType; 138 } 139 140 public SoapMethod(QName name, QName returnType, Class returnClass) 141 { 142 this.name = name; 143 this.returnType = returnType; 144 this.returnClass = returnClass; 145 } 146 147 public SoapMethod(QName name, Class returnClass) 148 { 149 this.name = name; 150 this.returnClass = returnClass; 151 } 152 153 public SoapMethod(QName name, List namedParameters, QName returnType) 154 { 155 this.name = name; 156 this.namedParameters = namedParameters; 157 this.returnType = returnType; 158 } 159 160 public void addNamedParameter(NamedParameter param) 161 { 162 namedParameters.add(param); 163 } 164 165 public NamedParameter addNamedParameter(QName name, QName type, String mode) 166 { 167 if (StringUtils.isBlank(name.getNamespaceURI())) 168 { 169 name = new QName (getName().getNamespaceURI(), name.getLocalPart(), name.getPrefix()); 170 } 171 NamedParameter param = new NamedParameter(name, type, mode); 172 namedParameters.add(param); 173 return param; 174 } 175 176 public NamedParameter addNamedParameter(QName name, QName type, ParameterMode mode) 177 { 178 if (StringUtils.isBlank(name.getNamespaceURI())) 179 { 180 name = new QName (getName().getNamespaceURI(), name.getLocalPart(), name.getPrefix()); 181 } 182 NamedParameter param = new NamedParameter(name, type, mode); 183 namedParameters.add(param); 184 return param; 185 } 186 187 public void removeNamedParameter(NamedParameter param) 188 { 189 namedParameters.remove(param); 190 } 191 192 public QName getName() 193 { 194 return name; 195 } 196 197 public List getNamedParameters() 198 { 199 return namedParameters; 200 } 201 202 public QName getReturnType() 203 { 204 return returnType; 205 } 206 207 public void setReturnType(QName returnType) 208 { 209 this.returnType = returnType; 210 } 211 212 public Class getReturnClass() 213 { 214 return returnClass; 215 } 216 217 public void setReturnClass(Class returnClass) 218 { 219 this.returnClass = returnClass; 220 } 221 } 222 | Popular Tags |