com.eliasbalasis.tibcopagebus4gwt.client
Class PageBusAdapter

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Composite
              extended by com.eliasbalasis.tibcopagebus4gwt.client.PageBusAdapter
All Implemented Interfaces:
IPageBusAdapter, com.google.gwt.user.client.EventListener

public final class PageBusAdapter
extends com.google.gwt.user.client.ui.Composite
implements IPageBusAdapter

This is the main GWT widget which serves as an access point for all TIBCO PageBus™ functions.


How can PageBus help me?

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.

Ajax Portlets with Reverse Proxy Architecture

This diagram shows three Ajax widgets communicating with each other via the PageBus. Each widget has a file defining its visuals, a file controlling its behavior including the publish and subscribe calls to the PageBus, and a file that gets data from a service on the Web.

How can PageBusAdapter help me?

Assume now that one or more of the above mentioned Widgets are GWT modules and desire to communicate with the rest of the Ajax widgets on the page. This is a task for PageBusAdapter which exposes PageBus functions as a GWT widget. Assume that the information to be communicated is represented with the following Java classes
 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
  1. The bean must be compliant with Java Beans specification (getters, setters, default constructors etc.)
  2. The bean marshaller definition must be named after the respective bean class name with the Jsonizer suffix
  3. Each and every bean property must contain a hint to the marshaller in the form of javadoc annotations. The following annotations are currently supported
    AnnotationEffect
    jsonizer.transientThe property in not translatable
    jsonizer.propName 'prop'This property is named 'prop' in JavaScript
    jsonizer.requiredIf 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

Here is how a GWT module using PageBus functions would look like
 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

Here is how it should look like
 <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

PageBusAdapter

public PageBusAdapter()
default constructor
It is required for integration with Designer tools

Method Detail

PageBusSubscribe

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
Subscribes to PageBus hub for a desired message type

Specified by:
PageBusSubscribe in interface IPageBusAdapter
Parameters:
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

Throws:
PageBusAdapterException

PageBusPublish

public void PageBusPublish(java.lang.String subject,
                           java.lang.Object message,
                           org.juglar.gwt.jsonizer.client.Jsonizer jsonizer)
                    throws PageBusAdapterException
Publishes a new message to the PageBus hub

Specified by:
PageBusPublish in interface IPageBusAdapter
Parameters:
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

Throws:
PageBusAdapterException

PageBusUnsubscribe

public void PageBusUnsubscribe(java.lang.String subject)
                        throws PageBusAdapterException
Removes subscription of a desired message type from PageBus hub

Specified by:
PageBusUnsubscribe in interface IPageBusAdapter
Parameters:
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

Throws:
PageBusAdapterException

addPageBusSubscriptionCallbackListener

public 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

Parameters:
listener -

A reference to an instance of the desired listener implementation class


removePageBusSubscriptionCallbackListener

public void removePageBusSubscriptionCallbackListener(PageBusListener listener)
Unregisters a listener

Parameters:
listener -

A reference to an instance of the desired listener implementation class


getMaxLinesLogged

public int getMaxLinesLogged()
Gets the maximum number of lines for the displayed events buffer

Returns:
the maxLinesLogged

The maximum number of lines


setMaxLinesLogged

public void setMaxLinesLogged(int maxLinesLogged)
Sets the maximum number of lines for the displayed events buffer

Parameters:
maxLinesLogged -

The maximum number of lines


ClearBuffer

public void ClearBuffer()

EnableLogging

public void EnableLogging(boolean bLogEvents)
Enables or disables the logging of actions in the text area

Parameters:
bLogEvents - true enables logging, false disables logging

isLoggingEnabled

public boolean isLoggingEnabled()
Reports whether or not actions will be displayed in text area

Returns:
true when logging is enabled, false otherwise

isMoveCursorOnEvent

public boolean isMoveCursorOnEvent()
Reports whether cursos in text area moves to last entry when a new event is logged

Returns:
true moves cursos, false cursos remains at its present location

setMoveCursorOnEvent

public void setMoveCursorOnEvent(boolean moveCursorOnEvent)
Enables or disables moving of cursos position in text area to last entry when a new event is logged

Parameters:
moveCursorOnEvent - true moves cursos, false cursos remains at its present location