001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.ws.processor.model;
027:
028: import com.sun.tools.internal.ws.processor.model.java.JavaInterface;
029:
030: import javax.xml.namespace.QName;
031:
032: import java.util.ArrayList;
033: import java.util.HashMap;
034: import java.util.Iterator;
035: import java.util.List;
036: import java.util.Map;
037:
038: /**
039: *
040: * @author WS Development Team
041: */
042: public class Service extends ModelObject {
043:
044: public Service() {
045: }
046:
047: public Service(QName name, JavaInterface javaInterface) {
048: this .name = name;
049: this .javaInterface = javaInterface;
050: }
051:
052: public QName getName() {
053: return name;
054: }
055:
056: public void setName(QName n) {
057: name = n;
058: }
059:
060: public void addPort(Port port) {
061: if (portsByName.containsKey(port.getName())) {
062: throw new ModelException("model.uniqueness");
063: }
064: ports.add(port);
065: portsByName.put(port.getName(), port);
066: }
067:
068: public Port getPortByName(QName n) {
069: if (portsByName.size() != ports.size()) {
070: initializePortsByName();
071: }
072: return (Port) portsByName.get(n);
073: }
074:
075: /* serialization */
076: public List<Port> getPorts() {
077: return ports;
078: }
079:
080: /* serialization */
081: public void setPorts(List<Port> m) {
082: ports = m;
083: // initializePortsByName();
084: }
085:
086: private void initializePortsByName() {
087: portsByName = new HashMap();
088: if (ports != null) {
089: for (Iterator iter = ports.iterator(); iter.hasNext();) {
090: Port port = (Port) iter.next();
091: if (port.getName() != null
092: && portsByName.containsKey(port.getName())) {
093:
094: throw new ModelException("model.uniqueness");
095: }
096: portsByName.put(port.getName(), port);
097: }
098: }
099: }
100:
101: public JavaInterface getJavaIntf() {
102: return getJavaInterface();
103: }
104:
105: public JavaInterface getJavaInterface() {
106: return javaInterface;
107: }
108:
109: public void setJavaInterface(JavaInterface i) {
110: javaInterface = i;
111: }
112:
113: public void accept(ModelVisitor visitor) throws Exception {
114: visitor.visit(this );
115: }
116:
117: private QName name;
118: private List<Port> ports = new ArrayList();
119: private Map<QName, Port> portsByName = new HashMap<QName, Port>();
120: private JavaInterface javaInterface;
121: }
|