diff options
Diffstat (limited to 'source')
37 files changed, 651 insertions, 344 deletions
diff --git a/source/com/c2kernel/collection/AggregationMember.java b/source/com/c2kernel/collection/AggregationMember.java index d383f02..e3b213e 100644 --- a/source/com/c2kernel/collection/AggregationMember.java +++ b/source/com/c2kernel/collection/AggregationMember.java @@ -136,7 +136,7 @@ public class AggregationMember extends GraphableVertex implements CollectionMemb public Image getImage() {
if (image == null) {
- image = Resource.getImageResource("typeicons/"+getProperties().get("Type")+"_16.png").getImage();
+ image = Resource.findImage("typeicons/"+getProperties().get("Type")+"_16.png").getImage();
}
return image;
}
diff --git a/source/com/c2kernel/events/History.java b/source/com/c2kernel/events/History.java index a964a72..868eaea 100644 --- a/source/com/c2kernel/events/History.java +++ b/source/com/c2kernel/events/History.java @@ -68,14 +68,9 @@ public class History extends RemoteMap<Event> { synchronized (this) {
int newEventID = getLastId()+1;
newEvent.setID(newEventID);
- if (put(newEvent.getName(), newEvent) != null) {
- lastID = newEventID;
- return newEvent;
- }
- else {
- Logger.error("History.addEvent() - Event storage failed!");
- return null;
- }
+ put(newEvent.getName(), newEvent);
+ lastID = newEventID;
+ return newEvent;
}
}
diff --git a/source/com/c2kernel/graph/view/EditorToolBar.java b/source/com/c2kernel/graph/view/EditorToolBar.java index f84b084..61c7409 100644 --- a/source/com/c2kernel/graph/view/EditorToolBar.java +++ b/source/com/c2kernel/graph/view/EditorToolBar.java @@ -62,15 +62,15 @@ public class EditorToolBar extends Box implements Printable protected JComboBox mEdgeTypeBox = new JComboBox();
// Mode buttons
protected ButtonGroup mModeButtonGroup = new ButtonGroup();
- protected JToggleButton mVertexModeButton = new JToggleButton(Resource.getImageResource("graph/newvertex.png"));
- protected JToggleButton mSelectModeButton = new JToggleButton(Resource.getImageResource("graph/selection.gif"));
- protected JToggleButton mEdgeModeButton = new JToggleButton(Resource.getImageResource("graph/edge.png"));
+ protected JToggleButton mVertexModeButton = new JToggleButton(Resource.findImage("graph/newvertex.png"));
+ protected JToggleButton mSelectModeButton = new JToggleButton(Resource.findImage("graph/selection.gif"));
+ protected JToggleButton mEdgeModeButton = new JToggleButton(Resource.findImage("graph/edge.png"));
// Normal buttons
protected JButton[] mOtherButtons = null;
- protected JButton mStartButton = new JButton(Resource.getImageResource("graph/start.png"));
- protected JButton mDeleteButton = new JButton(Resource.getImageResource("graph/delete.png"));
- protected JButton mPrintButton = new JButton(Resource.getImageResource("graph/print.png"));
- protected JButton mCopyButton = new JButton(Resource.getImageResource("graph/copy.png"));
+ protected JButton mStartButton = new JButton(Resource.findImage("graph/start.png"));
+ protected JButton mDeleteButton = new JButton(Resource.findImage("graph/delete.png"));
+ protected JButton mPrintButton = new JButton(Resource.findImage("graph/print.png"));
+ protected JButton mCopyButton = new JButton(Resource.findImage("graph/copy.png"));
// Controllers
protected StartVertexController mStartVertexController = new StartVertexController();
protected DeletionController mDeletionController = new DeletionController();
diff --git a/source/com/c2kernel/graph/view/GraphPanel.java b/source/com/c2kernel/graph/view/GraphPanel.java index 5edd070..012fe25 100644 --- a/source/com/c2kernel/graph/view/GraphPanel.java +++ b/source/com/c2kernel/graph/view/GraphPanel.java @@ -27,7 +27,7 @@ public class GraphPanel extends JPanel implements Observer {
protected final Paint mSelectionPaint = Color.black;
protected final Paint mStartPaint = Color.green;
- protected final Image mResizePadImg = Resource.getImageResource("graph/resizepad.gif").getImage();
+ protected final Image mResizePadImg = Resource.findImage("graph/resizepad.gif").getImage();
protected final BasicStroke mDashed =
new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f);
protected GraphModelManager mGraphModelManager = null;
diff --git a/source/com/c2kernel/gui/Console.java b/source/com/c2kernel/gui/Console.java index a16e6f6..3427f82 100644 --- a/source/com/c2kernel/gui/Console.java +++ b/source/com/c2kernel/gui/Console.java @@ -130,7 +130,9 @@ public class Console extends JFrame { getContentPane().add(inputBox);
try {
- Properties utilProps = FileStringUtility.loadConfigFile( Resource.getDomainResourceURL("ScriptUtils.conf").toString());
+ // TODO: merge module script utilities together and prepend with namespace
+ Properties utilProps = FileStringUtility.loadConfigFile( Resource.findTextResource("ScriptUtils.conf") );
+
Box utilBox = Box.createHorizontalBox();
for (Object name2 : utilProps.keySet()) {
String name = (String) name2;
diff --git a/source/com/c2kernel/gui/DynamicTreeBuilder.java b/source/com/c2kernel/gui/DynamicTreeBuilder.java index a72c156..050a76a 100644 --- a/source/com/c2kernel/gui/DynamicTreeBuilder.java +++ b/source/com/c2kernel/gui/DynamicTreeBuilder.java @@ -25,15 +25,15 @@ import com.c2kernel.utils.Resource; public class DynamicTreeBuilder implements NodeSubscriber {
private DefaultTreeModel treeModel;
- private DefaultMutableTreeNode parent;
+ private final DefaultMutableTreeNode parent;
public short state = IDLE;
public static final short IDLE = 0;
public static final short LOADING = 1;
public static final short PARTIAL = 2;
public static final short FINISHED = 3;
- private DefaultMutableTreeNode loading;
- private static ImageIcon loadIcon = Resource.getImageResource("loading.gif");
- private static ImageIcon pauseIcon = Resource.getImageResource("reload.gif");
+ private final DefaultMutableTreeNode loading;
+ private static ImageIcon loadIcon = Resource.findImage("loading.gif");
+ private static ImageIcon pauseIcon = Resource.findImage("reload.gif");
/**
* The newly created DynamicTreeBuilder records its parent node - the one for which it will build child nodes for.
diff --git a/source/com/c2kernel/gui/EntityDetails.java b/source/com/c2kernel/gui/EntityDetails.java index 7cb4f66..0a04536 100644 --- a/source/com/c2kernel/gui/EntityDetails.java +++ b/source/com/c2kernel/gui/EntityDetails.java @@ -134,7 +134,7 @@ public class EntityDetails extends JPanel implements ChangeListener, Runnable { c.anchor = GridBagConstraints.NORTH;
c.ipadx = 5;
c.ipady = 5;
- current = new JLabel(Resource.getImageResource("typeicons/"+myEntity.getIconName()+"_32.png"));
+ current = new JLabel(Resource.findImage("typeicons/"+myEntity.getIconName()+"_32.png"));
gridbag.setConstraints(current, c);
titlePanel.add(current);
// Place Name/ID Label
diff --git a/source/com/c2kernel/gui/EntityFinder.java b/source/com/c2kernel/gui/EntityFinder.java index 18038c9..0d53545 100644 --- a/source/com/c2kernel/gui/EntityFinder.java +++ b/source/com/c2kernel/gui/EntityFinder.java @@ -43,8 +43,8 @@ public class EntityFinder extends Box implements Runnable { static {
try
{
- mNextIcon =Resource.getImageResource("next.png");
- mFindIcon =Resource.getImageResource("find.png");
+ mNextIcon =Resource.findImage("next.png");
+ mFindIcon =Resource.findImage("find.png");
}
catch (Exception e)
{
@@ -187,8 +187,8 @@ public class EntityFinder extends Box implements Runnable { }
private class ListenerButtonListener implements ItemListener {
- private DomainKeyListener listener;
- private JToggleButton listenerButton;
+ private final DomainKeyListener listener;
+ private final JToggleButton listenerButton;
public ListenerButtonListener(DomainKeyListener newListener, JToggleButton listenerButton) {
this.listener = newListener;
diff --git a/source/com/c2kernel/gui/LoginBox.java b/source/com/c2kernel/gui/LoginBox.java index 415469b..aee469f 100644 --- a/source/com/c2kernel/gui/LoginBox.java +++ b/source/com/c2kernel/gui/LoginBox.java @@ -47,8 +47,8 @@ import com.c2kernel.utils.Resource; */
public class LoginBox extends JFrame {
- private int xMov;
- private int yMov;
+ private final int xMov;
+ private final int yMov;
public String errorMessage=new String("");
private int maxNumberLogon;
public boolean action = false;
@@ -72,7 +72,7 @@ public class LoginBox extends JFrame { javax.swing.ImageIcon imageHolder,MainFrame mainFrame) {
String iconFile = Gateway.getProperty("AppIcon");
if (iconFile != null)
- this.setIconImage(Resource.getImageResource(iconFile).getImage());
+ this.setIconImage(Resource.findImage(iconFile).getImage());
this.errorLabel.setText(bottomMessage);
if (errorMessage.compareTo("")!=0) this.errorLabel.setText(errorMessage);
mainFrameFather=mainFrame;
diff --git a/source/com/c2kernel/gui/Main.java b/source/com/c2kernel/gui/Main.java index 5a9209e..7cf54cb 100644 --- a/source/com/c2kernel/gui/Main.java +++ b/source/com/c2kernel/gui/Main.java @@ -1,6 +1,7 @@ package com.c2kernel.gui;
+import com.c2kernel.process.Gateway;
import com.c2kernel.process.StandardClient;
import com.c2kernel.utils.Logger;
@@ -16,7 +17,7 @@ public class Main extends StandardClient {
try
{
- standardSetUp(args);
+ Gateway.init(readC2KArgs(args), false);
Logger.initConsole("GUI");
MainFrame client = new MainFrame();
client.showLogin();
@@ -28,7 +29,7 @@ public class Main extends StandardClient try
{
- standardTearDown();
+ Gateway.close();
}
catch(Exception ex1)
{
diff --git a/source/com/c2kernel/gui/MainFrame.java b/source/com/c2kernel/gui/MainFrame.java index 2e39d0d..d09bc4c 100644 --- a/source/com/c2kernel/gui/MainFrame.java +++ b/source/com/c2kernel/gui/MainFrame.java @@ -108,7 +108,7 @@ public class MainFrame extends javax.swing.JFrame { pictureUrl = new URL(logoURL);
imageHolder = new ImageIcon(pictureUrl);
} catch (java.net.MalformedURLException m) {
- imageHolder = Resource.getImageResource(logoURL);
+ imageHolder = Resource.findImage(logoURL);
}
LoginBox login =
@@ -133,10 +133,10 @@ public class MainFrame extends javax.swing.JFrame { String iconFile = Gateway.getProperty("AppIcon");
if (iconFile != null)
- this.setIconImage(Resource.getImageResource(iconFile).getImage());
+ this.setIconImage(Resource.findImage(iconFile).getImage());
//preload loading image
- Resource.getImageResource("loading.gif");
+ Resource.findImage("loading.gif");
// close listener
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
diff --git a/source/com/c2kernel/gui/MenuBuilder.java b/source/com/c2kernel/gui/MenuBuilder.java index 6d1bfbc..8acfca7 100644 --- a/source/com/c2kernel/gui/MenuBuilder.java +++ b/source/com/c2kernel/gui/MenuBuilder.java @@ -25,6 +25,7 @@ import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLEditorKit;
+import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.DomainPath;
import com.c2kernel.lookup.Path;
import com.c2kernel.persistency.ClusterStorage;
@@ -218,14 +219,23 @@ public class MenuBuilder extends JMenuBar implements ActionListener, ItemListene JLabel title = new JLabel(aboutInfo);
about.add(title);
- about.add(new JLabel("Domain version: "+Resource.getDomainVersion()));
about.add(new JLabel("Kernel version: "+Resource.getKernelVersion()));
+ about.add(new JLabel("Modules loaded: "+Gateway.getModuleManager().getModuleVersions()));
// get license info
+
StringBuffer lictxt = new StringBuffer();
- String domlictxt = Resource.getTextResource("license.html");
- if (domlictxt != null)
- lictxt.append(domlictxt);
- lictxt.append(Resource.getTextResource("textFiles/license.html"));
+ try {
+ lictxt.append(Resource.getTextResource(null, "textFiles/license.html"));
+ } catch (ObjectNotFoundException e) { } // no kernel license found
+ for (String ns : Resource.getModuleBaseURLs().keySet()) {
+ String domlictxt;
+ try {
+ domlictxt = Resource.getTextResource(ns, "license.html");
+ lictxt.append(domlictxt).append("\n");
+ } catch (ObjectNotFoundException e) { }
+
+ }
+
JEditorPane license = new JEditorPane();
license.setEditable(false);
@@ -242,7 +252,7 @@ public class MenuBuilder extends JMenuBar implements ActionListener, ItemListene myPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = myPane.createDialog(null, Language.translate("About"));
dialog.setResizable(false);
- Icon icon = Resource.getImageResource(Gateway.getProperty("banner"));
+ Icon icon = Resource.findImage(Gateway.getProperty("banner"));
myPane.setIcon(icon);
dialog.pack();
dialog.setVisible(true);
diff --git a/source/com/c2kernel/gui/data/Node.java b/source/com/c2kernel/gui/data/Node.java index 6556b3a..2f12d6b 100644 --- a/source/com/c2kernel/gui/data/Node.java +++ b/source/com/c2kernel/gui/data/Node.java @@ -37,8 +37,8 @@ public abstract class Node implements Runnable { private boolean loaded = false;
private String iconName;
protected EntityTabManager desktop;
- static ImageIcon folder = Resource.getImageResource("folder.png");
- static ImageIcon emptyLeaf = Resource.getImageResource("leaf.png");
+ static ImageIcon folder = Resource.findImage("folder.png");
+ static ImageIcon emptyLeaf = Resource.findImage("leaf.png");
public Node() {
}
@@ -214,7 +214,7 @@ public abstract class Node implements Runnable { public void setIcon(String icon) {
iconName = icon;
- this.icon = Resource.getImageResource("typeicons/"+icon+"_16.png");
+ this.icon = Resource.findImage("typeicons/"+icon+"_16.png");
}
public JPopupMenu getPopupMenu() {
diff --git a/source/com/c2kernel/gui/tabs/EntityTabPane.java b/source/com/c2kernel/gui/tabs/EntityTabPane.java index 5a374dd..0a8a0cd 100644 --- a/source/com/c2kernel/gui/tabs/EntityTabPane.java +++ b/source/com/c2kernel/gui/tabs/EntityTabPane.java @@ -43,7 +43,7 @@ public class EntityTabPane extends JPanel implements Runnable { protected NodeEntity sourceEntity;
protected String titleText = null;
protected ImageIcon titleIcon = null;
- private String tabName;
+ private final String tabName;
protected GridBagLayout gridbag = new GridBagLayout();
protected GridBagConstraints c = null;
public static Font titleFont = null;
@@ -53,7 +53,7 @@ public class EntityTabPane extends JPanel implements Runnable { protected Box titleBox;
static {
try {
- mReloadIcon = Resource.getImageResource("reload.gif");
+ mReloadIcon = Resource.findImage("reload.gif");
} catch (Exception e) {
Logger.warning("Couldn't load images: " + e);
}
@@ -96,7 +96,7 @@ public class EntityTabPane extends JPanel implements Runnable { if (titleText == null)
titleText = tabName;
if (titleIcon == null)
- titleIcon = Resource.getImageResource("info.png");
+ titleIcon = Resource.findImage("info.png");
JLabel title = new JLabel(titleText, titleIcon, SwingConstants.LEFT);
title.setFont(titleFont);
title.setForeground(headingColor);
@@ -113,7 +113,7 @@ public class EntityTabPane extends JPanel implements Runnable { });
String defaultStartTab = MainFrame.getPref("DefaultStartTab", "Properties");
JToggleButton defaultStart =
- new JToggleButton(Resource.getImageResource("graph/start.png"));
+ new JToggleButton(Resource.findImage("graph/start.png"));
defaultStart.setMargin(new Insets(0, 0, 0, 0));
defaultStart.setToolTipText(
Language.translate("Select this tab to be the default one opened when you double click an item"));
diff --git a/source/com/c2kernel/gui/tabs/WorkflowPane.java b/source/com/c2kernel/gui/tabs/WorkflowPane.java index 6bccd08..e4acd8d 100644 --- a/source/com/c2kernel/gui/tabs/WorkflowPane.java +++ b/source/com/c2kernel/gui/tabs/WorkflowPane.java @@ -41,10 +41,10 @@ public class WorkflowPane extends EntityTabPane implements EntityProxyObserver<W protected Workflow mWorkflow = null;
boolean init = false;
TransitionPanel transPanel;
- protected JButton mLoadButton = new JButton(Resource.getImageResource("graph/load.png"));
- protected JButton mSaveButton = new JButton(Resource.getImageResource("graph/save.png"));
- protected JButton mLayoutButton = new JButton(Resource.getImageResource("graph/autolayout.png"));
- protected JButton mZoomOutButton = new JButton(Resource.getImageResource("graph/zoomout.png"));
+ protected JButton mLoadButton = new JButton(Resource.findImage("graph/load.png"));
+ protected JButton mSaveButton = new JButton(Resource.findImage("graph/save.png"));
+ protected JButton mLayoutButton = new JButton(Resource.findImage("graph/autolayout.png"));
+ protected JButton mZoomOutButton = new JButton(Resource.findImage("graph/zoomout.png"));
protected JButton[] mOtherToolBarButtons;
// Workflow factories
protected EdgeFactory mWfEdgeFactory;
diff --git a/source/com/c2kernel/gui/tabs/collection/AggregationView.java b/source/com/c2kernel/gui/tabs/collection/AggregationView.java index 35cdb11..b6578bb 100644 --- a/source/com/c2kernel/gui/tabs/collection/AggregationView.java +++ b/source/com/c2kernel/gui/tabs/collection/AggregationView.java @@ -25,8 +25,8 @@ import com.c2kernel.utils.Resource; */
public class AggregationView extends CollectionView<AggregationMember>
{
- protected JButton mSaveButton = new JButton(Resource.getImageResource("graph/save.png"));
- protected JButton mHistoryButton = new JButton(Resource.getImageResource("graph/history.png"));
+ protected JButton mSaveButton = new JButton(Resource.findImage("graph/save.png"));
+ protected JButton mHistoryButton = new JButton(Resource.findImage("graph/history.png"));
protected JButton[] mOtherToolBarButtons = { mSaveButton, mHistoryButton };
// Graph editor panel
protected EditorPanel mEditorPanel;
diff --git a/source/com/c2kernel/lifecycle/chooser/ActivityChooser.java b/source/com/c2kernel/lifecycle/chooser/ActivityChooser.java index 4b0ae4c..d5f62a0 100644 --- a/source/com/c2kernel/lifecycle/chooser/ActivityChooser.java +++ b/source/com/c2kernel/lifecycle/chooser/ActivityChooser.java @@ -56,7 +56,7 @@ public class ActivityChooser extends JFrame {
super(title);
mMessage = message;
- img = Resource.getImageResource("graph/newvertex_large.png").getImage();
+ img = Resource.findImage("graph/newvertex_large.png").getImage();
setIconImage(img);
mParent = parent;
mhashmap = hashmap;
diff --git a/source/com/c2kernel/lifecycle/gui/model/WfVertexDefFactory.java b/source/com/c2kernel/lifecycle/gui/model/WfVertexDefFactory.java index da59efd..132fdcf 100644 --- a/source/com/c2kernel/lifecycle/gui/model/WfVertexDefFactory.java +++ b/source/com/c2kernel/lifecycle/gui/model/WfVertexDefFactory.java @@ -38,7 +38,7 @@ public class WfVertexDefFactory implements VertexFactory, WorkflowDialogue new ActivityChooser(
Language.translate("Please enter a Type for the new activityDef"),
Language.translate("New " + vertexTypeId + " Activity"),
- Resource.getImageResource("graph/newvertex_large.png").getImage(),
+ Resource.findImage("graph/newvertex_large.png").getImage(),
this,
mhm);
a.setVisible(true);
@@ -68,7 +68,7 @@ public class WfVertexDefFactory implements VertexFactory, WorkflowDialogue Language.translate("Please type a Name"),
Language.translate("New " + vertexTypeId + " Activity"),
JOptionPane.QUESTION_MESSAGE,
- Resource.getImageResource("graph/newvertex_large.png"),
+ Resource.findImage("graph/newvertex_large.png"),
null,
null);
act = (ActivityDef) mCompositeActivityDef.search(mCompositeActivityDef.getID() + "/" + newName);
diff --git a/source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java b/source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java index 58964aa..4c69f15 100644 --- a/source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java +++ b/source/com/c2kernel/lifecycle/gui/view/CompActDefOutcomeHandler.java @@ -45,8 +45,8 @@ public class CompActDefOutcomeHandler extends JPanel
implements OutcomeHandler {
- protected JButton mLoadButton = new JButton(Resource.getImageResource("graph/load.png"));
- protected JButton mLayoutButton = new JButton(Resource.getImageResource("graph/autolayout.png"));
+ protected JButton mLoadButton = new JButton(Resource.findImage("graph/load.png"));
+ protected JButton mLayoutButton = new JButton(Resource.findImage("graph/autolayout.png"));
protected JButton[] mOtherToolBarButtons = { mLayoutButton, mLoadButton };
protected CompositeActivityDef mCompActDef = null;
diff --git a/source/com/c2kernel/lifecycle/instance/Activity.java b/source/com/c2kernel/lifecycle/instance/Activity.java index 226f0af..8a07d15 100644 --- a/source/com/c2kernel/lifecycle/instance/Activity.java +++ b/source/com/c2kernel/lifecycle/instance/Activity.java @@ -600,7 +600,7 @@ public class Activity extends WfVertex event = auditEvent(transitionID, agent);
if (event != null)
eventID = event.getID();
- if (Boolean.TRUE.equals(getProperties().get("AlwaysUseOutcome")) || transitionID == Transitions.DONE || transitionID == Transitions.COMPLETE)
+ if (transitionID == Transitions.DONE || transitionID == Transitions.COMPLETE)
storeOutcome(eventID, requestData);
EntityPath entityPath = getItemEntityPath();
TransactionManager storage = Gateway.getStorage();
diff --git a/source/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java b/source/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java index 0b6c9e4..39e7ee9 100644 --- a/source/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java +++ b/source/com/c2kernel/lifecycle/instance/gui/model/WfVertexFactory.java @@ -36,7 +36,7 @@ public class WfVertexFactory implements VertexFactory, WorkflowDialogue new ActivityChooser(
Language.translate("Please enter a Type for the new activity"),
Language.translate("New " + vertexTypeId + " Activity"),
- Resource.getImageResource("graph/newvertex_large.png").getImage(),
+ Resource.findImage("graph/newvertex_large.png").getImage(),
this,
mhm);
a.setVisible(true);
@@ -69,7 +69,7 @@ public class WfVertexFactory implements VertexFactory, WorkflowDialogue Language.translate("Activity name not unique. Please give another."),
Language.translate("New " + vertexTypeId + " Activity"),
JOptionPane.QUESTION_MESSAGE,
- Resource.getImageResource("graph/newvertex_large.png"),
+ Resource.findImage("graph/newvertex_large.png"),
null,
null);
if (newName.equals(""))
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java index 96371dd..aa30677 100644 --- a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java +++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/CreateNewAgent.java @@ -33,15 +33,17 @@ public class CreateNewAgent extends PredefinedStep InvalidDataException
{
checkAccessRights(agent);
-
+ String redactedRequestData;
try {
NewAgent newAgent = (NewAgent)CastorXMLUtility.unmarshall(requestData);
newAgent.create(agent.getSysKey());
+ newAgent.password = "REDACTED";
+ redactedRequestData = CastorXMLUtility.marshall(newAgent);
} catch (Exception ex) {
Logger.error(ex);
throw new InvalidDataException("Error creating agent", "");
}
- sendEventStoreOutcome(transitionID, requestData, agent);
+ sendEventStoreOutcome(transitionID, redactedRequestData, agent);
}
}
diff --git a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java index 5666a00..f155ced 100644 --- a/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java +++ b/source/com/c2kernel/lifecycle/instance/predefined/entitycreation/NewItem.java @@ -24,6 +24,7 @@ import com.c2kernel.utils.Logger; *
* @version $Revision: 1.8 $ $Date: 2006/03/03 13:52:21 $
*/
+
public class NewItem {
public String name;
diff --git a/source/com/c2kernel/lookup/LDAPLookup.java b/source/com/c2kernel/lookup/LDAPLookup.java index 9bae873..39744ac 100644 --- a/source/com/c2kernel/lookup/LDAPLookup.java +++ b/source/com/c2kernel/lookup/LDAPLookup.java @@ -41,10 +41,10 @@ public class LDAPLookup {
private LDAPConnection mLDAPConn;
- private LDAPProperties mLDAPProps;
- private NextKeyManager mNextKeyManager;
+ private final LDAPProperties mLDAPProps;
+ private final NextKeyManager mNextKeyManager;
private LDAPPropertyManager mPropManager;
- private LDAPRoleManager mRoleManager;
+ private final LDAPRoleManager mRoleManager;
@@ -302,10 +302,10 @@ public class LDAPLookup LDAPLookupUtils.createCristalContext(getConnection(), Path.mLocalPath);
}
- public void install()
+ public void install() throws ObjectNotFoundException
{
createBootTree();
- initTree( Resource.getTextResource("boot/LDAPboot.txt"));
+ initTree( Resource.getTextResource(null, "boot/LDAPboot.txt"));
}
public void initTree(String bootFile)
diff --git a/source/com/c2kernel/persistency/RemoteMap.java b/source/com/c2kernel/persistency/RemoteMap.java index bc17e3f..e57cae2 100644 --- a/source/com/c2kernel/persistency/RemoteMap.java +++ b/source/com/c2kernel/persistency/RemoteMap.java @@ -4,6 +4,7 @@ import java.util.AbstractSet; import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeMap;
@@ -114,6 +115,7 @@ public class RemoteMap<V extends C2KLocalObject> extends TreeMap<String, V> impl public synchronized int getLastId() {
loadKeys();
+ if (size() == 0) return -1;
try {
return Integer.parseInt(lastKey());
} catch (NumberFormatException ex) {
diff --git a/source/com/c2kernel/process/AbstractMain.java b/source/com/c2kernel/process/AbstractMain.java index 9282d45..7401d1b 100644 --- a/source/com/c2kernel/process/AbstractMain.java +++ b/source/com/c2kernel/process/AbstractMain.java @@ -16,7 +16,6 @@ import java.io.PrintStream; import com.c2kernel.utils.FileStringUtility;
import com.c2kernel.utils.Logger;
-import com.c2kernel.utils.Resource;
/**************************************************************************
*
@@ -106,20 +105,6 @@ abstract public class AbstractMain }
logStream = new PrintStream(new FileOutputStream(args[++i], true));
}
- else if(args[i].equals("-resURL"))
- {
- String resString = args[++i];
- System.out.println("AbstractMain::readC2KArgs() - Resource location:" +
- resString);
- Resource.setKernelBaseURL(resString);
- }
- else if(args[i].equals("-domResURL"))
- {
- String resString = args[++i];
- System.out.println("AbstractMain::readC2KArgs() - Domain resource location:" +
- resString);
- Resource.setDomainBaseURL(resString);
- }
i++;
}
@@ -173,33 +158,4 @@ abstract public class AbstractMain return c2kProps;
}
- /**************************************************************************
- * Required for most of the client & server application
- *
- * reads arguments
- * initialises C2K properties
- * initialises ORB
- * initialises VirtualTreeManager
- * initialises EventValueFactory + ProxyEventValueFactory
- * initialises
- **************************************************************************/
- static protected void standardSetUp(String[] args)
- throws Exception
- {
- //Reads the C2Kernel arguments, and inits the Gateway with them
- Gateway.init(readC2KArgs(args));
-
- }
-
-
- /**************************************************************************
- *
- **************************************************************************/
- static protected void standardTearDown()
- throws Exception
- {
- Gateway.close();
- Logger.msg(5, "AbstractMain::standardTearDown() - DONE.");
- }
-
}
diff --git a/source/com/c2kernel/process/Bootstrap.java b/source/com/c2kernel/process/Bootstrap.java index 5011b7f..5b83d89 100644 --- a/source/com/c2kernel/process/Bootstrap.java +++ b/source/com/c2kernel/process/Bootstrap.java @@ -2,7 +2,6 @@ package com.c2kernel.process; import java.net.InetAddress;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.StringTokenizer;
import com.c2kernel.common.ObjectNotFoundException;
@@ -15,7 +14,6 @@ import com.c2kernel.lifecycle.instance.CompositeActivity; import com.c2kernel.lifecycle.instance.Workflow;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStepContainer;
import com.c2kernel.lifecycle.instance.predefined.ServerPredefinedStepContainer;
-import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewItem;
import com.c2kernel.lifecycle.instance.stateMachine.States;
import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.lookup.AgentPath;
@@ -44,7 +42,6 @@ import com.c2kernel.utils.Resource; public class Bootstrap
{
- static HashMap<String, String> bootstrapFactoryItems = new HashMap<String, String>();
static DomainPath thisServerPath;
/**
@@ -68,8 +65,6 @@ public class Bootstrap // verify the server item's wf
initServerItemWf();
- // create the factories etc.
- createBootstrapFactoryItems();
Logger.msg("Bootstrap.run() - Bootstrapping complete");
} catch (Exception e) {
Logger.error(e);
@@ -86,45 +81,11 @@ public class Bootstrap String bootItems;
Logger.msg(1, "Verifying kernel boot items");
bootItems = FileStringUtility.url2String(Resource.getKernelResourceURL("boot/allbootitems.txt"));
- verifyBootDataItems(bootItems, true);
- if (Resource.getDomainBaseURL() == null)
- Logger.msg(1, "No Domain base URL. Skipping domain boot check.");
- else {
- try {
- Logger.msg(1, "Verifying domain boot items");
- bootItems = FileStringUtility.url2String(Resource.getDomainResourceURL("boot/allbootitems.txt"));
- verifyBootDataItems(bootItems, false);
- } catch (Exception ex) {
- Logger.error(ex);
- Logger.msg("No domain boot items found.");
- return;
- }
- Logger.msg(1, "Verifying domain agents");
-
- try {
- bootItems = FileStringUtility.url2String(Resource.getDomainResourceURL("boot/domainagents.txt"));
- verifyDomainAgents(bootItems);
- } catch (Exception ex) {
- Logger.error(ex);
- Logger.msg("No domain agents found.");
- return;
- }
- }
-
+ verifyBootDataItems(bootItems, null);
Logger.msg(1, "Boot data items complete");
-
- }
-
- private static void verifyDomainAgents(String agentFile) throws Exception {
- StringTokenizer str = new StringTokenizer(agentFile, "\n\r");
- while (str.hasMoreTokens()) {
- String thisItem = str.nextToken();
- StringTokenizer agent = new StringTokenizer(thisItem, ",");
- checkAgent(agent.nextToken(), agent.nextToken(), agent.nextToken(), agent.nextToken().equalsIgnoreCase("true"));
- }
}
- private static void verifyBootDataItems(String bootList, boolean isKernel) {
+ private static void verifyBootDataItems(String bootList, String ns) {
StringTokenizer str = new StringTokenizer(bootList, "\n\r");
while (str.hasMoreTokens()) {
String thisItem = str.nextToken();
@@ -132,63 +93,62 @@ public class Bootstrap String itemType = thisItem.substring(0,delim);
String itemName = thisItem.substring(delim+1);
try {
- String data = Resource.getTextResource("boot/"+thisItem+".xml");
+ String data = Resource.getTextResource(ns, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
if (data == null)
Logger.die("No data found for "+getDataType(itemType)+" "+itemName);
- if (itemType.equals("factory")) {
- bootstrapFactoryItems.put(itemName, data);
- continue;
- }
-
- Logger.msg(1, "Bootstrap.verifyBootItems() - Verifying data of "+getDataType(itemType)+" "+itemName);
- Enumeration<Path> en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName);
- ItemProxy thisProxy;
-
- if (!en.hasMoreElements()) {
- Logger.msg("Bootstrap.verifyBootItems() - "+getDataType(itemType)+" "+itemName+" not found. Creating new.");
- thisProxy = createBootstrapDataItem(itemType, itemName, isKernel);
- }
- else {
- DomainPath path = (DomainPath)en.nextElement();
- thisProxy = (ItemProxy)Gateway.getProxyManager().getProxy(path);
- try {
- Viewpoint currentData = (Viewpoint)thisProxy.getObject(ClusterStorage.VIEWPOINT+"/"+getDataType(itemType)+"/last");
- String oldData = currentData.getOutcome().getData();
- if (data.equals(oldData)) {
- Logger.msg(5, "Bootstrap.verifyBootItems() - Data identical, no update required");
-
- continue;
- }
- } catch (ObjectNotFoundException ex) {
- Logger.error("Bootstrap.verifyBootItems() - Item exists but no data found! Attempting to insert new.");
- }
- }
- // data was missing or doesn't match
- Logger.msg("Bootstrap.verifyBootItems() - Writing new data to "+getDataType(itemType)+" "+itemName);
- History hist = (History)thisProxy.getObject(ClusterStorage.HISTORY);
- Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED);
- Outcome newOutcome = new Outcome(newEvent.getID(), data, getDataType(itemType), 0);
- Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "last", 0, newEvent.getID());
- Viewpoint newZeroView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "0", 0, newEvent.getID());
- Gateway.getStorage().put(thisProxy.getSystemKey(), newOutcome, thisProxy);
- Gateway.getStorage().put(thisProxy.getSystemKey(), newLastView, thisProxy);
- Gateway.getStorage().put(thisProxy.getSystemKey(), newZeroView, thisProxy);
- Gateway.getStorage().commit(thisProxy);
+ verifyResource(ns, itemName, itemType, data);
} catch (Exception e) {
Logger.error(e);
Logger.die("Error importing bootstrap items. Unsafe to continue.");
}
}
}
+
+
+ public static void verifyResource(String ns, String itemName, String itemType, String data) throws Exception {
+ Logger.msg(1, "Bootstrap.verifyResource() - Verifying data of "+getDataType(itemType)+" "+itemName);
+ Enumeration<Path> en = Gateway.getLDAPLookup().search(getTypeRoot(itemType), itemName);
+ ItemProxy thisProxy;
+
+ if (!en.hasMoreElements()) {
+ Logger.msg("Bootstrap.verifyResource() - "+getDataType(itemType)+" "+itemName+" not found. Creating new.");
+ thisProxy = createResourceItem(itemType, itemName, ns);
+ }
+ else {
+ DomainPath path = (DomainPath)en.nextElement();
+ thisProxy = (ItemProxy)Gateway.getProxyManager().getProxy(path);
+ try {
+ Viewpoint currentData = (Viewpoint)thisProxy.getObject(ClusterStorage.VIEWPOINT+"/"+getDataType(itemType)+"/last");
+ String oldData = currentData.getOutcome().getData();
+ if (data.equals(oldData)) {
+ Logger.msg(5, "Bootstrap.verifyResource() - Data identical, no update required");
+ return;
+ }
+ } catch (ObjectNotFoundException ex) {
+ Logger.error("Bootstrap.verifyResource() - Item exists but no data found! Attempting to insert new.");
+ }
+ }
+ // data was missing or doesn't match
+ Logger.msg("Bootstrap.verifyResource() - Writing new data to "+getDataType(itemType)+" "+itemName);
+ History hist = (History)thisProxy.getObject(ClusterStorage.HISTORY);
+ Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED);
+ Outcome newOutcome = new Outcome(newEvent.getID(), data, getDataType(itemType), 0);
+ Viewpoint newLastView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "last", 0, newEvent.getID());
+ Viewpoint newZeroView = new Viewpoint(thisProxy.getSystemKey(), getDataType(itemType), "0", 0, newEvent.getID());
+ Gateway.getStorage().put(thisProxy.getSystemKey(), newOutcome, thisProxy);
+ Gateway.getStorage().put(thisProxy.getSystemKey(), newLastView, thisProxy);
+ Gateway.getStorage().put(thisProxy.getSystemKey(), newZeroView, thisProxy);
+ Gateway.getStorage().commit(thisProxy);
+ }
/**
* @param itemType
* @param itemName
* @param data
*/
- private static ItemProxy createBootstrapDataItem(String itemType, String itemName, boolean isKernel) throws Exception {
+ private static ItemProxy createResourceItem(String itemType, String itemName, String ns) throws Exception {
// create props
- PropertyDescriptionList pdList = (PropertyDescriptionList)CastorXMLUtility.unmarshall(Resource.getTextResource("boot/property/"+itemType+"Prop.xml"));
+ PropertyDescriptionList pdList = (PropertyDescriptionList)CastorXMLUtility.unmarshall(Resource.getTextResource(null, "boot/property/"+itemType+"Prop.xml"));
PropertyArrayList props = new PropertyArrayList();
for (int i = 0; i < pdList.list.size(); i++) {
PropertyDescription pd = pdList.list.get(i);
@@ -204,7 +164,7 @@ public class Bootstrap 1,
CastorXMLUtility.marshall(props),
CastorXMLUtility.marshall(new CompositeActivity()));
- DomainPath newDomPath = new DomainPath(getTypeRoot(itemType).toString()+"/system/"+(isKernel?"kernel":"domain")+"/"+itemName);
+ DomainPath newDomPath = new DomainPath(getTypeRoot(itemType).toString()+"/system/"+(ns==null?"kernel":ns)+"/"+itemName);
newDomPath.setEntity(entityPath);
Gateway.getLDAPLookup().add(newDomPath);
return (ItemProxy)Gateway.getProxyManager().getProxy(entityPath);
@@ -325,32 +285,4 @@ public class Bootstrap Gateway.getStorage().put(thisServerPath.getSysKey(), wf, null);
// add this proxy server in case it was just registered, or the port has changed
}
-
- public static void createBootstrapFactoryItems() throws Exception {
- Logger.msg(1, "Verifying local object factories");
- for (String itemName : bootstrapFactoryItems.keySet()) {
- String itemXML = bootstrapFactoryItems.get(itemName);
- Logger.msg(2, "Verifying "+itemName);
- NewItem item = (NewItem)CastorXMLUtility.unmarshall(itemXML);
- DomainPath factPath = new DomainPath(new DomainPath(item.initialPath), item.name);
- if (factPath.exists()) continue;
- ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(thisServerPath);
- serverEntity.requestAction(
- Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(),
- "workflow/predefined/CreateNewItem",
- Transitions.DONE,
- itemXML);
- Logger.msg("Bootstrap.createBootstrapFactoryItems() - Created factory item: "+itemName);
- ItemProxy factProxy = (ItemProxy)Gateway.getProxyManager().getProxy(factPath);
- String propDesc = Resource.getTextResource("boot/property/"+itemName+"Prop.xml");
- History hist = (History)factProxy.getObject(ClusterStorage.HISTORY);
- Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED);
- Outcome newOutcome = new Outcome(newEvent.getID(), propDesc, "PropertyDescription", 0);
- Viewpoint newLastView = new Viewpoint(factProxy.getSystemKey(), "PropertyDescription", "last", 0, newEvent.getID());
- Gateway.getStorage().put(factProxy.getSystemKey(), newOutcome, factProxy);
- Gateway.getStorage().put(factProxy.getSystemKey(), newLastView, factProxy);
- Gateway.getStorage().commit(factProxy);
- }
- }
-
}
diff --git a/source/com/c2kernel/process/Gateway.java b/source/com/c2kernel/process/Gateway.java index 3a03088..f399351 100644 --- a/source/com/c2kernel/process/Gateway.java +++ b/source/com/c2kernel/process/Gateway.java @@ -5,8 +5,8 @@ package com.c2kernel.process; * @author $Author: abranson $
*/
+import java.io.IOException;
import java.net.MalformedURLException;
-import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
@@ -51,6 +51,7 @@ import com.c2kernel.utils.server.SimpleTCPIPServer; public class Gateway
{
static private Properties mC2KProps;
+ static private ModuleManager mModules;
static private org.omg.CORBA.ORB mORB;
static private LDAPLookup mLDAPLookup;
static private TransactionManager mStorage;
@@ -59,6 +60,7 @@ public class Gateway static private SimpleTCPIPServer mHTTPServer;
+
private Gateway() { }
/**
@@ -69,18 +71,21 @@ public class Gateway * If null, the java system properties are used
* @throws InvalidDataException - invalid properties caused a failure in initialisation
*/
- static public void init(Properties props) throws InvalidDataException {
+ static public void init(Properties props, boolean isServer) throws InvalidDataException {
+
// if supplied props are null, use system props
if (props == null) props = System.getProperties();
- // set resource URLs from config
- String resURL = props.getProperty("KernelResourceURL");
- if (resURL != null && resURL.length()>0)
- Resource.setKernelBaseURL(resURL);
-
- resURL = props.getProperty("DomainResourceURL");
- if (resURL != null && resURL.length()>0)
- Resource.setDomainBaseURL(resURL);
+ // report version info
+ Logger.msg("Kernel version: "+Resource.getKernelVersion());
+
+ // init module manager
+ try {
+ mModules = new ModuleManager(ClassLoader.getSystemResources("module.xml"), isServer);
+ } catch (IOException e) {
+ Logger.error(e);
+ throw new InvalidDataException("Could not load module definitions. Classpath problem", "");
+ }
// Start with default props from kernel jar
try {
@@ -88,6 +93,13 @@ public class Gateway } catch (MalformedURLException ex) {
Logger.die("Default properties not found. Probable cause is missing resources");
}
+
+ // merge in module props
+ Properties moduleProperties = mModules.getAllModuleProperties();
+ for (Enumeration<?> e = moduleProperties.propertyNames(); e.hasMoreElements();) {
+ String propName = (String)e.nextElement();
+ mC2KProps.put(propName, moduleProperties.get(propName));
+ }
// Overwrite with supplied props
for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) {
@@ -98,15 +110,9 @@ public class Gateway // dump properties
dumpC2KProps(7);
- // report version info
- Logger.msg("Domain version: "+Resource.getDomainVersion());
- Logger.msg("Kernel version: "+Resource.getKernelVersion());
-
- // load kernel and domain mapfiles
+ // load kernel mapfiles
try {
CastorXMLUtility.loadMapsFrom(Resource.getKernelResourceURL("mapFiles/"));
- if (Resource.getDomainBaseURL()!=null)
- CastorXMLUtility.loadMapsFrom(Resource.getDomainResourceURL("mapFiles/"));
} catch (MalformedURLException e1) {
throw new InvalidDataException("Invalid Resource Location", "");
}
@@ -117,12 +123,9 @@ public class Gateway Language.isTranlated=true;
Language.mTableOfTranslation = FileStringUtility.loadLanguageFile(languageFile);
}
-
- try {
- Resource.setImportURL(new URL("file:"+getProperty("Import.dir")));
- } catch (MalformedURLException e) {
- Logger.error("Import directory not set. "+getProperty("Import.dir"));
- }
+
+ // run module startup scripts
+ mModules.runScripts("startup");
}
/**
@@ -162,25 +165,32 @@ public class Gateway // start checking bootstrap items
Bootstrap.run();
+ // register modules
+ mModules.registerModules();
+
} catch (Exception ex) {
Logger.error(ex);
Logger.die("Exception starting server components. Shutting down.");
}
// start the http server
- try {
- int httpPort = Integer.parseInt(Gateway.getProperty("ItemServer.HTTP.port"));
- Logger.msg(2, "Starting HTTP Server on port "+httpPort);
- mHTTPServer = new SimpleTCPIPServer(httpPort, ItemHTTPBridge.class, 5);
- mHTTPServer.startListening();
- } catch (NumberFormatException ex) {
- Logger.msg(3, "Invalid or no HTTP port defined. HTTP server not available.");
- }
+// try {
+// int httpPort = Integer.parseInt(Gateway.getProperty("ItemServer.HTTP.port"));
+// Logger.msg(2, "Starting HTTP Server on port "+httpPort);
+// mHTTPServer = new SimpleTCPIPServer(httpPort, ItemHTTPBridge.class, 5);
+// mHTTPServer.startListening();
+// } catch (NumberFormatException ex) {
+// Logger.msg(3, "Invalid or no HTTP port defined. HTTP server not available.");
+// }
System.out.println("Server '"+Gateway.getCentreId()+"' initialised.");
}
- /**
+ public static ModuleManager getModuleManager() {
+ return mModules;
+ }
+
+ /**
* Connects to the LDAP server in an administrative context - using the admin username and
* password given in the LDAP.user and LDAP.password props of the kernel properties.
*
@@ -327,6 +337,9 @@ public class Gateway */
public static void close()
{
+ // run shutdown module scripts
+ mModules.runScripts("shutdown");
+
// shut down servers if running
if (mCorbaServer != null)
mCorbaServer.close();
diff --git a/source/com/c2kernel/process/Module.java b/source/com/c2kernel/process/Module.java new file mode 100644 index 0000000..e32c72e --- /dev/null +++ b/source/com/c2kernel/process/Module.java @@ -0,0 +1,303 @@ +package com.c2kernel.process;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.InputSource;
+
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.ItemProxy;
+import com.c2kernel.events.Event;
+import com.c2kernel.events.History;
+import com.c2kernel.lifecycle.instance.predefined.entitycreation.Dependency;
+import com.c2kernel.lifecycle.instance.predefined.entitycreation.DependencyMember;
+import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewAgent;
+import com.c2kernel.lifecycle.instance.predefined.entitycreation.NewItem;
+import com.c2kernel.lifecycle.instance.predefined.entitycreation.Property;
+import com.c2kernel.lifecycle.instance.stateMachine.States;
+import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.persistency.outcome.Viewpoint;
+import com.c2kernel.scripting.ErrorInfo;
+import com.c2kernel.scripting.Script;
+import com.c2kernel.scripting.ScriptingEngineException;
+import com.c2kernel.utils.CastorXMLUtility;
+import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.Resource;
+
+public class Module {
+
+ private final String ns, name, desc, version;
+ private String resURL;
+ private final ArrayList<String> dependency = new ArrayList<String>();
+ private final Properties clientProps = new Properties();
+ private final Properties serverProps = new Properties();
+ private final HashMap<String, Script> clientScripts = new HashMap<String, Script>();
+ private final HashMap<String, Script> serverScripts = new HashMap<String, Script>();
+ private final ArrayList<ModuleImport> imports = new ArrayList<ModuleImport>();
+ private static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ private final DocumentBuilder parser;
+
+ static {
+ dbf.setValidating(false);
+ dbf.setNamespaceAware(false);
+ }
+
+ public Module(String moduleXML) throws Exception {
+ parser = dbf.newDocumentBuilder();
+ Document moduleDOM = parser.parse(new InputSource(new StringReader(moduleXML)));
+
+ Element root = (Element)moduleDOM.getElementsByTagName("CristalModule").item(0);
+
+ // Get module metadata
+ ns = root.getAttribute("ns");
+ name = root.getAttribute("name");
+ Element info = (Element)moduleDOM.getElementsByTagName("Info").item(0);
+ desc = ((Text)info.getElementsByTagName("Description").item(0).getFirstChild()).getData();
+ version = ((Text)info.getElementsByTagName("Version").item(0).getFirstChild()).getData();
+ NodeList nl = info.getElementsByTagName("Dependency");
+ for (int i=0; i<nl.getLength();i++)
+ dependency.add(((Text)nl.item(i).getFirstChild()).getData());
+
+ // register resource URL
+ nl = root.getElementsByTagName("ResourceURL");
+ if (nl.getLength()>0) {
+ resURL = ((Text)nl.item(0).getFirstChild()).getData();
+ Resource.addModuleBaseURL(ns, resURL);
+ }
+
+ // Get config properties
+ nl = root.getElementsByTagName("Config");
+ for (int i=0; i<nl.getLength();i++) {
+ Element confElement = (Element)nl.item(i);
+ String target = confElement.getAttribute("target");
+ String name = confElement.getAttribute("name");
+ String value = ((Text)confElement.getFirstChild()).getData();
+ // target can be 'client', 'server' or missing, which implies both.
+ if (!target.equals("client")) serverProps.put(name, value);
+ if (!target.equals("server")) clientProps.put(name, value);
+ }
+
+ // find scripts
+ nl = root.getElementsByTagName("Script");
+ for (int i=0; i<nl.getLength();i++) {
+ Element confElement = (Element)nl.item(i);
+ String target = confElement.getAttribute("target");
+ String event = confElement.getAttribute("event");
+ String lang = confElement.getAttribute("lang");
+ Script thisScript = new Script(lang, ((Text)confElement.getFirstChild()).getData(), ErrorInfo.class);
+ // target can be 'client', 'server' or missing, which implies both.
+ if (!target.equals("client")) serverScripts.put(event, thisScript);
+ if (!target.equals("server")) clientScripts.put(event, thisScript);
+ }
+
+ // Get imports
+ nl = moduleDOM.getElementsByTagName("Imports");
+ if (nl.getLength()>0) {
+ Element impElem = (Element)nl.item(0);
+ nl = impElem.getChildNodes();
+ for (int i=0; i<nl.getLength();i++) {
+ if (!(nl.item(i) instanceof Element)) continue;
+ Element imp = (Element)nl.item(i);
+ ModuleImport newImp;
+ String type = imp.getTagName();
+ if (type.equals("Resource")) {
+ ModuleResource newRes = new ModuleResource();
+ newRes.resourceType = imp.getAttribute("type");
+ newRes.resourceLocation = ((Text)imp.getFirstChild()).getData();
+ newImp = newRes;
+ }
+ else if (type.equals("Item")) {
+ ModuleItem newItem = new ModuleItem();
+ newItem.workflow = imp.getAttribute("workflow");
+ NodeList pnl = imp.getElementsByTagName("Property");
+ for (int j=0; j<pnl.getLength(); j++) {
+ Element p = (Element)pnl.item(j);
+ newItem.props.add(new Property(p.getAttribute("name"), ((Text)p.getFirstChild()).getData()));
+ }
+ NodeList ocnl = imp.getElementsByTagName("Outcome");
+ for (int j=0; j<ocnl.getLength(); j++) {
+ Element oc = (Element)ocnl.item(j);
+ newItem.outcomes.put(oc.getAttribute("schema")+":"+oc.getAttribute("version")+":"+oc.getAttribute("viewname"), ((Text)oc.getFirstChild()).getData());
+ }
+ NodeList depnl = imp.getElementsByTagName("Dependency");
+ for (int j=0; j<depnl.getLength(); j++) {
+ Element dep = (Element)depnl.item(j);
+ Dependency newDep = new Dependency();
+ newDep.name = dep.getAttribute("name");
+ NodeList depmemnl = dep.getElementsByTagName("DependencyMember");
+ for (int k=0; k<depmemnl.getLength(); k++) {
+ newDep.dependencyMemberList.add(new DependencyMember(((Text)depmemnl.item(k).getFirstChild()).getData()));
+ }
+ newItem.deps.add(newDep);
+ }
+ newImp = newItem;
+ }
+ else if (type.equals("Agent")) {
+ ModuleAgent newAgent = new ModuleAgent();
+ newAgent.password = imp.getAttribute("password");
+ NodeList rolenl = imp.getElementsByTagName("Role");
+ for (int j=0; j<rolenl.getLength(); j++) {
+ newAgent.roles.add(((Text)rolenl.item(j).getFirstChild()).getData());
+ }
+ newImp = newAgent;
+ }
+ else {
+ Logger.warning("Unknown import type "+type);
+ continue;
+ }
+
+ newImp.importName = imp.getAttribute("name");
+ imports.add(newImp);
+ }
+ }
+
+ }
+
+ public ErrorInfo runScript(String event, boolean isServer) {
+ HashMap<String, Script> scripts = isServer?serverScripts:clientScripts;
+ Script thisScript = scripts.get(event);
+ if (thisScript == null) return null;
+ try {
+ Object result = thisScript.execute();
+ if (result instanceof ErrorInfo)
+ return (ErrorInfo)result;
+ else
+ return new ErrorInfo(result.toString());
+ } catch (ScriptingEngineException ex) {
+ Logger.error(ex);
+ return new ErrorInfo("Error running "+event+" script in module "+ns);
+ }
+ }
+
+ public void importAll(ItemProxy serverEntity) {
+ for (ModuleImport thisImp : imports) {
+ if (thisImp instanceof ModuleResource) {
+ ModuleResource thisRes = (ModuleResource)thisImp;
+ try {
+ Bootstrap.verifyResource(ns, thisRes.importName, thisRes.resourceType, Resource.getTextResource(ns, thisRes.resourceLocation));
+ } catch (Exception ex) {
+ Logger.error(ex);
+ }
+ }
+ else if (thisImp instanceof ModuleItem) {
+ ModuleItem thisItem = (ModuleItem)thisImp;
+ try {
+ NewItem item = new NewItem(thisItem.importName, "/desc/"+ns, thisItem.workflow);
+ item.propertyList = thisItem.props;
+ DomainPath itemPath = new DomainPath(new DomainPath(item.initialPath), item.name);
+ if (itemPath.exists()) continue;
+ serverEntity.requestAction(
+ Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(),
+ "workflow/predefined/CreateNewItem",
+ Transitions.DONE,
+ CastorXMLUtility.marshall(item));
+ Logger.msg("Module.importAll() - Created item: "+thisItem.importName);
+ ItemProxy newProxy = (ItemProxy)Gateway.getProxyManager().getProxy(itemPath);
+ History hist = (History)newProxy.getObject(ClusterStorage.HISTORY);
+ for (String thisView : thisItem.outcomes.keySet()) {
+ String[] info = thisView.split(":");
+ int version = Integer.parseInt(info[1]);
+ String data = Resource.getTextResource(ns, thisItem.outcomes.get(thisView));
+ Event newEvent = hist.addEvent("system", "Admin", Transitions.DONE, "Import", "Import", "Import", States.FINISHED);
+ Outcome newOutcome = new Outcome(newEvent.getID(), data, info[0], version);
+ Viewpoint newLastView = new Viewpoint(newProxy.getSystemKey(), info[0], info[2], version, newEvent.getID());
+ Gateway.getStorage().put(newProxy.getSystemKey(), newOutcome, newProxy);
+ Gateway.getStorage().put(newProxy.getSystemKey(), newLastView, newProxy);
+ }
+ for (Dependency thisDep : thisItem.deps) {
+ Gateway.getStorage().put(newProxy.getSystemKey(), thisDep.create(), newProxy);
+ }
+ Gateway.getStorage().commit(newProxy);
+ } catch (Exception ex) {
+ Logger.error("Error importing item "+thisItem.importName+" from module "+name);
+ Logger.error(ex);
+ }
+ }
+ else if (thisImp instanceof ModuleAgent) {
+ ModuleAgent thisAgent = (ModuleAgent)thisImp;
+ try {
+ Gateway.getLDAPLookup().getRoleManager().getAgentPath(thisAgent.importName);
+ Logger.msg(3, "Module.importAll() - User '"+thisAgent.importName+"' found.");
+ return;
+ } catch (ObjectNotFoundException ex) { }
+ Logger.msg("Module.importAll() - User '"+thisAgent.importName+"' not found. Creating.");
+
+ NewAgent agent = new NewAgent(thisAgent.importName, thisAgent.password);
+ agent.roles = thisAgent.roles;
+ try {
+ serverEntity.requestAction(
+ Gateway.getLDAPLookup().getRoleManager().getAgentPath("system").getSysKey(),
+ "workflow/predefined/CreateNewAgent",
+ Transitions.DONE,
+ CastorXMLUtility.marshall(agent));
+ } catch (Exception ex) {
+ Logger.error("Error importing agent "+thisAgent.importName+" from module "+name);
+ Logger.error(ex);
+ }
+ }
+ }
+ }
+
+ public Properties getClientProperties() {
+ return clientProps;
+ }
+
+ public Properties getServerProperties() {
+ return serverProps;
+ }
+
+ public String getNs() {
+ return ns;
+ }
+ public String getName() {
+ return name;
+ }
+ public String getDesc() {
+ return desc;
+ }
+ public String getVersion() {
+ return version;
+ }
+ public String getResURL() {
+ return resURL;
+ }
+ public ArrayList<String> getDependencies() {
+ return dependency;
+ }
+ public boolean hasDependency(String dep) {
+ return dependency.contains(dep);
+ }
+
+ public abstract class ModuleImport {
+ String importName;
+ }
+
+ public class ModuleResource extends ModuleImport {
+ String resourceType;
+ String resourceLocation;
+ }
+
+ public class ModuleItem extends ModuleImport {
+ ArrayList<Property> props = new ArrayList<Property>();
+ HashMap<String, String> outcomes = new HashMap<String, String>();
+ ArrayList<Dependency> deps = new ArrayList<Dependency>();
+ String workflow;
+ }
+
+ public class ModuleAgent extends ModuleImport {
+ String password;
+ ArrayList<String> roles = new ArrayList<String>();
+ }
+}
\ No newline at end of file diff --git a/source/com/c2kernel/process/ModuleManager.java b/source/com/c2kernel/process/ModuleManager.java new file mode 100644 index 0000000..e067a88 --- /dev/null +++ b/source/com/c2kernel/process/ModuleManager.java @@ -0,0 +1,81 @@ +package com.c2kernel.process;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.entity.proxy.ItemProxy;
+import com.c2kernel.lookup.DomainPath;
+import com.c2kernel.utils.FileStringUtility;
+import com.c2kernel.utils.Logger;
+
+public class ModuleManager {
+ ArrayList<Module> modules = new ArrayList<Module>();
+ Properties props = new Properties();
+ boolean isServer;
+
+ public ModuleManager(Enumeration<URL> moduleEnum, boolean isServer) {
+ this.isServer = isServer;
+ ArrayList<String> loadedModules = new ArrayList<String>();
+ while(moduleEnum.hasMoreElements()) {
+ URL newModuleURL = moduleEnum.nextElement();
+ try {
+ Module newModule = new Module(FileStringUtility.url2String(newModuleURL));
+ modules.add(newModule);
+ loadedModules.add(newModule.getName());
+ Properties modProp = isServer?newModule.getServerProperties():newModule.getClientProperties();
+ for (Enumeration<?> e = modProp.propertyNames(); e.hasMoreElements();) {
+ String propName = (String)e.nextElement();
+ props.put(propName, modProp.get(propName));
+ }
+ } catch (Exception e) {
+ Logger.error("Could not load module description from "+newModuleURL);
+ Logger.error(e);
+ }
+ }
+
+ Logger.debug(5, "Checking dependencies");
+ boolean depFailed = false;
+ for (Module thisMod : modules) {
+ ArrayList<String> deps = thisMod.getDependencies();
+ for (String dep : deps) {
+ if (!loadedModules.contains(dep)) {
+ Logger.error("UNMET MODULE DEPENDENCY: "+thisMod.getName()+" requires "+dep);
+ depFailed = true;
+ }
+ }
+ }
+ if (depFailed) Logger.die("Unmet module dependencies. Cannot continue");
+ }
+
+ public String getModuleVersions() {
+ StringBuffer ver = new StringBuffer();
+ for (Module thisMod : modules) {
+ if (ver.length()>0) ver.append(";");
+ ver.append(thisMod.getName()+"("+thisMod.getVersion()+")");
+ }
+ return ver.toString();
+ }
+
+
+ public Properties getAllModuleProperties() {
+ return props;
+ }
+
+ public void runScripts(String event) {
+ for (Module thisMod : modules) {
+ thisMod.runScript(event, isServer);
+ }
+ }
+
+ public void registerModules() throws ObjectNotFoundException {
+ ItemProxy serverEntity = (ItemProxy)Gateway.getProxyManager().getProxy(new DomainPath("/servers/"+Gateway.getProperty("ItemServer.name")));
+ Logger.debug(3, "Registering modules");
+ for (Module thisMod : modules) {
+ Logger.debug(4, "Registering module "+thisMod.getName());
+ thisMod.importAll(serverEntity);
+ }
+ }
+}
diff --git a/source/com/c2kernel/process/StandardServer.java b/source/com/c2kernel/process/StandardServer.java index 72b761e..6804da5 100644 --- a/source/com/c2kernel/process/StandardServer.java +++ b/source/com/c2kernel/process/StandardServer.java @@ -43,7 +43,7 @@ public class StandardServer extends AbstractMain implements WrapperListener throws Exception
{
// read args and init Gateway
- standardSetUp(args);
+ Gateway.init(readC2KArgs(args), true);
// connect to LDAP as root
Gateway.connect();
@@ -112,8 +112,7 @@ public class StandardServer extends AbstractMain implements WrapperListener public int stop(int arg0) {
try
{
- // close gateway
- standardTearDown();
+ Gateway.close();
}
catch( Exception ex )
{
diff --git a/source/com/c2kernel/process/UserCodeProcess.java b/source/com/c2kernel/process/UserCodeProcess.java index 9c2deab..7779802 100644 --- a/source/com/c2kernel/process/UserCodeProcess.java +++ b/source/com/c2kernel/process/UserCodeProcess.java @@ -125,7 +125,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv // shut down
try
{
- standardTearDown();
+ Gateway.close();
}
catch( Exception ex )
{
@@ -196,7 +196,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv try
{
- standardSetUp(args);
+ Gateway.init(readC2KArgs(args), false);
UserCodeProcess proc = getInstance();
new Thread(proc).start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@@ -212,7 +212,7 @@ public class UserCodeProcess extends StandardClient implements EntityProxyObserv try
{
- standardTearDown();
+ Gateway.close();
}
catch(Exception ex1)
{
diff --git a/source/com/c2kernel/scripting/ErrorInfo.java b/source/com/c2kernel/scripting/ErrorInfo.java index f14038f..26c0384 100644 --- a/source/com/c2kernel/scripting/ErrorInfo.java +++ b/source/com/c2kernel/scripting/ErrorInfo.java @@ -18,6 +18,11 @@ public class ErrorInfo { super();
msg = new ArrayList<String>();
}
+
+ public ErrorInfo(String error) {
+ this();
+ msg.add(error);
+ }
public void addError(String error) {
msg.add(error);
diff --git a/source/com/c2kernel/scripting/Script.java b/source/com/c2kernel/scripting/Script.java index 0820c26..c056e95 100644 --- a/source/com/c2kernel/scripting/Script.java +++ b/source/com/c2kernel/scripting/Script.java @@ -72,19 +72,24 @@ public class Script * Creates a script executor for the supplied expression, bypassing the xml parsing bit
* Output class is forced to an object.
*/
- public Script(String lang, String expr, BSFManager scriptManager) throws ScriptingEngineException
+ public Script(String lang, String expr, BSFManager scriptManager, Class<?> returnType) throws ScriptingEngineException
{
setScriptEnv(scriptManager);
mName = "<expr>";
mLang = lang;
mVersion = "";
- mOutputClass = Object.class;
+ mOutputClass = returnType;
mScript = expr;
}
public Script(String lang, String expr) throws ScriptingEngineException
{
- this(lang, expr, new BSFManager());
+ this(lang, expr, new BSFManager(), Object.class);
+ }
+
+ public Script(String lang, String expr, Class<?> returnType) throws ScriptingEngineException
+ {
+ this(lang, expr, new BSFManager(), returnType);
}
public Script(ItemProxy object, AgentProxy subject, Job job) throws ScriptingEngineException
diff --git a/source/com/c2kernel/scripting/ScriptConsole.java b/source/com/c2kernel/scripting/ScriptConsole.java index 33d4b7f..99ad90f 100644 --- a/source/com/c2kernel/scripting/ScriptConsole.java +++ b/source/com/c2kernel/scripting/ScriptConsole.java @@ -194,13 +194,13 @@ public class ScriptConsole implements SocketHandler { } catch (NumberFormatException ex) { }
}
else if(command.equals("help")) {
- output.println(Resource.getTextResource("textFiles/consoleHelp.txt"));
+ output.println(Resource.findTextResource("textFiles/consoleHelp.txt"));
continue;
}
else if(command.equals("version")) {
- output.println("Domain version: "+Resource.getDomainVersion());
output.println("Kernel version: "+Resource.getKernelVersion());
- continue;
+ output.println("Modules loaded: "+Gateway.getModuleManager().getModuleVersions());
+ continue;
}
try {
if (command.endsWith("\\")) {
diff --git a/source/com/c2kernel/utils/CastorArrayList.java b/source/com/c2kernel/utils/CastorArrayList.java index ed15c0f..ea9a090 100644 --- a/source/com/c2kernel/utils/CastorArrayList.java +++ b/source/com/c2kernel/utils/CastorArrayList.java @@ -15,7 +15,7 @@ import java.util.ArrayList; * All rights reserved.
**************************************************************************/
//
-abstract public class CastorArrayList<T> implements Serializable{
+abstract public class CastorArrayList<T> implements Serializable {
public ArrayList<T> list;
public CastorArrayList() {
diff --git a/source/com/c2kernel/utils/Resource.java b/source/com/c2kernel/utils/Resource.java index ba2f71a..10228da 100644 --- a/source/com/c2kernel/utils/Resource.java +++ b/source/com/c2kernel/utils/Resource.java @@ -3,7 +3,7 @@ package com.c2kernel.utils; //Java
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Hashtable;
import javax.swing.ImageIcon;
@@ -19,42 +19,36 @@ public class Resource { static private Hashtable<String, String> txtCache = new Hashtable<String, String>();
static private Hashtable<String, ImageIcon> imgCache = new Hashtable<String, ImageIcon>();
static private URL baseURL = getURLorResURL("com/c2kernel/utils/resources/");
- static private ArrayList<URL> domainBaseURL = new ArrayList<URL>();
- static public ImageIcon nullImg = new ImageIcon(new byte[] { 0 });
-
- /*
- * Kernel Resource URL section
- */
- public static void setKernelBaseURL(String newBaseURL) {
- baseURL = getURLorResURL(newBaseURL);
- }
+ static private HashMap<String, URL> moduleBaseURLs = new HashMap<String, URL>();
+ static public final ImageIcon nullImg = new ImageIcon(new byte[] { 0 });
public static URL getKernelBaseURL() {
return baseURL;
}
- static public URL getKernelResourceURL(String resName) throws MalformedURLException {
+ public static URL getKernelResourceURL(String resName) throws MalformedURLException {
return new URL(baseURL, resName);
}
-
- /*
- * Domain Resource URL section
- */
- public static void addDomainBaseURL(URL newBaseURL) {
- domainBaseURL.add(newBaseURL);
+ public static void addModuleBaseURL(String ns, URL newBaseURL) {
+ moduleBaseURLs.put(ns, newBaseURL);
+ Logger.msg("Adding resource URL for "+ns+": "+newBaseURL.toString());
}
- public static void addDomainBaseURL(String newBaseURL) {
- addDomainBaseURL(getURLorResURL(newBaseURL));
+ public static void addModuleBaseURL(String ns, String newBaseURL) {
+ addModuleBaseURL(ns, getURLorResURL(newBaseURL));
}
- public static ArrayList<URL> getDomainBaseURL() {
- return domainBaseURL;
+ public static URL getModuleBaseURL(String ns) {
+ return moduleBaseURLs.get(ns);
+ }
+
+ public static HashMap<String, URL> getModuleBaseURLs() {
+ return moduleBaseURLs;
}
- static public URL getDomainResourceURL(String resName) throws MalformedURLException {
- return new URL(domainBaseURL, resName);
+ static public URL getModuleResourceURL(String ns, String resName) throws MalformedURLException {
+ return new URL(moduleBaseURLs.get(ns), resName);
}
private static URL getURLorResURL(String newURL) {
@@ -71,29 +65,44 @@ public class Resource { /**************************************************************************
* Gets any text resource files
**************************************************************************/
- static public String getTextResource(String resName)
+
+ static public String findTextResource(String resName) {
+ try {
+ for (String ns : getModuleBaseURLs().keySet()) {
+ try {
+ return getTextResource(ns, resName);
+ } catch (ObjectNotFoundException ex) { }
+ }
+ return getTextResource(null, resName);
+ } catch (ObjectNotFoundException ex) {
+ Logger.warning("Text resource '"+resName+"' not found.");
+ return null;
+ }
+ }
+
+ static public String getTextResource(String ns, String resName) throws ObjectNotFoundException
// throws IOException
{
Logger.msg(8, "Resource::getTextResource() - Getting resource: " + resName);
- if (txtCache.containsKey(resName)) {
- return txtCache.get(resName);
+ if (txtCache.containsKey(ns+'/'+resName)) {
+ return txtCache.get(ns+'/'+resName);
}
try {
String newRes = null;
- try {
- newRes = FileStringUtility.url2String(getDomainResourceURL(resName));
- } catch (Exception ex) { } // no domain base
-
- if (newRes == null || newRes.length() == 0) { // not found in domain
- newRes = FileStringUtility.url2String(getKernelResourceURL(resName));
- }
- txtCache.put(resName, newRes);
+ URL loc;
+
+ if (ns == null) // kernel
+ loc = getKernelResourceURL(resName);
+ else
+ loc = getModuleResourceURL(ns, resName);
+ newRes = FileStringUtility.url2String(loc);
+ txtCache.put(ns+'/'+resName, newRes);
return newRes;
} catch (Exception e) {
- return null;
+ throw new ObjectNotFoundException(e.getMessage(),null);
}
}
/**
@@ -102,57 +111,48 @@ public class Resource { * @param resName - filename after resources/images
* @return
*/
- static public ImageIcon getImageResource(String resName) {
+ static public ImageIcon findImage(String resName) {
try {
- return getImage(resName);
+ for (String ns : getModuleBaseURLs().keySet()) {
+ try {
+ return getImage(ns, resName);
+ } catch (ObjectNotFoundException ex) { }
+ }
+ return getImage(null, resName);
} catch (ObjectNotFoundException ex) {
- Logger.error("Image "+resName+" not found. Using null icon");
+ Logger.warning("Image '"+resName+"' not found. Using null icon");
return nullImg;
}
}
- static public ImageIcon getImage(String resName) throws ObjectNotFoundException {
+ static public ImageIcon getImage(String ns, String resName) throws ObjectNotFoundException {
if (resName == null)
return nullImg;
- if (imgCache.containsKey(resName)) {
- return imgCache.get(resName);
+ if (imgCache.containsKey(ns+'/'+resName)) {
+ return imgCache.get(ns+'/'+resName);
}
URL imgLocation = null;
- ImageIcon newImg = null;
- // try domain resources first
- if (domainBaseURL != null) {
- try {
- imgLocation = new URL(domainBaseURL + "images/" + resName.toLowerCase());
- newImg = new ImageIcon(imgLocation);
- } catch (MalformedURLException e) { }
- }
-
- // try kernel resources next
- if (newImg == null || newImg.getIconHeight() == -1) {
- try {
- imgLocation = new URL(baseURL + "images/" + resName.toLowerCase());
- newImg = new ImageIcon(imgLocation);
- } catch (MalformedURLException e) { }
- }
-
- // else return null image
- if (newImg == null || newImg.getIconHeight() == -1) {
- throw new ObjectNotFoundException();
- }
-
- else imgCache.put(resName, newImg);
- Logger.msg(7, "Loaded "+resName+" "+newImg.getIconWidth()+"x"+newImg.getIconHeight());
- return newImg;
- }
-
- static public String getDomainVersion() {
- try {
- return FileStringUtility.url2String(getDomainResourceURL("version.txt"));
- } catch (Exception ex) {
- return "Domain application version not found";
- }
+ if (ns == null)
+ try {
+ imgLocation = getKernelResourceURL("images/"+resName);
+ } catch (MalformedURLException ex) { }
+ else
+ try {
+ imgLocation = getModuleResourceURL(ns, "images/"+resName);
+ } catch (MalformedURLException ex) { }
+
+ if (imgLocation!= null) {
+ ImageIcon newImg = new ImageIcon(imgLocation);
+
+ if (newImg.getIconHeight() > -1) {
+ imgCache.put(ns+'/'+resName, newImg);
+ Logger.msg(0, "Loaded "+resName+" "+newImg.getIconWidth()+"x"+newImg.getIconHeight());
+ return newImg;
+ }
+ }
+ throw new ObjectNotFoundException();
}
static public String getKernelVersion() {
|
