| |
"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();
}
}
}
|
|