Next: Beispiel für ein JMAPI
Up: C Manipulation von Managed
Previous: C.4 Datei NomadicSystemContentManagerApplet.java
/*
* Autor: Christian Schiller
* Datum: 15. August 1998
*/
package schiller.jmapi;
import java.awt.*;
import sunw.admin.avm.base.*;
import sunw.admin.arm.manager.*;
import sunw.admin.arm.common.*;
import sunw.admin.arm.rmi.*;
import schiller.jmapi.*;
/**
* The property book for NomadicSystemMO's
*/
public class NomadicSystemPropertyBook extends PropertyBook {
static final String moServerHost =
"sunhegering2.nm.informatik.uni-muenchen.de";
static final int moServerPort = 7401;
static final String className = "schiller.jmapi.NomadicSystemMO";
NomadicSystemSection nss;
SecurityContext sc = null;
Session session = null;
public NomadicSystemPropertyBook() {
addSection("Attributes", nss =
new NomadicSystemSection(this, getLabelFont()));
startSession();
nss.setSession(session);
try{
session.beginUpdate();
nss.setManagedObject(
(NomadicSystemMO) MOFactory.newObj(session, className));
session.commitUpdate();
} catch (Exception e) {
e.printStackTrace();
}
clearValues();
}
public NomadicSystemPropertyBook(NomadicSystemMO mo) {
addSection("Attributes", nss =
new NomadicSystemSection(this, getLabelFont()));
nss.setManagedObject(mo);
startSession();
nss.setSession(session);
setValuesFromDB();
}
public void clearValues() {
nss.setEthernetAddress("");
nss.setDomainName("");
}
public void setValuesFromDB() {
try{
nss.setEthernetAddress(nss.mo.getEthernetAddress(session));
nss.setDomainName(nss.mo.getDomainName(session));
System.err.println("values set.");
} catch (Exception e) {
e.printStackTrace();
}
}
public void startSession() {
if (session == null) {
try {
System.err.println("Initializing MOFactory ...");
MOFactory.initialize(moServerHost, moServerPort);
System.err.println("o.k.");
sc = new SecurityContext("nobody", null);
session = MOFactory.newSession(sc);
System.err.println("New session started.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
class NomadicSystemSection extends PropertySection {
TextField ethernetAddress;
TextField domainName;
// reference to the MO this property book applies to
NomadicSystemMO mo = null;
Session session = null;
public NomadicSystemSection(PropertyBook book, Font labelFont) {
Label label;
setLayout(new FieldLayout());
// Ethernet Address
label = new Label("Ethernet Address:");
label.setFont(labelFont);
add("Label", label);
add("Field", ethernetAddress = new TextField("", 20));
// Domain Name
label = new Label("Domain Name:");
label.setFont(labelFont);
add("Label", label);
add("Field", domainName = new TextField("", 20));
}
public String getEthernetAddress() {
return ethernetAddress.getText();
}
public String getDomainName() {
return domainName.getText();
}
public void setEthernetAddress(String ea) {
ethernetAddress.setText(ea);
}
public void setDomainName(String dn) {
domainName.setText(dn);
}
public void apply() {
if (mo == null) {
return;
}
String ea = getEthernetAddress();
String dn = getDomainName();
if (ea.equals("") || dn.equals("") || ea == null || dn == null) {
System.err.println(
"Apply failed: Empty string or null reference.");
return;
}
try {
System.err.println("Starting update ...");
session.beginUpdate();
mo.setDomainName(session, dn);
mo.setEthernetAddress(session, ea);
session.commitUpdate();
System.err.println("Update successful.");
} catch (Exception e) {
System.err.println("Error while updating database.");
e.printStackTrace();
}
}
public void reset() {
setEthernetAddress("");
setDomainName("");
}
void setManagedObject(NomadicSystemMO theMO) {
mo = theMO;
}
void setSession(Session theSession) {
session = theSession;
}
}
Copyright Munich Network Management Team