Search in sources :

Example 61 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class NavajoContextInstanceFactory method appendConditionalAlias.

private void appendConditionalAlias(Message aliasConditionalMessage, Map<String, Set<String>> aliases) {
    for (Message m : aliasConditionalMessage.getAllMessages()) {
        String name = m.getName();
        Property conditionProp = m.getProperty("condition");
        Property trueValueProp = m.getProperty("true_value");
        Property falseValueProp = m.getProperty("false_value");
        if (conditionProp == null || conditionProp.getTypedValue() == null) {
            logger.warn("Invalid conditional alias message! {}", m);
            continue;
        }
        boolean evaluated = checkEliasCondition(conditionProp.getValue());
        String aliasValue = null;
        if (evaluated && trueValueProp != null) {
            aliasValue = trueValueProp.getValue();
        } else if (!evaluated && falseValueProp != null) {
            aliasValue = falseValueProp.getValue();
        }
        if (aliasValue != null) {
            Set<String> found = aliases.get(aliasValue);
            if (found == null) {
                found = new HashSet<String>();
                aliases.put(aliasValue, found);
            }
            found.add(name);
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) Property(com.dexels.navajo.document.Property)

Example 62 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class TmlHttpServlet method sendResponse.

private static void sendResponse(HttpServletRequest request, HttpServletResponse response, Navajo resultMessage) {
    ServletOutputStream outputStream = null;
    try {
        String dataPath = request.getParameter("dataPath");
        outputStream = response.getOutputStream();
        if (dataPath != null) {
            Property bin = resultMessage.getProperty(dataPath);
            if (bin == null) {
                java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
                response.setContentType("text/xml; charset=UTF-8");
                resultMessage.write(out);
                out.flush();
                out.close();
            } else {
                // Will throw cce when not a binary?
                if (bin.getTypedValue() instanceof Binary) {
                    Binary b = (Binary) bin.getTypedValue();
                    response.setContentType(b.getMimeType());
                    if (b.getLength() > 0) {
                        response.setContentLength((int) b.getLength());
                        response.setHeader("Accept-Ranges", "none");
                        response.setHeader("Connection", "close");
                    }
                    copyResource(outputStream, b.getDataAsStream());
                } else {
                    outputStream.write(bin.getValue().getBytes());
                }
                outputStream.flush();
            }
        } else {
            java.io.OutputStreamWriter out = new java.io.OutputStreamWriter(outputStream, "UTF-8");
            response.setContentType("text/xml; charset=UTF-8");
            resultMessage.write(out);
            out.flush();
            out.close();
        }
    } catch (NavajoException e) {
        logger.error("Error handling response: ", e);
    } catch (IOException e) {
        logger.error("Error handling response: ", e);
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                logger.warn("Stream closing problem", e);
            }
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) NavajoException(com.dexels.navajo.document.NavajoException) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) IOException(java.io.IOException) Property(com.dexels.navajo.document.Property)

Example 63 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class DomainObjectMapper method mapObjectToProperties.

/**
 * Automatically maps all 'getters' to a property.
 *
 * Only add property if:
 *  1. attribute 'getter' does not expect any arguments.
 *  2. attribute has a 'getter'.
 *  3. corresponding property does not already exist in message.
 *  4. corresponding property is not in exclusion list.
 * @throws Exception
 */
private void mapObjectToProperties(Class myClass) throws Exception {
    java.lang.reflect.Method[] all = myClass.getMethods();
    if (myAccess == null) {
        return;
    }
    Navajo out = myAccess.getOutputDoc();
    Message currentOutMsg = myAccess.getCurrentOutMessage();
    if (currentOutMsg == null) {
        throw new Exception("No current message for mapping object attributes to properties.");
    }
    for (int i = 0; i < all.length; i++) {
        String attributeName = all[i].getName().substring(3);
        if (all[i].getParameterTypes().length == 0 && all[i].getName().startsWith("get") && !all[i].getName().startsWith("getClass") && currentOutMsg.getProperty(attributeName) == null && !isAnExcludedProperty(attributeName)) {
            Object result = all[i].invoke(myObject, (Object[]) null);
            if (result == null || !(result.toString().startsWith("[L") || List.class.isAssignableFrom(result.getClass()))) {
                Property p = NavajoFactory.getInstance().createProperty(out, attributeName, "string", "", 0, "", "", "");
                p.setAnyValue(result);
                p.setDirection(isAnInputProperty(attributeName) ? Property.DIR_IN : Property.DIR_OUT);
                currentOutMsg.addProperty(p);
            }
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) Method(java.lang.reflect.Method) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) MappingException(com.dexels.navajo.script.api.MappingException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 64 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class MappingUtils method getSelectedItems.

public static final List<Selection> getSelectedItems(Message msg, Navajo doc, String msgName) throws NavajoException {
    Property prop = null;
    if (msg != null) {
        prop = msg.getProperty(msgName);
    } else {
        prop = doc.getProperty(msgName);
    }
    if (!prop.getType().equals(Property.SELECTION_PROPERTY)) {
        throw doc.getNavajoFactory().createNavajoException("Selection Property expected");
    }
    List<Selection> result = prop.getAllSelectedSelections();
    return result;
}
Also used : Selection(com.dexels.navajo.document.Selection) Property(com.dexels.navajo.document.Property)

Example 65 with Property

use of com.dexels.navajo.document.Property in project navajo by Dexels.

the class MappingUtils method isSelection.

public static final boolean isSelection(Message msg, Navajo doc, String msgName) {
    Property prop = null;
    if (msgName.startsWith(Navajo.MESSAGE_SEPARATOR)) {
        // Absolute reference!
        msg = null;
        msgName = msgName.substring(1, msgName.length());
    }
    if (msg != null) {
        prop = msg.getProperty(msgName);
    } else {
        prop = doc.getProperty(msgName);
    }
    if (prop == null) {
        return false;
    }
    return prop.getType().equals(Property.SELECTION_PROPERTY);
}
Also used : Property(com.dexels.navajo.document.Property)

Aggregations

Property (com.dexels.navajo.document.Property)253 Message (com.dexels.navajo.document.Message)148 Test (org.junit.Test)88 Navajo (com.dexels.navajo.document.Navajo)84 Selection (com.dexels.navajo.document.Selection)36 NavajoException (com.dexels.navajo.document.NavajoException)30 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)17 ArrayList (java.util.ArrayList)17 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)16 Binary (com.dexels.navajo.document.types.Binary)16 UserException (com.dexels.navajo.script.api.UserException)16 Access (com.dexels.navajo.script.api.Access)15 StringWriter (java.io.StringWriter)13 List (java.util.List)11 Operand (com.dexels.navajo.document.Operand)10 MappableException (com.dexels.navajo.script.api.MappableException)9 IOException (java.io.IOException)9 Writer (java.io.Writer)9 StringTokenizer (java.util.StringTokenizer)9 JSONTML (com.dexels.navajo.document.json.JSONTML)8