diff options
Diffstat (limited to 'plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat')
8 files changed, 349 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/Chat.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/Chat.java new file mode 100644 index 0000000000..6f75253a0c --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/Chat.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat; + +import org.eclipse.net4j.buddies.chat.IChat; +import org.eclipse.net4j.buddies.chat.IComment; +import org.eclipse.net4j.buddies.common.IMessage; +import org.eclipse.net4j.buddies.spi.common.Facility; +import org.eclipse.net4j.util.event.IListener; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Eike Stepper + */ +public class Chat extends Facility implements IChat +{ + private List<IComment> comments = new ArrayList<IComment>(); + + public Chat() + { + super(TYPE); + } + + public IComment[] getComments() + { + synchronized (comments) + { + return comments.toArray(new IComment[comments.size()]); + } + } + + public void sendComment(String text) + { + TextMessage message = new TextMessage(text); + sendMessage(message); + addComment(message.getSenderID(), text); + } + + @Override + public void handleMessage(IMessage message) + { + if (message instanceof TextMessage) + { + addComment(message.getSenderID(), ((TextMessage)message).getText()); + } + } + + protected void addComment(String senderID, String text) + { + Comment comment = new Comment(System.currentTimeMillis(), senderID, text); + synchronized (comments) + { + comments.add(comment); + } + + IListener[] listeners = getListeners(); + if (listeners != null) + { + fireEvent(new CommentEvent(this, comment), listeners); + } + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatFactory.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatFactory.java new file mode 100644 index 0000000000..f22be39d81 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatFactory.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat; + +import org.eclipse.net4j.buddies.chat.IChat; +import org.eclipse.net4j.buddies.spi.common.ClientFacilityFactory; +import org.eclipse.net4j.util.factory.ProductCreationException; + +/** + * @author Eike Stepper + */ +public class ChatFactory extends ClientFacilityFactory +{ + public ChatFactory() + { + super(IChat.TYPE); + } + + public Chat create(String description) throws ProductCreationException + { + return new Chat(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatRoom.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatRoom.java new file mode 100644 index 0000000000..d1325ccdaa --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatRoom.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat; + +import org.eclipse.net4j.buddies.chat.IChatRoom; +import org.eclipse.net4j.buddies.common.IMessage; + +/** + * @author Eike Stepper + */ +public class ChatRoom extends Chat implements IChatRoom +{ + public ChatRoom() + { + } + + @Override + public void sendComment(String text) + { + throw new UnsupportedOperationException(); + } + + @Override + public void handleMessage(IMessage message) + { + sendMessage(message); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatRoomFactory.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatRoomFactory.java new file mode 100644 index 0000000000..4676e76799 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/ChatRoomFactory.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat; + +import org.eclipse.net4j.buddies.spi.common.ServerFacilityFactory; +import org.eclipse.net4j.util.factory.ProductCreationException; + +/** + * @author Eike Stepper + */ +public class ChatRoomFactory extends ServerFacilityFactory +{ + public static final String TYPE = "chat"; //$NON-NLS-1$ + + public ChatRoomFactory() + { + super(TYPE); + } + + public ChatRoom create(String description) throws ProductCreationException + { + return new ChatRoom(); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/Comment.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/Comment.java new file mode 100644 index 0000000000..a56fa81eb3 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/Comment.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat; + +import org.eclipse.net4j.buddies.chat.IComment; + +import java.io.Serializable; + +/** + * @author Eike Stepper + */ +public class Comment implements IComment, Serializable +{ + private static final long serialVersionUID = 1L; + + private long receiveTime; + + private String senderID; + + private String text; + + public Comment(long receiveTime, String senderID, String text) + { + this.receiveTime = receiveTime; + this.senderID = senderID; + this.text = text; + } + + public long getReceiveTime() + { + return receiveTime; + } + + public String getSenderID() + { + return senderID; + } + + public String getText() + { + return text; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/CommentEvent.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/CommentEvent.java new file mode 100644 index 0000000000..6045ff4204 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/CommentEvent.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat; + +import org.eclipse.net4j.buddies.chat.IChat; +import org.eclipse.net4j.buddies.chat.IComment; +import org.eclipse.net4j.buddies.chat.ICommentEvent; +import org.eclipse.net4j.util.event.Event; + +/** + * @author Eike Stepper + */ +public class CommentEvent extends Event implements ICommentEvent +{ + private static final long serialVersionUID = 1L; + + private IComment comment; + + public CommentEvent(IChat chat, IComment comment) + { + super(chat); + this.comment = comment; + } + + /** + * @since 3.0 + */ + @Override + public IChat getSource() + { + return (IChat)super.getSource(); + } + + public IComment getComment() + { + return comment; + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/TextMessage.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/TextMessage.java new file mode 100644 index 0000000000..8f74e4624e --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/TextMessage.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat; + +import org.eclipse.net4j.buddies.spi.common.Message; + +/** + * @author Eike Stepper + */ +public class TextMessage extends Message +{ + private static final long serialVersionUID = 1L; + + private String text; + + public TextMessage(String text) + { + this.text = encode(text); + } + + protected TextMessage() + { + } + + public String getText() + { + return decode(text); + } +} diff --git a/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/bundle/OM.java b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/bundle/OM.java new file mode 100644 index 0000000000..7a19b9a749 --- /dev/null +++ b/plugins/org.eclipse.net4j.examples.installer/examples/org.eclipse.net4j.buddies.chat/src/org/eclipse/net4j/buddies/internal/chat/bundle/OM.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) 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: + * Eike Stepper - initial API and implementation + */ +package org.eclipse.net4j.buddies.internal.chat.bundle; + +import org.eclipse.net4j.util.om.OMBundle; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.OSGiActivator; +import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.trace.OMTracer; + +/** + * The <em>Operations & Maintenance</em> class of this bundle. + * + * @author Eike Stepper + */ +public abstract class OM +{ + public static final String BUNDLE_ID = "org.eclipse.net4j.buddies.chat"; //$NON-NLS-1$ + + public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class); + + public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$ + + public static final OMLogger LOG = BUNDLE.logger(); + + /** + * @author Eike Stepper + */ + public static final class Activator extends OSGiActivator + { + public Activator() + { + super(BUNDLE); + } + } +} |