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.lib.collab.xmpp;
043:
044: import java.util.*;
045: import org.jabberstudio.jso.JID;
046:
047: import org.netbeans.lib.collab.*;
048:
049: /**
050: *
051: *
052: * @author Vijayakumar Palaniappan
053: *
054: */
055: public class XMPPPersonalGateway extends XMPPPersonalStoreEntry
056: implements PersonalGateway {
057:
058: private String _service;
059: private boolean _registered;
060:
061: private Set _features = new TreeSet();
062:
063: //public static final String GATEWAY_FOLDER = "Transports";
064: public static final String GATEWAY_FOLDER = "";
065:
066: public XMPPPersonalGateway(XMPPSession s, String name, String jid) {
067: super (s, name, PersonalStoreEntry.GATEWAY, jid);
068: }
069:
070: /** Creates a new instance of XMPPPersonalStoreGateway */
071: public XMPPPersonalGateway(XMPPSession s, String name, String jid,
072: String service) {
073: super (s, name, PersonalStoreEntry.GATEWAY, jid);
074: _service = service;
075: }
076:
077: public String getHostName() throws CollaborationException {
078: return getEntryId();
079: }
080:
081: public String getName() throws CollaborationException {
082: return getDisplayName();
083: }
084:
085: public String getService() throws CollaborationException {
086: return _service;
087: }
088:
089: public void setService(String service)
090: throws CollaborationException {
091: _service = service;
092: }
093:
094: public void register(RegistrationListener listener)
095: throws CollaborationException {
096: XMPPRegistrationListenerWrapper regisListenerWrapper = new XMPPRegistrationListenerWrapper(
097: listener);
098: regisListenerWrapper
099: .setRequestType(XMPPRegistrationListenerWrapper.GATEWAY_REGISTRATION);
100: _session.register(getHostName(), regisListenerWrapper);
101: }
102:
103: public void unregister(RegistrationListener regisListener)
104: throws CollaborationException {
105: XMPPRegistrationListenerWrapper regisListenerWrapper = new XMPPRegistrationListenerWrapper(
106: regisListener);
107: regisListenerWrapper
108: .setRequestType(XMPPRegistrationListenerWrapper.GATEWAY_UNREGISTRATION);
109: _session.unregister(new JID(getHostName()),
110: regisListenerWrapper);
111: // remove all the legacy users from the roster
112: XMPPPersonalStoreService pss = (XMPPPersonalStoreService) _session
113: .getPersonalStoreService();
114: for (Iterator i = pss.getEntries(PersonalStoreEntry.CONTACT)
115: .iterator(); i.hasNext();) {
116: PersonalContact pc = (PersonalContact) i.next();
117: String domain = pc.getPrincipal().getDomainName();
118: if (domain != null && domain.equalsIgnoreCase(_jid)) {
119: pc.remove();
120: }
121: }
122: _registered = false;
123: }
124:
125: public void addSupportedFeature(String feature)
126: throws CollaborationException {
127: _features.add(feature);
128: }
129:
130: public Set getSupportedFeatures() throws CollaborationException {
131: return _features;
132: }
133:
134: public boolean isSupportedFeature(String feature)
135: throws CollaborationException {
136: return _features.contains(feature);
137: }
138:
139: public void removeSupportedFeature(String feature)
140: throws CollaborationException {
141: _features.remove(feature);
142: }
143:
144: public boolean isRegistered() throws CollaborationException {
145: PersonalStoreService pss = (PersonalStoreService) _session
146: .getPersonalStoreService();
147: return pss.getEntry(PersonalStoreEntry.GATEWAY, getHostName()) != null;
148: }
149:
150: }
|