diff options
author | Bernard Normier <bernard@zeroc.com> | 2005-08-02 20:51:54 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2005-08-02 20:51:54 +0000 |
commit | a2282c6f2cd77126cadd614d9259e60456d2e358 (patch) | |
tree | 47f39027f224a19f143b0381b7254792d017d803 /java/src | |
parent | More java metadata (diff) | |
download | ice-a2282c6f2cd77126cadd614d9259e60456d2e358.tar.bz2 ice-a2282c6f2cd77126cadd614d9259e60456d2e358.tar.xz ice-a2282c6f2cd77126cadd614d9259e60456d2e358.zip |
More fixes
Diffstat (limited to 'java/src')
-rwxr-xr-x | java/src/IceGrid/MainPane.java | 34 | ||||
-rwxr-xr-x | java/src/IceGrid/Model.java | 17 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Adapter.java | 37 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Adapters.java | 50 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Application.java | 18 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/DbEnv.java | 7 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/DbEnvs.java | 34 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Node.java | 4 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Parent.java | 9 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Server.java | 21 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/ServerInstance.java | 606 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/ServerTemplate.java | 11 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Service.java | 65 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/ServiceInstance.java | 102 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/ServiceInstances.java | 147 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/ServiceTemplate.java | 6 | ||||
-rwxr-xr-x | java/src/IceGrid/TreeNode/Services.java | 94 | ||||
-rwxr-xr-x | java/src/IceGrid/Utils.java | 158 |
18 files changed, 338 insertions, 1082 deletions
diff --git a/java/src/IceGrid/MainPane.java b/java/src/IceGrid/MainPane.java index 1953b5bb55d..781a2d24db6 100755 --- a/java/src/IceGrid/MainPane.java +++ b/java/src/IceGrid/MainPane.java @@ -43,7 +43,7 @@ import javax.swing.border.AbstractBorder; import IceGrid.TreeNode.CommonBase; -public class MainPane extends JSplitPane implements Model.TreeNodeSelector +public class MainPane extends JSplitPane { static class PopupListener extends MouseAdapter { @@ -112,31 +112,34 @@ public class MainPane extends JSplitPane implements Model.TreeNodeSelector { super(JSplitPane.HORIZONTAL_SPLIT, true); _model = model; - _model.setTreeNodeSelector(this); setBorder(new EmptyBorder(10, 10, 10, 10)); TreeCellRenderer renderer = new CellRenderer(); PopupListener popupListener = new PopupListener(); - _tree = new JTree(_model.getTreeModel()); - _tree.setCellRenderer(renderer); - ToolTipManager.sharedInstance().registerComponent(_tree); - _tree.addMouseListener(popupListener); + JTree tree = new JTree(_model.getTreeModel()); + tree.setBorder(new EmptyBorder(5, 5, 5, 5)); + tree.setCellRenderer(renderer); + ToolTipManager.sharedInstance().registerComponent(tree); + tree.addMouseListener(popupListener); - _tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + tree.getSelectionModel().setSelectionMode + (TreeSelectionModel.SINGLE_TREE_SELECTION); SelectionListener appSelectionListener = new SelectionListener(); - _tree.addTreeSelectionListener(appSelectionListener); - _tree.setRootVisible(true); + tree.addTreeSelectionListener(appSelectionListener); + tree.setRootVisible(false); + _model.setTree(tree); JScrollPane appScroll = - new JScrollPane(_tree, + new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); appScroll.setBorder(Borders.DIALOG_BORDER); - JPanel leftPane = new JPanel(new BorderLayout()); - leftPane.add(_tree); + SimpleInternalFrame leftPane = new SimpleInternalFrame("Applications"); + leftPane.setContent(tree); + leftPane.setPreferredSize(new Dimension(280, 350)); // // Right pane @@ -151,11 +154,6 @@ public class MainPane extends JSplitPane implements Model.TreeNodeSelector setRightComponent(_rightPane); } - public void selectNode(TreePath path) - { - _tree.setSelectionPath(path); - } - // // Adapted from JGoodies SimpleInternalFrame // @@ -208,8 +206,6 @@ public class MainPane extends JSplitPane implements Model.TreeNodeSelector } private Model _model; - - private JTree _tree; private SimpleInternalFrame _rightPane; static private JPanel _emptyPanel; diff --git a/java/src/IceGrid/Model.java b/java/src/IceGrid/Model.java index bbecb12971a..aee5cc6fffd 100755 --- a/java/src/IceGrid/Model.java +++ b/java/src/IceGrid/Model.java @@ -14,6 +14,7 @@ import java.awt.Component; import java.awt.Cursor;
import javax.swing.tree.TreeModel;
import javax.swing.JOptionPane;
+import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.TreePath;
@@ -83,12 +84,6 @@ public class Model // |
// -- adapters, databases (see above)
-
- public static interface TreeNodeSelector
- {
- void selectNode(TreePath path);
- }
-
public static class ConnectInfo
{
ConnectInfo(Preferences connectionPrefs,
@@ -348,14 +343,14 @@ public class Model return _statusBar;
}
- public void setTreeNodeSelector(TreeNodeSelector selector)
+ public void setTree(JTree tree)
{
- _treeNodeSelector = selector;
+ _tree = tree;
}
- public TreeNodeSelector getTreeNodeSelector()
+ public JTree getTree()
{
- return _treeNodeSelector;
+ return _tree;
}
public void setPropertiesFrame(SimpleInternalFrame frame)
@@ -388,7 +383,7 @@ public class Model private int _latestSerial = -1;
- private TreeNodeSelector _treeNodeSelector;
+ private JTree _tree;
private boolean _substituteVariables = false;
diff --git a/java/src/IceGrid/TreeNode/Adapter.java b/java/src/IceGrid/TreeNode/Adapter.java index 93517163092..25357b0b1ed 100755 --- a/java/src/IceGrid/TreeNode/Adapter.java +++ b/java/src/IceGrid/TreeNode/Adapter.java @@ -81,18 +81,15 @@ class Adapter extends Leaf _adapter = adapter;
AdapterDescriptor descriptor = adapter.getDescriptor();
- final java.util.Map[] variables =
- _adapter.getModel().substituteVariables() ?
- adapter.getVariables() : null;
-
- boolean editable = adapter.isEditable() && (variables == null);
+ boolean editable = adapter.isEditable();
+ final Utils.Resolver resolver = adapter.getResolver();
_name.setText(
- Utils.substituteVariables(descriptor.name, variables));
+ Utils.substitute(descriptor.name, resolver));
_name.setEditable(editable);
_id.setText(
- Utils.substituteVariables(descriptor.id, variables));
+ Utils.substitute(descriptor.id, resolver));
_id.setEditable(editable);
Ice.StringHolder toolTipHolder = new Ice.StringHolder();
@@ -103,12 +100,12 @@ class Adapter extends Leaf {
ObjectDescriptor od = (ObjectDescriptor)obj;
Ice.Identity sid = new Ice.Identity(
- Utils.substituteVariables(od.id.name, variables),
- Utils.substituteVariables(od.id.category, variables));
+ Utils.substitute(od.id.name, resolver),
+ Utils.substitute(od.id.category, resolver));
return Ice.Util.identityToString(sid)
+ " as '"
- + Utils.substituteVariables(od.type, variables)
+ + Utils.substitute(od.type, resolver)
+ "'";
}
};
@@ -181,19 +178,15 @@ class Adapter extends Leaf Adapter(String adapterName, AdapterDescriptor descriptor,
- boolean editable, java.util.Map[] variables,
+ boolean editable, Utils.Resolver resolver,
Model model)
{
super(adapterName, model);
_descriptor = descriptor;
_editable = editable;
- _variables = variables;
+ _resolver = resolver;
}
- void unregister()
- {
-
- }
void updateProxy(Ice.ObjectPrx proxy)
{
@@ -207,14 +200,14 @@ class Adapter extends Leaf return _descriptor;
}
- boolean isEditable()
+ Utils.Resolver getResolver()
{
- return _editable;
+ return _resolver;
}
-
- java.util.Map[] getVariables()
+
+ boolean isEditable()
{
- return _variables;
+ return _editable;
}
private void createToolTip()
@@ -231,7 +224,7 @@ class Adapter extends Leaf private AdapterDescriptor _descriptor;
private boolean _editable;
- private java.util.Map[] _variables;
+ private Utils.Resolver _resolver;
private String _adapterId;
private Ice.ObjectPrx _proxy;
diff --git a/java/src/IceGrid/TreeNode/Adapters.java b/java/src/IceGrid/TreeNode/Adapters.java index be467bc29a7..a7482fac2c4 100755 --- a/java/src/IceGrid/TreeNode/Adapters.java +++ b/java/src/IceGrid/TreeNode/Adapters.java @@ -14,56 +14,20 @@ import IceGrid.Utils; class Adapters extends Parent
{
- //
- // In server or service template
- //
- Adapters(java.util.List descriptors, Model model)
- {
- this(descriptors, true, null, model);
- }
-
- //
- // In server or service instance
- //
Adapters(java.util.List descriptors, boolean editable,
- java.util.Map[] variables,
- Model model)
+ Utils.Resolver resolver, Model model)
{
super("Adapters", model);
- _descriptors = descriptors;
- _editable = editable;
- _variables = variables;
-
- java.util.Iterator p = _descriptors.iterator();
+ java.util.Iterator p = descriptors.iterator();
while(p.hasNext())
{
AdapterDescriptor descriptor = (AdapterDescriptor)p.next();
- String adapterName = descriptor.name;
- if(_variables != null)
- {
- adapterName = Utils.substituteVariables(adapterName,
- _variables);
- }
-
- Adapter child = new Adapter(adapterName, descriptor,
- _editable, _variables,
- _model);
- addChild(child);
- }
- }
-
- void unregisterAll()
- {
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- Adapter adapter = (Adapter)p.next();
- adapter.unregister();
+ String adapterName = Utils.substitute(descriptor.name,
+ resolver);
+
+ addChild(new Adapter(adapterName, descriptor, editable,
+ resolver, _model));
}
}
-
- private java.util.List _descriptors;
- private boolean _editable;
- private java.util.Map[] _variables;
}
diff --git a/java/src/IceGrid/TreeNode/Application.java b/java/src/IceGrid/TreeNode/Application.java index acb7ac2b562..740b2b9d10b 100755 --- a/java/src/IceGrid/TreeNode/Application.java +++ b/java/src/IceGrid/TreeNode/Application.java @@ -20,8 +20,7 @@ class Application extends Parent //
// Builds the application and all its subtrees
//
- Application(ApplicationDescriptor descriptor, Model model,
- boolean fireEvent)
+ Application(ApplicationDescriptor descriptor, Model model)
{
super(descriptor.name, model);
_descriptor = descriptor;
@@ -38,7 +37,7 @@ class Application extends Parent this);
addChild(_serverTemplates);
- _nodes = new Nodes(_descriptor.nodes, _model);
+ _nodes = new Nodes(_descriptor.nodes, this);
addChild(_nodes);
}
@@ -132,19 +131,6 @@ class Application extends Parent return _descriptor.variables;
}
- java.util.Map getNodeVariables(String id)
- {
- Node node = findNode(id);
- if(node != null)
- {
- return node.getVariables();
- }
- else
- {
- return null;
- }
- }
-
void nodeUp(String nodeName, java.util.Map serverMap,
java.util.Map adapterMap)
{
diff --git a/java/src/IceGrid/TreeNode/DbEnv.java b/java/src/IceGrid/TreeNode/DbEnv.java index 00eaf631c3a..a73acfb44b5 100755 --- a/java/src/IceGrid/TreeNode/DbEnv.java +++ b/java/src/IceGrid/TreeNode/DbEnv.java @@ -10,20 +10,21 @@ package IceGrid.TreeNode; import IceGrid.DbEnvDescriptor;
import IceGrid.Model;
+import IceGrid.Utils;
class DbEnv extends Leaf
{
DbEnv(String dbEnvName, DbEnvDescriptor descriptor,
- boolean editable, java.util.Map[] variables,
+ boolean editable, Utils.Resolver resolver,
Model model)
{
super(dbEnvName, model);
_descriptor = descriptor;
_editable = editable;
- _variables = variables;
+ _resolver = resolver;
}
private DbEnvDescriptor _descriptor;
private boolean _editable;
- private java.util.Map[] _variables;
+ private Utils.Resolver _resolver;
}
diff --git a/java/src/IceGrid/TreeNode/DbEnvs.java b/java/src/IceGrid/TreeNode/DbEnvs.java index 320ee9a9c5d..aa44785fe08 100755 --- a/java/src/IceGrid/TreeNode/DbEnvs.java +++ b/java/src/IceGrid/TreeNode/DbEnvs.java @@ -14,44 +14,20 @@ import IceGrid.Utils; class DbEnvs extends Parent
{
- //
- // In server or service template
- //
- DbEnvs(java.util.List descriptors, Model model)
- {
- this(descriptors, true, null, model);
- }
-
- //
- // In server or service instance
- //
DbEnvs(java.util.List descriptors,
boolean editable,
- java.util.Map[] variables,
+ Utils.Resolver resolver,
Model model)
{
super("DbEnvs", model);
- _descriptors = descriptors;
- _editable = editable;
- _variables = variables;
-
- java.util.Iterator p = _descriptors.iterator();
+ java.util.Iterator p = descriptors.iterator();
while(p.hasNext())
{
DbEnvDescriptor descriptor = (DbEnvDescriptor)p.next();
- String dbEnvName = descriptor.name;
- if(_variables != null)
- {
- dbEnvName = Utils.substituteVariables(dbEnvName, _variables);
- }
- addChild(new DbEnv(dbEnvName, descriptor, _editable, _variables,
- _model));
+ String dbEnvName = Utils.substitute(descriptor.name, resolver);
+ addChild(new DbEnv(dbEnvName, descriptor, editable,
+ resolver, _model));
}
}
-
- private java.util.List _descriptors;
- private boolean _editable;
- private java.util.Map[] _variables;
-
}
diff --git a/java/src/IceGrid/TreeNode/Node.java b/java/src/IceGrid/TreeNode/Node.java index 5d84ec255d5..dbb6f91561a 100755 --- a/java/src/IceGrid/TreeNode/Node.java +++ b/java/src/IceGrid/TreeNode/Node.java @@ -101,7 +101,7 @@ class Node extends Parent java.util.Iterator p = _children.iterator();
while(p.hasNext())
{
- ServerInstance child = (ServerInstance)p.next();
+ Server child = (Server)p.next();
ServerDynamicInfo info =
(ServerDynamicInfo)_serverInfoMap.get(child.getId());
@@ -141,7 +141,7 @@ class Node extends Parent java.util.Iterator p = _children.iterator();
while(p.hasNext())
{
- ServerInstance child = (ServerInstance)p.next();
+ Server child = (Server)p.next();
child.updateDynamicInfo(_unknownServerDynamicInfo);
}
diff --git a/java/src/IceGrid/TreeNode/Parent.java b/java/src/IceGrid/TreeNode/Parent.java index c5a8cdf40dc..09f8458dfbb 100755 --- a/java/src/IceGrid/TreeNode/Parent.java +++ b/java/src/IceGrid/TreeNode/Parent.java @@ -200,6 +200,15 @@ class Parent extends CommonBaseI _children.clear();
}
+ void expandChildren()
+ {
+ java.util.Iterator p = _children.iterator();
+ while(p.hasNext())
+ {
+ CommonBase child = (CommonBase)p.next();
+ _model.getTree().expandPath(child.getPath());
+ }
+ }
//
// The following methods fire events
diff --git a/java/src/IceGrid/TreeNode/Server.java b/java/src/IceGrid/TreeNode/Server.java index e1f388672ae..8f27db0090f 100755 --- a/java/src/IceGrid/TreeNode/Server.java +++ b/java/src/IceGrid/TreeNode/Server.java @@ -216,8 +216,8 @@ class Server extends Parent _template.getSelectedItem();
if(template != null && _server != null)
{
- _server.getModel().getTreeNodeSelector().
- selectNode(template.getPath());
+ _server.getModel().getTree().setSelectionPath
+ (template.getPath());
}
}
};
@@ -420,21 +420,26 @@ class Server extends Parent editable, _resolver, application);
addChild(_services);
_services.setParent(this);
+
+ //
+ // IceBox has not dbEnv
+ //
+ assert serverDescriptor.dbEnvs.size() == 0;
+ _dbEnvs = null;
}
else
{
- _services = null;
+ _services = null;
+ _dbEnvs = new DbEnvs(serverDescriptor.dbEnvs,
+ editable, _resolver, _model);
+ addChild(_dbEnvs);
+ _dbEnvs.setParent(this);
}
_adapters = new Adapters(serverDescriptor.adapters,
editable, _resolver, _model);
addChild(_adapters);
_adapters.setParent(this);
-
- _dbEnvs = new DbEnvs(serverDescriptor.dbEnvs,
- editable, _resolver, _model);
- addChild(_dbEnvs);
- _dbEnvs.setParent(this);
}
void updateDynamicInfo(ServerDynamicInfo info)
diff --git a/java/src/IceGrid/TreeNode/ServerInstance.java b/java/src/IceGrid/TreeNode/ServerInstance.java deleted file mode 100755 index 9396c33bb05..00000000000 --- a/java/src/IceGrid/TreeNode/ServerInstance.java +++ /dev/null @@ -1,606 +0,0 @@ -// **********************************************************************
-//
-// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-
-import javax.swing.AbstractAction;
-import javax.swing.Action;
-import javax.swing.DefaultComboBoxModel;
-import javax.swing.Icon;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import javax.swing.JLabel;
-import javax.swing.JMenuItem;
-import javax.swing.JPanel;
-import javax.swing.JPopupMenu;
-import javax.swing.JRadioButton;
-import javax.swing.JScrollPane;
-import javax.swing.JTextField;
-import javax.swing.JToggleButton;
-import javax.swing.JTree;
-import javax.swing.UIManager;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.factories.Borders;
-import com.jgoodies.forms.layout.FormLayout;
-import com.jgoodies.forms.layout.Sizes;
-import com.jgoodies.forms.util.LayoutStyle;
-import com.jgoodies.uif_lite.panel.SimpleInternalFrame;
-
-import IceGrid.IceBoxDescriptor;
-import IceGrid.Model;
-import IceGrid.TemplateDescriptor;
-import IceGrid.TreeModelI;
-import IceGrid.ServerDescriptor;
-import IceGrid.ServerDynamicInfo;
-import IceGrid.ServerInstanceDescriptor;
-import IceGrid.ServerState;
-import IceGrid.Utils;
-
-class ServerInstance extends Parent
-{
-
- static class Editor
- {
- JComponent getComponent()
- {
- if(_scrollPane == null)
- {
- //
- // Build everything using JGoodies's DefaultFormBuilder
- //
- FormLayout layout = new FormLayout(
- "right:pref, 3dlu, fill:pref:grow, 3dlu, pref", "");
- DefaultFormBuilder builder = new DefaultFormBuilder(layout);
- builder.setBorder(Borders.DLU2_BORDER);
- builder.setRowGroupingEnabled(true);
-
-
- builder.setLineGapSize(LayoutStyle.getCurrent().getLinePad());
-
- //
- // Type combox box
- //
- builder.append("Type");
- builder.append(_type, 3);
- builder.nextLine();
-
- //
- // Template combox box
- //
- builder.append(_templateLabel, _template, _templateButton);
- builder.nextLine();
-
- //
- // Parameters
- //
- builder.append(_parameterValuesLabel, _parameterValues, _parameterValuesButton);
- builder.nextLine();
-
- builder.setLineGapSize(LayoutStyle.getCurrent().getParagraphPad());
-
- _serverDescriptorEditor.build(builder);
-
- _scrollPane = new JScrollPane(builder.getPanel(),
- JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
- _scrollPane.setBorder(Borders.DIALOG_BORDER);
- }
- return _scrollPane;
- }
-
- void show(ServerInstance server)
- {
- /*
- _server = server;
- ServerInstanceDescriptor descriptor = server.getDescriptor();
-
- ServerDescriptor serverDescriptor = null;
- Ice.StringHolder toolTipHolder = new Ice.StringHolder();
-
- java.util.Map[] variables = null;
-
- if(descriptor.template.length() == 0)
- {
- serverDescriptor = null;
- if(_server.getModel().substituteVariables())
- {
- variables = new java.util.Map[] {
- server.getNodeVariables(),
- server.getApplication().getVariables()};
- }
-
- if(serverDescriptor instanceof IceBoxDescriptor)
- {
- _type.setSelectedIndex(ICEBOX);
- }
- else
- {
- _type.setSelectedIndex(PLAIN_SERVER);
- }
-
- _templateLabel.setEnabled(false);
- _template.setEnabled(false);
- _template.setModel(new DefaultComboBoxModel());
- _template.setSelectedItem(null);
- _templateButton.setEnabled(false);
-
- _parameterValuesLabel.setEnabled(false);
- _parameterValues.setEnabled(false);
- _parameterValues.setText("");
- _parameterValues.setToolTipText(null);
- _parameterValuesButton.setEnabled(false);
- }
- else
- {
- _type.setSelectedIndex(TEMPLATE_INSTANCE);
-
- _templateLabel.setEnabled(true);
- _template.setEnabled(true);
- _templateButton.setEnabled(true);
-
- Application application = _server.getApplication();
-
- TemplateDescriptor templateDescriptor =
- application.findServerTemplateDescriptor(descriptor.template);
-
- _template.setModel(application.getServerTemplates().getComboBoxModel());
- _template.setSelectedItem(templateDescriptor);
- serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor;
-
- _parameterValuesLabel.setEnabled(true);
- _parameterValues.setEnabled(true);
- _parameterValuesButton.setEnabled(true);
-
- String stringifiedParameterValues;
- if(_server.getModel().substituteVariables())
- {
- java.util.Map substitutedParameters = Utils.substituteVariables(
- descriptor.parameterValues, _server.getNodeVariables(),
- application.getVariables());
-
- stringifiedParameterValues = Utils.stringify(substitutedParameters, "=",
- ", ", toolTipHolder);
- _parameterValues.setEditable(false);
-
- variables = new java.util.Map[]{
- substitutedParameters,
- server.getNodeVariables(),
- application.getVariables()};
- }
- else
- {
- stringifiedParameterValues = Utils.stringify(descriptor.parameterValues, "=",
- ", ", toolTipHolder);
- _parameterValues.setEditable(true);
- }
- _parameterValues.setText(stringifiedParameterValues);
- _parameterValues.setToolTipText(toolTipHolder.value);
- }
-
- _targets.setText(Utils.stringify(descriptor.targets, ", ", toolTipHolder));
- _targets.setToolTipText(toolTipHolder.value);
-
- _serverDescriptorEditor.show(serverDescriptor, variables);
- */
- }
-
- Editor(boolean editDetails)
- {
- _serverDescriptorEditor = new ServerDescriptorEditor(editDetails);
- //
- // gotoTemplate action
- //
- AbstractAction gotoTemplate = new AbstractAction("->")
- {
- public void actionPerformed(ActionEvent e)
- {
- ServerTemplate template = (ServerTemplate)
- _template.getSelectedItem();
- if(template != null && _server != null)
- {
- _server.getModel().getTreeNodeSelector().
- selectNode(template.getPath());
- }
- }
- };
- gotoTemplate.putValue(Action.SHORT_DESCRIPTION, "Goto this template");
- _templateButton = new JButton(gotoTemplate);
- _parameterValuesButton = new JButton("...");
- }
-
-
- private final int PLAIN_SERVER = 0;
- private final int ICEBOX = 1;
- private final int TEMPLATE_INSTANCE = 2;
- private String[] _typeList = {"Plain Server", "IceBox Server", "Template Instance"};
- private JComboBox _type = new JComboBox(_typeList);
-
- private JLabel _templateLabel = new JLabel("Template");
- private JComboBox _template = new JComboBox();
- private JButton _templateButton;
- private JLabel _parameterValuesLabel = new JLabel("Parameters");
- private JTextField _parameterValues = new JTextField(20);
- private JButton _parameterValuesButton;
-
- private ServerDescriptorEditor _serverDescriptorEditor;
-
- private ServerInstance _server;
- private JScrollPane _scrollPane;
- }
-
- static class PopupMenu extends JPopupMenu
- {
- PopupMenu()
- {
- _startAction = new AbstractAction("Start")
- {
- public void actionPerformed(ActionEvent e)
- {
- _server.start();
- }
- };
-
- _stopAction = new AbstractAction("Stop")
- {
- public void actionPerformed(ActionEvent e)
- {
- _server.stop();
- }
- };
-
- add(_startAction);
- add(_stopAction);
- }
-
- void setServer(ServerInstance server)
- {
- _server = server;
- ServerState state = _server.getState();
-
- boolean canStart = (_server.getState() == ServerState.Inactive);
- _startAction.setEnabled(canStart);
- _stopAction.setEnabled(!canStart);
- }
-
- private ServerInstance _server;
- private Action _startAction;
- private Action _stopAction;
- }
-
-
- public JPopupMenu getPopupMenu()
- {
- if(_popup == null)
- {
- _popup = new PopupMenu();
- }
- _popup.setServer(this);
- return _popup;
- }
-
- public void displayProperties()
- {
- SimpleInternalFrame propertiesFrame = _model.getPropertiesFrame();
-
- propertiesFrame.setTitle("Properties for " + _id);
-
- //
- // Pick the appropriate editor
- //
- Editor editor = null;
- if(_descriptor.template.length() > 0 || _model.substituteVariables())
- {
- if(_editor == null)
- {
- _editor = new Editor(false);
- }
-
- editor = _editor;
- }
- else
- {
- if(_fullEditor == null)
- {
- _fullEditor = new Editor(true);
- }
- editor = _fullEditor;
- }
-
- editor.show(this);
- propertiesFrame.setContent(editor.getComponent());
- propertiesFrame.validate();
- propertiesFrame.repaint();
- }
-
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus)
- {
- if(_cellRenderer == null)
- {
- //
- // Initialization
- //
- _cellRenderer = new DefaultTreeCellRenderer();
- _icons = new Icon[7];
- _icons[0] = Utils.getIcon("/icons/unknown.png");
- _icons[ServerState.Inactive.value() + 1] = Utils.getIcon("/icons/inactive.png");
- _icons[ServerState.Activating.value() + 1] =
- Utils.getIcon("/icons/activating.png");
- _icons[ServerState.Active.value() + 1] =
- Utils.getIcon("/icons/active.png");
- _icons[ServerState.Deactivating.value() + 1] =
- Utils.getIcon("/icons/deactivating.png");
- _icons[ServerState.Destroying.value() + 1] =
- Utils.getIcon("/icons/destroying.png");
- _icons[ServerState.Destroyed.value() + 1] =
- Utils.getIcon("/icons/destroyed.png");
- }
-
- //
- // TODO: separate icons for open and close
- //
- if(expanded)
- {
- _cellRenderer.setOpenIcon(_icons[_stateIconIndex]);
- }
- else
- {
- _cellRenderer.setClosedIcon(_icons[_stateIconIndex]);
- }
-
- _cellRenderer.setToolTipText(_toolTip);
- return _cellRenderer.getTreeCellRendererComponent(
- tree, value, sel, expanded, leaf, row, hasFocus);
- }
-
-
- //
- // Builds the server instance and all its sub-tree
- //
- ServerInstance(String serverName,
- ServerInstanceDescriptor descriptor,
- Application application,
- boolean fireNodeViewEvent)
- {
- super(serverName, application.getModel());
- rebuild(application, descriptor, fireNodeViewEvent);
- }
-
- //
- // Update the server instance and all its subtree
- //
- void rebuild(Application application,
- ServerInstanceDescriptor newDescriptor,
- boolean fireNodeViewEvent)
- {
- /*
- assert(newDescriptor != null);
- _descriptor = newDescriptor;
- clearChildren();
-
- java.util.Map appVariables = application.getVariables();
- _nodeVariables =
- application.getNodeVariables(_descriptor.node); // can be null
- java.util.Map parameters = null;
- ServerDescriptor serverDescriptor = null;
- boolean editable = false;
-
- if(_descriptor.template.length() > 0)
- {
- TemplateDescriptor templateDescriptor =
- application.findServerTemplateDescriptor(_descriptor.template);
- serverDescriptor = (ServerDescriptor)templateDescriptor.descriptor;
- parameters = Utils.substituteVariables(_descriptor.parameterValues,
- _nodeVariables, appVariables);
- }
- else
- {
- serverDescriptor = _descriptor.descriptor;
- editable = true;
- }
-
- if(serverDescriptor instanceof IceBoxDescriptor)
- {
- IceBoxDescriptor iceBoxDescriptor = (IceBoxDescriptor)serverDescriptor;
-
- //
- // We need to pass the node to register the adapters
- //
- _serviceInstances = new ServiceInstances(iceBoxDescriptor.services,
- editable,
- application,
- _nodeVariables,
- parameters,
- node);
- addChild(_serviceInstances);
- _serviceInstances.addParent(this); // no-op when newNode == true
- }
-
- java.util.Map[] variables = new java.util.Map[3];
- variables[0] = parameters;
- variables[1] = _nodeVariables;
- variables[2] = appVariables;
-
- _adapters = new Adapters(serverDescriptor.adapters,
- editable, variables,
- _model, node);
- addChild(_adapters);
- _adapters.addParent(this); // no-op when newNode == true
-
- _dbEnvs = new DbEnvs(serverDescriptor.dbEnvs,
- editable, variables, _model);
- addChild(_dbEnvs);
- _dbEnvs.addParent(this); // no-op when newNode == true
-
- if(newNode)
- {
- updateDynamicInfo(node.getServerDynamicInfo(_id), false);
- addParent(node); // propagates to children
- node.addChild(this, fireNodeViewEvent);
- }
-
- */
- }
-
- void updateDynamicInfo(ServerDynamicInfo info)
- {
- updateDynamicInfo(info, true);
- }
-
- private void updateDynamicInfo(ServerDynamicInfo info, boolean fireEvent)
- {
- if(info.state != _state || info.pid != _pid)
- {
- _state = info.state;
- _pid = info.pid;
- _toolTip = toolTip(info.state, info.pid);
- _stateIconIndex = (_state == null ? 0 : _state.value() + 1);
-
- if(fireEvent)
- {
- //
- // Change the node representation in all views
- //
- fireNodeChangedEvent(this);
- }
- }
- }
-
- void start()
- {
- //
- // TODO: if this can take a long time, make the invocation in a separate thread
- //
-
- boolean started = false;
- try
- {
- _model.getStatusBar().setText("Starting server '" + _id + "'...");
- started = _model.getAdmin().startServer(_id);
- }
- catch(IceGrid.ServerNotExistException e)
- {
- _model.getStatusBar().setText("Server '" + _id + "' no longer exists.");
- }
- catch(IceGrid.NodeUnreachableException e)
- {
- _model.getStatusBar().setText("Could not reach the node for server '" + _id
- + "'.");
- }
- catch(Ice.LocalException e)
- {
- _model.getStatusBar().setText("Starting server '" + _id + "'... failed: "
- + e.toString());
- }
- if(started)
- {
- _model.getStatusBar().setText("Starting server '" + _id + "'... success!");
- }
- else
- {
- _model.getStatusBar().setText("Starting server '" + _id + "'... failed!");
- }
- }
-
- void stop()
- {
- try
- {
- _model.getStatusBar().setText("Stopping server '" + _id + "'...");
- _model.getAdmin().stopServer(_id);
- }
- catch(IceGrid.ServerNotExistException e)
- {
- _model.getStatusBar().setText("Server '" + _id + "' no longer exists.");
- }
- catch(IceGrid.NodeUnreachableException e)
- {
- _model.getStatusBar().setText("Could not reach the node for server '"
- + _id + "'.");
- }
- catch(Ice.LocalException e)
- {
- _model.getStatusBar().setText("Stopping server '" + _id + "'... failed: "
- + e.toString());
- }
- _model.getStatusBar().setText("Stopping server '" + _id + "'... done.");
- }
-
- ServerState getState()
- {
- return _state;
- }
-
- ServerInstanceDescriptor getDescriptor()
- {
- return _descriptor;
- }
-
- public String toString()
- {
- return "";
- /*
- String result = _descriptor.descriptor.name;
-
- if(!_descriptor.template.equals(""))
- {
-
- result += ": " + templateLabel(_descriptor.template,
- _descriptor.parameterValues.values());
- }
- return result;
- */
- }
-
- private static String toolTip(ServerState state, int pid)
- {
- String result = (state == null ? "Unknown" : state.toString());
-
- if(pid != 0)
- {
- result += ", pid: " + pid;
- }
- return result;
- }
-
- private ServerState _state = null;
- private int _stateIconIndex = 0;
- private int _pid = 0;
- private String _toolTip = toolTip(_state, _pid);
-
- private ServerInstanceDescriptor _descriptor;
-
- //
- // Children
- //
- private ServiceInstances _serviceInstances;
- private Adapters _adapters;
- private DbEnvs _dbEnvs;
-
- static private DefaultTreeCellRenderer _cellRenderer;
- static private Icon[] _icons;
- static private PopupMenu _popup;
-
- static private Editor _fullEditor; // writable server descriptor
- static private Editor _editor; // read-only server descriptor
-
-}
diff --git a/java/src/IceGrid/TreeNode/ServerTemplate.java b/java/src/IceGrid/TreeNode/ServerTemplate.java index f94fd5d31d2..82bc6a7bf05 100755 --- a/java/src/IceGrid/TreeNode/ServerTemplate.java +++ b/java/src/IceGrid/TreeNode/ServerTemplate.java @@ -69,20 +69,23 @@ class ServerTemplate extends Parent _services = new Services(_iceBoxDescriptor.services, true, null, application);
addChild(_services);
+
+ assert _descriptor.descriptor.dbEnvs.size() == 0;
+ _dbEnvs = null;
}
else
{
_services = null;
_iceBoxDescriptor = null;
+
+ _dbEnvs = new DbEnvs(_descriptor.descriptor.dbEnvs, true,
+ null, _model);
+ addChild(_dbEnvs);
}
_adapters = new Adapters(_descriptor.descriptor.adapters, true,
null, _model);
addChild(_adapters);
-
- _dbEnvs = new DbEnvs(_descriptor.descriptor.dbEnvs, true,
- null, _model);
- addChild(_dbEnvs);
}
diff --git a/java/src/IceGrid/TreeNode/Service.java b/java/src/IceGrid/TreeNode/Service.java new file mode 100755 index 00000000000..9ff34a871b6 --- /dev/null +++ b/java/src/IceGrid/TreeNode/Service.java @@ -0,0 +1,65 @@ +// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGrid.TreeNode;
+
+import IceGrid.Model;
+import IceGrid.ServiceDescriptor;
+import IceGrid.ServiceInstanceDescriptor;
+import IceGrid.TemplateDescriptor;
+import IceGrid.Utils;
+
+class Service extends Parent
+{
+ Service(String name,
+ String displayString,
+ ServiceInstanceDescriptor instanceDescriptor,
+ ServiceDescriptor serviceDescriptor,
+ boolean editable,
+ Utils.Resolver resolver,
+ Model model)
+ {
+ super(name, model);
+ _displayString = displayString;
+ _instanceDescriptor = instanceDescriptor;
+ _serviceDescriptor = serviceDescriptor;
+ _editable = editable;
+ _resolver = resolver;
+
+ boolean childrenEditable = _editable && (_instanceDescriptor == null);
+
+ _adapters = new Adapters(serviceDescriptor.adapters,
+ childrenEditable, resolver, _model);
+ addChild(_adapters);
+
+ _dbEnvs = new DbEnvs(serviceDescriptor.dbEnvs,
+ childrenEditable, resolver, _model);
+ addChild(_dbEnvs);
+ }
+
+
+ public String toString()
+ {
+ if(_displayString != null)
+ {
+ return _displayString;
+ }
+ else
+ {
+ return _id;
+ }
+ }
+
+ private ServiceInstanceDescriptor _instanceDescriptor;
+ private ServiceDescriptor _serviceDescriptor;
+ private String _displayString;
+ private boolean _editable;
+ private Utils.Resolver _resolver;
+ private Adapters _adapters;
+ private DbEnvs _dbEnvs;
+}
diff --git a/java/src/IceGrid/TreeNode/ServiceInstance.java b/java/src/IceGrid/TreeNode/ServiceInstance.java deleted file mode 100755 index 06723f18d39..00000000000 --- a/java/src/IceGrid/TreeNode/ServiceInstance.java +++ /dev/null @@ -1,102 +0,0 @@ -// **********************************************************************
-//
-// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import IceGrid.Model;
-import IceGrid.ServiceDescriptor;
-import IceGrid.ServiceInstanceDescriptor;
-import IceGrid.TemplateDescriptor;
-
-
-class ServiceInstance extends Parent
-{
- ServiceInstance(String id,
- String displayString,
- ServiceInstanceDescriptor descriptor,
- ServiceDescriptor serviceDescriptor,
- boolean editable, // False when the enclosing server instance
- // is a template-instance
- java.util.Map serverParameters, // When the enclosing server instance
- // is a template instance,
- // this server's parameters (substituted);
- // null otherwise
- java.util.Map myParameters, // When this is a template instance within
- // a server instance, descriptor.parameterValues
- // substituted using parameters + variables
- java.util.Map nodeVariables,
- java.util.Map appVariables,
- Model model,
- Node node)
- {
- super(id, model);
- _displayString = displayString;
- _descriptor = descriptor;
- _editable = editable;
-
- if(serviceDescriptor != null)
- {
- boolean childrenEditable = _editable && (descriptor.template.length() == 0);
-
- //
- // For the children, the proper parameters can be used as variables.
- // Note that the fields of the service-instance itself should be
- // substituted with parameters (if any) + variables.
- //
- java.util.Map[] variables = null;
- if(node != null)
- {
- variables = new java.util.Map[3];
- if(myParameters != null)
- {
- variables[0] = myParameters;
- assert(descriptor.template.length() > 0);
- }
- else
- {
- variables[0] = serverParameters;
- assert(descriptor.template.length() == 0);
- }
- variables[1] = nodeVariables;
- variables[2] = appVariables;
- }
-
- _adapters = new Adapters(serviceDescriptor.adapters,
- childrenEditable,
- variables, _model);
- addChild(_adapters);
-
- _dbEnvs = new DbEnvs(serviceDescriptor.dbEnvs, childrenEditable,
- variables, _model);
- addChild(_dbEnvs);
- }
- }
-
- void unregisterAdapters()
- {
- _adapters.unregisterAll();
- }
-
- public String toString()
- {
- if(_displayString != null)
- {
- return _displayString;
- }
- else
- {
- return _id;
- }
- }
-
- private ServiceInstanceDescriptor _descriptor;
- private String _displayString;
- private boolean _editable;
- private Adapters _adapters;
- private DbEnvs _dbEnvs;
-}
diff --git a/java/src/IceGrid/TreeNode/ServiceInstances.java b/java/src/IceGrid/TreeNode/ServiceInstances.java deleted file mode 100755 index 0d6ebbddaea..00000000000 --- a/java/src/IceGrid/TreeNode/ServiceInstances.java +++ /dev/null @@ -1,147 +0,0 @@ -// **********************************************************************
-//
-// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-package IceGrid.TreeNode;
-
-import IceGrid.Model;
-import IceGrid.ServiceDescriptor;
-import IceGrid.ServiceInstanceDescriptor;
-import IceGrid.TemplateDescriptor;
-import IceGrid.Utils;
-
-class ServiceInstances extends Parent
-{
- //
- // In server template
- //
- ServiceInstances(java.util.List descriptors, Application application)
- {
- this(descriptors, true, application, null, null, null);
- }
-
- //
- // In server instance
- //
- ServiceInstances(java.util.List descriptors,
- boolean editable,
- Application application,
- java.util.Map nodeVariables,
- java.util.Map parameters,
- Node node)
- {
- super("Service instances", application.getModel());
- _descriptors = descriptors;
-
- java.util.Iterator p = _descriptors.iterator();
- while(p.hasNext())
- {
- ServiceInstanceDescriptor descriptor =
- (ServiceInstanceDescriptor)p.next();
-
- ServiceDescriptor serviceDescriptor = null;
- String serviceId = null;
- String displayString = null;
- java.util.Map substitutedParameters = null;
-
- if(descriptor.template.length() > 0)
- {
- TemplateDescriptor templateDescriptor
- = application.findServiceTemplateDescriptor(descriptor.template);
-
- if(templateDescriptor != null)
- {
- serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor;
- }
-
- if(node != null) // in server instance
- {
- //
- // Substitute parameter values with variables + parameters,
- // then use variables + these substituted parameter
- // values on the serviceDescriptor
- //
-
- substitutedParameters =
- Utils.substituteVariables(descriptor.parameterValues,
- parameters,
- nodeVariables,
- application.getVariables());
-
- if(serviceDescriptor != null)
- {
- serviceId = Utils.substituteVariables(serviceDescriptor.name,
- substitutedParameters,
- nodeVariables,
- application.getVariables());
-
- displayString = serviceId + ": " + templateLabel(descriptor.template,
- substitutedParameters.values());
- }
- else
- {
- serviceId = "????: " + templateLabel(descriptor.template,
- substitutedParameters.values());
- }
- }
- else
- {
- //
- // serviceId = TemplateName<unsubstituted param 1, ....>
- //
- serviceId = templateLabel(descriptor.template,
- descriptor.parameterValues.values());
- }
- }
- else
- {
- serviceDescriptor = descriptor.descriptor; // can't be null
-
- if(node != null) // in server instance
- {
- //
- // Use variables and parameters on this serviceDescriptor
- //
-
- serviceId = Utils.substituteVariables(serviceDescriptor.name,
- parameters,
- nodeVariables,
- application.getVariables());
-
- }
- else
- {
- serviceId = serviceDescriptor.name;
- }
- }
-
- addChild(new ServiceInstance(serviceId,
- displayString,
- descriptor,
- serviceDescriptor,
- editable,
- parameters,
- substitutedParameters,
- nodeVariables,
- application.getVariables(),
- _model,
- node));
- }
- }
-
- void unregisterAdapters()
- {
- java.util.Iterator p = _children.iterator();
- while(p.hasNext())
- {
- ServiceInstance instance = (ServiceInstance)p.next();
- instance.unregisterAdapters();
- }
- }
-
- private java.util.List _descriptors;
-}
diff --git a/java/src/IceGrid/TreeNode/ServiceTemplate.java b/java/src/IceGrid/TreeNode/ServiceTemplate.java index 613aa2534a9..91738d220d1 100755 --- a/java/src/IceGrid/TreeNode/ServiceTemplate.java +++ b/java/src/IceGrid/TreeNode/ServiceTemplate.java @@ -29,10 +29,12 @@ class ServiceTemplate extends Parent //
java.util.Collections.sort(_descriptor.parameters);
- _adapters = new Adapters(_descriptor.descriptor.adapters, _model);
+ _adapters = new Adapters(_descriptor.descriptor.adapters, true,
+ null, _model);
addChild(_adapters);
- _dbEnvs = new DbEnvs(_descriptor.descriptor.dbEnvs, _model);
+ _dbEnvs = new DbEnvs(_descriptor.descriptor.dbEnvs, true,
+ null, _model);
addChild(_dbEnvs);
}
diff --git a/java/src/IceGrid/TreeNode/Services.java b/java/src/IceGrid/TreeNode/Services.java new file mode 100755 index 00000000000..a54b58cfc19 --- /dev/null +++ b/java/src/IceGrid/TreeNode/Services.java @@ -0,0 +1,94 @@ +// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+package IceGrid.TreeNode;
+
+import IceGrid.Model;
+import IceGrid.ServiceDescriptor;
+import IceGrid.ServiceInstanceDescriptor;
+import IceGrid.TemplateDescriptor;
+import IceGrid.Utils;
+
+class Services extends Parent
+{
+ Services(java.util.List descriptors,
+ boolean editable,
+ Utils.Resolver resolver, // Null within template
+ Application application)
+ {
+ super("Services", application.getModel());
+ _descriptors = descriptors;
+
+ java.util.Iterator p = _descriptors.iterator();
+ while(p.hasNext())
+ {
+ ServiceInstanceDescriptor descriptor =
+ (ServiceInstanceDescriptor)p.next();
+
+ ServiceDescriptor serviceDescriptor = null;
+ String serviceName = null;
+ String displayString = null;
+ Utils.Resolver serviceResolver = null;
+
+ if(descriptor.template.length() > 0)
+ {
+ TemplateDescriptor templateDescriptor
+ = application.findServiceTemplateDescriptor(descriptor.template);
+
+ assert templateDescriptor != null;
+ serviceDescriptor = (ServiceDescriptor)templateDescriptor.descriptor;
+ assert serviceDescriptor != null;
+
+ if(resolver != null)
+ {
+ serviceResolver = new Utils.Resolver(resolver, descriptor.parameterValues);
+ serviceName = serviceResolver.substitute(serviceDescriptor.name);
+ serviceResolver.put("service", serviceName);
+ displayString = serviceName + ": "
+ + templateLabel(descriptor.template,
+ serviceResolver.getParameters().values());
+ }
+ else
+ {
+ //
+ // serviceName = TemplateName<unsubstituted param 1, ....>
+ //
+ serviceName = templateLabel(descriptor.template,
+ descriptor.parameterValues.values());
+
+ }
+ }
+ else
+ {
+ serviceDescriptor = descriptor.descriptor;
+ assert serviceDescriptor != null;
+
+ if(resolver != null)
+ {
+ serviceResolver = new Utils.Resolver(resolver);
+ serviceName = resolver.substitute(serviceDescriptor.name);
+ serviceResolver.put("service", serviceName);
+ }
+ else
+ {
+ serviceName = serviceDescriptor.name;
+ }
+ }
+
+ addChild(new Service(serviceName,
+ displayString,
+ descriptor,
+ serviceDescriptor,
+ editable,
+ serviceResolver,
+ _model));
+ }
+ }
+
+ private java.util.List _descriptors;
+}
diff --git a/java/src/IceGrid/Utils.java b/java/src/IceGrid/Utils.java index c5524262be8..22b51ccd31d 100755 --- a/java/src/IceGrid/Utils.java +++ b/java/src/IceGrid/Utils.java @@ -249,17 +249,33 @@ public class Utils public Resolver(Resolver parent, java.util.TreeMap parameters)
{
java.util.TreeMap substitutedParameters =
- substituteParameterValues(parameters, parent);
+ parent.substituteParameterValues(parameters);
_variables = parent._variables;
_resolvedVariableCache = (java.util.HashMap)parent._resolvedVariableCache.clone();
_parameters = substitutedParameters;
}
-
+
+ //
+ // Resolver for plain server
+ //
+ public Resolver(Resolver parent)
+ {
+ _variables = parent._variables;
+ _resolvedVariableCache = (java.util.HashMap)parent._resolvedVariableCache.clone();
+ if(parent._parameters == null)
+ {
+ _parameters = null;
+ }
+ else
+ {
+ _parameters = (java.util.TreeMap)parent._parameters.clone();
+ }
+ }
private Resolver(java.util.Map[] variables, // ordered read-only variable maps
java.util.HashMap resolvedVariableCache, // null or read-write
- java.util.Map parameters) // null or read-only
+ java.util.TreeMap parameters) // null or read-only
{
_variables = variables;
_resolvedVariableCache = resolvedVariableCache;
@@ -340,90 +356,96 @@ public class Utils return _parameters;
}
- private java.util.Map[] _variables;
- private java.util.HashMap _resolvedVariableCache;
- private java.util.Map _parameters;
- private Resolver _subResolver;
- static private String _recursiveDefError = "<recursive def error>";
- }
-
-
- static public String substitute(String input, Resolver resolver)
- {
- if(resolver == null)
- {
- return input;
- }
-
- int beg = 0;
- int end = 0;
-
- while((beg = input.indexOf("${", beg)) != -1)
+ public String substitute(String input)
{
- if(beg > 0 && input.charAt(beg - 1) == '$')
+ int beg = 0;
+ int end = 0;
+
+ while((beg = input.indexOf("${", beg)) != -1)
{
- int escape = beg - 1;
- while(escape > 0 && input.charAt(escape = 1) == '$')
+ if(beg > 0 && input.charAt(beg - 1) == '$')
{
- --escape;
+ int escape = beg - 1;
+ while(escape > 0 && input.charAt(escape = 1) == '$')
+ {
+ --escape;
+ }
+
+ input = input.substring(0, escape) + input.substring(beg - (beg - escape) / 2);
+ if((beg - escape) % 2 != 0)
+ {
+ ++beg;
+ continue;
+ }
+ else
+ {
+ beg -= (beg - escape) / 2;
+ }
}
- input = input.substring(0, escape) + input.substring(beg - (beg - escape) / 2);
- if((beg - escape) % 2 != 0)
+ end = input.indexOf('}', beg);
+ if(end == -1)
{
- ++beg;
- continue;
+ //
+ // Malformed variable, can't substitute anything else
+ //
+ return input;
+ }
+
+ String name = input.substring(beg + 2, end);
+
+ //
+ // Resolve name
+ //
+ String val = find(name);
+ if(val != null)
+ {
+ input = input.substring(0, beg) + val + input.substring(end + 1);
+ beg += val.length();
}
else
{
- beg -= (beg - escape) / 2;
+ //
+ // No substitution, keep ${name} in the result
+ //
+ ++beg;
}
}
+ return input;
+ }
- end = input.indexOf('}', beg);
- if(end == -1)
- {
- //
- // Malformed variable, can't substitute anything else
- //
- return input;
- }
-
- String name = input.substring(beg + 2, end);
-
- //
- // Resolve name
- //
- String val = resolver.find(name);
- if(val != null)
- {
- input = input.substring(0, beg) + val + input.substring(end + 1);
- beg += val.length();
- }
- else
+ //
+ // Substitute all the values from the input map
+ //
+ public java.util.TreeMap substituteParameterValues(java.util.TreeMap input)
+ {
+ java.util.TreeMap result = (java.util.TreeMap)input.clone();
+ java.util.Iterator p = result.entrySet().iterator();
+ while(p.hasNext())
{
- //
- // No substitution, keep ${name} in the result
- //
- ++beg;
+ java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
+ entry.setValue(substitute((String)entry.getValue()));
}
+ return result;
}
- return input;
+
+ private java.util.Map[] _variables;
+ private java.util.HashMap _resolvedVariableCache;
+ private java.util.TreeMap _parameters;
+ private Resolver _subResolver;
+ static private String _recursiveDefError = "<recursive def error>";
}
- //
- // Substitute all the values from the input map
- //
- static public java.util.TreeMap substituteParameterValues(java.util.TreeMap input,
- Resolver resolver)
+
+ static public String substitute(String input, Resolver resolver)
{
- java.util.TreeMap result = (java.util.TreeMap)input.clone();
- java.util.Iterator p = result.entrySet().iterator();
- while(p.hasNext())
+ if(resolver != null)
{
- java.util.Map.Entry entry = (java.util.Map.Entry)p.next();
- entry.setValue(substitute((String)entry.getValue(), resolver));
+ return resolver.substitute(input);
+ }
+ else
+ {
+ return input;
}
- return result;
}
}
|