package c.t.s.xfire; import java.util.Collections; import java.util.HashSet; import java.util.Set; import javax.wsdl.PortType; import javax.xml.namespace.QName; /** * Contains information required for defining partnerLinkType * elements as part of a WSDL definition. * * The partnerLinkType XML schema is at * * http://schemas.xmlsoap.org/ws/2003/05/partner-link/. * * @author deanj */ public class PartnerLinkType { // contains the roles defined for this element private final Set _roles; // the name of the partnerLinkType element private final String _name; /** * Constructor. */ public PartnerLinkType(String name) { _roles = new HashSet(); _name = name; } /** * Add a role to the partnerLinkType. * * @param roleName the value of the name attribute * of the role element * @param portType The PortType that this partnerLinkType refers to. * of the portType element * @throws IllegalStateException if there are already two * roles defined for this partnerLinkType */ public void addRole(String roleName, PortType portType) { if (_roles.size()==2) { throw new IllegalStateException("Cannot add a role to a partnerLinkType that already has two roles defined"); } else { _roles.add(new Role(roleName, portType)); } } /** * Retrieve the roles defined on this * partnerLinkType. Note that this * method makes a defensive unmodifiable copy of the * roles stored by this object (this ensures that the * restriction on the allowed number of roles cannot * be broken). * * @return an Iterator over the roles (at most two). */ public Set getRoles() { return Collections.unmodifiableSet(_roles); } /** * Retrieve the name of the partnerLinkType element * * @return the value of the name attribute * of the partnerLinkType element */ public String getName() { return _name; } /** * Represents a role child element of a * PartnerLinkType element. * * @author deanj */ public class Role { private final String _roleName; private final QName _portTypeName; /** * Constructor. * * @param roleName the value of the name attribute of the role element * @param portType the PortType that this Role relates to, populates the value of the name * attribute of the portType element */ public Role(String roleName, PortType portType) { _portTypeName = portType.getQName(); _roleName = roleName; } /** * Getter for the name of the role * * @return the name of the role */ public String getName() { return _roleName; } /** * Getter for the qname of the port type * * @return the qname of the port type */ public QName getPortTypeName() { return _portTypeName; } } }