001: /*
002: * Copyright 2005 Joe Walker
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.directwebremoting.proxy.openajax;
017:
018: import java.util.Collection;
019:
020: import org.directwebremoting.ScriptSession;
021: import org.directwebremoting.event.PublishListener;
022: import org.directwebremoting.proxy.ScriptProxy;
023:
024: /**
025: * Util is a server-side proxy that allows Java programmers to call client
026: * side Javascript from Java.
027: * <p>
028: * Each Util object is associated with a list of ScriptSessions and the
029: * proxy code is creates will be dynamically forwarded to all those browsers.
030: * <p>
031: * Currently this class contains only the write-only DOM manipulation functions
032: * from Util. It is possible that we could add the read methods, however
033: * the complexity in the callback and the fact that you are probably not going
034: * to need it means that we'll leave it for another day. Specifically,
035: * <code>getValue</code>, <code>getValues</code> and <code>getText</code> have
036: * been left out as being read functions and <code>useLoadingMessage</code> etc
037: * have been left out as not being DOM related.
038: * @author Joe Walker [joe at getahead dot ltd dot uk]
039: * @author Jorge Martin Cuervo [darthkorr at gmail dot com]
040: */
041: public class OpenAjax extends ScriptProxy {
042: /**
043: * Http thread constructor, that affects no browsers.
044: * Calls to {@link OpenAjax#addScriptSession(ScriptSession)} or to
045: * {@link OpenAjax#addScriptSessions(Collection)} will be needed
046: */
047: public OpenAjax() {
048: super ();
049: }
050:
051: /**
052: * Http thread constructor that alters a single browser
053: * @param scriptSession The browser to alter
054: */
055: public OpenAjax(ScriptSession scriptSession) {
056: super (scriptSession);
057: }
058:
059: /**
060: * Http thread constructor that alters a number of browsers
061: * @param scriptSessions A collection of ScriptSessions that we should act on.
062: */
063: public OpenAjax(Collection<ScriptSession> scriptSessions) {
064: super (scriptSessions);
065: }
066:
067: /**
068: * Publishes (broadcasts) an event based on a library-specific prefix and
069: * event name.
070: * @param prefix The prefix that corresponds to this event. This must be a
071: * prefix that has been registered via OpenAjax.registerLibrary().
072: * @param name The name of the event to listen for. Names can be any string
073: */
074: public void publish(String prefix, String name) {
075: addFunctionCall("OpenAjax.publish", prefix, name);
076: }
077:
078: /**
079: * Publishes (broadcasts) an event based on a library-specific prefix and
080: * event name.
081: * @param prefix The prefix that corresponds to this event. This must be a
082: * prefix that has been registered via OpenAjax.registerLibrary().
083: * @param name The name of the event to listen for. Names can be any string
084: * @param publisherData An arbitrary Object holding extra information that
085: * will be passed as an argument to the handler function. Can be null.
086: */
087: public void publish(String prefix, String name, Object publisherData) {
088: addFunctionCall("OpenAjax.publish", prefix, name, publisherData);
089: }
090:
091: /**
092: * Allows registration of interest in named events based on library-specific
093: * prefix and event name. Global event matching is provided by passing "*"
094: * in the prefix and/or name arguments. Optional arguments may be specified
095: * for executing the specified handler function in a provided scope and for
096: * further filtering events prior to application.
097: * <p>
098: * The callback function will receive the following parameters
099: * (see OpenAjax.publish() for description of publisherData):
100: * <pre>
101: * function(prefix, name, subscriberData, publisherData){ ... }
102: * </pre>
103: * @param prefix The prefix that corresponds to this library. This is the
104: * same value that was previously passed to registerLibrary(). Can be "*" to
105: * match the provided event name across all libraries.
106: * @param name The name of the event to listen for. Names can be any string.
107: * Can be "*" to match all events in the specified toolkit (see prefix). If
108: * both name and prefix specify "*", all events in the system will be routed
109: * to the registered handler (modulo any filtering provided by filter).
110: * @param listener The object to deliver messages to
111: */
112: public void subscribe(String prefix, String name,
113: PublishListener listener) {
114: }
115:
116: /**
117: * Allows registration of interest in named events based on library-specific
118: * prefix and event name. Global event matching is provided by passing "*"
119: * in the prefix and/or name arguments. Optional arguments may be specified
120: * for executing the specified handler function in a provided scope and for
121: * further filtering events prior to application.
122: * <p>
123: * The callback function will receive the following parameters
124: * (see OpenAjax.publish() for description of publisherData):
125: * <pre>
126: * function(prefix, name, subscriberData, publisherData){ ... }
127: * </pre>
128: * @param prefix The prefix that corresponds to this library. This is the
129: * same value that was previously passed to registerLibrary(). Can be "*" to
130: * match the provided event name across all libraries.
131: * @param name The name of the event to listen for. Names can be any string.
132: * Can be "*" to match all events in the specified toolkit (see prefix). If
133: * both name and prefix specify "*", all events in the system will be routed
134: * to the registered handler (modulo any filtering provided by filter).
135: * @param listener The object to deliver messages to
136: */
137: public void subscribe(String prefix, String name,
138: PublishListener listener, Object subscriberData) {
139: }
140:
141: /**
142: * Removes a subscription to an event. In order for a subscription to be
143: * removed, the values of the parameters supplied to OpenAjax.unsubscribe()
144: * must exactly match the values of the parameters supplied to a previous
145: * call to OpenAjax.subscribe(). Note that it is possible that one
146: * invocation of OpenAjax.unsubscribe() might result in removal of multiple
147: * subscriptions.
148: * @param prefix The prefix that corresponds to this library. This is the
149: * same value that was previously passed to registerLibrary(). Can be "*" to
150: * match the provided event name across all libraries.
151: * @param name The name of the event to listen for. Names can be any string.
152: * Can be "*" to match all events in the specified toolkit (see prefix). If
153: * both name and prefix specify "*", all events in the system will be routed
154: * to the registered handler (modulo any filtering provided by filter).
155: * @param listener The object to deliver messages to
156: */
157: public void unsubscribe(String prefix, String name,
158: PublishListener listener) {
159: }
160: }
|