Commits

hatboyzero committed ddaad3e

Mavenizing gwt-gae-channel

Comments (0)

Files changed (12)

src/com/google/gwt/appengine/channel/Channel.gwt.xml

-<module>
-  <inherits name="com.google.gwt.core.Core" />
-  <inherits name="com.google.gwt.dom.DOM" />
-</module>

src/com/google/gwt/appengine/channel/client/Channel.java

-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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.gwt.appengine.channel.client;
-
-import com.google.gwt.core.client.JavaScriptObject;
-
-/** Represents a channel to receive messages from the server. */
-public class Channel extends JavaScriptObject {
-  protected Channel() {
-  }
-
-  /** Opens the channel and attaches the given listener. */
-  public final native Socket open(SocketListener listener) /*-{
-    var socket = this.open();
-    socket.onopen = function(event) {
-      listener.@com.google.gwt.appengine.channel.client.SocketListener::onOpen()();
-    };
-    socket.onmessage = function(event) {
-      listener.
-      @com.google.gwt.appengine.channel.client.SocketListener::onMessage(Ljava/lang/String;)
-      (event.data);
-    };
-    socket.onerror = function(error) {
-      listener.
-      @com.google.gwt.appengine.channel.client.SocketListener::onError(Lcom/google/gwt/appengine/channel/client/SocketError;)
-      (error);
-    };
-    socket.onclose = function(event) {
-      listener.
-      @com.google.gwt.appengine.channel.client.SocketListener::onClose()();
-    };
-    return socket;
-  }-*/;
-}

src/com/google/gwt/appengine/channel/client/ChannelFactory.java

-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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.gwt.appengine.channel.client;
-
-import com.google.gwt.dom.client.Document;
-import com.google.gwt.dom.client.ScriptElement;
-import com.google.gwt.user.client.Timer;
-
-/** Manages creating {@link Channel}s to receive messages from the server. */
-public class ChannelFactory {
-
-  private static final String CHANNEL_SRC = "/_ah/channel/jsapi";
-  private static Channel channel;
-
-  /**
-   * Creates a {@link Channel} with the given client ID, passing it to the given
-   * {@link ChannelCreatedCallback}.
-   *
-   * <p>
-   * If a Channel has already been created, this will immediately be passed to
-   * the callback, so only one Channel will ever be created by this method.
-   * </p>
-   */
-  public static void createChannel(final String clientId, final ChannelCreatedCallback callback) {
-    if (channel == null) {
-      ScriptElement script = Document.get().createScriptElement();
-      script.setSrc(CHANNEL_SRC);
-      Document.get().getElementsByTagName("head").getItem(0).appendChild(script);
-
-      new Timer() {
-        @Override
-        public void run() {
-          if (scriptLoaded()) {
-            channel = createChannelImpl(clientId);
-            callback.onChannelCreated(channel);
-            this.cancel();
-          }
-        }
-      }.scheduleRepeating(100);
-    } else {
-      callback.onChannelCreated(channel);
-    }
-  }
-
-  private static native boolean scriptLoaded() /*-{
-    return !!$wnd.goog && !!$wnd.goog.appengine && !!$wnd.goog.appengine.Channel;
-  }-*/;
-
-  private static final native Channel createChannelImpl(String clientId) /*-{
-    return new $wnd.goog.appengine.Channel(clientId);
-  }-*/;
-
-  public interface ChannelCreatedCallback {
-    public void onChannelCreated(Channel channel);
-  }
-}

src/com/google/gwt/appengine/channel/client/Socket.java

-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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.gwt.appengine.channel.client;
-
-import com.google.gwt.core.client.JavaScriptObject;
-
-/** Returned by calls to {@link Channel#open(SocketListener)}. */
-public class Socket extends JavaScriptObject {
-  protected Socket() {
-  }
-
-  /**
-   * Closes this socket to incoming messages from the server. The socket cannot
-   * be used again after calling close; the server must create a new socket.
-   */
-  public final native void close() /*-{
-    this.close();
-  }-*/;
-}

src/com/google/gwt/appengine/channel/client/SocketError.java

-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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.gwt.appengine.channel.client;
-
-import com.google.gwt.core.client.JavaScriptObject;
-
-/**
- * An error encountered by a {@link Socket}, passed to the
- * {@link SocketListener}.
- */
-public final class SocketError extends JavaScriptObject {
-
-  protected SocketError() {
-  }
-
-  /** Returns a short description of the error encountered. */
-  public final native String getDescription() /*-{
-    return this.description;
-  }-*/;
-
-  /** Returns the HTTP error code corresponding to the error encountered. */
-  public final native int getCode() /*-{
-    return this.code;
-  }-*/;
-
-
-}

src/com/google/gwt/appengine/channel/client/SocketListener.java

-/*
- * Copyright (C) 2011 Google Inc.
- *
- * Licensed 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.gwt.appengine.channel.client;
-
-/**
- * Listener to receive messages from the server.
- *
- * <p>
- * For more information about the events handled by this listener, see the
- * Channel API JavaScript Reference: {@link
- * "http://code.google.com/appengine/docs/java/channel/javascript.html"}.
- * </p>
- */
-public interface SocketListener {
-  /** Called when the channel is opened. */
-  void onOpen();
-
-  /** Called when the channel receives a message from the server. */
-  void onMessage(String message);
-
-  /** Called when the channel receives an error. */
-  void onError(SocketError error);
-
-  /** Called when the channel is closed. */
-  void onClose();
-}

src/main/java/com/google/gwt/appengine/channel/Channel.gwt.xml

+<module>
+  <inherits name="com.google.gwt.core.Core" />
+  <inherits name="com.google.gwt.dom.DOM" />
+</module>

src/main/java/com/google/gwt/appengine/channel/client/Channel.java

+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed 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.gwt.appengine.channel.client;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/** Represents a channel to receive messages from the server. */
+public class Channel extends JavaScriptObject {
+  protected Channel() {
+  }
+
+  /** Opens the channel and attaches the given listener. */
+  public final native Socket open(SocketListener listener) /*-{
+    var socket = this.open();
+    socket.onopen = function(event) {
+      listener.@com.google.gwt.appengine.channel.client.SocketListener::onOpen()();
+    };
+    socket.onmessage = function(event) {
+      listener.
+      @com.google.gwt.appengine.channel.client.SocketListener::onMessage(Ljava/lang/String;)
+      (event.data);
+    };
+    socket.onerror = function(error) {
+      listener.
+      @com.google.gwt.appengine.channel.client.SocketListener::onError(Lcom/google/gwt/appengine/channel/client/SocketError;)
+      (error);
+    };
+    socket.onclose = function(event) {
+      listener.
+      @com.google.gwt.appengine.channel.client.SocketListener::onClose()();
+    };
+    return socket;
+  }-*/;
+}

src/main/java/com/google/gwt/appengine/channel/client/ChannelFactory.java

+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed 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.gwt.appengine.channel.client;
+
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.ScriptElement;
+import com.google.gwt.user.client.Timer;
+
+/** Manages creating {@link Channel}s to receive messages from the server. */
+public class ChannelFactory {
+
+  private static final String CHANNEL_SRC = "/_ah/channel/jsapi";
+  private static Channel channel;
+
+  /**
+   * Creates a {@link Channel} with the given client ID, passing it to the given
+   * {@link ChannelCreatedCallback}.
+   *
+   * <p>
+   * If a Channel has already been created, this will immediately be passed to
+   * the callback, so only one Channel will ever be created by this method.
+   * </p>
+   */
+  public static void createChannel(final String clientId, final ChannelCreatedCallback callback) {
+    if (channel == null) {
+      ScriptElement script = Document.get().createScriptElement();
+      script.setSrc(CHANNEL_SRC);
+      Document.get().getElementsByTagName("head").getItem(0).appendChild(script);
+
+      new Timer() {
+        @Override
+        public void run() {
+          if (scriptLoaded()) {
+            channel = createChannelImpl(clientId);
+            callback.onChannelCreated(channel);
+            this.cancel();
+          }
+        }
+      }.scheduleRepeating(100);
+    } else {
+      callback.onChannelCreated(channel);
+    }
+  }
+
+  private static native boolean scriptLoaded() /*-{
+    return !!$wnd.goog && !!$wnd.goog.appengine && !!$wnd.goog.appengine.Channel;
+  }-*/;
+
+  private static final native Channel createChannelImpl(String clientId) /*-{
+    return new $wnd.goog.appengine.Channel(clientId);
+  }-*/;
+
+  public interface ChannelCreatedCallback {
+    public void onChannelCreated(Channel channel);
+  }
+}

src/main/java/com/google/gwt/appengine/channel/client/Socket.java

+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed 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.gwt.appengine.channel.client;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/** Returned by calls to {@link Channel#open(SocketListener)}. */
+public class Socket extends JavaScriptObject {
+  protected Socket() {
+  }
+
+  /**
+   * Closes this socket to incoming messages from the server. The socket cannot
+   * be used again after calling close; the server must create a new socket.
+   */
+  public final native void close() /*-{
+    this.close();
+  }-*/;
+}

src/main/java/com/google/gwt/appengine/channel/client/SocketError.java

+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed 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.gwt.appengine.channel.client;
+
+import com.google.gwt.core.client.JavaScriptObject;
+
+/**
+ * An error encountered by a {@link Socket}, passed to the
+ * {@link SocketListener}.
+ */
+public final class SocketError extends JavaScriptObject {
+
+  protected SocketError() {
+  }
+
+  /** Returns a short description of the error encountered. */
+  public final native String getDescription() /*-{
+    return this.description;
+  }-*/;
+
+  /** Returns the HTTP error code corresponding to the error encountered. */
+  public final native int getCode() /*-{
+    return this.code;
+  }-*/;
+
+
+}

src/main/java/com/google/gwt/appengine/channel/client/SocketListener.java

+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed 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.gwt.appengine.channel.client;
+
+/**
+ * Listener to receive messages from the server.
+ *
+ * <p>
+ * For more information about the events handled by this listener, see the
+ * Channel API JavaScript Reference: {@link
+ * "http://code.google.com/appengine/docs/java/channel/javascript.html"}.
+ * </p>
+ */
+public interface SocketListener {
+  /** Called when the channel is opened. */
+  void onOpen();
+
+  /** Called when the channel receives a message from the server. */
+  void onMessage(String message);
+
+  /** Called when the channel receives an error. */
+  void onError(SocketError error);
+
+  /** Called when the channel is closed. */
+  void onClose();
+}