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
 

"mBedded Server 4.0"
Vol. 5, Issue 11, p. 114

	


Listing 1

import java.awt.event.*;
import java.awt.*;

public class SimpleDisplayImpl extends Frame implements SimpleTextDisplayer {
	Label theTextToDisplay = new Label("",Label.CENTER);
	public SimpleDisplayImpl() {

		super("SimpleDisplayImpl");	
		initializeUI();
		setVisible(false);
	}

	public void displaySimpleText(String theNewText) {
		theTextToDisplay.setText(theNewText);
		setVisible(true);
	}

	private void initializeUI(){

		setTitle("SimpleDisplayImpl");
		setBounds(20,20,300,300);
		add(theTextToDisplay);

		addWindowListener(new WindowAdapter(){
		public void windowClosing(java.awt.event.WindowEvent e) {
			SimpleDisplayImpl.this.dispose();
			return;
			}
		});
	}	
}

Listing 2

import org.osgi.framework.*;

import java.util.*;

//	Class SimpleDisplayActivator
//		activates the SimpleDisplay Service bundle

public class SimpleDisplayActivator implements BundleActivator {

	public void start(BundleContext bc) throws BundleException {
		try {  

			SimpleDisplayImpl tImpl = new SimpleDisplayImpl(); 
			Hashtable dict = new Hashtable();

			dict.put("Description", "SimpleTextDisplayer service");
			ServiceRegistration servReg
= bc.registerService("SimpleTextDisplayer", tImpl, dict);

		} catch (Exception e) {

			System.out.println("Exception.."+e);
			throw new BundleException("Failure in start method, " + e.getMessage(), e);

		}
	} 

	public void stop(BundleContext bc) throws BundleException {

	}

}


import com.prosyst.mbs.client.pmp.*;

public class SimpleSend {

static String SIMPLEDISPLAY = "SimpleTextDisplayer";

	// This demonstrates how to
	//	call a method of some service in the framework through PMP.

	public static void main(String [] args) {

		try {      

			// Init connection object.

			Connection con = new Connection();
			con.connect("127.0.0.1", 
1449, "admin", "admin", (byte) 0);

			// Get remote reference to service.

			RemoteObject rObject = con.getReference(SIMPLEDISPLAY, "");                        

			String [] str = new String[1];
			str[0] = new String("java.lang.String");      

			// Get method of service.

			RemoteMethod rMethod = rObject.getMethod("displaySimpleText", str);             
			Object [] objArr = new Object[1];      
			objArr[0] = new String("This String came from SimpleSend");

			// Call method.

			rMethod.invoke(objArr, false);                        
			System.exit(1);

		} catch (Exception e) {

			e.printStackTrace();

		}  
	}
}

  
 
 

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.