Search in sources :

Example 1 with NavajoFactory

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

the class TestOperation method testOperation.

@Test
public void testOperation() {
    NavajoFactory f = NavajoFactory.getInstance();
    Navajo n = f.createNavajo();
    Message msg = f.createMessage(n, "__Mongo__");
    Operation o = f.createOperation(n, "PUT", "vla/ProcessInsertPerson", null, "Person", null);
    n.addOperation(o);
    o.setExtraMessage(msg);
    Method m = f.createMethod(n, "vla/ProcessUpdatePerson", null);
    m.addRequired("Apenoot");
    n.addMethod(m);
    n.write(System.err);
}
Also used : NavajoFactory(com.dexels.navajo.document.NavajoFactory) Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Operation(com.dexels.navajo.document.Operation) Method(com.dexels.navajo.document.Method) Test(org.junit.Test)

Example 2 with NavajoFactory

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

the class FunctionInterface method genPipedParamMsg.

private final String genPipedParamMsg(Class[] c) {
    if (c == null) {
        return "unknown";
    }
    NavajoFactory nf = NavajoFactory.getInstance();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < c.length; i++) {
        if (c[i] != null) {
            sb.append(nf.getNavajoType(c[i]));
        } else {
            sb.append("empty");
        }
        if (i < c.length - 1) {
            sb.append(" | ");
        }
    }
    return sb.toString();
}
Also used : NavajoFactory(com.dexels.navajo.document.NavajoFactory)

Example 3 with NavajoFactory

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

the class FunctionInterface method checkTypes.

@SuppressWarnings({ "unchecked", "unused" })
private final void checkTypes() {
    Class[][] mytypes = null;
    if (myinputtypes != null) {
        mytypes = myinputtypes;
    } else {
        mytypes = types.get(this.getClass());
    }
    if (mytypes != null) {
        StringBuilder msg = new StringBuilder();
        for (int paramIndex = 0; paramIndex < mytypes.length; paramIndex++) {
            Class[] possibleParameters = mytypes[paramIndex];
            boolean correct = false;
            Class passedParam = null;
            for (int possParam = 0; possParam < possibleParameters.length; possParam++) {
                Class p = possibleParameters[possParam];
                boolean notpresent = false;
                try {
                    Object o = operand(paramIndex).value;
                    passedParam = (o != null ? o.getClass() : null);
                } catch (Exception e) {
                    passedParam = null;
                    notpresent = true;
                }
                if (// Passedparam could be present but NULL.
                (!notpresent && passedParam == null) || // Passedparam could not be present but
                (notpresent && p == null && passedParam == null) || // expected could be empty.
                (// Expected could not be empty and p could be set
                p != null && p.equals(Set.class)) || // (=...)
                (p != null && passedParam != null && p.isAssignableFrom(passedParam))) {
                    // Expected is
                    // assignable
                    // from
                    // passedparam.
                    correct = true;
                }
            }
            if (!correct) {
                NavajoFactory nf = NavajoFactory.getInstance();
                msg.append("Parameter " + (paramIndex + 1) + " has type " + (passedParam != null ? nf.getNavajoType(passedParam) : "empty") + ", expected: " + genPipedParamMsg(possibleParameters) + "\n");
            }
        }
        if (!msg.toString().equals("")) {
            throw new TMLExpressionException(this, msg.toString(), null);
        }
    }
}
Also used : NavajoFactory(com.dexels.navajo.document.NavajoFactory)

Example 4 with NavajoFactory

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

the class FunctionInterface method loadInputTypes.

private Class[][] loadInputTypes(String[][] navajotypes) {
    // Convert navajo types to Java classes.
    NavajoFactory nf = NavajoFactory.getInstance();
    Class[][] mytypes = new Class[navajotypes.length][];
    boolean hasEmptyOptions = false;
    boolean hasMultipleOptions = false;
    for (int i = 0; i < navajotypes.length; i++) {
        mytypes[i] = new Class[navajotypes[i].length];
        boolean emptyOptionSpecified = false;
        boolean multipleOptionsSpecified = false;
        for (int j = 0; j < navajotypes[i].length; j++) {
            if (navajotypes[i][j] != null && navajotypes[i][j].trim().equals("...")) {
                // Use Set class to denote multiple parameter option.
                mytypes[i][j] = Set.class;
                multipleOptionsSpecified = true;
                hasMultipleOptions = true;
            } else if (navajotypes[i][j] == null || navajotypes[i][j].trim().equalsIgnoreCase("empty")) {
                mytypes[i][j] = null;
                emptyOptionSpecified = true;
                hasEmptyOptions = true;
            } else {
                mytypes[i][j] = nf.getJavaType(navajotypes[i][j].trim());
            }
        }
        if (hasMultipleOptions && !multipleOptionsSpecified) {
            throw new IllegalArgumentException("Multiple parameter options can only be specified in one sequence of last parameters.");
        }
        if (hasEmptyOptions && !emptyOptionSpecified && !hasMultipleOptions) {
            throw new IllegalArgumentException("Empty parameter options can only be specified in one sequence of last parameters.");
        }
    }
    return mytypes;
}
Also used : NavajoFactory(com.dexels.navajo.document.NavajoFactory)

Aggregations

NavajoFactory (com.dexels.navajo.document.NavajoFactory)4 Message (com.dexels.navajo.document.Message)1 Method (com.dexels.navajo.document.Method)1 Navajo (com.dexels.navajo.document.Navajo)1 Operation (com.dexels.navajo.document.Operation)1 Test (org.junit.Test)1