http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/data/converter/v21/EventDataConverterV21.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/data/converter/v21/EventDataConverterV21.java b/wave/src/main/java/com/google/wave/api/data/converter/v21/EventDataConverterV21.java deleted file mode 100644 index 694567a..0000000 --- a/wave/src/main/java/com/google/wave/api/data/converter/v21/EventDataConverterV21.java +++ /dev/null @@ -1,293 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter.v21; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Lists; -import com.google.wave.api.Annotation; -import com.google.wave.api.ApiIdSerializer; -import com.google.wave.api.BlipData; -import com.google.wave.api.Range; -import com.google.wave.api.data.ApiView; -import com.google.wave.api.data.ElementSerializer; -import com.google.wave.api.data.converter.EventDataConverter; -import com.google.wave.api.impl.EventMessageBundle; -import com.google.wave.api.impl.WaveletData; - -import org.waveprotocol.wave.model.account.DocumentBasedRoles; -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.conversation.ConversationThread; -import org.waveprotocol.wave.model.conversation.TagsDocument; -import org.waveprotocol.wave.model.conversation.TitleHelper; -import org.waveprotocol.wave.model.document.Document; -import org.waveprotocol.wave.model.document.ObservableDocument; -import org.waveprotocol.wave.model.document.RangedAnnotation; -import org.waveprotocol.wave.model.document.util.XmlStringBuilder; -import org.waveprotocol.wave.model.id.IdConstants; -import org.waveprotocol.wave.model.id.IdUtil; -import org.waveprotocol.wave.model.wave.ParticipantId; -import org.waveprotocol.wave.model.wave.Wavelet; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * An implementation of {@link EventDataConverter} for all protocol versions - * that are less than or equal to v0.21. - * - */ -public class EventDataConverterV21 implements EventDataConverter { - - @Override - public WaveletData toWaveletData(Wavelet wavelet, Conversation conversation, - EventMessageBundle eventMessageBundle) { - final WaveletData waveletData = new WaveletData(); - waveletData.setCreationTime(wavelet.getCreationTime()); - waveletData.setCreator(wavelet.getCreatorId().getAddress()); - waveletData.setWaveId(ApiIdSerializer.instance().serialiseWaveId(wavelet.getWaveId())); - waveletData.setWaveletId(ApiIdSerializer.instance().serialiseWaveletId(wavelet.getId())); - waveletData.setLastModifiedTime(wavelet.getLastModifiedTime()); - waveletData.setParticipants(idsToParticipantIdList(wavelet.getParticipantIds())); - waveletData.setRootBlipId(conversation.getRootThread().getFirstBlip().getId()); - waveletData.setTitle(getTitle(wavelet, conversation)); - waveletData.setVersion(wavelet.getVersion()); - - // Add Data Docs. All data documents are silently name spaced under the - // robot prefix to avoid conflicts. Any docId containing a '+' will be - // ignored for now. - for (String documentId : wavelet.getDocumentIds()) { - if (IdUtil.isRobotDocId(documentId)) { - String[] parts = IdUtil.split(documentId); - if (parts.length == 2) { - Document document = wavelet.getDocument(documentId); - String val = XmlStringBuilder.innerXml(document).getXmlString(); - waveletData.setDataDocument(parts[1], val); - } - } - } - - // Add the tags. - if (wavelet.getDocument(IdConstants.TAGS_DOC_ID) != null) { - @SuppressWarnings({"unchecked", "rawtypes"}) - TagsDocument tags = new TagsDocument(wavelet.getDocument(IdConstants.TAGS_DOC_ID)); - tags.addListener(new TagsDocument.Listener() { - @Override - public void onAdd(String tagName) { - waveletData.addTag(tagName); - } - @Override - public void onRemove(int tagPosition) { - // Not called. - }}); - tags.processInitialState(); - } - - // Add the participant roles. - ObservableDocument rolesDocument = wavelet.getDocument(IdConstants.ROLES_DATA_DOC_ID); - if (rolesDocument != null) { - DocumentBasedRoles roles = DocumentBasedRoles.create(rolesDocument); - for (ParticipantId participantId : wavelet.getParticipantIds()) { - waveletData.setParticipantRole(participantId.getAddress(), - roles.getRole(participantId).name()); - } - } - return waveletData; - } - - @Override - public BlipData toBlipData(ConversationBlip blip, Wavelet wavelet, - EventMessageBundle eventMessageBundle) { - ConversationBlip parentBlip = findBlipParent(blip); - BlipData blipData = new BlipData(); - blipData.setCreator(blip.getAuthorId().getAddress()); - blipData.setContributors(idsToParticipantIdList(blip.getContributorIds())); - blipData.setBlipId(blip.getId()); - blipData.setLastModifiedTime(blip.getLastModifiedTime()); - blipData.setVersion(blip.getLastModifiedVersion()); - blipData.setParentBlipId(parentBlip == null ? null : parentBlip.getId()); - blipData.setWaveId(ApiIdSerializer.instance().serialiseWaveId(wavelet.getWaveId())); - blipData.setWaveletId(ApiIdSerializer.instance().serialiseWaveletId(wavelet.getId())); - blipData.setChildBlipIds(toBlipIdList(findBlipChildren(blip))); - - ApiView apiView = new ApiView(blip.getContent(), wavelet); - // Set content. - blipData.setContent(apiView.apiContents()); - // Set Annotations. - blipData.setAnnotations(extractAnnotations(blip.getContent(), apiView)); - // blip.getContent().rangedAnnotations(0, blip.getContent().size(), null), - // Set Form Elements. - blipData.setElements(ElementSerializer.serialize(blip.getContent(), wavelet)); - return blipData; - } - - /** - * Finds the children of a blip, defined as the next sibling blip and the - * first blip in each reply thread. - * - * @param blip the blip. - * @return the children of the given blip. - */ - @Override - public List<ConversationBlip> findBlipChildren(ConversationBlip blip) { - List<ConversationBlip> siblings = Lists.newArrayList(); - ConversationBlip nextSibling = findNextSibling(blip); - if (nextSibling != null) { - siblings.add(nextSibling); - } - for (ConversationThread reply : blip.getReplyThreads()) { - if (reply.getFirstBlip() != null) { - siblings.add(reply.getFirstBlip()); - } - } - return siblings; - } - - /** - * Finds the parent of a blip. The parent is the preceding blip in the thread, - * or the blip to which the thread is a reply for the first blip in a thread. - * The first blip of the root thread has no parent. - * - * @param blip the blip. - * @return the blip's parent, or {@code null} if the blip is the first blip - * in a conversation. - */ - @Override - public ConversationBlip findBlipParent(ConversationBlip blip) { - ConversationThread containingThread = blip.getThread(); - if (containingThread.getFirstBlip() == blip - && containingThread != blip.getConversation().getRootThread()) { - return containingThread.getParentBlip(); - } - return findPreviousSibling(blip); - } - - /** - * Converts a collection of {@link ParticipantId}s to a list of addresses. - * - * @param participantIds the participant ids to convert. - * @return a list of addresses. - */ - public List<String> idsToParticipantIdList(Collection<ParticipantId> participantIds) { - List<String> addresses = Lists.newArrayListWithCapacity(participantIds.size()); - for (ParticipantId id : participantIds) { - addresses.add(id.getAddress()); - } - return addresses; - } - - /** - * Finds the previous sibling of a blip in a thread. The first blip in a - * thread has no previous sibling. - * - * @param blip the blip. - * @return the previous sibling of the blip, or {@code null}. - */ - @VisibleForTesting - static ConversationBlip findPreviousSibling(ConversationBlip blip) { - ConversationThread thread = blip.getThread(); - ConversationBlip previous = null; - for (ConversationBlip sibling : thread.getBlips()) { - if (sibling == blip) { - break; - } - previous = sibling; - } - return previous; - } - - /** - * Finds the next sibling of a blip in a thread. The last blip in a thread has - * no next sibling. - * - * @param blip the blip. - * @return the next sibling of the blip, or {@code null} if blip is the last - * blip in a thread. - */ - @VisibleForTesting - static ConversationBlip findNextSibling(ConversationBlip blip) { - ConversationThread thread = blip.getThread(); - Iterator<? extends ConversationBlip> blips = thread.getBlips().iterator(); - boolean foundBlip = false; - while (!foundBlip && blips.hasNext()) { - if (blips.next() == blip) { - foundBlip = true; - } - } - return blips.hasNext() ? blips.next() : null; - } - - /** - * Retrieves the title of a {@link Wavelet}. - * - * @param wavelet The {@link Wavelet} to retrieve the title from. - * @param conversation The wavelet conversation - * @return the title of the {@link Wavelet}, or an empty string if it has - * no title. - */ - private static String getTitle(Wavelet wavelet, Conversation conversation) { - ConversationThread rootThread = conversation.getRootThread(); - if (rootThread == null) { - return ""; - } - ConversationBlip firstBlip = rootThread.getFirstBlip(); - if (firstBlip == null) { - return ""; - } - Document doc = firstBlip.getContent(); - return TitleHelper.extractTitle(doc); - } - - /** - * Extracts the blip ids of the given list of blips. - * - * @param children the blips. - * @return the blip ids of the blips. - */ - private static List<String> toBlipIdList(List<ConversationBlip> children) { - List<String> ids = Lists.newArrayListWithCapacity(children.size()); - for (ConversationBlip child : children) { - ids.add(child.getId()); - } - return ids; - } - - /** - * Extracts all annotations that span inside the body tag of the given - * document. - * - * @param doc the document to get the annotations from. - * @param apiView provides a utility function to convert an xml offset point - * into text offset. - * @return the annotations represented as a list of {@link Annotation}. - */ - private static List<Annotation> extractAnnotations(Document doc, ApiView apiView) { - List<Annotation> result = Lists.newArrayList(); - for (RangedAnnotation<String> annotation : doc.rangedAnnotations(0, doc.size(), null)) { - if (annotation.key() != null && annotation.value() != null) { - int start = apiView.transformToTextOffset(annotation.start()); - int end = apiView.transformToTextOffset(annotation.end()); - result.add(new Annotation(annotation.key(), annotation.value(), new Range(start, end))); - } - } - return result; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/data/converter/v22/EventDataConverterV22.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/data/converter/v22/EventDataConverterV22.java b/wave/src/main/java/com/google/wave/api/data/converter/v22/EventDataConverterV22.java deleted file mode 100644 index 185a9b2..0000000 --- a/wave/src/main/java/com/google/wave/api/data/converter/v22/EventDataConverterV22.java +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.data.converter.v22; - -import com.google.common.collect.Lists; -import com.google.wave.api.BlipData; -import com.google.wave.api.BlipThread; -import com.google.wave.api.data.ApiView; -import com.google.wave.api.data.converter.EventDataConverter; -import com.google.wave.api.data.converter.v21.EventDataConverterV21; -import com.google.wave.api.impl.EventMessageBundle; -import com.google.wave.api.impl.WaveletData; - -import org.waveprotocol.wave.model.conversation.Conversation; -import org.waveprotocol.wave.model.conversation.ConversationBlip; -import org.waveprotocol.wave.model.conversation.ConversationBlip.LocatedReplyThread; -import org.waveprotocol.wave.model.conversation.ConversationThread; -import org.waveprotocol.wave.model.wave.Wavelet; - -import java.util.List; - -/** - * An implementation of {@link EventDataConverter} for protocol version v0.22. - * - * The previous converter implementation, {@link EventDataConverterV21}, does - * not expose the proper blip hierarchy, for example, parent blip can be the - * blip that contains the container thread, or the previous sibling blip. This - * implementation, however, is purely based on the {@link ConversationThread}. - * - */ -public class EventDataConverterV22 extends EventDataConverterV21 { - - @Override - public WaveletData toWaveletData(Wavelet wavelet, Conversation conversation, - EventMessageBundle eventMessageBundle) { - WaveletData waveletData = super.toWaveletData(wavelet, conversation, - eventMessageBundle); - List<String> blipIds = Lists.newLinkedList(); - for (ConversationBlip conversationBlip : conversation.getRootThread().getBlips()) { - blipIds.add(conversationBlip.getId()); - } - waveletData.setRootThread(new BlipThread("", -1 , blipIds, null)); - return waveletData; - } - - @Override - public BlipData toBlipData(ConversationBlip blip, Wavelet wavelet, - EventMessageBundle eventMessageBundle) { - BlipData blipData = super.toBlipData(blip, wavelet, eventMessageBundle); - String threadId = blip.getThread().getId(); - blipData.setThreadId(threadId); - - // If it's the root thread, that doesn't have thread id, then skip. - if (!threadId.isEmpty()) { - ConversationThread thread = blip.getThread(); - addThread(eventMessageBundle, thread, -1, wavelet); - } - - // Add the inline reply threads. - List<String> threadIds = Lists.newLinkedList(); - for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { - String replyThreadId = thread.getThread().getId(); - threadIds.add(replyThreadId); - addThread(eventMessageBundle, thread.getThread(), thread.getLocation(), wavelet); - } - - blipData.setReplyThreadIds(threadIds); - return blipData; - } - - /** - * Finds the children of a blip, defined as all blips in all reply threads. - * - * @param blip the blip. - * @return the children of the given blip. - */ - @Override - public List<ConversationBlip> findBlipChildren(ConversationBlip blip) { - List<ConversationBlip> children = Lists.newArrayList(); - // Add all children from the inline reply threads. - for (LocatedReplyThread<? extends ConversationThread> thread : blip.locateReplyThreads()) { - for (ConversationBlip child : thread.getThread().getBlips()) { - children.add(child); - } - } - return children; - } - - /** - * Finds the parent of a blip. - * - * @param blip the blip. - * @return the blip's parent, or {@code null} if the blip is the first blip - * in a conversation. - */ - @Override - public ConversationBlip findBlipParent(ConversationBlip blip) { - return blip.getThread().getParentBlip(); - } - - /** - * Converts a {@link ConversationThread} into API {@link BlipThread}, then add it - * to the given {@link EventMessageBundle}. - * - * @param eventMessageBundle the event message bundle to add the thread to. - * @param thread the {@link ConversationThread} to convert. - * @param location the anchor location of the thread, or -1 if it's not an - * inline reply thread. - * @param wavelet the wavelet to which the given thread belongs. - */ - private static void addThread(EventMessageBundle eventMessageBundle, ConversationThread thread, - int location, Wavelet wavelet) { - String threadId = thread.getId(); - if (eventMessageBundle.hasThreadId(threadId)) { - // The bundle already has the thread, so we don't need to do the - // conversion. - return; - } - - // Convert the XML offset into the text offset. - ConversationBlip parent = thread.getParentBlip(); - - // Locate the thread, if necessary. - if (location == -1) { - for (LocatedReplyThread<? extends ConversationThread> inlineReplyThread : - parent.locateReplyThreads()) { - if (thread.getId().equals(inlineReplyThread.getThread().getId())) { - location = inlineReplyThread.getLocation(); - break; - } - } - } - - // Use ApiView to convert the offset. - if (location != -1) { - ApiView apiView = new ApiView(parent.getContent(), wavelet); - location = apiView.transformToTextOffset(location); - } - - // Get the ids of the contained blips. - List<String> blipIds = Lists.newLinkedList(); - for (ConversationBlip blip : thread.getBlips()) { - blipIds.add(blip.getId()); - } - eventMessageBundle.addThread(threadId, new BlipThread(thread.getId(), location, blipIds, null)); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/AbstractEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/AbstractEvent.java b/wave/src/main/java/com/google/wave/api/event/AbstractEvent.java deleted file mode 100644 index 65c7986..0000000 --- a/wave/src/main/java/com/google/wave/api/event/AbstractEvent.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Blip; -import com.google.wave.api.NonJsonSerializable; -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * The base class for all events. - */ -public abstract class AbstractEvent implements Event { - - /** The wavelet in which this event occurs. */ - @NonJsonSerializable protected final Wavelet wavelet; - - /** The type of the event. */ - private final EventType type; - - /** The id of the participant that triggered this event. */ - private final String modifiedBy; - - /** The timestamp of the event. */ - private final long timestamp; - - /** - * The id of the blip in which this event occurs, or the root blip id in the - * case of a wavelet event. - */ - private final String blipId; - - /** - * The message bundle this event belongs to. - */ - @NonJsonSerializable private final EventMessageBundle bundle; - - /** - * Constructor. - * - * @param eventType the type of the event. - * @param wavelet the wavelet in which this event occurs. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - */ - protected AbstractEvent(EventType eventType, Wavelet wavelet, EventMessageBundle bundle, - String modifiedBy, long timestamp, String blipId) { - this.type = eventType; - this.wavelet = wavelet; - this.modifiedBy = modifiedBy; - this.timestamp = timestamp; - this.blipId = blipId; - this.bundle = bundle; - } - - /** - * Constructor for deserialization. - */ - protected AbstractEvent() { - this(null, null, null, null, -1, null); - } - - @Override - public EventType getType() { - return type; - } - - @Override - public Wavelet getWavelet() { - return wavelet; - } - - @Override - public Blip getBlip() { - return wavelet.getBlip(blipId); - } - - @Override - public String getModifiedBy() { - return modifiedBy; - } - - @Override - public long getTimestamp() { - return timestamp; - } - - @Override - public EventMessageBundle getBundle() { - return bundle; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/AnnotatedTextChangedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/AnnotatedTextChangedEvent.java b/wave/src/main/java/com/google/wave/api/event/AnnotatedTextChangedEvent.java deleted file mode 100644 index c86d215..0000000 --- a/wave/src/main/java/com/google/wave/api/event/AnnotatedTextChangedEvent.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when text with an annotation has changed. - */ -public class AnnotatedTextChangedEvent extends AbstractEvent { - - /** The name of the annotation. */ - private final String name; - - /** The value of the annotation that changed. */ - private final String value; - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the blip that holds the text. - * @param name the name of the annotation. - * @param value the value of the annotation that changed. - */ - public AnnotatedTextChangedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId, String name, String value) { - super(EventType.ANNOTATED_TEXT_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - this.name = name; - this.value = value; - } - - /** - * Constructor for deserialization. - */ - AnnotatedTextChangedEvent() { - this.name = null; - this.value = null; - } - - /** - * Returns the name of the annotation. - * - * @return the name of the annotation. - */ - public String getName() { - return name; - } - - /** - * Returns the value of the annotation that changed. - * - * @return the value of the annotation that changed. - */ - public String getValue() { - return value; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static AnnotatedTextChangedEvent as(Event event) { - if (!(event instanceof AnnotatedTextChangedEvent)) { - return null; - } - return AnnotatedTextChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/BlipContributorsChangedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/BlipContributorsChangedEvent.java b/wave/src/main/java/com/google/wave/api/event/BlipContributorsChangedEvent.java deleted file mode 100644 index 4079f84..0000000 --- a/wave/src/main/java/com/google/wave/api/event/BlipContributorsChangedEvent.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -import java.util.ArrayList; -import java.util.List; - -/** - * Event triggered when contributors are added and/or removed from a blip. - */ -public class BlipContributorsChangedEvent extends AbstractEvent { - - /** The newly added contributors. */ - private final List<String> contributorsAdded; - - /** The removed contributors. */ - private final List<String> contributorsRemoved; - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the blip in which the the contributors were added - * and/or removed from. - * @param contributorsAdded the added contributors. - * @param contributorsRemoved the removed contributors. - */ - public BlipContributorsChangedEvent(Wavelet wavelet, EventMessageBundle bundle, - String modifiedBy, Long timestamp, String blipId, List<String> contributorsAdded, - List<String> contributorsRemoved) { - super(EventType.BLIP_CONTRIBUTORS_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - this.contributorsAdded = new ArrayList<String>(contributorsAdded); - this.contributorsRemoved = new ArrayList<String>(contributorsRemoved); - } - - /** - * Constructor for deserialization. - */ - BlipContributorsChangedEvent() { - this.contributorsAdded = null; - this.contributorsRemoved = null; - } - - /** - * Returns a list of the new contributors. - * - * @return the added contributors. - */ - public List<String> getContributorsAdded() { - return contributorsAdded; - } - - /** - * Returns a list of the removed contributors. - * - * @return the removed contributors. - */ - public List<String> getContributorsRemoved() { - return contributorsRemoved; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static BlipContributorsChangedEvent as(Event event) { - if (!(event instanceof BlipContributorsChangedEvent)) { - return null; - } - return BlipContributorsChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/BlipSubmittedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/BlipSubmittedEvent.java b/wave/src/main/java/com/google/wave/api/event/BlipSubmittedEvent.java deleted file mode 100644 index f0fa302..0000000 --- a/wave/src/main/java/com/google/wave/api/event/BlipSubmittedEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a blip is submitted. - */ -public class BlipSubmittedEvent extends AbstractEvent { - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the submitted blip. - */ - public BlipSubmittedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId) { - super(EventType.BLIP_SUBMITTED, wavelet, bundle, modifiedBy, timestamp, blipId); - } - - /** - * Constructor for deserialization. - */ - BlipSubmittedEvent() {} - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static BlipSubmittedEvent as(Event event) { - if (!(event instanceof BlipSubmittedEvent)) { - return null; - } - return BlipSubmittedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/DocumentChangedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/DocumentChangedEvent.java b/wave/src/main/java/com/google/wave/api/event/DocumentChangedEvent.java deleted file mode 100644 index 90b57b3..0000000 --- a/wave/src/main/java/com/google/wave/api/event/DocumentChangedEvent.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a blip content is changed. - */ -public class DocumentChangedEvent extends AbstractEvent { - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the submitted blip. - */ - public DocumentChangedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId) { - super(EventType.DOCUMENT_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - } - - /** - * Constructor for deserialization. - */ - DocumentChangedEvent() {} - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static DocumentChangedEvent as(Event event) { - if (!(event instanceof DocumentChangedEvent)) { - return null; - } - return DocumentChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/Event.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/Event.java b/wave/src/main/java/com/google/wave/api/event/Event.java deleted file mode 100644 index dad08f0..0000000 --- a/wave/src/main/java/com/google/wave/api/event/Event.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Blip; -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Object describing a single event, that captures changes made to a - * wavelet or blip in a wave. - */ -public interface Event { - - /** - * Returns the type of the event. - * - * @return the type of the event. - */ - EventType getType(); - - /** - * Returns the wavelet in which this event occurs. - * - * @return the wavelet in which this event occurs. - */ - Wavelet getWavelet(); - - /** - * Returns the blip in which this event occurs, or the root blip for a wavelet - * event. - * - * @return the blip in which this event occurs, or the root blip. - */ - Blip getBlip(); - - /** - * Returns the id of the participant that triggered this event. - * - * @return the id of the participant that triggered this event. - */ - String getModifiedBy(); - - /** - * Returns the timestamp when this event occurred on the server. - * - * @return the timestamp of the event. - */ - long getTimestamp(); - - /** - * Returns the message bundle which this event belongs to. - * - * @return the message bundle object. - */ - EventMessageBundle getBundle(); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/EventHandler.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/EventHandler.java b/wave/src/main/java/com/google/wave/api/event/EventHandler.java deleted file mode 100644 index 5304a4e..0000000 --- a/wave/src/main/java/com/google/wave/api/event/EventHandler.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Context; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An interface for robot event handler. This interface defines various methods - * that would respond to all possible robot events. - */ -public interface EventHandler { - - /** - * An annotation that would define the robot's interest in handling a - * particular event. Robot should annotate the overriden event handler method - * with this annotation to specify the event contexts and filter. - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.METHOD) - static @interface Capability { - - /** - * @return the list of contexts that should be send with this particular - * event. - */ - Context[] contexts() default {Context.ROOT, Context.PARENT, Context.CHILDREN}; - - /** - * @return the filter for this particular event. - */ - String filter() default ""; - } - - /** - * Handler for {@link AnnotatedTextChangedEvent}. - * - * @param event the annotated text changed event. - */ - void onAnnotatedTextChanged(AnnotatedTextChangedEvent event); - - /** - * Handler for {@link BlipContributorsChangedEvent}. - * - * @param event the blip contributors changed event. - */ - void onBlipContributorsChanged(BlipContributorsChangedEvent event); - - /** - * Handler for {@link BlipSubmittedEvent}. - * - * @param event the blip submitted event. - */ - void onBlipSubmitted(BlipSubmittedEvent event); - - /** - * Handler for {@link DocumentChangedEvent}. - * - * @param event the document changed event. - */ - void onDocumentChanged(DocumentChangedEvent event); - - /** - * Handler for {@link FormButtonClickedEvent}. - * - * @param event the form button clicked event. - */ - void onFormButtonClicked(FormButtonClickedEvent event); - - /** - * Handler for {@link GadgetStateChangedEvent}. - * - * @param event the gadget state changed event. - */ - void onGadgetStateChanged(GadgetStateChangedEvent event); - - /** - * Handler for {@link WaveletBlipCreatedEvent}. - * - * @param event the blip created event. - */ - void onWaveletBlipCreated(WaveletBlipCreatedEvent event); - - /** - * Handler for {@link WaveletBlipRemovedEvent}. - * - * @param event the blip removed event. - */ - void onWaveletBlipRemoved(WaveletBlipRemovedEvent event); - - /** - * Handler for {@link WaveletCreatedEvent}. - * - * @param event the wavelet created event. - */ - void onWaveletCreated(WaveletCreatedEvent event); - - /** - * Handler for {@link WaveletFetchedEvent}. - * - * @param event the wavelet fetched event. - */ - void onWaveletFetched(WaveletFetchedEvent event); - - /** - * Handler for {@link WaveletParticipantsChangedEvent}. - * - * @param event the participants changed event. - */ - void onWaveletParticipantsChanged(WaveletParticipantsChangedEvent event); - - /** - * Handler for {@link WaveletSelfAddedEvent}. - * - * @param event the self added event. - */ - void onWaveletSelfAdded(WaveletSelfAddedEvent event); - - /** - * Handler for {@link WaveletSelfRemovedEvent}. - * - * @param event the self removed event. - */ - void onWaveletSelfRemoved(WaveletSelfRemovedEvent event); - - /** - * Handler for {@link WaveletTagsChangedEvent}. - * - * @param event the tags changed event. - */ - void onWaveletTagsChanged(WaveletTagsChangedEvent event); - - /** - * Handler for {@link WaveletTitleChangedEvent}. - * - * @param event the title changed event. - */ - void onWaveletTitleChanged(WaveletTitleChangedEvent event); - - /** - * Handler for {@link OperationErrorEvent}. - * - * @param event the operation error event. - */ - void onOperationError(OperationErrorEvent event); -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/EventSerializationException.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/EventSerializationException.java b/wave/src/main/java/com/google/wave/api/event/EventSerializationException.java deleted file mode 100644 index 4f180be..0000000 --- a/wave/src/main/java/com/google/wave/api/event/EventSerializationException.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.gson.JsonObject; - -/** - * Checked exception for signaling problem serializing or deserializing event - * JSON. - */ -public class EventSerializationException extends Exception { - - /** The event JSON object that couldn't be deserialized. */ - private final JsonObject eventJson; - - /** - * Constructor. - * - * @param message the exception message. - * @param eventJson the event JSON. - */ - public EventSerializationException(String message, JsonObject eventJson) { - super(message); - this.eventJson = eventJson; - } - - /** - * Constructor. - * - * @param message the exception message. - */ - public EventSerializationException(String message) { - super(message); - this.eventJson = null; - } - - /** - * Returns the event JSON. - * - * @return the event JSON. - */ - public JsonObject getEventJson() { - return eventJson; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/EventSerializer.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/EventSerializer.java b/wave/src/main/java/com/google/wave/api/event/EventSerializer.java deleted file mode 100644 index 0e65279..0000000 --- a/wave/src/main/java/com/google/wave/api/event/EventSerializer.java +++ /dev/null @@ -1,283 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.wave.api.Wavelet; -import com.google.wave.api.JsonRpcConstant.ParamsProperty; -import com.google.wave.api.impl.EventMessageBundle; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; - -/** - * Object that is responsible for serializing and deserializing implementors - * of {@link Event} to and from {@link JsonObject}. - */ -public class EventSerializer { - - /** - * An interface for map key conversion. - * - * @param <T> the generic type of the resulting key. - */ - private static interface KeyConverter<T> { - - /** - * Converts the given string key into an instance of {@code T}. - * - * @param key the key to be converted. - * @return an instance of {@code T} that represents the given string key. - */ - T convert(String key); - } - - /** Constants for accessing the properties of the given JSON object. */ - private static final String TYPE = "type"; - private static final String MODIFIED_BY = "modifiedBy"; - private static final String TIMESTAMP = "timestamp"; - private static final String BLIP_ID = "blipId"; - private static final String WAVELET = "wavelet"; - private static final String PROPERTIES = "properties"; - private static final String BUNDLE = "bundle"; - - /** - * Serializes the given {@link Event} into a {@link JsonObject}. - * - * @param event the {@link Event} to be serialized. - * @param context the serialization context. - * @return an instance of {@link JsonObject}, that is the JSON representation - * of the given {@link Event}. - */ - public static JsonObject serialize(Event event, JsonSerializationContext context) - throws EventSerializationException { - JsonObject result = new JsonObject(); - - // Serialize basic properties from Event. - result.addProperty(TYPE, event.getType().name()); - result.addProperty(MODIFIED_BY, event.getModifiedBy()); - result.addProperty(TIMESTAMP, event.getTimestamp()); - result.addProperty(TIMESTAMP, event.getTimestamp()); - - // Construct a properties object. - JsonObject properties = new JsonObject(); - - try { - // Serialize the blip id. - Field blipIdField = AbstractEvent.class.getDeclaredField(BLIP_ID); - blipIdField.setAccessible(true); - properties.addProperty(BLIP_ID, (String) blipIdField.get(event)); - - // Serialize event specific properties. - for (Field field : event.getClass().getDeclaredFields()) { - field.setAccessible(true); - properties.add(field.getName(), context.serialize(field.get(event))); - } - } catch (IllegalArgumentException e) { - throw new EventSerializationException("Unable to serialize event: " + BLIP_ID + - " in " + event.getClass() + " is not accessible."); - } catch (IllegalAccessException e) { - throw new EventSerializationException("Unable to serialize event: " + BLIP_ID + - " in " + event.getClass() + " is not accessible."); - } catch (NoSuchFieldException e) { - throw new EventSerializationException("Unable to serialize event: " + BLIP_ID + - " in " + event.getClass() + " is not accessible."); - } - - result.add(PROPERTIES, properties); - return result; - } - - /** - * Deserializes the given {@link JsonObject} into an {@link Event}, and - * assign the given {@link Wavelet} to the {@link Event}. - * - * @param wavelet the wavelet where the event occurred. - * @param json the JSON representation of {@link Event}. - * @param context the deserialization context. - * @return an instance of {@link Event}. - * - * @throw {@link EventSerializationException} if there is a problem - * deserializing the event JSON. - */ - public static Event deserialize(Wavelet wavelet, EventMessageBundle bundle, JsonObject json, - JsonDeserializationContext context) throws EventSerializationException { - // Construct the event object. - String eventTypeString = json.get(TYPE).getAsString(); - EventType type = EventType.valueOfIgnoreCase(eventTypeString); - if (type == EventType.UNKNOWN) { - throw new EventSerializationException("Trying to deserialize event JSON with unknown " + - "type: " + json, json); - } - - // Parse the generic parameters. - String modifiedBy = json.get(MODIFIED_BY).getAsString(); - Long timestamp = json.get(TIMESTAMP).getAsLong(); - - // Construct the event object. - Class<? extends Event> clazz = type.getClazz(); - Constructor<? extends Event> ctor; - try { - ctor = clazz.getDeclaredConstructor(); - ctor.setAccessible(true); - Event event = ctor.newInstance(); - - // Set the default fields from AbstractEvent. - Class<?> rootClass = AbstractEvent.class; - setField(event, rootClass.getDeclaredField(WAVELET), wavelet); - setField(event, rootClass.getDeclaredField(MODIFIED_BY), modifiedBy); - setField(event, rootClass.getDeclaredField(TIMESTAMP), timestamp); - setField(event, rootClass.getDeclaredField(TYPE), type); - setField(event, rootClass.getDeclaredField(BUNDLE), bundle); - - JsonObject properties = json.get(PROPERTIES).getAsJsonObject(); - - // Set the blip id field, that can be null for certain events, such as - // OPERATION_ERROR. - JsonElement blipId = properties.get(BLIP_ID); - if (blipId != null && !(blipId instanceof JsonNull)) { - setField(event, rootClass.getDeclaredField(BLIP_ID), blipId.getAsString()); - } - - // Set the additional fields. - for (Field field : clazz.getDeclaredFields()) { - String fieldName = field.getName(); - if (properties.has(fieldName)) { - setField(event, field, context.deserialize(properties.get(fieldName), - field.getGenericType())); - } - } - return event; - } catch (NoSuchMethodException e) { - throw new EventSerializationException("Unable to deserialize event JSON: " + json, json); - } catch (NoSuchFieldException e) { - throw new EventSerializationException("Unable to deserialize event JSON: " + json, json); - } catch (InstantiationException e) { - throw new EventSerializationException("Unable to deserialize event JSON: " + json, json); - } catch (IllegalAccessException e) { - throw new EventSerializationException("Unable to deserialize event JSON: " + json, json); - } catch (InvocationTargetException e) { - throw new EventSerializationException("Unable to deserialize event JSON: " + json, json); - } catch (JsonParseException e) { - throw new EventSerializationException("Unable to deserialize event JSON: " + json, json); - } - } - - /** - * Extracts event specific properties into a map. This method will not include - * the basic properties from {@link AbstractEvent}, except for blip id, in the - * resulting map. - * - * @param event the event whose properties will be extracted. - * @return a map of {@link ParamsProperty} to {@link Object} of properties. - * - * @throws EventSerializationException if there is a problem accessing the - * event's fields. - */ - public static Map<ParamsProperty, Object> extractPropertiesToParamsPropertyMap(Event event) - throws EventSerializationException { - return extractProperties(event, new KeyConverter<ParamsProperty>() { - @Override - public ParamsProperty convert(String key) { - return ParamsProperty.fromKey(key); - } - }); - } - - /** - * Extracts event specific properties into a map. This method will not include - * the basic properties from {@link AbstractEvent}, except for blip id, in the - * resulting map. - * - * @param event the event whose properties will be extracted. - * @return a map of {@link String} to {@link Object} of properties. - * - * @throws EventSerializationException if there is a problem accessing the - * event's fields. - */ - public static Map<String, Object> extractPropertiesToStringMap(Event event) - throws EventSerializationException { - return extractProperties(event, new KeyConverter<String>() { - @Override - public String convert(String key) { - return key; - } - }); - } - - /** - * Extracts event specific properties into a map. This method will not include - * the basic properties from {@link AbstractEvent}, except for blip id, in the - * resulting map. - * - * @param event the event whose properties will be extracted. - * @param keyConverter the converter to convert the event property name into - * a proper key object for the resulting map. - * @return a map of {@code T} to {@link Object} of properties. - * - * @throws EventSerializationException if there is a problem accessing the - * event's fields. - */ - private static <T> Map<T, Object> extractProperties(Event event, KeyConverter<T> keyConverter) - throws EventSerializationException { - Field[] fields = event.getClass().getDeclaredFields(); - Map<T, Object> data = new HashMap<T, Object>(fields.length + 1); - try { - for (Field field : fields) { - field.setAccessible(true); - data.put(keyConverter.convert(field.getName()), field.get(event)); - } - - Field field = AbstractEvent.class.getDeclaredField(BLIP_ID); - field.setAccessible(true); - data.put(keyConverter.convert(BLIP_ID), field.get(event)); - } catch (IllegalArgumentException e) { - throw new EventSerializationException(e.getMessage()); - } catch (IllegalAccessException e) { - throw new EventSerializationException(e.getMessage()); - } catch (NoSuchFieldException e) { - throw new EventSerializationException(e.getMessage()); - } - return data; - } - - /** - * Sets the field of the given {@link Event} object. - * - * @param event the {@link Event} object whose field will be set. - * @param field the {@link Field} object that represents the field. - * @param value the value to be set to the field. - * - * @throws IllegalAccessException if the field is not accessible. - */ - private static void setField(Event event, Field field, Object value) - throws IllegalAccessException { - field.setAccessible(true); - field.set(event, value); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/EventType.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/EventType.java b/wave/src/main/java/com/google/wave/api/event/EventType.java deleted file mode 100644 index c3472e9..0000000 --- a/wave/src/main/java/com/google/wave/api/event/EventType.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import java.util.HashMap; -import java.util.Map; - -/** - * The types of events. - */ -public enum EventType { - WAVELET_BLIP_CREATED(WaveletBlipCreatedEvent.class), - WAVELET_BLIP_REMOVED(WaveletBlipRemovedEvent.class), - WAVELET_PARTICIPANTS_CHANGED(WaveletParticipantsChangedEvent.class), - WAVELET_SELF_ADDED(WaveletSelfAddedEvent.class), - WAVELET_SELF_REMOVED(WaveletSelfRemovedEvent.class), - WAVELET_TITLE_CHANGED(WaveletTitleChangedEvent.class), - WAVELET_CREATED(WaveletCreatedEvent.class), - WAVELET_FETCHED(WaveletFetchedEvent.class), - WAVELET_TAGS_CHANGED(WaveletTagsChangedEvent.class), - - BLIP_CONTRIBUTORS_CHANGED(BlipContributorsChangedEvent.class), - BLIP_SUBMITTED(BlipSubmittedEvent.class), - DOCUMENT_CHANGED(DocumentChangedEvent.class), - FORM_BUTTON_CLICKED(FormButtonClickedEvent.class), - GADGET_STATE_CHANGED(GadgetStateChangedEvent.class), - ANNOTATED_TEXT_CHANGED(AnnotatedTextChangedEvent.class), - - OPERATION_ERROR(OperationErrorEvent.class), - UNKNOWN(null); - - private static final Map<Class<?>, EventType> REVERSE_LOOKUP_MAP = - new HashMap<Class<?>, EventType>(); - - static { - for (EventType eventType : EventType.values()) { - REVERSE_LOOKUP_MAP.put(eventType.getClazz(), eventType); - } - } - - /** The class that represents this event. */ - private final Class<? extends Event> clazz; - - /** - * Constructor. - * - * @param clazz the class that represents this event. - */ - private EventType(Class<? extends Event> clazz) { - this.clazz = clazz; - } - - /** - * Returns the class that represents this event type. - * - * @return the class that represents this event type. - */ - public Class<? extends Event> getClazz() { - return clazz; - } - - /** - * Converts a string into an {@link EventType} ignoring case in the process. - * - * @param name the name of the event type. - * @return the converted event type. - */ - public static EventType valueOfIgnoreCase(String name) { - try { - return valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - return UNKNOWN; - } - } - - /** - * Returns an {@link EventType} enumeration that has the given class. If no - * match is found, UNKNOWN is returned. - * - * @param clazz The class that represents an event type. - * @return An {@link EventType} that has the given class. - */ - public static EventType fromClass(Class<?> clazz) { - if (!REVERSE_LOOKUP_MAP.containsKey(clazz)) { - return UNKNOWN; - } - return REVERSE_LOOKUP_MAP.get(clazz); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/FormButtonClickedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/FormButtonClickedEvent.java b/wave/src/main/java/com/google/wave/api/event/FormButtonClickedEvent.java deleted file mode 100644 index 75c2db1..0000000 --- a/wave/src/main/java/com/google/wave/api/event/FormButtonClickedEvent.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a form button is clicked. - */ -public class FormButtonClickedEvent extends AbstractEvent { - - /** The name of the button that was clicked. */ - private final String buttonName; - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the submitted blip. - * @param buttonName the name of the button that was clicked. - */ - public FormButtonClickedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId, String buttonName) { - super(EventType.FORM_BUTTON_CLICKED, wavelet, bundle, modifiedBy, timestamp, blipId); - this.buttonName = buttonName; - } - - /** - * Constructor for deserialization. - */ - FormButtonClickedEvent() { - this.buttonName = null; - } - - /** - * Returns the name of the button that was clicked. - * - * @return the name of the button that was clicked. - */ - public String getButtonName() { - return buttonName; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static FormButtonClickedEvent as(Event event) { - if (!(event instanceof FormButtonClickedEvent)) { - return null; - } - return FormButtonClickedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/GadgetStateChangedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/GadgetStateChangedEvent.java b/wave/src/main/java/com/google/wave/api/event/GadgetStateChangedEvent.java deleted file mode 100644 index c46b642..0000000 --- a/wave/src/main/java/com/google/wave/api/event/GadgetStateChangedEvent.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -import java.util.HashMap; -import java.util.Map; - -/** - * Event triggered when the state of a gadget has changed. - */ -public class GadgetStateChangedEvent extends AbstractEvent { - - /** The index of the gadget that changed in the document. */ - private final Integer index; - - /** The old state of the gadget. */ - private Map<String, String> oldState; - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param blipId the id of the submitted blip. - * @param index the index of the gadget that changed in the document. - * @param oldState the old state of the gadget. - */ - public GadgetStateChangedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId, int index, Map<String, String> oldState) { - super(EventType.GADGET_STATE_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - this.index = index; - this.oldState = new HashMap<String, String>(oldState); - } - - /** - * Constructor for deserialization. - */ - GadgetStateChangedEvent() { - this.index = null; - this.oldState = null; - } - - /** - * Returns the index of the gadget that changed in the document. - * - * @return the index of the gadget that changed in the document. - */ - public Integer getIndex() { - return index; - } - - /** - * Returns the old state of the gadget. - * - * @return the old state of the gadget. - */ - public Map<String, String> getOldState() { - return oldState; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static GadgetStateChangedEvent as(Event event) { - if (!(event instanceof GadgetStateChangedEvent)) { - return null; - } - return GadgetStateChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/OperationErrorEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/OperationErrorEvent.java b/wave/src/main/java/com/google/wave/api/event/OperationErrorEvent.java deleted file mode 100644 index 15df953..0000000 --- a/wave/src/main/java/com/google/wave/api/event/OperationErrorEvent.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when an error on the server occurred when processing - * operations. - */ -public class OperationErrorEvent extends AbstractEvent { - - /** The id of the operation that caused the error. */ - private final String operationId; - - /** The error message. */ - private final String message; - - /** - * Constructor. - * - * @param wavelet the wavelet where this event occurred. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param operationId the id of the operation that caused the error. - * @param message the error message. - */ - public OperationErrorEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String operationId, String message) { - super(EventType.OPERATION_ERROR, wavelet, bundle, modifiedBy, timestamp, null); - this.operationId = operationId; - this.message = message; - } - - /** - * Constructor for deserialization. - */ - OperationErrorEvent() { - this.operationId = null; - this.message = null; - } - - /** - * Returns the id of the operation that caused the error. - * - * @return the id of the operation that caused the error. - */ - public String getOperationId() { - return operationId; - } - - /** - * Returns the error message. - * - * @return the error message. - */ - public String getMessage() { - return message; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static OperationErrorEvent as(Event event) { - if (!(event instanceof OperationErrorEvent)) { - return null; - } - return OperationErrorEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/WaveletBlipCreatedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/WaveletBlipCreatedEvent.java b/wave/src/main/java/com/google/wave/api/event/WaveletBlipCreatedEvent.java deleted file mode 100644 index 1c59186..0000000 --- a/wave/src/main/java/com/google/wave/api/event/WaveletBlipCreatedEvent.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Blip; -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a new blip is created. - */ -public class WaveletBlipCreatedEvent extends AbstractEvent { - - /** The id of the new blip. */ - private final String newBlipId; - - /** - * Constructor. - * - * @param wavelet the wavelet in which this new blip was created. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that created this new blip. - * @param timestamp the timestamp of this event. - * @param rootBlipId the root blip id of the wavelet where this event occurs. - * @param newBlipId the id of the new blip. - */ - public WaveletBlipCreatedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String rootBlipId, String newBlipId) { - super(EventType.WAVELET_BLIP_CREATED, wavelet, bundle, modifiedBy, timestamp, rootBlipId); - this.newBlipId = newBlipId; - } - - /** - * Constructor for deserialization. - */ - WaveletBlipCreatedEvent() { - this.newBlipId = null; - } - - /** - * Returns the id of the new blip. - * - * @return the id of the new blip. - */ - public String getNewBlipId() { - return newBlipId; - } - - /** - * Returns the new blip. - * - * @return the new blip. - */ - public Blip getNewBlip() { - return wavelet.getBlip(newBlipId); - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static WaveletBlipCreatedEvent as(Event event) { - if (!(event instanceof WaveletBlipCreatedEvent)) { - return null; - } - return WaveletBlipCreatedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/WaveletBlipRemovedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/WaveletBlipRemovedEvent.java b/wave/src/main/java/com/google/wave/api/event/WaveletBlipRemovedEvent.java deleted file mode 100644 index e5d66e8..0000000 --- a/wave/src/main/java/com/google/wave/api/event/WaveletBlipRemovedEvent.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Blip; -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a blip is removed. - */ -public class WaveletBlipRemovedEvent extends AbstractEvent { - - /** The id of the removed blip. */ - private final String removedBlipId; - - /** - * Constructor. - * - * @param wavelet the wavelet in which this blip was removed. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that removed this blip. - * @param timestamp the timestamp of this event. - * @param rootBlipId the root blip id of the wavelet where this event occurs. - * @param removedBlipId the id of the removed blip. - */ - public WaveletBlipRemovedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String rootBlipId, String removedBlipId) { - super(EventType.WAVELET_BLIP_REMOVED, wavelet, bundle, modifiedBy, timestamp, rootBlipId); - this.removedBlipId = removedBlipId; - } - - /** - * Constructor for deserialization. - */ - WaveletBlipRemovedEvent() { - this.removedBlipId = null; - } - - /** - * Returns the id of the removed blip. - * - * @return the id of the removed blip. - */ - public String getRemovedBlipId() { - return removedBlipId; - } - - /** - * Returns the removed blip. - * - * @return the removed blip. - */ - public Blip getRemovedBlip() { - return wavelet.getBlip(removedBlipId); - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static WaveletBlipRemovedEvent as(Event event) { - if (!(event instanceof WaveletBlipRemovedEvent)) { - return null; - } - return WaveletBlipRemovedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/WaveletCreatedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/WaveletCreatedEvent.java b/wave/src/main/java/com/google/wave/api/event/WaveletCreatedEvent.java deleted file mode 100644 index b70f243..0000000 --- a/wave/src/main/java/com/google/wave/api/event/WaveletCreatedEvent.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; - -/** - * Event triggered when a new wavelet is created. This event is only triggered - * if the robot creates a new wavelet and can be used to initialize the newly - * created wave. Wavelets created by other participants remain invisible to the - * robot until the robot is added to the wave in which case - * {@link WaveletSelfAddedEvent} is triggered. - */ -public class WaveletCreatedEvent extends AbstractEvent { - - /** The message that was passed into the wavelet create operation. */ - private final String message; - - /** The id of the new wave. */ - private final String waveId; - - /** The id of the new wavelet. */ - private final String waveletId; - - /** - * Constructor. - * - * @param wavelet the wavelet in which this event was triggered. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param rootBlipId the root blip id of the new wavelet. - * @param message the message that was passed into the wavelet create - * operation. - * @param waveId the id of the new wave. - * @param waveletId the id of the new wavelet. - */ - public WaveletCreatedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String rootBlipId, String message, String waveId, String waveletId) { - super(EventType.WAVELET_CREATED, wavelet, bundle, modifiedBy, timestamp, rootBlipId); - this.message = message; - this.waveId = waveId; - this.waveletId = waveletId; - } - - /** - * Constructor for deserialization. - */ - WaveletCreatedEvent() { - this.message = null; - this.waveId = null; - this.waveletId = null; - } - - /** - * Returns the message that was passed into the wavelet create operation. - * - * @return the message that was passed into the wavelet create operation. - */ - public String getMessage() { - return message; - } - - /** - * Returns the id of the new wave. - * - * @return the id of the new wave. - */ - public String getWaveId() { - return waveId; - } - - /** - * Returns the id of the new wavelet. - * - * @return the id of the new wavelet. - */ - public String getWaveletId() { - return waveletId; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static WaveletCreatedEvent as(Event event) { - if (!(event instanceof WaveletCreatedEvent)) { - return null; - } - return WaveletCreatedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/051db092/wave/src/main/java/com/google/wave/api/event/WaveletFetchedEvent.java ---------------------------------------------------------------------- diff --git a/wave/src/main/java/com/google/wave/api/event/WaveletFetchedEvent.java b/wave/src/main/java/com/google/wave/api/event/WaveletFetchedEvent.java deleted file mode 100644 index d78f3d9..0000000 --- a/wave/src/main/java/com/google/wave/api/event/WaveletFetchedEvent.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package com.google.wave.api.event; - -import com.google.wave.api.BlipData; -import com.google.wave.api.BlipThread; -import com.google.wave.api.Wavelet; -import com.google.wave.api.impl.EventMessageBundle; -import com.google.wave.api.impl.WaveletData; - -import java.util.Map; - -/** - * Event triggered when a wavelet is fetched. This event is triggered after a - * robot requests to see another wavelet. The robot has to be a participant of - * the requested wavelet. - */ -public class WaveletFetchedEvent extends AbstractEvent { - - /** The message that was passed into the wavelet fetch operation. */ - private final String message; - - /** The fetched wavelet. */ - private final WaveletData waveletData; - - /** The blips that are associated with the fetched wavelet. */ - private final Map<String, BlipData> blips; - - /** The threads that are associated with the fetched wavelet. */ - private final Map<String, BlipThread> threads; - - /** - * Constructor. - * - * @param wavelet the wavelet in which this event was triggered. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that triggered this event. - * @param timestamp the timestamp of this event. - * @param message the message that was passed into the wavelet fetch - * operation. - * @param rootBlipId the root blip id of the wavelet where this event occurs. - * @param waveletData the wavelet data of the fetched wavelet. - * @param blips the blips of the fetched wavelet. - * @param threads the threads of the fetched wavelet. - */ - public WaveletFetchedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String message, String rootBlipId, WaveletData waveletData, - Map<String, BlipData> blips, Map<String, BlipThread> threads) { - super(EventType.WAVELET_FETCHED, wavelet, bundle, modifiedBy, timestamp, rootBlipId); - this.message = message; - this.waveletData = waveletData; - this.blips = blips; - this.threads = threads; - } - - /** - * Constructor for deserialization. - */ - WaveletFetchedEvent() { - this.message = null; - this.waveletData = null; - this.blips = null; - this.threads = null; - } - - /** - * Returns the message that was passed into the wavelet fetch operation. - * - * @return the message that was passed into the wavelet fetch operation. - */ - public String getMessage() { - return message; - } - - /** - * Returns the fetched wavelet. - * - * @return an instance of {@link WaveletData} that represents the fetched - * wavelet. - */ - public WaveletData getWaveletData() { - return waveletData; - } - - /** - * Returns the blips that are associated with the fetched wavelet. - * - * @return a map of {@link BlipData} that are associated with the fetched - * wavelet. - */ - public Map<String, BlipData> getBlips() { - return blips; - } - - /** - * Returns the threads that are associated with the fetched wavelet. - * - * @return a map of {@link BlipThread} that are associated with the fetched - * wavelet. - */ - public Map<String, BlipThread> getThreads() { - return threads; - } - - /** - * Helper method for type conversion. - * - * @return the concrete type of this event, or {@code null} if it is of a - * different event type. - */ - public static WaveletFetchedEvent as(Event event) { - if (!(event instanceof WaveletFetchedEvent)) { - return null; - } - return WaveletFetchedEvent.class.cast(event); - } -}
