Search in sources :

Example 1 with BaseMessageImpl

use of com.dexels.navajo.document.base.BaseMessageImpl 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);
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) BaseSelectionImpl(com.dexels.navajo.document.base.BaseSelectionImpl) Property(com.dexels.navajo.document.Property) NavajoException(com.dexels.navajo.document.NavajoException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 2 with BaseMessageImpl

use of com.dexels.navajo.document.base.BaseMessageImpl in project navajo by Dexels.

the class SaxHandler method parseSelection.

private final void parseSelection(Map<String, String> h) throws NavajoException {
    String name = h.get("name");
    String value = h.get("value");
    int selected = Integer.parseInt(h.get("selected"));
    Property definitionProperty = null;
    BaseMessageImpl arrayParent = (BaseMessageImpl) currentProperty.getParentMessage().getArrayParentMessage();
    if (arrayParent != null) {
        definitionProperty = arrayParent.getPropertyDefinition(currentProperty.getName());
    }
    if (definitionProperty == null || definitionProperty.getSelected().getName().equals(Selection.DUMMY_SELECTION) || currentProperty.getParentMessage().getType().equals(Message.MSG_TYPE_DEFINITION)) {
        Selection s = NavajoFactory.getInstance().createSelection(currentDocument, name, value, selected != 0);
        currentProperty.addSelection(s);
    } else {
        if (currentProperty.getSelectionByValue(value) != null && selected == 1) {
            currentProperty.setSelectedByValue(value);
        } else {
            Selection s = NavajoFactory.getInstance().createSelection(currentDocument, name, value, selected != 0);
            currentProperty.addSelection(s);
        }
    }
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) Selection(com.dexels.navajo.document.Selection) Property(com.dexels.navajo.document.Property)

Example 3 with BaseMessageImpl

use of com.dexels.navajo.document.base.BaseMessageImpl in project navajo by Dexels.

the class TestProperty method tesMoneyProperty.

@Test
public void tesMoneyProperty() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BaseMessageImpl m = new BaseMessageImpl(n, "Aap");
    n.addMessage(m);
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    m.addProperty(p1);
    p1.setType(Property.MONEY_PROPERTY);
    p1.setValue("10.30");
    StringWriter sw = new StringWriter();
    n.write(sw);
    StringReader sr = new StringReader(sw.toString());
    Navajo n2 = NavajoFactory.getInstance().createNavajo(sr);
    Property p2 = n2.getProperty("Aap/Noot");
    Money mon = (Money) p2.getTypedValue();
    logger.info("m: " + mon.toTmlString() + " :: " + mon.editingString() + " :: " + mon.toString());
    Assert.assertEquals(mon.toTmlString(), "10.30");
    Assert.assertEquals(mon.doubleValue(), 10.30d, 0.1);
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) Money(com.dexels.navajo.document.types.Money) StringWriter(java.io.StringWriter) BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) StringReader(java.io.StringReader) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 4 with BaseMessageImpl

use of com.dexels.navajo.document.base.BaseMessageImpl in project navajo by Dexels.

the class TestProperty method tesExpression.

@Test
public void tesExpression() {
    BaseNavajoImpl n = new BaseNavajoImpl(NavajoFactory.getInstance());
    BaseMessageImpl m = new BaseMessageImpl(n, "Aap");
    n.addMessage(m);
    BasePropertyImpl p1 = new BasePropertyImpl(n, "Noot");
    m.addProperty(p1);
    p1.setType(Property.EXPRESSION_PROPERTY);
    String illegalExpression = "123";
    p1.setValue(illegalExpression);
    String res = p1.getValue();
    assertEquals(illegalExpression, res);
// Can't really test, need an expression evaluator, which has a dep to
// Navajo
}
Also used : BaseMessageImpl(com.dexels.navajo.document.base.BaseMessageImpl) BaseNavajoImpl(com.dexels.navajo.document.base.BaseNavajoImpl) BasePropertyImpl(com.dexels.navajo.document.base.BasePropertyImpl) Test(org.junit.Test)

Aggregations

BaseMessageImpl (com.dexels.navajo.document.base.BaseMessageImpl)4 Property (com.dexels.navajo.document.Property)3 Selection (com.dexels.navajo.document.Selection)2 BaseNavajoImpl (com.dexels.navajo.document.base.BaseNavajoImpl)2 BasePropertyImpl (com.dexels.navajo.document.base.BasePropertyImpl)2 Test (org.junit.Test)2 Message (com.dexels.navajo.document.Message)1 Navajo (com.dexels.navajo.document.Navajo)1 NavajoException (com.dexels.navajo.document.NavajoException)1 BaseSelectionImpl (com.dexels.navajo.document.base.BaseSelectionImpl)1 Money (com.dexels.navajo.document.types.Money)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1