diff options
19 files changed, 972 insertions, 0 deletions
diff --git a/framework/bundles/org.eclipse.ecf.presence/.classpath b/framework/bundles/org.eclipse.ecf.presence/.classpath new file mode 100644 index 000000000..065ac06e1 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/framework/bundles/org.eclipse.ecf.presence/.cvsignore b/framework/bundles/org.eclipse.ecf.presence/.cvsignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/framework/bundles/org.eclipse.ecf.presence/.project b/framework/bundles/org.eclipse.ecf.presence/.project new file mode 100644 index 000000000..3d09b4bb7 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ecf.presence</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/framework/bundles/org.eclipse.ecf.presence/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.presence/META-INF/MANIFEST.MF new file mode 100644 index 000000000..1f3706464 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/META-INF/MANIFEST.MF @@ -0,0 +1,12 @@ +Manifest-Version: 1.0 +Bundle-Name: ECF Presence Plug-in +Bundle-SymbolicName: org.eclipse.ecf.presence +Bundle-Version: 1.0.0 +Bundle-ClassPath: presence.jar +Bundle-Activator: org.eclipse.ecf.presence.PresencePlugin +Bundle-Vendor: Eclipse.org +Bundle-Localization: plugin +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.ecf +Eclipse-AutoStart: true +Export-Package: org.eclipse.ecf.presence, org.eclipse.ecf.presence.impl diff --git a/framework/bundles/org.eclipse.ecf.presence/build.properties b/framework/bundles/org.eclipse.ecf.presence/build.properties new file mode 100644 index 000000000..bf31c24b1 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/build.properties @@ -0,0 +1,5 @@ +source.presence.jar = src/ +output.presence.jar = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + presence.jar diff --git a/framework/bundles/org.eclipse.ecf.presence/plugin.xml b/framework/bundles/org.eclipse.ecf.presence/plugin.xml new file mode 100644 index 000000000..8e49b5212 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/plugin.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin> + +</plugin> diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IMessageListener.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IMessageListener.java new file mode 100644 index 000000000..2d707f01c --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IMessageListener.java @@ -0,0 +1,65 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence; + +import org.eclipse.ecf.core.identity.ID; + +public interface IMessageListener { + + public void handleMessage(ID fromID, ID toID, Type type, String subject, String message); + + public static class Type { + + private static final String NORMAL_NAME = "normal"; + private static final String CHAT_NAME = "chat"; + private static final String GROUP_CHAT_NAME = "group_chat"; + private static final String HEADLINE_NAME = "headline"; + private static final String ERROR_NAME = "error"; + + private final transient String name; + // Protected constructor so that only subclasses are allowed to create instances + protected Type(String name) { + this.name = name; + } + public static Type fromString(String itemType) { + if (itemType == null) return null; + if (itemType.equals(NORMAL_NAME)) { + return NORMAL; + } else if (itemType.equals(CHAT_NAME)) { + return CHAT; + } else if (itemType.equals(GROUP_CHAT_NAME)) { + return GROUP_CHAT; + } else if (itemType.equals(HEADLINE_NAME)) { + return HEADLINE; + } else if (itemType.equals(ERROR_NAME)) { + return ERROR; + } else return null; + } + + public static final Type NORMAL = new Type(NORMAL_NAME); + public static final Type CHAT = new Type(CHAT_NAME); + public static final Type GROUP_CHAT = new Type(GROUP_CHAT_NAME); + public static final Type HEADLINE = new Type(HEADLINE_NAME); + public static final Type ERROR = new Type(ERROR_NAME); + + public String toString() { return name; } + // This is to make sure that subclasses don't screw up these methods + public final boolean equals(Object that) { + return super.equals(that); + } + public final int hashCode() { + return super.hashCode(); + } + } + + +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IMessageSender.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IMessageSender.java new file mode 100644 index 000000000..3dfb2dee2 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IMessageSender.java @@ -0,0 +1,20 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ +package org.eclipse.ecf.presence; + +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.presence.IMessageListener.Type; + +public interface IMessageSender { + + public void sendMessage(ID fromID, ID toID, Type type, String subject, String message); + +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresence.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresence.java new file mode 100644 index 000000000..ab897220f --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresence.java @@ -0,0 +1,153 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence; + +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.util.Map; +import org.eclipse.core.runtime.IAdaptable; + +public interface IPresence extends IAdaptable, Serializable { + + public Mode getMode(); + public int getPriority(); + public Map getProperties(); + public String getStatus(); + public Type getType(); + + /** + * A type-safe enum class to represent the presence type information + * + */ + public static class Type implements Serializable { + + private static final String AVAILABLE_NAME = "available"; + private static final String ERROR_NAME = "error"; + private static final String SUBSCRIBE_NAME = "subscribe"; + private static final String SUBSCRIBED_NAME = "subscribed"; + private static final String UNAVAILABLE_NAME = "unavailable"; + private static final String UNSUBSCRIBE_NAME = "unsubscribe"; + private static final String UNSUBSCRIBED_NAME = "unsubscribed"; + private static final String UNKWOWN_NAME = "unknown"; + + private final transient String name; + // Protected constructor so that only subclasses are allowed to create instances + protected Type(String name) { + this.name = name; + } + public static Type fromString(String presenceType) { + if (presenceType == null) return null; + if (presenceType.equals(AVAILABLE_NAME)) { + return AVAILABLE; + } else if (presenceType.equals(ERROR_NAME)) { + return ERROR; + } else if (presenceType.equals(SUBSCRIBE_NAME)) { + return SUBSCRIBE; + } else if (presenceType.equals(SUBSCRIBED_NAME)) { + return SUBSCRIBED; + } else if (presenceType.equals(UNAVAILABLE_NAME)) { + return UNAVAILABLE; + } else if (presenceType.equals(UNSUBSCRIBE_NAME)) { + return UNSUBSCRIBE; + } else if (presenceType.equals(UNSUBSCRIBED_NAME)) { + return UNSUBSCRIBED; + } else if (presenceType.equals(UNKWOWN_NAME)) { + return UNKNOWN; + } else return null; + } + + public static final Type AVAILABLE = new Type(AVAILABLE_NAME); + public static final Type ERROR = new Type(ERROR_NAME); + public static final Type SUBSCRIBE = new Type(SUBSCRIBE_NAME); + public static final Type SUBSCRIBED = new Type(SUBSCRIBED_NAME); + public static final Type UNAVAILABLE = new Type(UNAVAILABLE_NAME); + public static final Type UNSUBSCRIBE = new Type(UNSUBSCRIBE_NAME); + public static final Type UNSUBSCRIBED = new Type(UNSUBSCRIBED_NAME); + public static final Type UNKNOWN = new Type(UNKWOWN_NAME); + + public String toString() { return name; } + // This is to make sure that subclasses don't screw up these methods + public final boolean equals(Object that) { + return super.equals(that); + } + public final int hashCode() { + return super.hashCode(); + } + // For serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private static final Type [] VALUES = { AVAILABLE, ERROR, SUBSCRIBE, SUBSCRIBED, UNAVAILABLE, UNSUBSCRIBE, UNSUBSCRIBED, UNKNOWN }; + Object readResolve() throws ObjectStreamException { + return VALUES[ordinal]; + } + } + + /** + * A type-safe enum class to represent the presence mode information + * + */ + public static class Mode implements Serializable { + + private static final String AVAILABLE_NAME = "available"; + private static final String AWAY_NAME = "away"; + private static final String CHAT_NAME = "chat"; + private static final String DND_NAME = "do not disturb"; + private static final String EXTENDED_AWAY_NAME = "extended away"; + private static final String INVISIBLE_NAME = "unsubscribed"; + + private final transient String name; + // Protected constructor so that only subclasses are allowed to create instances + protected Mode(String name) { + this.name = name; + } + public static Mode fromString(String presenceMode) { + if (presenceMode == null) return null; + if (presenceMode.equals(AVAILABLE_NAME)) { + return AVAILABLE; + } else if (presenceMode.equals(AWAY_NAME)) { + return AWAY; + } else if (presenceMode.equals(CHAT_NAME)) { + return CHAT; + } else if (presenceMode.equals(DND_NAME)) { + return DND; + } else if (presenceMode.equals(EXTENDED_AWAY_NAME)) { + return EXTENDED_AWAY; + } else if (presenceMode.equals(INVISIBLE_NAME)) { + return INVISIBLE; + } else return null; + } + + public static final Mode AVAILABLE = new Mode(AVAILABLE_NAME); + public static final Mode AWAY = new Mode(AWAY_NAME); + public static final Mode CHAT = new Mode(CHAT_NAME); + public static final Mode DND = new Mode(DND_NAME); + public static final Mode EXTENDED_AWAY = new Mode(EXTENDED_AWAY_NAME); + public static final Mode INVISIBLE = new Mode(INVISIBLE_NAME); + + public String toString() { return name; } + // This is to make sure that subclasses don't screw up these methods + public final boolean equals(Object that) { + return super.equals(that); + } + public final int hashCode() { + return super.hashCode(); + } + // For serialization + private static int nextOrdinal = 0; + private final int ordinal = nextOrdinal++; + private static final Mode [] VALUES = { AVAILABLE, AWAY, CHAT, DND, EXTENDED_AWAY, INVISIBLE }; + Object readResolve() throws ObjectStreamException { + return VALUES[ordinal]; + } + } + +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresenceContainer.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresenceContainer.java new file mode 100644 index 000000000..9df56423c --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresenceContainer.java @@ -0,0 +1,26 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ +package org.eclipse.ecf.presence; + +import org.eclipse.ecf.core.ISharedObjectContainer; +import org.eclipse.ecf.core.SharedObjectContainerInstantiationException; + +public interface IPresenceContainer { + + public void addPresenceListener(IPresenceListener listener); + public void addMessageListener(IMessageListener listener); + public void addSharedObjectMessageListener(ISharedObjectMessageListener listener); + + public IMessageSender getMessageSender(); + + public ISharedObjectContainer makeSharedObjectContainer(Class [] types, Object [] args) throws SharedObjectContainerInstantiationException; + +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresenceListener.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresenceListener.java new file mode 100644 index 000000000..347f847ba --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IPresenceListener.java @@ -0,0 +1,22 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ +package org.eclipse.ecf.presence; + +import org.eclipse.ecf.core.identity.ID; + +public interface IPresenceListener { + + public void handleContainerJoined(ID joinedContainer); + public void handleRosterEntry(IRosterEntry entry); + public void handlePresence(ID fromID, IPresence presence); + public void handleContainerDeparted(ID departedContainer); + +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IRosterEntry.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IRosterEntry.java new file mode 100644 index 000000000..01673d0de --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IRosterEntry.java @@ -0,0 +1,73 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence; + +import java.util.Iterator; +import org.eclipse.ecf.core.identity.ID; + +public interface IRosterEntry { + + public void add(IRosterGroup group); + public void remove(IRosterGroup group); + public Iterator getGroups(); + public String getName(); + public ID getUserID(); + public void setName(String name); + public InterestType getInterestType(); + public IPresence getPresenceState(); + public void setPresenceState(IPresence presence); + + public static class InterestType { + + private static final String BOTH_NAME = "both"; + private static final String FROM_NAME = "from"; + private static final String NONE_NAME = "none"; + private static final String REMOVE_NAME = "remove"; + private static final String TO_NAME = "to"; + + private final transient String name; + // Protected constructor so that only subclasses are allowed to create instances + protected InterestType(String name) { + this.name = name; + } + public static InterestType fromString(String itemType) { + if (itemType == null) return null; + if (itemType.equals(BOTH_NAME)) { + return BOTH; + } else if (itemType.equals(FROM_NAME)) { + return FROM; + } else if (itemType.equals(NONE_NAME)) { + return NONE; + } else if (itemType.equals(REMOVE_NAME)) { + return REMOVE; + } else if (itemType.equals(TO_NAME)) { + return TO; + } else return null; + } + + public static final InterestType BOTH = new InterestType(BOTH_NAME); + public static final InterestType FROM = new InterestType(FROM_NAME); + public static final InterestType NONE = new InterestType(NONE_NAME); + public static final InterestType REMOVE = new InterestType(REMOVE_NAME); + public static final InterestType TO = new InterestType(TO_NAME); + + public String toString() { return name; } + // This is to make sure that subclasses don't screw up these methods + public final boolean equals(Object that) { + return super.equals(that); + } + public final int hashCode() { + return super.hashCode(); + } + } + +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IRosterGroup.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IRosterGroup.java new file mode 100644 index 000000000..9ad393d39 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/IRosterGroup.java @@ -0,0 +1,25 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence; + +import java.util.Iterator; +import java.util.Map; + +public interface IRosterGroup { + public IRosterEntry add(IRosterEntry entry); + public void addAll(Map existing); + public IRosterEntry contains(IRosterEntry entry); + public Iterator getRosterEntries(); + public int size(); + public String getName(); + public IRosterEntry removeEntry(IRosterEntry entry); +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/ISharedObjectMessageListener.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/ISharedObjectMessageListener.java new file mode 100644 index 000000000..8566b3679 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/ISharedObjectMessageListener.java @@ -0,0 +1,18 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ +package org.eclipse.ecf.presence; + +import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; + +public interface ISharedObjectMessageListener { + + public void handleSharedObjectMessage(ISharedObjectMessageEvent event); +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/PresencePlugin.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/PresencePlugin.java new file mode 100644 index 000000000..78961aba7 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/PresencePlugin.java @@ -0,0 +1,74 @@ +package org.eclipse.ecf.presence; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; +import java.util.*; + +/** + * The main plugin class to be used in the desktop. + */ +public class PresencePlugin extends Plugin { + + public static final String PLUGIN_ID = "org.eclise.ecf.presence"; + //The shared instance. + private static PresencePlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + /** + * The constructor. + */ + public PresencePlugin() { + super(); + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + resourceBundle = null; + } + + /** + * Returns the shared instance. + */ + public static PresencePlugin getDefault() { + return plugin; + } + + /** + * Returns the string from the plugin's resource bundle, + * or 'key' if not found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = PresencePlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + try { + if (resourceBundle == null) + resourceBundle = ResourceBundle.getBundle("org.eclipse.ecf.presence.PresencePluginResources"); + } catch (MissingResourceException x) { + resourceBundle = null; + } + return resourceBundle; + } +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/Trace.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/Trace.java new file mode 100644 index 000000000..e20dc7464 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/Trace.java @@ -0,0 +1,120 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence; + +import java.text.SimpleDateFormat; +import java.util.Date; +import org.eclipse.core.runtime.Platform; + +public class Trace { + public static final String tracePrefix = "(trace)"; + + public static boolean ON = false; + protected static boolean isEclipse = false; + protected static String pluginName = ""; + protected static String debugPrefix = "/debug/"; + static { + try { + ON = Platform.inDebugMode(); + String val = System.getProperty(PresencePlugin.PLUGIN_ID+".Trace"); + if (val != null) { + setTrace(true); + isEclipse = false; + // No eclipse Platform available + System.out.println("WARNING: Eclipse platform not being use for trace...overridden by system property org.eclipse.ecf.ui.Trace"); + } else { + isEclipse = true; + pluginName = PresencePlugin.PLUGIN_ID; + } + } catch (Exception e) { + try { + String val = System.getProperty(PresencePlugin.PLUGIN_ID+".Trace"); + if (val != null) { + setTrace(true); + isEclipse = false; + // No eclipse Platform available + System.out.println("WARNING: Eclipse platform not available for trace...using system.out for org.eclipse.ecf.ui"); + } else { + System.out.println(Trace.class.getName()+": OFF"); + } + } catch (Exception except) { + } + } + } + public static void setTrace(boolean on) { + ON = on; + } + + public static Trace create(String key) { + if (isEclipse) { + String res = Platform + .getDebugOption(pluginName + debugPrefix + key); + if (res != null) { + Boolean on = new Boolean(res); + if (on.booleanValue()) + return new Trace(pluginName + "(" + key + ")"); + else + return null; + } else { + return null; + } + } else + return new Trace(key); + } + + String name; + + public void dumpStack(Throwable e, String msg) { + msg(msg); + e.printStackTrace(System.err); + } + + public void msg(String msg) { + StringBuffer sb = new StringBuffer(name); + sb.append(getTimeString()).append(msg); + System.out.println(sb.toString()); + } + + protected static String getTimeString() { + Date d = new Date(); + SimpleDateFormat df = new SimpleDateFormat("[MM/dd/yy;HH:mm:ss:SSS]"); + return df.format(d); + } + + protected Trace(String str) { + name = tracePrefix+str; + } + public static String convertStringAToString(String [] strings) { + if (strings==null) return ""; + StringBuffer sb = new StringBuffer(); + for(int i=0; i < strings.length; i++) { + if (strings[i]==null) sb.append("(null)"); + else sb.append(strings[i]); + if (i != (strings.length-1)) sb.append(";"); + } + return sb.toString(); + } + public static String convertObjectAToString(Object [] objs) { + if (objs==null) return ""; + StringBuffer sb = new StringBuffer(); + for(int i=0; i < objs.length; i++) { + if (objs[i]==null) sb.append("(null)"); + else sb.append(objs[i].toString()); + if (i != (objs.length-1)) sb.append(";"); + } + return sb.toString(); + } + + public static void setThreadDebugGroup(Object obj) { + // Do nothing + } +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/Presence.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/Presence.java new file mode 100644 index 000000000..fab8d9493 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/Presence.java @@ -0,0 +1,77 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence.impl; + +import java.util.Map; +import java.util.Properties; +import org.eclipse.ecf.presence.IPresence; + +public class Presence implements IPresence { + + protected Type type; + protected Mode mode; + protected int priority; + protected String status; + protected Map properties; + + public Presence() { + this(Type.AVAILABLE); + } + public Presence(Type type) { + this(type,"",Mode.AVAILABLE); + } + public Presence(Type type, int priority, String status, Mode mode, Map props) { + this.type = type; + this.priority = priority; + this.status = status; + this.mode = mode; + this.properties = props; + } + public Presence(Type type, int priority, String status, Mode mode) { + this(type,priority,status,mode,new Properties()); + } + public Presence(Type type, String status, Mode mode) { + this(type,-1,status,mode); + } + public Mode getMode() { + return mode; + } + public int getPriority() { + return priority; + } + public Map getProperties() { + return properties; + } + public String getStatus() { + return status; + } + public Type getType() { + return type; + } + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + return null; + } + + public String toString() { + StringBuffer sb = new StringBuffer("Presence["); + sb.append("type=").append(type).append(";"); + sb.append("mode=").append(mode).append(";"); + sb.append("priority=").append(priority).append(";"); + sb.append("status=").append(status).append(";"); + sb.append("props=").append(properties).append(";"); + sb.append("]"); + return sb.toString(); + } +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/RosterEntry.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/RosterEntry.java new file mode 100644 index 000000000..600ba71b8 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/RosterEntry.java @@ -0,0 +1,129 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence.impl; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.presence.IPresence; +import org.eclipse.ecf.presence.IRosterEntry; +import org.eclipse.ecf.presence.IRosterGroup; + +public class RosterEntry implements IRosterEntry { + + protected ID userID; + protected String name; + protected IPresence presenceState; + protected InterestType interestType; + protected List groups; + + public RosterEntry(ID userID, String name, IPresence presenceState, InterestType interestType, Collection grps) { + this.userID = userID; + this.name = name; + this.presenceState = presenceState; + this.interestType = interestType; + this.groups = new ArrayList(); + if (grps != null) this.groups.addAll(groups); + } + + public RosterEntry(ID userID, String name) { + this(userID,name,null,InterestType.BOTH,null); + } + + public RosterEntry(ID userID, String name, IPresence presenceState) { + this(userID,name,presenceState,InterestType.BOTH,null); + } + public RosterEntry(ID userID, String name, InterestType interestType) { + this(userID,name,null,interestType,null); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#getGroups() + */ + public Iterator getGroups() { + return groups.iterator(); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#getName() + */ + public String getName() { + return name; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#getUserID() + */ + public ID getUserID() { + return userID; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#setName(java.lang.String) + */ + public void setName(String name) { + this.name = name; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#getInterestType() + */ + public InterestType getInterestType() { + return interestType; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#getPresenceState() + */ + public IPresence getPresenceState() { + return presenceState; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#setPresenceState(org.eclipse.ecf.ui.presence.IPresence) + */ + public void setPresenceState(IPresence presence) { + this.presenceState = presence; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#addGroup(org.eclipse.ecf.ui.presence.IRosterGroup) + */ + public void add(IRosterGroup group) { + groups.add(group); + } + + public void addAll(Collection grps) { + groups.addAll(grps); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterEntry#remvoe(org.eclipse.ecf.ui.presence.IRosterGroup) + */ + public void remove(IRosterGroup group) { + groups.remove(group); + } + + public String toString() { + StringBuffer sb = new StringBuffer("RosterEntry["); + sb.append("userID=").append(userID).append(";"); + sb.append("name=").append(name).append(";"); + sb.append("presence=").append(presenceState).append(";"); + sb.append("interest=").append(interestType).append(";"); + sb.append("groups=").append(groups).append(";"); + sb.append("]"); + return sb.toString(); + } + +} diff --git a/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/RosterGroup.java b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/RosterGroup.java new file mode 100644 index 000000000..f554e7ba2 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.presence/src/org/eclipse/ecf/presence/impl/RosterGroup.java @@ -0,0 +1,112 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* All rights reserved. This program and the accompanying materials +* are made available under the terms of the Eclipse Public License v1.0 +* which accompanies this distribution, and is available at +* http://www.eclipse.org/legal/epl-v10.html +* +* Contributors: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + +package org.eclipse.ecf.presence.impl; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.presence.IRosterEntry; +import org.eclipse.ecf.presence.IRosterGroup; + +public class RosterGroup implements IRosterGroup { + + protected Map entries; + protected String name; + + public RosterGroup(String name, Map existing) { + super(); + this.name = name; + entries = new HashMap(); + if (existing != null) addAll(existing); + } + + public RosterGroup(String name) { + this(name,null); + } + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterGroup#add(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.ui.presence.IRosterEntry) + */ + public IRosterEntry add(IRosterEntry entry) { + if (entry != null) { + synchronized (entries) { + IRosterEntry res = (IRosterEntry) entries.put(entry.getUserID(),entry); + entry.add(this); + return res; + } + } else return null; + } + public void addAll(Map existing) { + synchronized (entries) { + for(Iterator i=existing.entrySet().iterator(); i.hasNext(); ) { + IRosterEntry entry = (IRosterEntry) i.next(); + add(entry); + } + } + } + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterGroup#contains(org.eclipse.ecf.core.identity.ID) + */ + public IRosterEntry contains(IRosterEntry entry) { + if (entry == null) return null; + synchronized (entries) { + ID uID = entry.getUserID(); + boolean has = entries.containsKey(uID); + if (has) { + return (IRosterEntry) entries.get(uID); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterGroup#getRosterEntries() + */ + public Iterator getRosterEntries() { + return entries.values().iterator(); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterGroup#size() + */ + public int size() { + return entries.size(); + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterGroup#getName() + */ + public String getName() { + return this.name; + } + + /* (non-Javadoc) + * @see org.eclipse.ecf.ui.presence.IRosterGroup#removeEntry(org.eclipse.ecf.ui.presence.IRosterEntry) + */ + public IRosterEntry removeEntry(IRosterEntry entry) { + synchronized (entries) { + boolean hasEntry = entries.containsValue(entry); + IRosterEntry res = (IRosterEntry) entries.remove(entry.getUserID()); + return res; + } + } + + public String toString() { + StringBuffer sb = new StringBuffer("RosterGroup["); + sb.append("name=").append(name).append(";"); + sb.append("entries=").append(entries).append(";"); + sb.append("]"); + return sb.toString(); + } + + +} |