HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"Pervasive Computing:
The Next Generation of Consumer Applications"
Vol. 7, Issue 4, p. 70


Listing 1

 * Returns the text of the document specified in documentName.
public String getDocument(String documentName)
  System.out.println("getDocument(" + documentName +")");
  StringBuffer documentText = new StringBuffer();
      // We prepend /tmp to prevent creative people
      // from hosing our system...
      BufferedReader inStream = 
        new BufferedReader(new FileReader("/tmp/JDJTemp/" + 								documentName));        
      String tmp = inStream.readLine();
      while (tmp != null)
          tmp = inStream.readLine();
  catch (IOException e) 
      documentText.append("<Error reading document>"); 
  return documentText.toString();

Listing 2

<?xml version="1.0"?>
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
  <isd:provider 										type="org.apache.soap.providers.StatelessEJBProvider"
                methods="getDocument saveDocument">
    <isd:option key="JNDIName" 
    <isd:option key="FullHomeInterfaceName" 
                value="com.pilone.texteditor.TextEditorServiceHome" />
    <isd:option key="ContextProviderURL" 
                value="nova.slac.com:1099" />
    <isd:option key="FullContextFactoryName" 
                value="org.jnp.interfaces.NamingContextFactory" />

Listing 3

import org.ksoap.*;
import org.ksoap.transport.*;

public class TextEditorServiceProxy
  public String getDocument(String documentName)
    String document = null;
    try {
      SoapObject rpc = new SoapObject("urn:TextEditorService", "getDocument");
      rpc.addProperty ("documentName", documentName);
      HttpTransport transport = new HttpTransport("http://www.sys-con.com/soap/servlet/rpcrouter", "");
      document = transport.call(rpc).toString();
    catch (Exception e) { e.printStackTrace(); document = e.toString(); }
    return document;

  public void saveDocument(String documentName, String documentText)
    try {
      SoapObject rpc = new SoapObject("urn:TextEditorService", "saveDocument");
      rpc.addProperty("documentName", documentName);
      rpc.addProperty("documentText", documentText);
      HttpTransport transport = new HttpTransport("http://www.sys-con.com/soap/servlet/rpcrouter", "");
    catch (Exception e) { e.printStackTrace(); }

Listing 4

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;

// SOAP imports...
import org.ksoap.*;
import org.ksoap.transport.*;

public class TextEditorClient extends MIDlet 
  implements CommandListener 
    public TextEditorClient () 
	// Create the main form
	// Create the document viewing form
	// We'll handle button presses for both
	mainForm.setCommandListener (this);
    public void startApp () 
	Display.getDisplay (this).setCurrent (mainForm);

    public void pauseApp () 

    public void destroyApp (boolean unconditional) 
        // We could persist our current document 
        // to a record store here if needed

    public void commandAction (Command c, Displayable d) {
	// Find out which command was activated
	if (c == m_GetCommand)
	    // Retrieve the document name, then retrieve the 
        // document from our proxy.
	    String documentName = m_DocumentName.getString (); 
	    m_DocumentText.setString 									(m_TEProxy.getDocument(documentName));
	else if (c == m_SaveCommand)
        // Ask our proxy to save the object, 
        // then return to the main form
	else if (c == m_CancelCommand)
	    // Simply redisplay the main form.  We can ignore 
        // changes that were made to the document since 
        // the only way to return to this screen is to
        // try to load a document that will refresh the
        // contents of our document variable
    private Form mainForm = new Form("Text Editor");
    private TextField m_DocumentName = 
      new TextField("Document Name:", "foo", 100, TextField.ANY);
    private TextBox m_DocumentText = 
      new TextBox("", "", 1000, TextField.ANY);
    private Command m_GetCommand = 
      new Command("Load", Command.SCREEN, 1);
    private Command m_SaveCommand = 
      new Command("Save", Command.SCREEN, 1);
    private Command m_CancelCommand = 
      new Command("Cancel", Command.SCREEN, 1); 
    private TextEditorServiceProxy m_TEProxy = 
      new TextEditorServiceProxy();


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.