http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/EventHandler.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/EventHandler.java b/src/com/google/wave/api/event/EventHandler.java deleted file mode 100644 index 5304a4e..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/EventSerializationException.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/EventSerializationException.java b/src/com/google/wave/api/event/EventSerializationException.java deleted file mode 100644 index 4f180be..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/EventSerializer.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/EventSerializer.java b/src/com/google/wave/api/event/EventSerializer.java deleted file mode 100644 index 0e65279..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/EventType.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/EventType.java b/src/com/google/wave/api/event/EventType.java deleted file mode 100644 index c3472e9..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/FormButtonClickedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/FormButtonClickedEvent.java b/src/com/google/wave/api/event/FormButtonClickedEvent.java deleted file mode 100644 index 75c2db1..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/GadgetStateChangedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/GadgetStateChangedEvent.java b/src/com/google/wave/api/event/GadgetStateChangedEvent.java deleted file mode 100644 index c46b642..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/OperationErrorEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/OperationErrorEvent.java b/src/com/google/wave/api/event/OperationErrorEvent.java deleted file mode 100644 index 15df953..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/WaveletBlipCreatedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletBlipCreatedEvent.java b/src/com/google/wave/api/event/WaveletBlipCreatedEvent.java deleted file mode 100644 index 1c59186..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/WaveletBlipRemovedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletBlipRemovedEvent.java b/src/com/google/wave/api/event/WaveletBlipRemovedEvent.java deleted file mode 100644 index e5d66e8..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/WaveletCreatedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletCreatedEvent.java b/src/com/google/wave/api/event/WaveletCreatedEvent.java deleted file mode 100644 index b70f243..0000000 --- a/src/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/7d8609e7/src/com/google/wave/api/event/WaveletFetchedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletFetchedEvent.java b/src/com/google/wave/api/event/WaveletFetchedEvent.java deleted file mode 100644 index d78f3d9..0000000 --- a/src/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); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/WaveletParticipantsChangedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletParticipantsChangedEvent.java b/src/com/google/wave/api/event/WaveletParticipantsChangedEvent.java deleted file mode 100644 index f4e4b99..0000000 --- a/src/com/google/wave/api/event/WaveletParticipantsChangedEvent.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 participants are added and/or removed from a wavelet. - */ -public class WaveletParticipantsChangedEvent extends AbstractEvent { - - /** The newly added participants. */ - private final List<String> participantsAdded; - - /** The removed participants. */ - private final List<String> participantsRemoved; - - /** - * Constructor. - * - * @param wavelet the wavelet in which the participants were added or removed. - * @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 wavelet where this event occurs. - * @param participantsAdded the added participants. - * @param participantsRemoved the removed participants. - */ - public WaveletParticipantsChangedEvent(Wavelet wavelet, EventMessageBundle bundle, - String modifiedBy, Long timestamp, String rootBlipId, List<String> participantsAdded, - List<String> participantsRemoved) { - super(EventType.WAVELET_PARTICIPANTS_CHANGED, wavelet, bundle, modifiedBy, timestamp, - rootBlipId); - this.participantsAdded = new ArrayList<String>(participantsAdded); - this.participantsRemoved = new ArrayList<String>(participantsRemoved); - } - - /** - * Constructor for deserialization. - */ - WaveletParticipantsChangedEvent() { - this.participantsAdded = null; - this.participantsRemoved = null; - } - - /** - * Returns a list of the new participants. - * - * @return the added participants. - */ - public List<String> getParticipantsAdded() { - return participantsAdded; - } - - /** - * Returns a list of the removed participants. - * - * @return the removed participants. - */ - public List<String> getParticipantsRemoved() { - return participantsRemoved; - } - - /** - * 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 WaveletParticipantsChangedEvent as(Event event) { - if (!(event instanceof WaveletParticipantsChangedEvent)) { - return null; - } - return WaveletParticipantsChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/WaveletSelfAddedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletSelfAddedEvent.java b/src/com/google/wave/api/event/WaveletSelfAddedEvent.java deleted file mode 100644 index 2275724..0000000 --- a/src/com/google/wave/api/event/WaveletSelfAddedEvent.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 robot is added to a wavelet. - */ -public class WaveletSelfAddedEvent extends AbstractEvent { - - /** - * Constructor. - * - * @param wavelet the wavelet in which this robot was added. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that added this robot. - * @param timestamp the timestamp of this event. - * @param rootBlipId the root blip id of the wavelet where this event occurs. - */ - public WaveletSelfAddedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String rootBlipId) { - super(EventType.WAVELET_SELF_ADDED, wavelet, bundle, modifiedBy, timestamp, rootBlipId); - } - - /** - * Constructor for deserialization. - */ - WaveletSelfAddedEvent() {} - - /** - * 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 WaveletSelfAddedEvent as(Event event) { - if (!(event instanceof WaveletSelfAddedEvent)) { - return null; - } - return WaveletSelfAddedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/WaveletSelfRemovedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletSelfRemovedEvent.java b/src/com/google/wave/api/event/WaveletSelfRemovedEvent.java deleted file mode 100644 index 125e916..0000000 --- a/src/com/google/wave/api/event/WaveletSelfRemovedEvent.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 robot is removed from a wavelet. - */ -public class WaveletSelfRemovedEvent extends AbstractEvent { - - /** - * Constructor. - * - * @param wavelet the wavelet in which this robot was removed. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that removed this robot. - * @param timestamp the timestamp of this event. - * @param rootBlipId the root blip id of the wavelet where this event occurs. - */ - public WaveletSelfRemovedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String rootBlipId) { - super(EventType.WAVELET_SELF_REMOVED, wavelet, bundle, modifiedBy, timestamp, rootBlipId); - } - - /** - * Constructor for deserialization. - */ - WaveletSelfRemovedEvent() {} - - /** - * 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 WaveletSelfRemovedEvent as(Event event) { - if (!(event instanceof WaveletSelfRemovedEvent)) { - return null; - } - return WaveletSelfRemovedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/WaveletTagsChangedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletTagsChangedEvent.java b/src/com/google/wave/api/event/WaveletTagsChangedEvent.java deleted file mode 100644 index bb76fca..0000000 --- a/src/com/google/wave/api/event/WaveletTagsChangedEvent.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 the tags on a wavelet change. - */ -public class WaveletTagsChangedEvent 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 WaveletTagsChangedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String blipId) { - super(EventType.WAVELET_TAGS_CHANGED, wavelet, bundle, modifiedBy, timestamp, blipId); - } - - /** - * Constructor for deserialization. - */ - public WaveletTagsChangedEvent() {} - - /** - * 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 WaveletTagsChangedEvent as(Event event) { - if (!(event instanceof WaveletTagsChangedEvent)) { - return null; - } - return WaveletTagsChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/event/WaveletTitleChangedEvent.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/event/WaveletTitleChangedEvent.java b/src/com/google/wave/api/event/WaveletTitleChangedEvent.java deleted file mode 100644 index 49a2123..0000000 --- a/src/com/google/wave/api/event/WaveletTitleChangedEvent.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 the title of the wavelet has changed. - */ -public class WaveletTitleChangedEvent extends AbstractEvent { - - /** The new title. */ - private final String title; - - /** - * Constructor. - * - * @param wavelet the wavelet which title was changed. - * @param bundle the message bundle this event belongs to. - * @param modifiedBy the id of the participant that changed the title. - * @param timestamp the timestamp of this event. - * @param rootBlipId the root blip id of the wavelet where this event occurs. - * @param title the new title. - */ - public WaveletTitleChangedEvent(Wavelet wavelet, EventMessageBundle bundle, String modifiedBy, - Long timestamp, String rootBlipId, String title) { - super(EventType.WAVELET_TITLE_CHANGED, wavelet, bundle, modifiedBy, timestamp, rootBlipId); - this.title = title; - } - - /** - * Constructor for deserialization. - */ - WaveletTitleChangedEvent() { - this.title = null; - } - - /** - * Returns the new title. - * - * @return the new title. - */ - public String getTitle() { - return title; - } - - /** - * 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 WaveletTitleChangedEvent as(Event event) { - if (!(event instanceof WaveletTitleChangedEvent)) { - return null; - } - return WaveletTitleChangedEvent.class.cast(event); - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/DocumentModifyAction.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/DocumentModifyAction.java b/src/com/google/wave/api/impl/DocumentModifyAction.java deleted file mode 100644 index 1bcee55..0000000 --- a/src/com/google/wave/api/impl/DocumentModifyAction.java +++ /dev/null @@ -1,148 +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.impl; - -import com.google.wave.api.Element; - -import java.util.ArrayList; -import java.util.List; - - -/** - * DocumentModifyAction is a class specific to how operations of type - * DOCUMENT_MODIFY are serialized. DocumentModifyAction specifies what should - * happen to matched bits of the document. - * - */ - -public class DocumentModifyAction { - - public enum ModifyHow { - DELETE, REPLACE, INSERT, INSERT_AFTER, ANNOTATE, CLEAR_ANNOTATION, UPDATE_ELEMENT; - } - - /** - * Initial annotations to be applied to the document modification range. - */ - static public class BundledAnnotation { - public String key; - public String value; - - - /** - * Convenience method to create a list of bundled annotations with - * the even values passed being the keys, the uneven ones the values. - */ - public static List<BundledAnnotation> listOf(String... values) { - if (values.length % 2 != 0) { - throw new IllegalArgumentException("listOf takes an even number of parameters"); - } - List<BundledAnnotation> res = new ArrayList<BundledAnnotation>(values.length / 2); - for (int i = 0; i < values.length - 1; i += 2) { - BundledAnnotation next = new BundledAnnotation(); - next.key = values[i]; - next.value = values[i + 1]; - res.add(next); - } - return res; - } - } - - private ModifyHow modifyHow; - private List<String> values; - private String annotationKey; - private List<Element> elements; - private List<BundledAnnotation> bundledAnnotations; - private boolean useMarkup; - - public DocumentModifyAction(ModifyHow modifyHow, List<String> values, String annotationKey, - List<Element> elements, List<BundledAnnotation> initialAnnotations, boolean useMarkup) { - this.modifyHow = modifyHow; - this.values = values; - this.annotationKey = annotationKey; - this.elements = elements; - this.useMarkup = useMarkup; - this.bundledAnnotations = initialAnnotations; - } - - // No parameter constructor for serialization - public DocumentModifyAction() { - this.modifyHow = null; - this.values = null; - this.annotationKey = null; - this.elements = null; - this.useMarkup = false; - this.bundledAnnotations = null; - } - - public ModifyHow getModifyHow() { - return modifyHow; - } - - public List<String> getValues() { - return values; - } - - public String getAnnotationKey() { - return annotationKey; - } - - public List<Element> getElements() { - return elements; - } - - public boolean isUseMarkup() { - return useMarkup; - } - - /** - * @return the value from values (wrapping around) for the given index. - */ - public String getValue(int valueIndex) { - if (values == null || values.isEmpty()) { - return null; - } - return values.get(valueIndex % values.size()); - } - - /** - * @return the element from elements (wrapping around) for the given index. - */ - public Element getElement(int valueIndex) { - if (elements == null || elements.isEmpty()) { - return null; - } - return elements.get(valueIndex % elements.size()); - } - - /** - * @return whether there is text at the specified index - */ - public boolean hasTextAt(int valueIndex) { - if (values == null || values.isEmpty()) { - return false; - } - return values.get(valueIndex % values.size()) != null; - } - - public List<BundledAnnotation> getBundledAnnotations() { - return bundledAnnotations; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/DocumentModifyQuery.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/DocumentModifyQuery.java b/src/com/google/wave/api/impl/DocumentModifyQuery.java deleted file mode 100644 index 9892edd..0000000 --- a/src/com/google/wave/api/impl/DocumentModifyQuery.java +++ /dev/null @@ -1,90 +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.impl; - -import com.google.wave.api.ElementType; - -import java.util.Map; - -/** - * DocumentModifyQuery is a class specific to how operations of type - * DOCUMENT_MODIFY are serialized. DocumentModifyQuery specifies which - * bit of a blip is matched. - * - * The query specifies either a textMatch in which case the blip is - * searched for that string literal, or an elementMatch is specified in - * which case the blip is searched of an instance of that element. In the - * latter case restrictions can also be set to restrict the elements matched - * by attribute value. In either case maxRes can be specified to restrict - * how many matches are returned; specify -1 for as many as possible. - */ -public class DocumentModifyQuery { - - private ElementType elementMatch; - private int maxRes; - private String textMatch; - private Map<String, String> restrictions; - - public DocumentModifyQuery( - ElementType elementMatch, Map<String, String> restrictions, int maxRes) { - this.textMatch = null; - this.elementMatch = elementMatch; - this.restrictions = restrictions; - this.maxRes = maxRes; - } - - public DocumentModifyQuery(String stringMatch, int maxRes) { - this.textMatch = stringMatch; - this.elementMatch = null; - this.restrictions = null; - this.maxRes = maxRes; - } - - // No Parameter constructor for serialization: - public DocumentModifyQuery() { - this.textMatch = null; - this.elementMatch = null; - this.restrictions = null; - this.maxRes = -1; - } - - /** - * @return textMatch if any is set or null if not. - */ - public String getTextMatch() { - return textMatch; - } - - /** - * @return elementMatch if any is set or null if not. - */ - public ElementType getElementMatch() { - return elementMatch; - } - - public Map<String, String> getRestrictions() { - return restrictions; - } - - public int getMaxRes() { - return maxRes; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/ElementGsonAdaptor.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/ElementGsonAdaptor.java b/src/com/google/wave/api/impl/ElementGsonAdaptor.java deleted file mode 100644 index 7313c3b..0000000 --- a/src/com/google/wave/api/impl/ElementGsonAdaptor.java +++ /dev/null @@ -1,124 +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.impl; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.google.wave.api.Attachment; -import com.google.wave.api.Element; -import com.google.wave.api.ElementType; -import com.google.wave.api.FormElement; -import com.google.wave.api.Gadget; -import com.google.wave.api.Image; -import com.google.wave.api.Line; - -import org.apache.commons.codec.binary.Base64; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Type; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Gson adaptor to serialize and deserialize {@link Element}. - * - * @author [email protected] (Marcel Prasetya) - */ -public class ElementGsonAdaptor implements JsonDeserializer<Element>, - JsonSerializer<Element> { - - protected static final String TYPE_TAG = "type"; - protected static final String PROPERTIES_TAG = "properties"; - - @Override - public Element deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - Element result = null; - ElementType type = ElementType.valueOfIgnoreCase( - json.getAsJsonObject().get(TYPE_TAG).getAsString()); - - Map<String, String> properties = context.deserialize( - json.getAsJsonObject().get(PROPERTIES_TAG), GsonFactory.STRING_MAP_TYPE); - - if (FormElement.getFormElementTypes().contains(type)) { - result = new FormElement(type, properties); - } else if (type == ElementType.GADGET) { - result = new Gadget(properties); - } else if (type == ElementType.IMAGE) { - result = new Image(properties); - } else if (type == ElementType.ATTACHMENT) { - byte[] data = null; - String encodedData = properties.get(Attachment.DATA); - if (encodedData != null) { - try { - data = Base64.decodeBase64(encodedData.getBytes("UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new JsonParseException("Couldn't convert to utf-8", e); - } - } - result = new Attachment(properties, data); - } else if (type == ElementType.LINE) { - result = new Line(properties); - } else { - result = new Element(type, properties); - } - return result; - } - - @Override - public JsonElement serialize(Element src, Type typeOfSrc, JsonSerializationContext context) { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty(TYPE_TAG, src.getType().toString()); - JsonObject properties = new JsonObject(); - if (src.isAttachment()) { - Attachment attachment = (Attachment) src; - if (attachment.hasData()) { - byte[] encodedData = Base64.encodeBase64(attachment.getData()); - try { - properties.add(Attachment.DATA, new JsonPrimitive( - new String(encodedData, "UTF-8"))); - } catch (UnsupportedEncodingException e) { - // this shouldn't happen, so let it slide. - } - } - } - for (Entry<String, String> entry : src.getProperties().entrySet()) { - // Note: Gson's JsonObject and MapTypeAdapter don't escape the key - // automatically, so we have to manually escape it here by calling - // JsonSerializationContext.serialize(). Also, unfortunately, calling - // JsonPrimitive.toString() wraps the text inside double quotes, that we - // need to strip out. - String quotedKey = context.serialize(entry.getKey()).toString(); - String key = quotedKey.substring(1, quotedKey.length() - 1); - - JsonElement value = context.serialize(entry.getValue()); - properties.add(key, value); - } - - jsonObject.add(PROPERTIES_TAG, properties); - return jsonObject; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/EventMessageBundle.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/EventMessageBundle.java b/src/com/google/wave/api/impl/EventMessageBundle.java deleted file mode 100644 index 67ddb08..0000000 --- a/src/com/google/wave/api/impl/EventMessageBundle.java +++ /dev/null @@ -1,209 +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.impl; - -import com.google.wave.api.BlipData; -import com.google.wave.api.Context; -import com.google.wave.api.BlipThread; -import com.google.wave.api.Wavelet; -import com.google.wave.api.event.Event; -import com.google.wave.api.event.EventType; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * A container for a bundle of messages to be sent to a robot. - * - * @author [email protected] (Seth Covitz) - */ -public class EventMessageBundle { - - private List<Event> events; - private WaveletData waveletData; - private Wavelet wavelet; - private Map<String, BlipData> blipData; - private Map<String, BlipThread> threads; - private Map<String, Set<Context>> requiredBlips; - private String proxyingFor; - private final String robotAddress; - private final String rpcServerUrl; - - public EventMessageBundle(String robotAddress, String rpcServerUrl) { - this.robotAddress = robotAddress; - events = new ArrayList<Event>(); - this.rpcServerUrl = rpcServerUrl; - blipData = new HashMap<String, BlipData>(); - requiredBlips = new HashMap<String, Set<Context>>(); - threads = new HashMap<String, BlipThread>(); - } - - public Map<String, Set<Context>> getRequiredBlips() { - return requiredBlips; - } - - /** - * Require the availability of the specified blipId for this bundle. - * - * @param blipId the id of the blip that is required. - * @param contexts we need for this blip. - */ - public void requireBlip(String blipId, List<Context> contexts) { - Set<Context> contextSet = requiredBlips.get(blipId); - if (contextSet == null) { - contextSet = new HashSet<Context>(); - requiredBlips.put(blipId, contextSet); - } - for (Context context : contexts) { - contextSet.add(context); - } - } - - /** - * Add an event to the events that are tracked. - * @param event to add. - */ - public void addEvent(Event event) { - events.add(event); - } - - public boolean hasMessages() { - return !events.isEmpty(); - } - - public List<Event> getEvents() { - return events; - } - - public WaveletData getWaveletData() { - return waveletData; - } - - public Wavelet getWavelet() { - return wavelet; - } - - public Map<String, BlipData> getBlipData() { - return blipData; - } - - public Map<String, BlipThread> getThreads() { - return threads; - } - - public void setEvents(List<Event> events) { - this.events = events; - } - - public void setWaveletData(WaveletData waveletData) { - this.waveletData = waveletData; - } - - public void setWavelet(Wavelet wavelet) { - this.wavelet = wavelet; - } - - public void setBlipData(Map<String, BlipData> blipData) { - this.blipData = blipData; - } - - public void setThreads(Map<String, BlipThread> threads) { - this.threads = threads; - } - - public void clear() { - events.clear(); - blipData.clear(); - requiredBlips.clear(); - waveletData = null; - } - - /** - * Return whether a blip is already in the blipdata - * - * @param id of the blip - * @return whether it is in blipData - */ - public boolean hasBlipId(String id) { - return blipData.containsKey(id); - } - - /** - * Add a blip to the blipdata - * - * @param id - * @param blip - */ - public void addBlip(String id, BlipData blip) { - blipData.put(id, blip); - } - - /** - * Add a thread to the map of threads. - * - * @param id the thread id. - * @param thread the thread to add. - */ - public void addThread(String id, BlipThread thread) { - threads.put(id, thread); - } - - /** - * Check whether a given thread has been added to the thread map or not. - * - * @param id the id of the thread to check. - * @return {@code true} if the map contains the given thread id. - */ - public boolean hasThreadId(String id) { - return threads.containsKey(id); - } - - /** - * Return whether the lookingFor event is contained in this bundle. - */ - public boolean hasEvent(EventType eventType) { - for (Event event : events) { - if (event.getType() == eventType) { - return true; - } - } - return false; - } - - public String getProxyingFor() { - return proxyingFor; - } - - public void setProxyingFor(String proxyingFor) { - this.proxyingFor = proxyingFor; - } - - public String getRobotAddress() { - return robotAddress; - } - - public String getRpcServerUrl() { - return rpcServerUrl; - } -} http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/7d8609e7/src/com/google/wave/api/impl/EventMessageBundleGsonAdaptor.java ---------------------------------------------------------------------- diff --git a/src/com/google/wave/api/impl/EventMessageBundleGsonAdaptor.java b/src/com/google/wave/api/impl/EventMessageBundleGsonAdaptor.java deleted file mode 100644 index 9db7bc5..0000000 --- a/src/com/google/wave/api/impl/EventMessageBundleGsonAdaptor.java +++ /dev/null @@ -1,163 +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.impl; - -import com.google.gson.InstanceCreator; -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.google.wave.api.Blip; -import com.google.wave.api.BlipData; -import com.google.wave.api.OperationQueue; -import com.google.wave.api.OperationRequest; -import com.google.wave.api.BlipThread; -import com.google.wave.api.Wavelet; -import com.google.wave.api.event.Event; -import com.google.wave.api.event.EventSerializationException; -import com.google.wave.api.event.EventSerializer; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * Gson adaptor to serialize and deserialize {@link EventMessageBundle}. - * - * @author [email protected] (Douwe Osinga) - */ -public class EventMessageBundleGsonAdaptor implements - InstanceCreator<EventMessageBundle>, - JsonSerializer<EventMessageBundle>, - JsonDeserializer<EventMessageBundle> { - - public static final String EVENTS_TAG = "events"; - public static final String WAVELET_TAG = "wavelet"; - public static final String BLIPS_TAG = "blips"; - public static final String THREADS_TAG = "threads"; - private static final String PROXYING_FOR_TAG = "proxyingFor"; - private static final String ROBOT_ADDRESS_TAG = "robotAddress"; - private static final String RPC_SERVER_URL_TAG = "rpcServerUrl"; - - @Override - public EventMessageBundle createInstance(Type type) { - return new EventMessageBundle("", "http://opensocial.example.com"); - } - - @Override - public JsonElement serialize(EventMessageBundle src, Type typeOfSrc, - JsonSerializationContext context) { - JsonObject result = new JsonObject(); - - JsonArray events = new JsonArray(); - for (Event event : src.getEvents()) { - try { - events.add(EventSerializer.serialize(event, context)); - } catch (EventSerializationException e) { - throw new JsonParseException(e); - } - } - result.add(EVENTS_TAG, events); - - result.add(WAVELET_TAG, context.serialize(src.getWaveletData())); - result.add(BLIPS_TAG, context.serialize(src.getBlipData())); - result.add(THREADS_TAG, context.serialize(src.getThreads())); - result.addProperty(ROBOT_ADDRESS_TAG, src.getRobotAddress()); - - String proxyingFor = src.getProxyingFor(); - if (proxyingFor != null && !proxyingFor.isEmpty()) { - result.addProperty(PROXYING_FOR_TAG, proxyingFor); - } - - String rpcServerUrl = src.getRpcServerUrl(); - if (rpcServerUrl != null && !rpcServerUrl.isEmpty()) { - result.addProperty(RPC_SERVER_URL_TAG, rpcServerUrl); - } - return result; - } - - @Override - public EventMessageBundle deserialize(JsonElement json, Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - JsonObject jsonObj = json.getAsJsonObject(); - String robotAddress = jsonObj.get(ROBOT_ADDRESS_TAG).getAsString(); - String rpcServerUrl = ""; - if (jsonObj.has(RPC_SERVER_URL_TAG)) { - rpcServerUrl = jsonObj.get(RPC_SERVER_URL_TAG).getAsString(); - } - EventMessageBundle result = new EventMessageBundle(robotAddress, rpcServerUrl); - - OperationQueue operationQueue; - if (jsonObj.has(PROXYING_FOR_TAG)) { - result.setProxyingFor(jsonObj.get(PROXYING_FOR_TAG).getAsString()); - operationQueue = new OperationQueue(new ArrayList<OperationRequest>(), - result.getProxyingFor()); - } else { - operationQueue = new OperationQueue(); - } - - // Deserialize wavelet. - WaveletData waveletData = context.deserialize(jsonObj.get(WAVELET_TAG), WaveletData.class); - result.setWaveletData(waveletData); - Map<String, Blip> blips = new HashMap<String, Blip>(); - Map<String, BlipThread> threads = new HashMap<String, BlipThread>(); - Wavelet wavelet = Wavelet.deserialize(operationQueue, blips, threads, waveletData); - wavelet.setRobotAddress(robotAddress); - result.setWavelet(wavelet); - - // Deserialize threads. - Map<String, BlipThread> tempThreads = context.deserialize(jsonObj.get(THREADS_TAG), - GsonFactory.THREAD_MAP_TYPE); - for (Entry<String, BlipThread> entry : tempThreads.entrySet()) { - BlipThread thread = entry.getValue(); - threads.put(entry.getKey(), new BlipThread(thread.getId(), thread.getLocation(), - thread.getBlipIds(), blips)); - } - - // Deserialize blips. - Map<String, BlipData> blipDatas = context.deserialize(jsonObj.get(BLIPS_TAG), - GsonFactory.BLIP_MAP_TYPE); - result.setBlipData(blipDatas); - for(Entry<String, BlipData> entry : blipDatas.entrySet()) { - blips.put(entry.getKey(), Blip.deserialize(operationQueue, wavelet, entry.getValue())); - } - - // Deserialize events. - JsonArray eventsArray = jsonObj.get(EVENTS_TAG).getAsJsonArray(); - List<Event> events = new ArrayList<Event>(eventsArray.size()); - for (JsonElement element : eventsArray) { - JsonObject eventObject = element.getAsJsonObject(); - try { - events.add(EventSerializer.deserialize(wavelet, result, eventObject, context)); - } catch (EventSerializationException e) { - throw new JsonParseException(e.getMessage()); - } - } - result.setEvents(events); - return result; - } -}
