[Devel] Starting to implement element maps

This commit is contained in:
Robert von Burg 2013-11-19 23:14:36 +01:00
parent 548a34b9f3
commit fc3fc3e203
23 changed files with 1150 additions and 19 deletions

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.agent;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface AgentLifecycleController {
public void initialize();
public void start();
public void stop();
public void destroy();
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.agent;
import java.text.MessageFormat;
import li.strolch.runtime.configuration.ComponentConfiguration;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
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$
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.agent;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface ElementMap<T extends StrolchElement> {
public T getBy(String type, String id);
public void add(T element);
public void update(T element);
public void remove(T element);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
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);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
public abstract class InMemoryElementMap<T extends StrolchElement> implements ElementMap<T> {
private Map<String, Map<String, T>> 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<String, T> 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<String, T> 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<String, T> getByTypeMap(String type) {
Map<String, T> 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<String, T> 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<String, T> 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());
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.agent;
import li.strolch.model.Order;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class InMemoryOrderMap extends InMemoryElementMap<Order> implements OrderMap {
//
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.agent;
import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class InMemoryResourceMap extends InMemoryElementMap<Resource> implements ResourceMap {
//
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
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);
}
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.agent;
import li.strolch.model.Order;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface OrderMap extends ElementMap<Order> {
//
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.agent;
import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface ResourceMap extends ElementMap<Resource> {
//
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
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();
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
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();
}
}

View File

@ -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) {

View File

@ -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<String, String> 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;
}
}

View File

@ -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;
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class ByElementSelection {
private String id;
private String name;
private String type;
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.query;
import java.util.List;
import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class ResourceQuery {
private String byType;
public void accept(ResourceQueryVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public interface ResourceQueryVisitor {
public void visit(ResourceQuery query);
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime.query;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
public class TypeSelection {
private String type;
/**
* @param type
*/
public TypeSelection(String type) {
this.type = type;
}
/**
* @return the type
*/
public String getType() {
return this.type;
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
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 <eitch@eitchnet.ch>
*
*/
public class InMemoryResourceQueryVisitor implements ResourceQueryVisitor {
private ArrayList<Resource> result;
public List<Resource> 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
}
}

View File

@ -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
* <http://www.gnu.org/licenses/>.
*/
package li.strolch.runtime;
import org.junit.Ignore;
import org.junit.Test;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*
*/
@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<Resource> result = resQuery.doQuery();
}
}

View File

@ -6,10 +6,20 @@
<verbose>true</verbose>
</Properties>
</Runtime>
<Component>
<name>Agent</name>
<api>li.strolch.runtime.agent.StrolchAgent</api>
<impl>li.strolch.runtime.agent.StrolchAgent</impl>
<Properties>
<dataStoreMode>EMPTY</dataStoreMode>
<dataStoreModelFile>StrolcheModel.xml</dataStoreModelFile>
</Properties>
</Component>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.service.ServiceHandler</api>
<impl>li.strolch.service.SimpleServiceHandler</impl>
<depends>Agent</depends>
<Properties>
</Properties>
</Component>

View File

@ -6,10 +6,20 @@
<verbose>true</verbose>
</Properties>
</Runtime>
<Component>
<name>Agent</name>
<api>li.strolch.runtime.agent.StrolchAgent</api>
<impl>li.strolch.runtime.agent.StrolchAgent</impl>
<Properties>
<dataStoreMode>EMPTY</dataStoreMode>
<dataStoreModelFile>StrolcheModel.xml</dataStoreModelFile>
</Properties>
</Component>
<Component>
<name>ServiceHandler</name>
<api>li.strolch.runtime.test.ServiceHandlerTest</api>
<impl>li.strolch.runtime.test.ServiceHandlerTestImpl</impl>
<depends>Agent</depends>
<Properties>
</Properties>
</Component>