[Major] added missing parsing of StrolchTimedState and fixed locators
Locators are now a bit different, to handle finding StrolchTimedState as well, the Locator has the form: Resource/<type>/<id>/State/<id> Resource/<type>/<id>/Bag/<id>/<param_id>
This commit is contained in:
parent
a95822689d
commit
07085f8aa0
|
@ -1,13 +1,13 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_ORDER_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ORDER_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
@ -22,7 +22,7 @@ public class CachedOrderMap extends CachedElementMap<Order> implements OrderMap
|
|||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator(), INTERPRETATION_ORDER_REF));
|
||||
}
|
||||
|
||||
if (refP.getUom().equals(Parameter.UOM_NONE)) {
|
||||
if (refP.getUom().equals(UOM_NONE)) {
|
||||
String msg = "{0} is not an Order reference as its UOM is not set to a type!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_RESOURCE_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_RESOURCE_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
@ -23,7 +23,7 @@ public class CachedResourceMap extends CachedElementMap<Resource> implements Res
|
|||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
if (refP.getUom().equals(Parameter.UOM_NONE)) {
|
||||
if (refP.getUom().equals(UOM_NONE)) {
|
||||
String msg = MessageFormat.format("{0} is not an Resource reference as its UOM is not set to a type!", //$NON-NLS-1$
|
||||
refP.getLocator());
|
||||
throw new StrolchException(msg);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_ORDER_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_ORDER_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.OrderMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Order;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.OrderDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
@ -22,7 +22,7 @@ public class TransactionalOrderMap extends TransactionalElementMap<Order> implem
|
|||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator(), INTERPRETATION_ORDER_REF));
|
||||
}
|
||||
|
||||
if (refP.getUom().equals(Parameter.UOM_NONE)) {
|
||||
if (refP.getUom().equals(UOM_NONE)) {
|
||||
String msg = "{0} is not an Order reference as its UOM is not set to a type!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.runtime.StrolchConstants.INTERPRETATION_RESOURCE_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.INTERPRETATION_RESOURCE_REF;
|
||||
import static li.strolch.model.StrolchModelConstants.UOM_NONE;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.agent.api.ResourceMap;
|
||||
import li.strolch.exception.StrolchException;
|
||||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.parameter.Parameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.persistence.api.ResourceDao;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
|
@ -22,7 +22,7 @@ public class TransactionalResourceMap extends TransactionalElementMap<Resource>
|
|||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator(), INTERPRETATION_RESOURCE_REF));
|
||||
}
|
||||
|
||||
if (refP.getUom().equals(Parameter.UOM_NONE)) {
|
||||
if (refP.getUom().equals(UOM_NONE)) {
|
||||
String msg = "{0} is not an Resource reference as its UOM is not set to a type!"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, refP.getLocator()));
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ import li.strolch.model.parameter.Parameter;
|
|||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.query.OrderQuery;
|
||||
import li.strolch.model.query.ResourceQuery;
|
||||
import li.strolch.model.timedstate.StrolchTimedState;
|
||||
import li.strolch.model.timevalue.IValue;
|
||||
import li.strolch.model.visitor.NoStrategyOrderVisitor;
|
||||
import li.strolch.model.visitor.NoStrategyResourceVisitor;
|
||||
import li.strolch.persistence.inmemory.InMemoryTransaction;
|
||||
|
@ -194,15 +196,18 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
@Override
|
||||
public <T extends StrolchElement> T findElement(Locator locator) {
|
||||
|
||||
// Resource/<type>/<id>
|
||||
// Resource/<type>/<id>/Bag/<id>
|
||||
// Resource/<type>/<id>/Bag/<id>/<param_id>
|
||||
// Resource/<type>/<id>/State/<id>
|
||||
// Order/<type>/<id>
|
||||
// Order/<type>/<id>/Bag/<id>
|
||||
// Order/<type>/<id>/Bag/<id>/<param_id>
|
||||
|
||||
if (locator.getSize() < 3) {
|
||||
String msg = "The locator is invalid as it does not have at least three path elements (e.g. Resource/MyType/@id): {0}"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, locator.toString());
|
||||
throw new StrolchException(msg);
|
||||
} else if (locator.getSize() > 5) {
|
||||
// TODO handle state variables, which will probably be separated by an additional part so we can differentiate between parameters and state variables on a parameter bag
|
||||
String msg = "The locator is invalid as it has more than 5 parts. The fifth part references a Parameter, which is the deepest fetchable entry: {0}"; //$NON-NLS-1$
|
||||
msg = MessageFormat.format(msg, locator.toString());
|
||||
throw new StrolchException(msg);
|
||||
}
|
||||
|
||||
List<String> elements = locator.getPathElements();
|
||||
|
@ -229,19 +234,40 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
if (elements.size() == 3)
|
||||
return (T) groupedParameterizedElement;
|
||||
|
||||
String parameterBagId = elements.get(3);
|
||||
ParameterBag bag = groupedParameterizedElement.getParameterBag(parameterBagId);
|
||||
if (bag == null) {
|
||||
String msg = "Could not find ParameterBag for locator {0} on element {1}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, locator, groupedParameterizedElement.getLocator()));
|
||||
// state or bag
|
||||
String stateOrBag = elements.get(3);
|
||||
if (stateOrBag.equals(Tags.BAG)) {
|
||||
|
||||
String parameterBagId = elements.get(4);
|
||||
ParameterBag bag = groupedParameterizedElement.getParameterBag(parameterBagId);
|
||||
if (bag == null) {
|
||||
String msg = "Could not find ParameterBag for locator {0} on element {1}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, locator, groupedParameterizedElement.getLocator()));
|
||||
}
|
||||
|
||||
if (elements.size() == 5)
|
||||
return (T) bag;
|
||||
|
||||
String parameterId = elements.get(5);
|
||||
Parameter<?> parameter = bag.getParameter(parameterId);
|
||||
return (T) parameter;
|
||||
|
||||
} else if (stateOrBag.equals(Tags.STATE)) {
|
||||
|
||||
if (elements.size() != 5) {
|
||||
String msg = "Missing state Id on locator {0}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, locator));
|
||||
}
|
||||
|
||||
Resource resource = (Resource) groupedParameterizedElement;
|
||||
String stateId = elements.get(4);
|
||||
|
||||
StrolchTimedState<IValue<?>> timedState = resource.getTimedState(stateId);
|
||||
return (T) timedState;
|
||||
}
|
||||
|
||||
if (elements.size() == 4)
|
||||
return (T) bag;
|
||||
|
||||
String parameterId = elements.get(4);
|
||||
Parameter<?> parameter = bag.getParameter(parameterId);
|
||||
return (T) parameter;
|
||||
String msg = "Invalid locator {0} on with part {1}"; //$NON-NLS-1$
|
||||
throw new StrolchException(MessageFormat.format(msg, locator, stateOrBag));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,7 @@ import li.strolch.model.ParameterBag;
|
|||
import li.strolch.model.Resource;
|
||||
import li.strolch.model.parameter.FloatParameter;
|
||||
import li.strolch.model.parameter.StringParameter;
|
||||
import li.strolch.model.timedstate.IntegerTimedState;
|
||||
import li.strolch.persistence.api.StrolchTransaction;
|
||||
import li.strolch.runtime.StrolchConstants;
|
||||
|
||||
|
@ -45,21 +46,41 @@ public class FindByLocatorTest {
|
|||
ComponentContainer container = agent.getContainer();
|
||||
|
||||
try (StrolchTransaction tx = container.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) {
|
||||
Locator locResStringParam = Locator.valueOf("Resource/TestType/MyTestResource/@bag01/@param5");
|
||||
StringParameter resStringParam = tx.findElement(locResStringParam);
|
||||
assertNotNull("Should have found a StringParameter with the locator " + locResStringParam, resStringParam);
|
||||
|
||||
Locator locOrderFloatParam = Locator.valueOf("Order/TestType/MyTestOrder/@bag01/@param2");
|
||||
FloatParameter orderFloatP = tx.findElement(locOrderFloatParam);
|
||||
assertNotNull("Should have found a FloatParameter with the locator " + locOrderFloatParam, orderFloatP);
|
||||
|
||||
Locator locOrderBag = Locator.valueOf("Order/TestType/MyTestOrder/@bag01");
|
||||
ParameterBag orderBag = tx.findElement(locOrderBag);
|
||||
assertNotNull("Should have found a FloatParameter with the locator " + locOrderBag, orderBag);
|
||||
|
||||
// Resource
|
||||
Locator locResource = Locator.valueOf("Resource/TestType/MyTestResource");
|
||||
Resource resource = tx.findElement(locResource);
|
||||
assertNotNull("Should have found a FloatParameter with the locator " + locResource, resource);
|
||||
|
||||
// Order
|
||||
Locator locOrderBag = Locator.valueOf("Order/TestType/MyTestOrder/Bag/@bag01");
|
||||
ParameterBag orderBag = tx.findElement(locOrderBag);
|
||||
assertNotNull("Should have found a FloatParameter with the locator " + locOrderBag, orderBag);
|
||||
|
||||
// Bag on Resource
|
||||
Locator locResBag = Locator.valueOf("Resource/TestType/MyTestResource/Bag/@bag01");
|
||||
ParameterBag resBag = tx.findElement(locResBag);
|
||||
assertNotNull("Should have found a ParameterBag with the locator " + locResBag, resBag);
|
||||
|
||||
// Bag on Order
|
||||
Locator locOrdBag = Locator.valueOf("Order/TestType/MyTestOrder/Bag/@bag01");
|
||||
ParameterBag ordBag = tx.findElement(locOrdBag);
|
||||
assertNotNull("Should have found a ParameterBag with the locator " + ordBag, locOrdBag);
|
||||
|
||||
// Parameter on Resource
|
||||
Locator locResStringParam = Locator.valueOf("Resource/TestType/MyTestResource/Bag/@bag01/@param5");
|
||||
StringParameter resStringParam = tx.findElement(locResStringParam);
|
||||
assertNotNull("Should have found a StringParameter with the locator " + locResStringParam, resStringParam);
|
||||
|
||||
// Parameter on Order
|
||||
Locator locOrderFloatParam = Locator.valueOf("Order/TestType/MyTestOrder/Bag/@bag01/@param2");
|
||||
FloatParameter orderFloatP = tx.findElement(locOrderFloatParam);
|
||||
assertNotNull("Should have found a FloatParameter with the locator " + locOrderFloatParam, orderFloatP);
|
||||
|
||||
// TimedState on Resource
|
||||
Locator locResIntegerState = Locator.valueOf("Resource/TestType/MyTestResource/State/@integerState");
|
||||
IntegerTimedState integerS = tx.findElement(locResIntegerState);
|
||||
assertNotNull("Should have found a IntegerTimedState with the locator " + locResIntegerState, integerS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,5 +10,31 @@
|
|||
<Parameter Id="@param2" Name="Float Param" Type="Float" Value="44.3" />
|
||||
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
|
||||
</ParameterBag>
|
||||
<TimedState Id="@booleanState" Name="Boolean State" Type="BooleanState">
|
||||
<Value Time="0" Value="false" />
|
||||
<Value Time="1" Value="true" />
|
||||
<Value Time="2" Value="false" />
|
||||
</TimedState>
|
||||
<TimedState Id="@integerState" Name="Integer State" Type="IntegerState">
|
||||
<Value Time="0" Value="1" />
|
||||
<Value Time="1" Value="2" />
|
||||
<Value Time="2" Value="3" />
|
||||
<Value Time="3" Value="2" />
|
||||
<Value Time="4" Value="1" />
|
||||
<Value Time="5" Value="0" />
|
||||
</TimedState>
|
||||
<TimedState Id="@floatState" Name="Float State" Type="FloatState">
|
||||
<Value Time="0" Value="1.1" />
|
||||
<Value Time="1" Value="2.2" />
|
||||
<Value Time="2" Value="3.3" />
|
||||
<Value Time="3" Value="2.2" />
|
||||
<Value Time="4" Value="1.1" />
|
||||
<Value Time="5" Value="0.0" />
|
||||
</TimedState>
|
||||
<TimedState Id="@stringSetState" Name="StringSet State" Type="StringSetState">
|
||||
<Value Time="0" Value="foo" />
|
||||
<Value Time="1" Value="foo, bar" />
|
||||
<Value Time="2" Value="bar" />
|
||||
</TimedState>
|
||||
</Resource>
|
||||
</StrolchModel>
|
||||
|
|
Loading…
Reference in New Issue