Websphere MQ Everyplace

examples.midp.exampleapp.textapp
Class MidpClient

java.lang.Object
  |
  +--javax.microedition.midlet.MIDlet
        |
        +--examples.midp.exampleapp.textapp.MidpClient
All Implemented Interfaces:
AppController, javax.microedition.lcdui.CommandListener

public class MidpClient
extends javax.microedition.midlet.MIDlet
implements AppController, javax.microedition.lcdui.CommandListener

This is the MIDP client controller for the text app. It is designed to work as a MIDlet and cannot be run from the commandline (use Client.java for that).

The client is required to register with the registration server before it can send messages to the gateway. This is done by the registerWithCentral() function located in the AppModel class.

The MIDP controller works as follows:

If the registry of a previous queue manager is still present in the record store, load the queue manager's details from that and start running without bothering to register (since the client must have registered before for the registry to be there).
If no signs of a previous QM are visible, the user is prompted for a name for the new queue manager. Once they have chosen a name, the client registers with the reg server.

The following jad properties are available:

      App_Registration_ServerIP
        The IP address of the registration server

      App_Gateway_ServerIP
        The IP address of the gateway server
      


Field Summary
static short[] version
           
 
Constructor Summary
MidpClient()
           
 
Method Summary
protected  void addNewQM(java.lang.String name)
          adds a new recordstore to the device containing the name of the queue manager this can be used of the app is restarted to keep the same qm name.
protected  void attachButtons(javax.microedition.lcdui.Displayable screen, javax.microedition.lcdui.Command[] commands)
          Attaches buttons to a given screen.
protected  void changeDisplay(javax.microedition.lcdui.Screen newDisplay)
          Changes the display to the given screen.
protected  void clearMessage()
          Clears the messagebox that is used by the user to enter messages.
 void commandAction(javax.microedition.lcdui.Command c, javax.microedition.lcdui.Displayable d)
          See CommandListener#commandAction method for more details.
 void deleteQueueManager()
          Completely removes the queue manager from the system.
 void destroyApp(boolean arg0)
          See javax.microedition.midlet.MIDlet#destroyApp for more details.
 void displayStatus(java.lang.String msg)
          If the controller is initializing, use the initialScreen to display the message, otherwise use the statusbar.
 java.lang.String getQMname()
          This will search the record store for signs of a previous queue manager.
protected  void initialize(java.lang.String localQMname)
          Initializes the view.
protected  void initializeMainScreen()
          Initializes the main screen - this involves creating a new form and adding the 2 components:
message - a text field so the user can enter a message to send.
 void pauseApp()
          There's nothing to pause.
 void promptFor(java.lang.String title, java.lang.String stringDefault)
          Due to the way MIDP works, the user will hit the ok button on the screen at which point commandAction will be called and initialization will continue.
protected  void setPumpProperties()
           
protected  void showStatus()
          Displays a status report to the user.
protected  void start()
          This is the first thing run when the midlet is started.
 void startApp()
          See javax.microedition.midlet.MIDlet#startApp for more details.
 void stop()
          Stops the controller and all constituent parts - in this case, the model.
 
Methods inherited from class javax.microedition.midlet.MIDlet
getAppProperty, notifyDestroyed, notifyPaused, resumeRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static short[] version
Constructor Detail

MidpClient

public MidpClient()
Method Detail

startApp

public void startApp()
              throws javax.microedition.midlet.MIDletStateChangeException
See javax.microedition.midlet.MIDlet#startApp for more details.

Specified by:
startApp in class javax.microedition.midlet.MIDlet
javax.microedition.midlet.MIDletStateChangeException

attachButtons

protected void attachButtons(javax.microedition.lcdui.Displayable screen,
                             javax.microedition.lcdui.Command[] commands)
Attaches buttons to a given screen.

Parameters:
screen - The screen to attach the buttons to
commands - An array of buttons to attach to the screen
Returns:
Displayable - the given windows with the buttons attached

setPumpProperties

protected void setPumpProperties()

start

protected void start()
This is the first thing run when the midlet is started. It will attempt to get the name of a previous queue manger from the system and if it fails, the user will be prompted to enter one.

When the user hits the OK button, commandAction() is notified and will continue the initialization.

If a previous queue manager did exist, the name is retrieved from the record store and initialization is started.

Returns:
void

initializeMainScreen

protected void initializeMainScreen()
Initializes the main screen - this involves creating a new form and adding the 2 components:
message - a text field so the user can enter a message to send.
statusbar - to give status information to the user.

Buttons are also attached to the form.

Returns:
void

initialize

protected void initialize(java.lang.String localQMname)
Initializes the view. This is only called once a name for the QM has been established.

Parameters:
localQMname - The name of the queue manager
Returns:
void

deleteQueueManager

public void deleteQueueManager()
Completely removes the queue manager from the system. This involves indiscriminately purging all record stores that the MIDlet / MIDlet suite has access to.

This will of course mean that if you have both the textapp and the message pump in the same MIDlet suite, wiping one queue manager will also remove the other.

Returns:
void

stop

public void stop()
          throws java.lang.Exception
Stops the controller and all constituent parts - in this case, the model.

Returns:
void
java.lang.Exception

pauseApp

public void pauseApp()
There's nothing to pause.

See javax.microedition.midlet.MIDlet#pauseApp for more details.

Specified by:
pauseApp in class javax.microedition.midlet.MIDlet

destroyApp

public void destroyApp(boolean arg0)
                throws javax.microedition.midlet.MIDletStateChangeException
See javax.microedition.midlet.MIDlet#destroyApp for more details.

Specified by:
destroyApp in class javax.microedition.midlet.MIDlet
javax.microedition.midlet.MIDletStateChangeException

promptFor

public void promptFor(java.lang.String title,
                      java.lang.String stringDefault)
Due to the way MIDP works, the user will hit the ok button on the screen at which point commandAction will be called and initialization will continue.

Parameters:
title - The title of the prompt
stringDefault - The default string to display
Returns:
void

changeDisplay

protected void changeDisplay(javax.microedition.lcdui.Screen newDisplay)
Changes the display to the given screen.

Parameters:
newDisplay - The screen to display
Returns:
void

commandAction

public void commandAction(javax.microedition.lcdui.Command c,
                          javax.microedition.lcdui.Displayable d)
See CommandListener#commandAction method for more details.

Specified by:
commandAction in interface javax.microedition.lcdui.CommandListener

addNewQM

protected void addNewQM(java.lang.String name)
adds a new recordstore to the device containing the name of the queue manager this can be used of the app is restarted to keep the same qm name.

Parameters:
name - The name of the queue manager
Returns:
void

showStatus

protected void showStatus()
Displays a status report to the user.

Returns:
void

clearMessage

protected void clearMessage()
Clears the messagebox that is used by the user to enter messages.

Returns:
void

getQMname

public java.lang.String getQMname()
This will search the record store for signs of a previous queue manager. If one existed, it will return the name of it, otherwise it will return null.

Specified by:
getQMname in interface AppController
Returns:
String - the name of the queue manager
See Also:
AppController.getQMname()

displayStatus

public void displayStatus(java.lang.String msg)
If the controller is initializing, use the initialScreen to display the message, otherwise use the statusbar. Either way, throw it to stdout too to make debugging easier.

Specified by:
displayStatus in interface AppController
Parameters:
msg - The message to be displayed
Returns:
void
See Also:
AppController.displayStatus(java.lang.String)

Websphere MQ Everyplace