|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
com.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapter
public final class PageBusAdapter
This is the main GWT widget which serves as an access point for all TIBCO PageBus™ functions.
As Ajax expands the capabilities of Web pages into solutions patterns such as mashups, composite applications, and rich interactive portals, PageBus helps developers drastically simplify development by using publish and subscribe APIs to send events and messages between components rather than get bogged down in point to point integrations between components that lead to unwieldy and less manageable code. In addition, adherence to publish and subscribe architecture helps modularize applications into distinct pieces making team development, unit testing, and source code management easier as well.
Publish and subscribe architecture is also the basis for Ajax standards. The first specification from The OpenAjax Alliance, an industry group with more than 70 members working to set Ajax interoperability standards, centers on publish and subscribe APIs as its core strategy for facilitating interoperation between Ajax libraries. TIBCO has been an active participant in these processes and has donated the core of the PageBus to the OpenAjax Alliance's implementation of the OpenAjax Hub 1.0.
package com.mycompany.mybeans; ... // a Person bean class. class Person{ ... public String getName(){...} public void setName(String name){...} ... public int getAge(){...} public void setAge(int age){...} ... } class SubscriberData { ... public String getHeader(){...} public void setHeader(String header){...} ... public String getBody(){...} public void setBody(String header){...} ... }as part of the publish and subscribe calls to the PageBus. Not only
Person
beans must be translated to JavaScript objects before being passed around to PageBus but also JavaScripts objects passed through PageBus by other widgets must be translated to Person
beans before the GWT module can use them.
PageBusAdapter makes uses marshaller implementations created using the the gwt-jsonizer library to perform the translation.
Here is the gwt-jsonizer marshaller implementation for the Person
bean.
interface PersonJsonizer extends Jsonizer{} interface SubscriberDataJsonizer extends Jsonizer{}It is quite simple don't you think? But you may wonder where is the marshalling/unmarshalling code? It is automatically created by the gwt-jsonizer GWT compiler hook the first time a bean class is accessed. The requirements of the gwt-jsonizer marshaller are
Jsonizer
suffixAnnotation | Effect |
jsonizer.transient | The property in not translatable |
jsonizer.propName 'prop' | This property is named 'prop' in JavaScript |
jsonizer.required | If the property doesn't exist in respetive JavaScript version an exception will be thrown (org.juglar.gwt.jsonizer.client.JsonizerException) |
gwt.typeArgs | Used for bean properties of Collection type to reference the type of each element in the collection |
package ...; import com.mycompany.myapplication; ... public class MyGWTModule implements EntryPoint { final PageBusAdapter pageBusAdapter = new PageBusAdapter(); ... RootPanel.add(pageBusAdapter); SubscriberData subscriberData = new SubscriberData(); subscriberData.setHeader("myHeader"); subscriberData.setBody("myHeader"); // Subscribe to message and associate subsequent receptions with custom subscriber data pageBusAdapter.PageBusSubscribe("com.mycompany.mymessagesubjects.person", null, null, subscriberData, (Jsonizer)GWT.create(SubscriberDataJsonizer.class)); ... Person person = new Person(); person.setName("Elias Balasis"); person.setAge(37); ... // publish a message with Person bean data pageBusAdapter.PageBusPublish("com.mycompany.mymessagesubjects.person", person, (Jsonizer)GWT.create(PersonJsonizer.class)); ... // register listener pageBusAdapter.addPageBusSubscriptionCallbackListener( new PageBusListener() { public void onPageBusSubscriptionCallback(PageBusEvent event) { // translate JavaScript message contents and subscriber data to their Java equivalents Person message = (Person)event.getMessage((Jsonizer)GWT.create(PersonJsonizer.class)); SubscriberData subscriberData = (SubscriberData)event.getSubscriberData((Jsonizer)GWT.create(SubscriberDataJsonizer.class)); ... ... ... } } ); ... // unsubscribe from message. future publications of message will not trigger callback pageBusAdapter.PageBusUnsubscribe("com.mycompany.mymessagesubjects.person"); }
Do not forget to include the pagebus.js
reference in the HTML file of your GWT module
<html> <head> <!-- --> <!-- Any title is fine --> <!-- --> <title>Wrapper HTML for ...</title> <script src="pagebus.js" language="JavaScript1.2"></script> <script type="text/javascript"> if(window.parent.PageBus) { window.PageBus = window.parent.PageBus; } </script> <!-- --> <!-- The module reference below is the link --> <!-- between html and your Web Toolkit module --> <!-- --> <meta name='gwt:module' content='com.mycompany.mygwtapp.MyApp'/> <!-- --> <!-- Link CSS file --> <!-- --> <link type="text/css" rel='stylesheet' href='Test.css'/> </head> <!-- --> <!-- The body can have arbitrary html, or --> <!-- we leave the body empty because we want --> <!-- to create a completely dynamic ui --> <!-- --> <body> <!-- --> <!-- This script is required bootstrap stuff. --> <!-- You can put it in the HEAD, but startup --> <!-- is slightly faster if you include it here. --> <!-- --> <script language="javascript" src="gwt.js"></script> <!-- OPTIONAL: include this if you want history support --> <iframe id="__gwt_historyFrame" style="width:0;height:0;border:0"></iframe> </body> </html>
Do not forget to include the gwt-jsonizer library reference configuration file (file.gwt.xml) of your GWT module
Here is how it should look like<module> <inherits name="com.google.gwt.user.User"/> <inherits name="com.eliasbalasis.tibcopagebus4gwt.tibcopagebus4gwt"/> <inherits name="org.juglar.gwt.jsonizer.Jsonizer"/> ... ... ... </module>
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject |
---|
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled |
Field Summary |
---|
Fields inherited from class com.google.gwt.user.client.ui.UIObject |
---|
DEBUG_ID_PREFIX |
Constructor Summary | |
---|---|
PageBusAdapter()
default constructor It is required for integration with Designer tools |
Method Summary | |
---|---|
void |
addPageBusSubscriptionCallbackListener(PageBusListener listener)
Registers a listener whose PageBusListener.onPageBusSubscriptionCallback(PageBusEvent) method will be called when a message of any subscribed type is published through the PageBus hub |
void |
ClearBuffer()
|
void |
EnableLogging(boolean bLogEvents)
Enables or disables the logging of actions in the text area |
int |
getMaxLinesLogged()
Gets the maximum number of lines for the displayed events buffer |
boolean |
isLoggingEnabled()
Reports whether or not actions will be displayed in text area |
boolean |
isMoveCursorOnEvent()
Reports whether cursos in text area moves to last entry when a new event is logged |
void |
PageBusPublish(java.lang.String subject,
java.lang.Object message,
org.juglar.gwt.jsonizer.client.Jsonizer jsonizer)
Publishes a new message to the PageBus hub |
void |
PageBusSubscribe(java.lang.String subject,
java.lang.Object scope,
org.juglar.gwt.jsonizer.client.Jsonizer scopeJsonizer,
java.lang.Object subscriberData,
org.juglar.gwt.jsonizer.client.Jsonizer subscriberDataJsonizer)
Subscribes to PageBus hub for a desired message type |
void |
PageBusUnsubscribe(java.lang.String subject)
Removes subscription of a desired message type from PageBus hub |
void |
removePageBusSubscriptionCallbackListener(PageBusListener listener)
Unregisters a listener |
void |
setMaxLinesLogged(int maxLinesLogged)
Sets the maximum number of lines for the displayed events buffer |
void |
setMoveCursorOnEvent(boolean moveCursorOnEvent)
Enables or disables moving of cursos position in text area to last entry when a new event is logged |
Methods inherited from class com.google.gwt.user.client.ui.Composite |
---|
getWidget, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, setWidget |
Methods inherited from class com.google.gwt.user.client.ui.Widget |
---|
doAttachChildren, doDetachChildren, getParent, onLoad, onUnload, removeFromParent |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PageBusAdapter()
Method Detail |
---|
public void PageBusSubscribe(java.lang.String subject, java.lang.Object scope, org.juglar.gwt.jsonizer.client.Jsonizer scopeJsonizer, java.lang.Object subscriberData, org.juglar.gwt.jsonizer.client.Jsonizer subscriberDataJsonizer) throws PageBusAdapterException
PageBusSubscribe
in interface IPageBusAdapter
subject
-
The identity of the message type
It can be anything although a package notation is recommended by the PageBus manufacturer
For example com.mycompany.mymessages.notifyChange
If null or an empty string is passed subscription will not take place
scope
-
The message scope. It can be any Java Bean
provided that it is compatible with the marshaller provided in
scopeJsonizer
parameter
scopeJsonizer
- The marshaller implementation of the message scope. It is used to translate the message scope to its JavaScript equivalent
subscriberData
-
Special data to be included in all future message receptions.
It can be any Java Bean provided that it is compatible
with the marshaller provided in
subscriberDataJsonizer
parameter
subscriberDataJsonizer
- The marshaller implementation of the special message data. It is used to translate the special data to its JavaScript equivalent
PageBusAdapterException
public void PageBusPublish(java.lang.String subject, java.lang.Object message, org.juglar.gwt.jsonizer.client.Jsonizer jsonizer) throws PageBusAdapterException
PageBusPublish
in interface IPageBusAdapter
subject
-
The identity of the message type
It can be anything although a package notation is recommended by the PageBus manufacturer
For example com.mycompany.mymessages.notifyChange
If null or an empty string is passed publication will not take place
message
-
The message data.
It can be any Java Bean provided that it is
compatible with the marshaller
provided in jsonizer
parameter
jsonizer
- The marshaller implementation for the message data. It is used to translate the message data to its JavaScript equivalent
PageBusAdapterException
public void PageBusUnsubscribe(java.lang.String subject) throws PageBusAdapterException
PageBusUnsubscribe
in interface IPageBusAdapter
subject
-
The identity of the message type
It can be anything although a package notation is recommended by the PageBus manufacturer
For example com.mycompany.mymessages.notifyChange
If null or an empty string is passed unsubscribe will not take place
PageBusAdapterException
public void addPageBusSubscriptionCallbackListener(PageBusListener listener)
listener
- A reference to an instance of the desired listener implementation class
public void removePageBusSubscriptionCallbackListener(PageBusListener listener)
listener
- A reference to an instance of the desired listener implementation class
public int getMaxLinesLogged()
The maximum number of lines
public void setMaxLinesLogged(int maxLinesLogged)
maxLinesLogged
- The maximum number of lines
public void ClearBuffer()
public void EnableLogging(boolean bLogEvents)
bLogEvents
- true enables logging, false disables loggingpublic boolean isLoggingEnabled()
public boolean isMoveCursorOnEvent()
public void setMoveCursorOnEvent(boolean moveCursorOnEvent)
moveCursorOnEvent
- true moves cursos, false cursos remains at its present location
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |