001: // AdminServerEditor.java
002: // $Id: AdminServerEditor.java,v 1.11 2000/08/16 21:37:30 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadmin.editors;
007:
008: import java.awt.GridLayout;
009: import java.awt.Font;
010: import java.awt.Component;
011:
012: import javax.swing.JPanel;
013: import javax.swing.JLabel;
014: import javax.swing.BorderFactory;
015: import javax.swing.border.TitledBorder;
016:
017: import java.util.Properties;
018: import java.util.Vector;
019:
020: import org.w3c.jigadmin.RemoteResourceWrapper;
021: import org.w3c.jigadmin.gui.Message;
022: import org.w3c.jigadmin.events.ResourceActionListener;
023: import org.w3c.jigadmin.events.ResourceActionEvent;
024:
025: import org.w3c.jigsaw.admin.RemoteAccessException;
026: import org.w3c.jigsaw.admin.RemoteResource;
027:
028: import org.w3c.tools.widgets.Utilities;
029:
030: /**
031: * The admin server editor
032: * @version $Revision: 1.11 $
033: * @author Benoît Mahé (bmahe@w3.org)
034: */
035: public class AdminServerEditor extends ServerEditor implements
036: ServerEditorInterface, ResourceActionListener {
037:
038: protected final static String CONTROL_NAME = "control";
039: protected final static String REALMS_NAME = "realms";
040:
041: private RemoteResource[] controls = null;
042:
043: /**
044: * initialize the server helpers. There is only one helper for the
045: * Admin server, the ControlServerHelper
046: * @exception RemoteAccessException if a remote error occurs
047: */
048: protected void initializeServerHelpers()
049: throws RemoteAccessException {
050: shelpers = new ServerHelperInterface[2]; //control + realms
051: //control
052: RemoteResourceWrapper rrw = server
053: .getChildResource(CONTROL_NAME);
054: shelpers[0] = ServerHelperFactory.getServerHelper(CONTROL_NAME,
055: rrw);
056: ControlServerHelper control = (ControlServerHelper) shelpers[0];
057: control.setResOpEnabled(false);
058: control.setSaveToolTipText("Save all servers configuration");
059: control.setStopToolTipText("Stop all servers");
060: control.addResourceActionListener(this );
061: //realms
062: rrw = server.getChildResource(REALMS_NAME);
063: shelpers[1] = ServerHelperFactory.getServerHelper(REALMS_NAME,
064: rrw);
065: }
066:
067: /**
068: * Get the control resource of all administrated servers.
069: * @return a RemoteResource Array
070: * @exception RemoteAccessException if a remote error occurs
071: */
072: protected RemoteResource[] getControls()
073: throws RemoteAccessException {
074: if (controls == null) {
075: RemoteResource admin = server.getResource();
076: String names[] = admin.enumerateResourceIdentifiers();
077: Vector vcontrols = new Vector(2);
078: for (int i = 0; i < names.length; i++) {
079: if ((!names[i].equals("control"))
080: && (!names[i].equals("realms"))) {
081: RemoteResource srr = admin.loadResource(names[i]);
082: //load the control node
083: RemoteResource control = srr
084: .loadResource("control");
085: vcontrols.addElement(control);
086: }
087: }
088: controls = new RemoteResource[vcontrols.size()];
089: vcontrols.copyInto(controls);
090: }
091: return controls;
092: }
093:
094: /**
095: * A resource action occured.
096: * @param e the ResourceActionEvent
097: */
098: public void resourceActionPerformed(ResourceActionEvent e) {
099: switch (e.getResourceActionCommand()) {
100: case ResourceActionEvent.SAVE_EVENT:
101: try {
102: RemoteResource ctrls[] = getControls();
103: for (int i = 0; i < ctrls.length; i++)
104: ctrls[i].loadResource("save");
105: } catch (RemoteAccessException ex) {
106: Message.showErrorMessage(server, ex);
107: }
108: break;
109: case ResourceActionEvent.STOP_EVENT:
110: try {
111: RemoteResource ctrls[] = getControls();
112: for (int i = 0; i < ctrls.length; i++)
113: ctrls[i].loadResource("stop");
114: } catch (RemoteAccessException ex) {
115: Message.showErrorMessage(server, ex);
116: }
117: break;
118: default:
119: //nothing to do
120: }
121: }
122:
123: /**
124: * Initialize this editor.
125: * @param name the editor name
126: * @param rrw the RemoteResourceWrapper wrapping the editor node.
127: * @param p the editor properties
128: */
129: public void initialize(String name, RemoteResourceWrapper rrw,
130: Properties p) {
131: super .initialize(name, rrw, p);
132: //must be built at init time
133: setServer(rrw);
134: }
135:
136: /**
137: * Constructor.
138: */
139: public AdminServerEditor() {
140: //for newInstance
141: }
142:
143: }
|