001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.registry.model;
043:
044: import java.util.ArrayList;
045: import java.util.HashSet;
046: import java.util.Iterator;
047: import java.util.List;
048: import java.util.Set;
049: import org.netbeans.modules.websvc.registry.model.WebServiceListModel;
050: import org.netbeans.modules.websvc.registry.util.Util;
051:
052: /**
053: *
054: * @author Winston Prakash
055: */
056: public class WebServiceGroup {
057:
058: Set listeners = new HashSet();
059: String groupId = null;
060: String groupName = null;
061:
062: Set webserviceIds = new HashSet();
063:
064: public WebServiceGroup() {
065: this (WebServiceListModel.getInstance()
066: .getUniqueWebServiceGroupId());
067: }
068:
069: public WebServiceGroup(String id) {
070: setId(id);
071: }
072:
073: public void addWebServiceGroupListener(
074: WebServiceGroupListener listener) {
075: listeners.add(listener);
076: }
077:
078: public void removeWebServiceGroupListener(
079: WebServiceGroupListener listener) {
080: listeners.remove(listener);
081: }
082:
083: public void setId(String id) {
084: groupId = id;
085: }
086:
087: public String getId() {
088: return groupId;
089: }
090:
091: public String getName() {
092: return groupName;
093: }
094:
095: public void setName(String name) {
096: groupName = name;
097: }
098:
099: public void add(String webServiceId) {
100: //System.out.println("WebServiceGroup add called - " + webServiceId);
101: if (!webserviceIds.contains(webServiceId)) {
102: WebServiceData wsData = WebServiceListModel.getInstance()
103: .getWebService(webServiceId);
104: wsData.setGroupId(getId());
105: webserviceIds.add(webServiceId);
106: Iterator iter = listeners.iterator();
107: while (iter.hasNext()) {
108: WebServiceGroupEvent evt = new WebServiceGroupEvent(
109: webServiceId);
110: ((WebServiceGroupListener) iter.next())
111: .webServiceAdded(evt);
112: }
113: }
114: }
115:
116: public void remove(String webServiceId) {
117: //System.out.println("WebServiceGroup remove called - " + webServiceId);
118: if (webserviceIds.contains(webServiceId)) {
119: webserviceIds.remove(webServiceId);
120: Iterator iter = listeners.iterator();
121: while (iter.hasNext()) {
122: WebServiceGroupEvent evt = new WebServiceGroupEvent(
123: webServiceId);
124: ((WebServiceGroupListener) iter.next())
125: .webServiceRemoved(evt);
126: }
127: }
128: }
129:
130: public void setWebServiceIds(Set ids) {
131: webserviceIds = ids;
132: Iterator iter = webserviceIds.iterator();
133: while (iter.hasNext()) {
134: WebServiceData wsData = WebServiceListModel.getInstance()
135: .getWebService((String) iter.next());
136: wsData.setGroupId(getId());
137: }
138: }
139:
140: public Set getWebServiceIds() {
141: return webserviceIds;
142: }
143:
144: }
|