use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.
the class SaxHandler method parseProperty.
private final void parseProperty(Map<String, String> h) throws NavajoException {
// logger.info("NAME: "+(String)h.get("name"));
String sLength = null;
String myName = h.get(Property.PROPERTY_NAME);
String myValue = h.get(Property.PROPERTY_VALUE);
String subType = h.get(Property.PROPERTY_SUBTYPE);
String description = h.get(Property.PROPERTY_DESCRIPTION);
String direction = h.get(Property.PROPERTY_DIRECTION);
String type = h.get(Property.PROPERTY_TYPE);
sLength = h.get(Property.PROPERTY_LENGTH);
String cardinality = h.get(Property.PROPERTY_CARDINALITY);
String extendsProp = h.get(Property.PROPERTY_EXTENDS);
String reference = h.get(Property.PROPERTY_REFERENCE);
String key = h.get(Property.PROPERTY_KEY);
String bind = h.get(Property.PROPERTY_BIND);
String method = h.get(Property.PROPERTY_METHOD);
Integer plength = null;
Property definitionProperty = null;
String subtype = null;
int length = 0;
try {
if (sLength != null) {
length = Integer.parseInt(sLength);
plength = Integer.valueOf(length);
}
} catch (Exception e1) {
// logger.info("ILLEGAL LENGTH IN PROPERTY " + myName + ": " +
// sLength);
}
if (myName == null) {
throw NavajoFactory.getInstance().createNavajoException("Can not parse property without a name ");
}
boolean isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
if (isListType) {
currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, cardinality, description, direction);
} else {
currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, type, myValue, length, description, direction, subtype);
}
if (messageStack.isEmpty()) {
throw NavajoFactory.getInstance().createNavajoException("Can not parse property without being inside a message, probably an input error");
}
Message current = messageStack.peek();
current.addProperty(currentProperty);
BaseMessageImpl arrayParent = (BaseMessageImpl) current.getArrayParentMessage();
if (arrayParent != null && arrayParent.isArrayMessage()) {
definitionProperty = arrayParent.getPropertyDefinition(myName);
if (definitionProperty != null) {
if (description == null || "".equals(description)) {
description = definitionProperty.getDescription();
}
if (direction == null || "".equals(direction)) {
direction = definitionProperty.getDirection();
}
if (type == null || "".equals(type)) {
type = definitionProperty.getType();
}
if (plength == null) {
length = definitionProperty.getLength();
}
if (subType == null) {
if (definitionProperty.getSubType() != null) {
currentProperty.setSubType(definitionProperty.getSubType());
}
} else {
if (definitionProperty.getSubType() != null) {
/**
* Concatenated subtypes. The if the same key of a subtype is present
* in both the property and the definition property.
*/
currentProperty.setSubType(definitionProperty.getSubType() + "," + subType);
}
}
}
}
if (subType == null && NavajoFactory.getInstance().getDefaultSubtypeForType(type) != null) {
currentProperty.setSubType(NavajoFactory.getInstance().getDefaultSubtypeForType(type));
} else {
currentProperty.setSubType(subType);
}
if (type == null && current.isArrayMessage()) {
logger.info("Found undefined property: " + currentProperty.getName());
}
isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
if (isListType && definitionProperty != null) {
if (cardinality == null) {
cardinality = definitionProperty.getCardinality();
}
type = Property.SELECTION_PROPERTY;
List<Selection> l = definitionProperty.getAllSelections();
for (int i = 0; i < l.size(); i++) {
BaseSelectionImpl s1 = (BaseSelectionImpl) l.get(i);
BaseSelectionImpl s2 = (BaseSelectionImpl) s1.copy(currentDocument);
currentProperty.addSelection(s2);
}
}
currentProperty.setType(type);
currentProperty.setDescription(description);
currentProperty.setDirection(direction);
currentProperty.setCardinality(cardinality);
currentProperty.setLength(length);
currentProperty.setExtends(extendsProp);
currentProperty.setKey(key);
currentProperty.setReference(reference);
currentProperty.setBind(bind);
currentProperty.setMethod(method);
}
use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.
the class TestProperty method tesSelectionEqualsUpdateFix.
@Test
public void tesSelectionEqualsUpdateFix() {
BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
p1.setType("selection");
p1.setCardinality("1");
p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
p1.addPropertyChangeListener(e -> {
logger.info("Old: {}", e.getOldValue());
logger.info("New: {}", e.getNewValue());
// no real change.
Assert.fail();
});
p1.setSelected(p1.getSelection("opt2"));
}
use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.
the class TestProperty method tesSelections.
@Test
@Deprecated
public void tesSelections() {
BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
p1.setType("selection");
p1.setCardinality("1");
p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", false));
p1.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
assertEquals("___DUMMY_ELEMENT___", p1.getSelected().getValue());
// Cardinality 1
p1.setSelected("1");
assertEquals("1", p1.getSelected().getValue());
assertFalse("2".equals(p1.getSelected().getValue()));
assertFalse("3".equals(p1.getSelected().getValue()));
p1.setSelected("2");
assertEquals("2", p1.getSelected().getValue());
assertFalse("1".equals(p1.getSelected().getValue()));
assertFalse("3".equals(p1.getSelected().getValue()));
p1.setSelected("3");
assertEquals("3", p1.getSelected().getValue());
assertFalse("1".equals(p1.getSelected().getValue()));
assertFalse("2".equals(p1.getSelected().getValue()));
// Cardinality +
p1.setCardinality("+");
p1.clearSelections();
assertFalse("1".equals(p1.getSelected().getValue()));
assertFalse("2".equals(p1.getSelected().getValue()));
assertFalse("3".equals(p1.getSelected().getValue()));
p1.setSelected("1");
p1.setSelected("2");
List<Selection> all = p1.getAllSelectedSelections();
for (int i = 0; i < all.size(); i++) {
assertTrue(all.get(i).getValue().equals("1") || all.get(i).getValue().equals("2"));
assertFalse(all.get(i).getValue().equals("3"));
}
}
use of com.dexels.navajo.document.base.BaseSelectionImpl in project navajo by Dexels.
the class TestProperty method tesEqualProperties.
@Test
public void tesEqualProperties() {
BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
BasePropertyImpl p2 = new BasePropertyImpl(n, "Noot");
// Strings
p1.setAnyValue("Aap");
p2.setAnyValue("Aap");
assertTrue(p1.isEqual(p2));
p2.setAnyValue("Kip");
assertFalse(p1.isEqual(p2));
// Selections
p1.setType("selection");
p1.setCardinality("1");
p1.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
p1.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
p1.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
p2.setType("selection");
p2.setCardinality("1");
p2.addSelection(new BaseSelectionImpl(n, "opt1", "1", false));
p2.addSelection(new BaseSelectionImpl(n, "opt2", "2", true));
p2.addSelection(new BaseSelectionImpl(n, "opt3", "3", false));
assertTrue(p1.isEqual(p2));
p2.setSelected(new BaseSelectionImpl(n, "opt2", "2", true), false);
p2.setSelected(new BaseSelectionImpl(n, "opt2", "3", true), true);
assertFalse(p1.isEqual(p2));
p1.setSelected(new BaseSelectionImpl(n, "opt2", "2", true), false);
p1.setSelected(new BaseSelectionImpl(n, "opt2", "3", true), true);
assertTrue(p1.isEqual(p2));
// Date
p1.setType("date");
p1.removeAllSelections();
p2.setType("date");
p2.removeAllSelections();
// these could be non-equal, right?
p1.setAnyValue(new java.util.Date());
p2.setAnyValue(new java.util.Date());
assertTrue(p1.isEqual(p2));
p2.setAnyValue(new java.util.Date(32131332L));
assertFalse(p1.isEqual(p2));
}
Aggregations