1 55 package org.jboss.axis.description; 56 57 import org.jboss.axis.enums.Style; 58 import org.jboss.axis.enums.Use; 59 import org.jboss.logging.Logger; 60 61 import javax.xml.namespace.QName ; 62 import java.lang.reflect.Method ; 63 import java.util.ArrayList ; 64 import java.util.Iterator ; 65 66 67 72 public class OperationDesc 73 { 74 77 public static final int MSG_METHOD_BODYARRAY = 1; 79 public static final int MSG_METHOD_SOAPENVELOPE = 2; 81 public static final int MSG_METHOD_ELEMENTARRAY = 3; 83 public static final int MSG_METHOD_DOCUMENT = 4; 85 86 public static final int MSG_METHOD_NONCONFORMING = -4; 87 88 private static Logger log = Logger.getLogger(OperationDesc.class.getName()); 89 90 93 private ServiceDesc parent; 94 95 98 private ArrayList parameters = new ArrayList (); 99 100 103 private String name; 104 105 108 private QName elementQName; 109 110 113 private Method method; 114 115 118 private Style style = null; 119 private Use use = null; 120 121 124 private int numInParams = 0; 125 128 private int numOutParams = 0; 129 130 133 private String soapAction = null; 134 135 138 private ArrayList faults = null; 139 140 private ParameterDesc returnDesc = new ParameterDesc(); 141 142 145 private int messageOperationStyle = -1; 146 147 151 private boolean oneWay = false; 152 153 156 public OperationDesc() 157 { 158 returnDesc.setMode(ParameterDesc.OUT); 159 returnDesc.setIsReturn(true); 160 } 161 162 165 public OperationDesc(String name, ParameterDesc[] parameters, QName returnQName) 166 { 167 this.name = name; 168 returnDesc.setQName(returnQName); 169 returnDesc.setMode(ParameterDesc.OUT); 170 returnDesc.setIsReturn(true); 171 for (int i = 0; i < parameters.length; i++) 172 { 173 addParameter(parameters[i]); 174 } 175 } 176 177 180 public String getName() 181 { 182 return name; 183 } 184 185 188 public void setName(String name) 189 { 190 this.name = name; 191 } 192 193 public QName getReturnQName() 194 { 195 return returnDesc.getQName(); 196 } 197 198 public void setReturnQName(QName returnQName) 199 { 200 returnDesc.setQName(returnQName); 201 } 202 203 public QName getReturnType() 204 { 205 return returnDesc.getTypeQName(); 206 } 207 208 public void setReturnType(QName returnType) 209 { 210 returnDesc.setTypeQName(returnType); 211 } 212 213 public Class getReturnClass() 214 { 215 return returnDesc.getJavaType(); 216 } 217 218 public void setReturnClass(Class returnClass) 219 { 220 returnDesc.setJavaType(returnClass); 221 } 222 223 public QName getElementQName() 224 { 225 return elementQName; 226 } 227 228 public void setElementQName(QName elementQName) 229 { 230 this.elementQName = elementQName; 231 } 232 233 public boolean isOneWay() 234 { 235 return oneWay; 236 } 237 238 public void setOneWay(boolean oneWay) 239 { 240 this.oneWay = oneWay; 241 } 242 243 public ServiceDesc getParent() 244 { 245 return parent; 246 } 247 248 public void setParent(ServiceDesc parent) 249 { 250 this.parent = parent; 251 } 252 253 public String getSoapAction() 254 { 255 return soapAction; 256 } 257 258 public void setSoapAction(String soapAction) 259 { 260 this.soapAction = soapAction; 261 } 262 263 public void setStyle(Style style) 264 { 265 this.style = style; 266 } 267 268 272 public Style getStyle() 273 { 274 if (style == null) 275 { 276 if (parent != null) 277 { 278 return parent.getStyle(); 279 } 280 return Style.DEFAULT; } 282 283 return style; 284 } 285 286 public void setUse(Use use) 287 { 288 this.use = use; 289 } 290 291 295 public Use getUse() 296 { 297 if (use == null) 298 { 299 if (parent != null) 300 { 301 return parent.getUse(); 302 } 303 return Use.DEFAULT; } 305 306 return use; 307 } 308 309 public void addParameter(ParameterDesc param) 310 { 311 313 parameters.add(param); 314 if ((param.getMode() == ParameterDesc.IN) || 315 (param.getMode() == ParameterDesc.INOUT)) 316 { 317 param.setOrder(numInParams++); 318 } 319 if ((param.getMode() == ParameterDesc.OUT) || 320 (param.getMode() == ParameterDesc.INOUT)) 321 { 322 numOutParams++; 323 } 324 } 325 326 public void addParameter(QName paramName, 327 QName xmlType, 328 Class javaType, 329 byte parameterMode, 330 boolean inHeader, 331 boolean outHeader) 332 { 333 ParameterDesc param = 334 new ParameterDesc(paramName, parameterMode, xmlType, 335 javaType, inHeader, outHeader); 336 addParameter(param); 337 } 338 339 public ParameterDesc getParameter(int i) 340 { 341 if (parameters.size() <= i) 342 return null; 343 344 return (ParameterDesc)parameters.get(i); 345 } 346 347 public ArrayList getParameters() 348 { 349 return parameters; 350 } 351 352 357 public void setParameters(ArrayList newParameters) 358 { 359 parameters = new ArrayList (); numInParams = 0; 361 numOutParams = 0; 362 363 for (java.util.ListIterator li = newParameters.listIterator(); 364 li.hasNext();) 365 { 366 addParameter((ParameterDesc)li.next()); 367 } 368 } 369 370 public int getNumInParams() 371 { 372 return numInParams; 373 } 374 375 public int getNumOutParams() 376 { 377 return numOutParams; 378 } 379 380 public int getNumParams() 381 { 382 return parameters.size(); 383 } 384 385 public Method getMethod() 386 { 387 return method; 388 } 389 390 public void setMethod(Method method) 391 { 392 this.method = method; 393 } 394 395 398 public boolean isReturnHeader() 399 { 400 return returnDesc.isOutHeader(); 401 } 402 403 406 public void setReturnHeader(boolean value) 407 { 408 returnDesc.setOutHeader(value); 409 } 410 411 public ParameterDesc getParamByQName(QName qname) 412 { 413 for (Iterator i = parameters.iterator(); i.hasNext();) 414 { 415 ParameterDesc param = (ParameterDesc)i.next(); 416 if (param.getQName().equals(qname)) 417 return param; 418 } 419 420 return null; 421 } 422 423 public ParameterDesc getInputParamByQName(QName qname) 424 { 425 ParameterDesc param = null; 426 427 param = getParamByQName(qname); 428 429 if ((param == null) || (param.getMode() == ParameterDesc.OUT)) 430 { 431 param = null; 432 } 433 434 return param; 435 } 436 437 public ParameterDesc getOutputParamByQName(QName qname) 438 { 439 ParameterDesc param = null; 440 441 for (Iterator i = parameters.iterator(); i.hasNext();) 442 { 443 ParameterDesc pnext = (ParameterDesc)i.next(); 444 if (pnext.getQName().equals(qname) && 445 pnext.getMode() != ParameterDesc.IN) 446 { 447 param = pnext; 448 break; 449 } 450 } 451 452 if (param == null) 453 { 454 if (null == returnDesc.getQName()) 455 { 456 param = new ParameterDesc(returnDesc); param.setQName(qname); 458 } 459 else if (qname.equals(returnDesc.getQName())) 460 { 461 param = returnDesc; 462 } 463 } 464 465 return param; 466 } 467 468 476 public ArrayList getAllInParams() 477 { 478 ArrayList result = new ArrayList (); 479 for (Iterator i = parameters.iterator(); i.hasNext();) 480 { 481 ParameterDesc desc = (ParameterDesc)i.next(); 482 if (desc.getMode() != ParameterDesc.OUT) 483 { 484 result.add(desc); 485 } 486 } 487 return result; 488 } 489 490 498 public ArrayList getAllOutParams() 499 { 500 ArrayList result = new ArrayList (); 501 for (Iterator i = parameters.iterator(); i.hasNext();) 502 { 503 ParameterDesc desc = (ParameterDesc)i.next(); 504 if (desc.getMode() != ParameterDesc.IN) 505 { 506 result.add(desc); 507 } 508 } 509 return result; 510 } 511 512 515 public ArrayList getInParams() 516 { 517 ArrayList result = new ArrayList (); 518 for (Iterator i = parameters.iterator(); i.hasNext();) 519 { 520 ParameterDesc desc = (ParameterDesc)i.next(); 521 if (desc.getMode() == ParameterDesc.IN) 522 { 523 result.add(desc); 524 } 525 } 526 return result; 527 } 528 529 532 public ArrayList getOutParams() 533 { 534 ArrayList result = new ArrayList (); 535 for (Iterator i = parameters.iterator(); i.hasNext();) 536 { 537 ParameterDesc desc = (ParameterDesc)i.next(); 538 if (desc.getMode() == ParameterDesc.OUT) 539 { 540 result.add(desc); 541 } 542 } 543 return result; 544 } 545 546 public void addFault(FaultDesc fault) 547 { 548 if (faults == null) 549 faults = new ArrayList (); 550 faults.add(fault); 551 } 552 553 public ArrayList getFaults() 554 { 555 return faults; 556 } 557 558 562 public FaultDesc getFaultByClass(Class cls) 563 { 564 if (faults == null || cls == null) 565 { 566 return null; 567 } 568 569 while (cls != null) 570 { 571 574 for (Iterator iterator = faults.iterator(); iterator.hasNext();) 575 { 576 FaultDesc desc = (FaultDesc)iterator.next(); 577 if (cls.getName().equals(desc.getClassName())) 578 { 579 return desc; 580 } 581 } 582 583 cls = cls.getSuperclass(); 584 if (cls != null && (cls.getName().startsWith("java.") || 585 cls.getName().startsWith("javax."))) 586 { 587 cls = null; 588 } 589 } 590 591 return null; 592 } 593 594 599 public FaultDesc getFaultByQName(QName qname) 600 { 601 if (faults != null) 602 { 603 for (Iterator iterator = faults.iterator(); iterator.hasNext();) 604 { 605 FaultDesc desc = (FaultDesc)iterator.next(); 606 if (qname.equals(desc.getQName())) 607 { 608 return desc; 609 } 610 } 611 } 612 return null; 613 } 614 615 619 public FaultDesc getFaultByXmlType(QName xmlType) 620 { 621 if (faults != null) 622 { 623 for (Iterator iterator = faults.iterator(); iterator.hasNext();) 624 { 625 FaultDesc desc = (FaultDesc)iterator.next(); 626 if (xmlType.equals(desc.getXmlType())) 627 { 628 return desc; 629 } 630 } 631 } 632 return null; 633 } 634 635 public ParameterDesc getReturnParamDesc() 636 { 637 return returnDesc; 638 } 639 640 public String toString() 641 { 642 return toString(""); 643 } 644 645 public String toString(String indent) 646 { 647 String text = "\nOperationDesc\n"; 648 text += indent + "name: " + getName() + "\n"; 649 text += indent + "returnQName: " + getReturnQName() + "\n"; 650 text += indent + "returnType: " + getReturnType() + "\n"; 651 text += indent + "returnClass: " + getReturnClass() + "\n"; 652 text += indent + "elementQName:" + getElementQName() + "\n"; 653 text += indent + "soapAction: " + getSoapAction() + "\n"; 654 text += indent + "style: " + getStyle().getName() + "\n"; 655 text += indent + "use: " + getUse().getName() + "\n"; 656 text += indent + "numInParams: " + getNumInParams() + "\n"; 657 text += indent + "method:" + getMethod() + "\n"; 658 for (int i = 0; i < parameters.size(); i++) 659 { 660 text += indent + " ParameterDesc[" + i + "]:\n"; 661 text += indent + ((ParameterDesc)parameters.get(i)).toString(" ") + "\n"; 662 } 663 if (faults != null) 664 { 665 for (int i = 0; i < faults.size(); i++) 666 { 667 text += indent + " FaultDesc[" + i + "]:\n"; 668 text += indent + ((FaultDesc)faults.get(i)).toString(" ") + "\n"; 669 } 670 } 671 return text; 672 } 673 674 public int getMessageOperationStyle() 675 { 676 return messageOperationStyle; 677 } 678 679 public void setMessageOperationStyle(int messageOperationStyle) 680 { 681 this.messageOperationStyle = messageOperationStyle; 682 } 683 } 684 685 | Popular Tags |