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.netbeans.lib.collab.xmpp.*;
046: import org.jabberstudio.jso.*;
047: import org.netbeans.lib.collab.CollaborationPrincipal;
048:
049: /**
050: *
051: *
052: */
053: public class XMPPPrincipal implements CollaborationPrincipal {
054:
055: String _displayName = null;
056:
057: private Properties _attrs = new Properties();
058: JID _jid;
059:
060: /** Creates a new instance of XMPPPrincipal */
061: public XMPPPrincipal(JID jid) {
062: setJID(jid);
063: }
064:
065: public XMPPPrincipal(String jid) throws JIDFormatException {
066: this (new JID(jid));
067: }
068:
069: public XMPPPrincipal(JID jid, String displayName) {
070: this (jid);
071: _displayName = displayName;
072: }
073:
074: public String getJid() {
075: return getJID().toString();
076: }
077:
078: public String getUID() {
079: //return getJID().toBareJID().toString();
080: return getJID().toString();
081: }
082:
083: public JID getJID() {
084: return _jid;
085: }
086:
087: public void setJID(JID jid) {
088: _jid = jid;
089: }
090:
091: public String getName() {
092: return getJID().getNode();
093: }
094:
095: public String getFQName() {
096: return getJID().toBareJID().toString();
097: }
098:
099: public String getDisplayName() {
100: if (_displayName == null) {
101: return getFQName();
102: }
103: return _displayName;
104: }
105:
106: public String getDomainName() {
107: return getJID().getDomain();
108: }
109:
110: public String getResource() {
111: return getJID().getResource();
112: }
113:
114: /**
115: * @deprecated
116: */
117: private void setAttribute(String name, Object value) {
118: if (_attrs == null)
119: _attrs = new Properties();
120: _attrs.put(name, value);
121: }
122:
123: public void setAttributes(Map attrs) {
124: if (attrs instanceof Properties) {
125: this ._attrs = (Properties) attrs;
126: } else {
127: if (_attrs == null)
128: _attrs = new Properties();
129: _attrs.putAll(attrs);
130: }
131: }
132:
133: public Properties getAttributes() {
134: return _attrs;
135: }
136:
137: public Object getValue(String attributeName) {
138: if (_attrs == null)
139: return null;
140: return _attrs.get(attributeName);
141: }
142:
143: public void setProperty(String name, String value) {
144: _attrs.put(name, value);
145: }
146:
147: public String getProperty(String attributeName) {
148: if (_attrs == null)
149: return null;
150: String val = null;
151: Object o = _attrs.get(attributeName);
152: if (o instanceof Set) {
153: Set s = (Set) o;
154: if (s != null && !s.isEmpty()) {
155: val = (String) s.iterator().next();
156: }
157: } else {
158: val = (String) o;
159: }
160: return val;
161: }
162:
163: public Set getAttributeValues(String attributeName) {
164: if (_attrs == null)
165: return null;
166: Set val = null;
167: Object o = _attrs.get(attributeName);
168: if (o instanceof String) {
169: val = new HashSet();
170: val.add(o);
171: } else {
172: val = (Set) o;
173: }
174: return val;
175: }
176:
177: public Enumeration propertyNames() {
178: return _attrs.propertyNames();
179: }
180:
181: /**
182: * set the values of a single-valued or multi-valued attribute
183: */
184: public void setAttributeValues(String attribute, Set values) {
185: if (_attrs == null)
186: _attrs = new Properties();
187: _attrs.put(attribute, values);
188: }
189:
190: public boolean equals(Object o) {
191: return (o != null && o instanceof CollaborationPrincipal && ((CollaborationPrincipal) o)
192: .getUID().equals(getUID()));
193: }
194:
195: }
|