001: /**
002: * $Id: PortTypeDescriptorImpl.java,v 1.5 2003/06/03 10:49:24 sy131129 Exp $
003: * Copyright 2002-2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.providers.simplewebservice.wsdl.impl;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017: import java.util.Iterator;
018:
019: import com.sun.portal.providers.simplewebservice.wsdl.PortTypeDescriptor;
020: import com.sun.portal.providers.simplewebservice.wsdl.OperationDescriptor;
021:
022: /**
023: * This class represents a port type. It contains information about
024: * operations associated with this port type.
025: *
026: */
027: public class PortTypeDescriptorImpl implements PortTypeDescriptor {
028:
029: private String name = null;
030: private List operationDescriptors = new ArrayList();
031:
032: /**
033: * Default Constructor.
034: *
035: * @param name the name of the DefinitionDescriptor.
036: * @param operationDescriptors the OperationDescriptors in the PortTypeDescriptor.
037: */
038: public PortTypeDescriptorImpl(String name, List operationDescriptors) {
039: this .name = name;
040: this .operationDescriptors = operationDescriptors;
041: }
042:
043: /**
044: * Get the name of this port type.
045: *
046: * @return the port type name
047: */
048: public String getName() {
049: return name;
050: }
051:
052: /**
053: * Get the specified OperationDescriptor. Note that operation names
054: * can be overloaded within a PortType. In case of overloading, the
055: * names of the input and output messages can be used to further
056: * refine the search.
057: *
058: * @param name the name of the desired OperationDescriptor.
059: * @param inputName the name of the input message; if this is null
060: * it will be ignored.
061: * @param outputName the name of the output message; if this is null
062: * it will be ignored.
063: *
064: * @return the corresponding operation, or null if there wasn't
065: * any matching operation
066: */
067: public OperationDescriptor getOperationDescriptor(String name,
068: String inputName, String outputName) {
069: OperationDescriptor op = null;
070:
071: Iterator opIterator = operationDescriptors.iterator();
072:
073: while (opIterator.hasNext()) {
074: op = (OperationDescriptor) opIterator.next();
075: String opName = op.getName();
076:
077: if (name != null && opName != null) {
078: if (!name.equals(opName)) {
079: op = null;
080: }
081: } else if (name != null || opName != null) {
082: op = null;
083: }
084:
085: if (op != null && inputName != null) {
086: String opInputDescriptorName = op
087: .getInputMessageDescriptorName();
088:
089: if (opInputDescriptorName == null
090: || !opInputDescriptorName.equals(inputName)) {
091: op = null;
092: }
093: }
094:
095: if (op != null && outputName != null) {
096: String opOutputDescriptorName = op
097: .getOutputMessageDescriptorName();
098:
099: if (opOutputDescriptorName == null
100: || !opOutputDescriptorName.equals(outputName)) {
101: op = null;
102: }
103: }
104:
105: // Need to break if right operation is found. Otherwise it would
106: // work only for the last operation-- mjain
107: if (op != null) {
108: return op;
109: }
110: }
111: return null;
112: }
113:
114: /**
115: * Get all the OperationDescriptors defined here.
116: *
117: * @return the list of OperationDescriptors.
118: */
119: public List getOperationDescriptors() {
120: return operationDescriptors;
121: }
122:
123: /**
124: * Get the String representation of this PortTypeDescriptor.
125: *
126: * @return the String representation of this PortTypeDescriptor.
127: */
128: public String toString() {
129: StringBuffer strBuf = new StringBuffer();
130:
131: strBuf.append("\nPortTypeDescriptor: name=" + name);
132:
133: if (operationDescriptors != null) {
134: Iterator opIterator = operationDescriptors.iterator();
135:
136: while (opIterator.hasNext()) {
137: strBuf.append("\n" + opIterator.next());
138: }
139: }
140:
141: return strBuf.toString();
142: }
143: }
|