diff --git a/src/main/java/li/strolch/runtime/agent/AgentLifecycleController.java b/src/main/java/li/strolch/runtime/agent/AgentLifecycleController.java
new file mode 100644
index 000000000..47810b43b
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/AgentLifecycleController.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public interface AgentLifecycleController {
+
+ public void initialize();
+
+ public void start();
+
+ public void stop();
+
+ public void destroy();
+}
diff --git a/src/main/java/li/strolch/runtime/agent/DataStoreMode.java b/src/main/java/li/strolch/runtime/agent/DataStoreMode.java
new file mode 100644
index 000000000..fd285874a
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/DataStoreMode.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import java.text.MessageFormat;
+
+import li.strolch.runtime.configuration.ComponentConfiguration;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public enum DataStoreMode {
+ EMPTY {
+ @Override
+ public AgentLifecycleController getAgentLifecycleController(StrolchAgent strolchAgent,
+ ComponentConfiguration configuration) {
+ return new EmptyDataStoreModeAgentInitializer(strolchAgent, configuration);
+ }
+ }, //
+ TRANSIENT {
+ @Override
+ public AgentLifecycleController getAgentLifecycleController(StrolchAgent strolchAgent,
+ ComponentConfiguration configuration) {
+ return new TransientDataStoreModeAgentInitializer(strolchAgent, configuration);
+ }
+ }, //
+ CACHED {
+ @Override
+ public AgentLifecycleController getAgentLifecycleController(StrolchAgent strolchAgent,
+ ComponentConfiguration configuration) {
+ throw new UnsupportedOperationException(MessageFormat.format("The mode {0} is not yet supported!", this)); //$NON-NLS-1$
+ }
+ }, //
+ TRANSACTIONAL {
+ @Override
+ public AgentLifecycleController getAgentLifecycleController(StrolchAgent strolchAgent,
+ ComponentConfiguration configuration) {
+ throw new UnsupportedOperationException(MessageFormat.format("The mode {0} is not yet supported!", this)); //$NON-NLS-1$
+ }
+ }; //
+
+ public AgentLifecycleController getAgentLifecycleController(StrolchAgent strolchAgent,
+ ComponentConfiguration configuration) {
+ throw new UnsupportedOperationException("Please implement in enum!"); //$NON-NLS-1$
+ }
+
+ public static DataStoreMode parseDataStoreMode(String modeS) {
+ for (DataStoreMode dataStoreMode : values()) {
+ if (dataStoreMode.name().endsWith(modeS))
+ return dataStoreMode;
+ }
+
+ throw new IllegalArgumentException(MessageFormat.format("There is no data store mode ''{0}''", modeS)); //$NON-NLS-1$
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/agent/ElementMap.java b/src/main/java/li/strolch/runtime/agent/ElementMap.java
new file mode 100644
index 000000000..3baab9aae
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/ElementMap.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import li.strolch.model.StrolchElement;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public interface ElementMap {
+
+ public T getBy(String type, String id);
+
+ public void add(T element);
+
+ public void update(T element);
+
+ public void remove(T element);
+
+}
diff --git a/src/main/java/li/strolch/runtime/agent/EmptyDataStoreModeAgentInitializer.java b/src/main/java/li/strolch/runtime/agent/EmptyDataStoreModeAgentInitializer.java
new file mode 100644
index 000000000..3a8bfc339
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/EmptyDataStoreModeAgentInitializer.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import java.text.MessageFormat;
+
+import li.strolch.runtime.configuration.ComponentConfiguration;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class EmptyDataStoreModeAgentInitializer implements AgentLifecycleController {
+
+ public static final String PROP_DATA_STORE_MODEL_FILE = "dataStoreModelFile"; //$NON-NLS-1$
+
+ protected static final Logger logger = LoggerFactory.getLogger(EmptyDataStoreModeAgentInitializer.class);
+
+ protected StrolchAgent strolchAgent;
+ protected ComponentConfiguration configuration;
+ protected OrderMap orderMap;
+ protected ResourceMap resourceMap;
+
+ /**
+ * @param strolchAgent
+ * @param configuration
+ */
+ public EmptyDataStoreModeAgentInitializer(StrolchAgent strolchAgent, ComponentConfiguration configuration) {
+
+ if (strolchAgent == null)
+ throw new IllegalStateException("The StrolchAgent is not set!"); //$NON-NLS-1$
+ if (configuration == null)
+ throw new IllegalStateException("The ComponentConfiguration is not set!"); //$NON-NLS-1$
+ if (!strolchAgent.getName().equals(configuration.getName())) {
+ String msg = "The StrolchAgent and component configuration don't fit together as their names don't match: {0} / {1}"; //$NON-NLS-1$
+ msg = MessageFormat.format(msg, strolchAgent.getName(), configuration.getName());
+ throw new IllegalStateException(msg);
+ }
+
+ this.strolchAgent = strolchAgent;
+ this.configuration = configuration;
+ }
+
+ @Override
+ public void initialize() {
+ this.resourceMap = new InMemoryResourceMap();
+ this.orderMap = new InMemoryOrderMap();
+ }
+
+ @Override
+ public void start() {
+ this.strolchAgent.setResourceMap(this.resourceMap);
+ this.strolchAgent.setOrderMap(this.orderMap);
+ }
+
+ @Override
+ public void stop() {
+ this.strolchAgent.setResourceMap(null);
+ this.strolchAgent.setOrderMap(null);
+ }
+
+ @Override
+ public void destroy() {
+ this.strolchAgent.setResourceMap(null);
+ this.strolchAgent.setOrderMap(null);
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/agent/InMemoryElementMap.java b/src/main/java/li/strolch/runtime/agent/InMemoryElementMap.java
new file mode 100644
index 000000000..3ed3305c1
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/InMemoryElementMap.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+import li.strolch.model.StrolchElement;
+import ch.eitchnet.utils.helper.StringHelper;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public abstract class InMemoryElementMap implements ElementMap {
+
+ private Map> elementMap;
+
+ @Override
+ public T getBy(String type, String id) {
+ if (StringHelper.isEmpty(type) || StringHelper.isEmpty(id))
+ throw new IllegalArgumentException("type and id may not be null!"); //$NON-NLS-1$
+
+ Map byTypeMap = this.elementMap.get(type);
+ if (byTypeMap == null)
+ return null;
+
+ return byTypeMap.get(id);
+ }
+
+ @Override
+ public void add(T element) {
+ if (element == null)
+ throw new IllegalArgumentException("element may not be null!"); //$NON-NLS-1$
+
+ String type = element.getType();
+ Map byTypeMap = getByTypeMap(type);
+
+ if (byTypeMap.containsKey(element.getId())) {
+ String msg = MessageFormat.format("The element already exists with the locator {0}", element.getLocator()); //$NON-NLS-1$
+ throw new IllegalStateException(msg);
+ }
+
+ byTypeMap.put(element.getId(), element);
+ }
+
+ private Map getByTypeMap(String type) {
+ Map byTypeMap = this.elementMap.get(type);
+ if (byTypeMap == null) {
+ byTypeMap = new HashMap<>();
+ this.elementMap.put(type, byTypeMap);
+ }
+ return byTypeMap;
+ }
+
+ @Override
+ public void update(T element) {
+ if (element == null)
+ throw new IllegalArgumentException("element may not be null!"); //$NON-NLS-1$
+
+ String type = element.getType();
+ Map byTypeMap = getByTypeMap(type);
+ if (!byTypeMap.containsKey(element.getId())) {
+ String msg = "The element can not be updated as it does not exist in map with locator {0}"; //$NON-NLS-1$
+ msg = MessageFormat.format(msg, element.getLocator());
+ throw new IllegalStateException(msg);
+ }
+
+ byTypeMap.remove(element.getId());
+ byTypeMap.put(element.getId(), element);
+ }
+
+ @Override
+ public void remove(T element) {
+ if (element == null)
+ throw new IllegalArgumentException("element may not be null!"); //$NON-NLS-1$
+
+ String type = element.getType();
+ Map byTypeMap = getByTypeMap(type);
+ if (!byTypeMap.containsKey(element.getId())) {
+ String msg = "The element can not be removed as it does not exist in map with locator {0}"; //$NON-NLS-1$
+ msg = MessageFormat.format(msg, element.getLocator());
+ throw new IllegalStateException(msg);
+ }
+
+ byTypeMap.remove(element.getId());
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/agent/InMemoryOrderMap.java b/src/main/java/li/strolch/runtime/agent/InMemoryOrderMap.java
new file mode 100644
index 000000000..1e3676b98
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/InMemoryOrderMap.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import li.strolch.model.Order;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class InMemoryOrderMap extends InMemoryElementMap implements OrderMap {
+
+ //
+}
diff --git a/src/main/java/li/strolch/runtime/agent/InMemoryResourceMap.java b/src/main/java/li/strolch/runtime/agent/InMemoryResourceMap.java
new file mode 100644
index 000000000..7e74d45cd
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/InMemoryResourceMap.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import li.strolch.model.Resource;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class InMemoryResourceMap extends InMemoryElementMap implements ResourceMap {
+
+ //
+}
diff --git a/src/main/java/li/strolch/runtime/agent/ModelFileDefaultHandler.java b/src/main/java/li/strolch/runtime/agent/ModelFileDefaultHandler.java
new file mode 100644
index 000000000..fc5c3fb39
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/ModelFileDefaultHandler.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Date;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import li.strolch.exception.StrolchException;
+import li.strolch.model.Order;
+import li.strolch.model.ParameterBag;
+import li.strolch.model.Resource;
+import li.strolch.model.State;
+import li.strolch.model.Tags;
+import li.strolch.model.parameter.BooleanParameter;
+import li.strolch.model.parameter.DateParameter;
+import li.strolch.model.parameter.FloatParameter;
+import li.strolch.model.parameter.IntegerParameter;
+import li.strolch.model.parameter.LongParameter;
+import li.strolch.model.parameter.Parameter;
+import li.strolch.model.parameter.StringListParameter;
+import li.strolch.model.parameter.StringParameter;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import ch.eitchnet.utils.helper.StringHelper;
+import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class ModelFileDefaultHandler extends DefaultHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(ModelFileDefaultHandler.class);
+
+ private File modelFile;
+
+ private Resource resource;
+ private Order order;
+ private ParameterBag pBag;
+
+ public ModelFileDefaultHandler(File modelFile) {
+ this.modelFile = modelFile;
+ }
+
+ @SuppressWarnings("nls")
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
+
+ switch (qName) {
+ case Tags.RESOURCE:
+ String resId = attributes.getValue(Tags.ID);
+ String resName = attributes.getValue(Tags.NAME);
+ String resType = attributes.getValue(Tags.TYPE);
+ Resource resource = new Resource(resId, resName, resType);
+ this.resource = resource;
+ break;
+ case Tags.ORDER:
+ String orderId = attributes.getValue(Tags.ID);
+ String orderName = attributes.getValue(Tags.NAME);
+ String orderType = attributes.getValue(Tags.TYPE);
+ String orderDateS = attributes.getValue(Tags.DATE);
+ String orderStateS = attributes.getValue(Tags.STATE);
+ Date orderDate = ISO8601FormatFactory.getInstance().getDateFormat().parse(orderDateS);
+ State orderState = State.valueOf(orderStateS);
+ Order order = new Order(orderId, orderName, orderType, orderDate, orderState);
+ this.order = order;
+ break;
+ case Tags.PARAMETER_BAG:
+ String pBagId = attributes.getValue(Tags.ID);
+ String pBagName = attributes.getValue(Tags.NAME);
+ String pBagType = attributes.getValue(Tags.TYPE);
+ ParameterBag pBag = new ParameterBag(pBagId, pBagName, pBagType);
+ this.pBag = pBag;
+ break;
+ case Tags.PARAMETER:
+ String paramId = attributes.getValue(Tags.ID);
+ String paramName = attributes.getValue(Tags.NAME);
+ String paramType = attributes.getValue(Tags.TYPE);
+ String paramValue = attributes.getValue(Tags.VALUE);
+ String paramHiddenS = attributes.getValue(Tags.HIDDEN);
+ boolean paramHidden = StringHelper.parseBoolean(paramHiddenS);
+ String paramUom = attributes.getValue(Tags.UOM);
+ String paramInterpretation = attributes.getValue(Tags.INTERPRETATION);
+ Parameter> param;
+ switch (paramType) {
+ case StringParameter.TYPE:
+ param = new StringParameter(paramId, paramName, paramValue);
+ break;
+ case IntegerParameter.TYPE:
+ param = new IntegerParameter(paramId, paramName, IntegerParameter.parseFromString(paramValue));
+ break;
+ case BooleanParameter.TYPE:
+ param = new BooleanParameter(paramId, paramName, BooleanParameter.parseFromString(paramValue));
+ break;
+ case LongParameter.TYPE:
+ param = new LongParameter(paramId, paramName, LongParameter.parseFromString(paramValue));
+ break;
+ case DateParameter.TYPE:
+ param = new DateParameter(paramId, paramName, DateParameter.parseFromString(paramValue));
+ break;
+ case StringListParameter.TYPE:
+ param = new StringListParameter(paramId, paramName, StringListParameter.parseFromString(paramValue));
+ break;
+ case FloatParameter.TYPE:
+ param = new FloatParameter(paramId, paramName, FloatParameter.parseFromString(paramValue));
+ break;
+ default:
+ throw new UnsupportedOperationException("Parameters of type " + paramType + " are not supported!");
+ }
+ param.setHidden(paramHidden);
+ param.setUom(paramUom);
+ param.setInterpretation(paramInterpretation);
+ this.pBag.addParameter(param);
+ break;
+ default:
+ throw new IllegalArgumentException("The element '" + qName + "' is unhandled!");
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+
+ switch (qName) {
+ case Tags.RESOURCE:
+ this.resource = null;
+ break;
+ case Tags.ORDER:
+ this.order = null;
+ break;
+ case Tags.PARAMETER_BAG:
+ this.pBag = null;
+ break;
+ case Tags.PARAMETER:
+ break;
+ default:
+ throw new IllegalArgumentException("The element '" + qName + "' is unhandled!");
+ }
+ }
+
+ public void parseFile() {
+
+ try {
+
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ SAXParser sp = spf.newSAXParser();
+
+ sp.parse(this.modelFile, this);
+
+ String msg = "SAX parsed model file {0}"; //$NON-NLS-1$
+ logger.info(MessageFormat.format(msg, this.modelFile.getAbsolutePath()));
+
+ } catch (ParserConfigurationException | SAXException | IOException e) {
+
+ String msg = "Parsing failed due to internal error: {0}"; //$NON-NLS-1$
+ throw new StrolchException(MessageFormat.format(msg, e.getMessage()), e);
+ }
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/agent/OrderMap.java b/src/main/java/li/strolch/runtime/agent/OrderMap.java
new file mode 100644
index 000000000..c51882d9a
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/OrderMap.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import li.strolch.model.Order;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public interface OrderMap extends ElementMap {
+
+ //
+}
diff --git a/src/main/java/li/strolch/runtime/agent/ResourceMap.java b/src/main/java/li/strolch/runtime/agent/ResourceMap.java
new file mode 100644
index 000000000..bf4f07c72
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/ResourceMap.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import li.strolch.model.Resource;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public interface ResourceMap extends ElementMap {
+
+ //
+}
diff --git a/src/main/java/li/strolch/runtime/agent/StrolchAgent.java b/src/main/java/li/strolch/runtime/agent/StrolchAgent.java
new file mode 100644
index 000000000..f45b9ca32
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/StrolchAgent.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import li.strolch.runtime.component.ComponentContainer;
+import li.strolch.runtime.component.StrolchComponent;
+import li.strolch.runtime.configuration.ComponentConfiguration;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class StrolchAgent extends StrolchComponent {
+
+ public static final String PROP_DATA_STORE_MODE = "dataStoreMode"; //$NON-NLS-1$
+
+ private ResourceMap resourceMap;
+ private OrderMap orderMap;
+ private AgentLifecycleController agentInitializer;
+
+ /**
+ * @param container
+ * @param componentName
+ */
+ public StrolchAgent(ComponentContainer container, String componentName) {
+ super(container, componentName);
+ }
+
+ /**
+ * @param resourceMap
+ * the resourceMap to set
+ */
+ void setResourceMap(ResourceMap resourceMap) {
+ this.resourceMap = resourceMap;
+ }
+
+ /**
+ * @param orderMap
+ * the orderMap to set
+ */
+ void setOrderMap(OrderMap orderMap) {
+ this.orderMap = orderMap;
+ }
+
+ /**
+ * @return the resourceMap
+ */
+ public ResourceMap getResourceMap() {
+ return this.resourceMap;
+ }
+
+ /**
+ * @return the orderMap
+ */
+ public OrderMap getOrderMap() {
+ return this.orderMap;
+ }
+
+ @Override
+ public void initialize(ComponentConfiguration configuration) {
+
+ DataStoreMode dataStoreMode = DataStoreMode.parseDataStoreMode(configuration.getString(PROP_DATA_STORE_MODE,
+ null));
+ this.agentInitializer = dataStoreMode.getAgentLifecycleController(this, configuration);
+ this.agentInitializer.initialize();
+
+ super.initialize(configuration);
+ }
+
+ @Override
+ public void start() {
+ this.agentInitializer.start();
+ super.start();
+ }
+
+ @Override
+ public void stop() {
+ this.agentInitializer.stop();
+ super.stop();
+ }
+
+ @Override
+ public void destroy() {
+ this.agentInitializer.destroy();
+ super.destroy();
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/agent/TransientDataStoreModeAgentInitializer.java b/src/main/java/li/strolch/runtime/agent/TransientDataStoreModeAgentInitializer.java
new file mode 100644
index 000000000..eb99ef9be
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/agent/TransientDataStoreModeAgentInitializer.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.agent;
+
+import java.io.File;
+
+import li.strolch.runtime.configuration.ComponentConfiguration;
+import li.strolch.runtime.configuration.RuntimeConfiguration;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class TransientDataStoreModeAgentInitializer extends EmptyDataStoreModeAgentInitializer {
+
+ /**
+ * @param strolchAgent
+ * @param configuration
+ */
+ public TransientDataStoreModeAgentInitializer(StrolchAgent strolchAgent, ComponentConfiguration configuration) {
+ super(strolchAgent, configuration);
+ }
+
+ @Override
+ public void start() {
+
+ RuntimeConfiguration runtimeConfiguration = this.configuration.getRuntimeConfiguration();
+ File modelFile = this.configuration.getDataFile(PROP_DATA_STORE_MODEL_FILE, null, runtimeConfiguration, true);
+
+ ModelFileDefaultHandler handler = new ModelFileDefaultHandler(modelFile);
+ handler.parseFile();
+
+ super.start();
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/configuration/AbstractionConfiguration.java b/src/main/java/li/strolch/runtime/configuration/AbstractionConfiguration.java
index b47615640..e40fa2ba1 100644
--- a/src/main/java/li/strolch/runtime/configuration/AbstractionConfiguration.java
+++ b/src/main/java/li/strolch/runtime/configuration/AbstractionConfiguration.java
@@ -32,14 +32,7 @@ public abstract class AbstractionConfiguration {
}
public String getString(String key, String defValue) {
- String value = this.configurationValues.get(key);
- if (!StringHelper.isEmpty(value)) {
- return value;
- }
-
- assertDefValueExist(key, defValue);
- logDefValueUse(key, defValue);
- return defValue;
+ return getValue(key, defValue);
}
public boolean getBoolean(String key, Boolean defValue) {
@@ -96,22 +89,38 @@ public abstract class AbstractionConfiguration {
return defValue;
}
- public File getConfigFile(String key, String defValue, ComponentConfiguration configuration) {
+ public File getConfigFile(String key, String defValue, RuntimeConfiguration configuration) {
+ String value = getValue(key, defValue);
+
+ File configFile = new File(configuration.getConfigPath(), value);
+ if (!configFile.isFile() || !configFile.canRead()) {
+ String msg = "Component {0} requires configuration file ''{1}'' which does not exist with value: {2}"; //$NON-NLS-1$
+ msg = MessageFormat.format(msg, this.name, key, value);
+ throw new StrolchConfigurationException(msg);
+ }
+ return configFile;
+ }
+
+ public File getDataFile(String key, String defValue, RuntimeConfiguration configuration, boolean checkExists) {
+ String value = getValue(key, defValue);
+
+ File dataFile = new File(configuration.getDataPath(), value);
+ if (checkExists && !dataFile.isFile() || !dataFile.canRead()) {
+ String msg = "Component {0} requires data file ''{1}'' which does not exist with value: {2}"; //$NON-NLS-1$
+ msg = MessageFormat.format(msg, this.name, key, value);
+ throw new StrolchConfigurationException(msg);
+ }
+ return dataFile;
+ }
+
+ private String getValue(String key, String defValue) {
String value = this.configurationValues.get(key);
if (StringHelper.isEmpty(value)) {
assertDefValueExist(key, defValue);
logDefValueUse(key, defValue);
value = defValue;
}
-
- File configFile = new File(configuration.getRuntimeConfiguration().getConfigPath(), value);
- if (!configFile.isFile() || !configFile.canRead()) {
-
- String msg = "Component {0} is missing required configuration file {1}!"; //$NON-NLS-1$
- msg = MessageFormat.format(msg, this.name, key, value);
- throw new StrolchConfigurationException(msg);
- }
- return configFile;
+ return value;
}
private void logDefValueUse(String key, Object defValue) {
diff --git a/src/main/java/li/strolch/runtime/configuration/RuntimeConfiguration.java b/src/main/java/li/strolch/runtime/configuration/RuntimeConfiguration.java
index 7fe571569..d99df62c0 100644
--- a/src/main/java/li/strolch/runtime/configuration/RuntimeConfiguration.java
+++ b/src/main/java/li/strolch/runtime/configuration/RuntimeConfiguration.java
@@ -8,13 +8,16 @@ public class RuntimeConfiguration extends AbstractionConfiguration {
public static final String RUNTIME = "Runtime"; //$NON-NLS-1$
public static final String PATH_CONFIG = "config"; //$NON-NLS-1$
+ public static final String PATH_DATA = "data"; //$NON-NLS-1$
private final String applicationName;
private final File rootPath;
private final File configPath;
+ private final File dataPath;
public RuntimeConfiguration(String applicationName, Map configurationValues, File rootPathF) {
super(RUNTIME, configurationValues);
+
if (!rootPathF.isDirectory() || !rootPathF.canRead()) {
String msg = "Root path is not readable at {0}"; //$NON-NLS-1$
msg = MessageFormat.format(msg, rootPathF.getAbsolutePath());
@@ -28,9 +31,22 @@ public class RuntimeConfiguration extends AbstractionConfiguration {
throw new StrolchConfigurationException(msg);
}
+ File dataPathF = new File(rootPathF, PATH_CONFIG);
+ if (!dataPathF.exists() && !dataPathF.mkdir()) {
+ String msg = "Could not create missing data path at {0}"; //$NON-NLS-1$
+ msg = MessageFormat.format(msg, configPathF);
+ throw new StrolchConfigurationException(msg);
+ }
+ if (!dataPathF.isDirectory() || !dataPathF.canRead() || !dataPathF.canWrite()) {
+ String msg = "Data path is not a directory or readable or writeable at {0}"; //$NON-NLS-1$
+ msg = MessageFormat.format(msg, configPathF);
+ throw new StrolchConfigurationException(msg);
+ }
+
this.applicationName = applicationName;
this.rootPath = rootPathF;
this.configPath = configPathF;
+ this.dataPath = dataPathF;
}
public String getApplicationName() {
@@ -44,4 +60,8 @@ public class RuntimeConfiguration extends AbstractionConfiguration {
public File getConfigPath() {
return this.configPath;
}
+
+ public File getDataPath() {
+ return this.dataPath;
+ }
}
diff --git a/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java b/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java
index ac9de35a1..89742c217 100644
--- a/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java
+++ b/src/main/java/li/strolch/runtime/privilege/DefaultStrolchPrivilegeHandler.java
@@ -5,6 +5,7 @@ import java.io.File;
import li.strolch.runtime.component.ComponentContainer;
import li.strolch.runtime.component.StrolchComponent;
import li.strolch.runtime.configuration.ComponentConfiguration;
+import li.strolch.runtime.configuration.RuntimeConfiguration;
import ch.eitchnet.privilege.base.PrivilegeException;
import ch.eitchnet.privilege.handler.PrivilegeHandler;
import ch.eitchnet.privilege.handler.SystemUserAction;
@@ -28,8 +29,9 @@ public class DefaultStrolchPrivilegeHandler extends StrolchComponent implements
super.initialize(configuration);
// initialize privilege
+ RuntimeConfiguration runtimeConfiguration = configuration.getRuntimeConfiguration();
File privilegeConfigFile = configuration.getConfigFile(PROP_PRIVILEGE_CONFIG_FILE, PRIVILEGE_CONFIG_XML,
- configuration);
+ runtimeConfiguration);
PrivilegeHandler privilegeHandler = PrivilegeInitializationHelper.initializeFromXml(privilegeConfigFile);
this.privilegeHandler = privilegeHandler;
}
diff --git a/src/main/java/li/strolch/runtime/query/ByElementSelection.java b/src/main/java/li/strolch/runtime/query/ByElementSelection.java
new file mode 100644
index 000000000..18dabf240
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/query/ByElementSelection.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.query;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class ByElementSelection {
+
+ private String id;
+ private String name;
+ private String type;
+}
diff --git a/src/main/java/li/strolch/runtime/query/ResourceQuery.java b/src/main/java/li/strolch/runtime/query/ResourceQuery.java
new file mode 100644
index 000000000..d3cec2274
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/query/ResourceQuery.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.query;
+
+import java.util.List;
+
+import li.strolch.model.Resource;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class ResourceQuery {
+
+
+ private String byType;
+
+
+
+ public void accept(ResourceQueryVisitor visitor) {
+ visitor.visit(this);
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/query/ResourceQueryVisitor.java b/src/main/java/li/strolch/runtime/query/ResourceQueryVisitor.java
new file mode 100644
index 000000000..f826bc2c2
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/query/ResourceQueryVisitor.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.query;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public interface ResourceQueryVisitor {
+
+ public void visit(ResourceQuery query);
+}
diff --git a/src/main/java/li/strolch/runtime/query/TypeSelection.java b/src/main/java/li/strolch/runtime/query/TypeSelection.java
new file mode 100644
index 000000000..7be6eb85e
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/query/TypeSelection.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.query;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class TypeSelection {
+
+ private String type;
+
+ /**
+ * @param type
+ */
+ public TypeSelection(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return this.type;
+ }
+}
diff --git a/src/main/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryVisitor.java b/src/main/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryVisitor.java
new file mode 100644
index 000000000..7cc02ac8c
--- /dev/null
+++ b/src/main/java/li/strolch/runtime/query/inmemory/InMemoryResourceQueryVisitor.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime.query.inmemory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import li.strolch.model.Resource;
+import li.strolch.runtime.component.ComponentContainer;
+import li.strolch.runtime.query.ResourceQuery;
+import li.strolch.runtime.query.ResourceQueryVisitor;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+public class InMemoryResourceQueryVisitor implements ResourceQueryVisitor {
+
+ private ArrayList result;
+
+ public List performQuery(ComponentContainer container, ResourceQuery query) {
+ this.result = new ArrayList<>();
+
+ query.accept(this);
+
+ return this.result;
+ }
+
+ @Override
+ public void visit(ResourceQuery resourceQuery) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+}
diff --git a/src/test/java/li/strolch/runtime/QueryTest.java b/src/test/java/li/strolch/runtime/QueryTest.java
new file mode 100644
index 000000000..df9b4affa
--- /dev/null
+++ b/src/test/java/li/strolch/runtime/QueryTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012, Robert von Burg
+ *
+ * All rights reserved.
+ *
+ * This file is part of the XXX.
+ *
+ * XXX is free software: you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
+ *
+ * XXX is distributed in the hope that it will
+ * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XXX. If not, see
+ * .
+ */
+package li.strolch.runtime;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @author Robert von Burg
+ *
+ */
+@SuppressWarnings("nls")
+public class QueryTest {
+
+ @Test
+ @Ignore
+ public void shouldQueryResourceWithParamValue() {
+
+// ResourceQuery resQuery = new ResourceQuery();
+// resQuery.with(new TypeMatcher("MyType"));
+// resQuery.with(new ParameterBagMatcher("Bla").with(ParameterMatcher.stringValue("color", "red")));
+//
+// List result = resQuery.doQuery();
+
+ }
+}
diff --git a/src/test/resources/configtest/config/StrolchConfiguration.xml b/src/test/resources/configtest/config/StrolchConfiguration.xml
index ee9879b1a..5fe013b7d 100644
--- a/src/test/resources/configtest/config/StrolchConfiguration.xml
+++ b/src/test/resources/configtest/config/StrolchConfiguration.xml
@@ -6,10 +6,20 @@
true
+
+ Agent
+ li.strolch.runtime.agent.StrolchAgent
+ li.strolch.runtime.agent.StrolchAgent
+
+ EMPTY
+ StrolcheModel.xml
+
+
ServiceHandler
li.strolch.service.ServiceHandler
li.strolch.service.SimpleServiceHandler
+ Agent
diff --git a/src/test/resources/runtimetest/config/StrolchConfiguration.xml b/src/test/resources/runtimetest/config/StrolchConfiguration.xml
index ce3c4c65d..8877e00bc 100644
--- a/src/test/resources/runtimetest/config/StrolchConfiguration.xml
+++ b/src/test/resources/runtimetest/config/StrolchConfiguration.xml
@@ -6,10 +6,20 @@
true
+
+ Agent
+ li.strolch.runtime.agent.StrolchAgent
+ li.strolch.runtime.agent.StrolchAgent
+
+ EMPTY
+ StrolcheModel.xml
+
+
ServiceHandler
li.strolch.runtime.test.ServiceHandlerTest
li.strolch.runtime.test.ServiceHandlerTestImpl
+ Agent