Search in sources :

Example 86 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class NS3ToNSXML method parseInclude.

private IncludeTag parseInclude(NS3Compatible parent, XMLElement currentXML) throws Exception {
    currentXML.setAttribute("PROCESSED", "true");
    IncludeTag it = new IncludeTag(myNavascript);
    it.addParent(parent);
    Vector<XMLElement> children = currentXML.getChildren();
    for (XMLElement child : children) {
        String name = child.getName();
        String content = (child.getContent() != null && !"".equals(child.getContent()) ? child.getContent() : null);
        if (name.equals("Conditional")) {
            ConditionFragment currentFragment = new ConditionFragment();
            consumeContent(currentFragment, child);
            it.setCondition(currentFragment.consumedFragment());
        }
        if (name.equals("ScriptIdentifier")) {
            it.setScript(content);
        }
    }
    return it;
}
Also used : IncludeTag(com.dexels.navajo.document.navascript.tags.IncludeTag) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 87 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class NS3ToNSXML method parseMethods.

private MethodsTag parseMethods(NS3Compatible parent, XMLElement xe) throws Exception {
    MethodsTag mt = new MethodsTag(myNavascript);
    mt.addParent(parent);
    Vector<XMLElement> children = xe.getChildren();
    for (XMLElement child : children) {
        String name = child.getName();
        if (name.equals("DefinedMethod")) {
            for (XMLElement c : child.getChildren()) {
                String cn = c.getName();
                String content = (c.getContent() != null && !"".equals(c.getContent()) ? c.getContent() : null);
                if (cn.equals("ScriptIdentifier")) {
                    MethodTag m = new MethodTag(myNavascript);
                    m.setScriptName(content);
                    mt.addMethod(m);
                }
            }
        }
    }
    return mt;
}
Also used : MethodTag(com.dexels.navajo.document.navascript.tags.MethodTag) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) MethodsTag(com.dexels.navajo.document.navascript.tags.MethodsTag)

Example 88 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class ValueDefinition method generateCode.

/**
 * in: 1) <map:sqlmap datasource="sportlinkkernel">
 *     2) <map:set field="datasource" value="sportlinkkernel"/>
 *     3) <map:set field="datasource">sportlinkkernel</map:set>
 * @param in
 * @param out
 * @throws MetaCompileException
 */
public XMLElement generateCode(XMLElement currentIn, String setterValue, boolean textNode, String condition, XMLElement out, boolean append, String filename) throws MetaCompileException {
    // Case I: <field><expression/></field> construct.
    if ((direction.equals("in") || direction.equals("automatic")) && map == null) {
        XMLElement field = new TSLElement(currentIn, "field");
        field.setAttribute("name", (this.getClass().getName().equals("com.dexels.navajo.mapping.compiler.meta.ValueDefinition") ? name : ((ParameterDefinition) this).getField()));
        if (condition != null && !condition.equals("")) {
            field.setAttribute("condition", condition);
        }
        XMLElement expression = new TSLElement(currentIn, "expression");
        field.addChild(expression);
        expression.setAttribute("xml:space", "preserve");
        // Case Ia: stringliteral, create construct <expression>[STRING CONTENT]<expression>
        if (textNode && (setterValue.length() == 0 || setterValue.charAt(0) != '{')) {
            expression.setContent(setterValue);
        } else // Case Ib: other, if string type automatically put quotes (') around string.
        // if string type surrounded by {} or any other type, assume normal expression,
        // use <expression><value>[EXPRESSION]</value></expression> construct.
        {
            if (setterValue.length() > 0 && setterValue.charAt(0) == '{') {
                // Force expression.
                setterValue = setterValue.replace('{', ' ');
                setterValue = setterValue.replace('}', ' ');
            }
            XMLElement value = new TSLElement(currentIn, "value");
            expression.addChild(value);
            value.setContent(setterValue);
        }
        if (append) {
            out.addChild(field);
        }
        return field;
    // Case II: <message><map ref=""/></message> or <property><map ref=""/></property> construct or <param type="array"><map ref="">
    } else if ((currentIn.getParent().getName().equals("message") || currentIn.getParent().getName().equals("property") || currentIn.getParent().getName().equals("param")) && map != null) {
        // Generate <map ref=""> construction
        XMLElement mapref = new TSLElement(currentIn, "map");
        mapref.setAttribute("ref", setterValue);
        if (condition != null && !condition.equals("")) {
            mapref.setAttribute("filter", condition);
        }
        out.addChild(mapref);
        return mapref;
    // Case III: <field><map ref=""/></field> construct.
    } else if (currentIn.getFirstChild().getName().equals("map") && map != null) {
        // Generate <field name=""><map ref=""></field> construction...
        XMLElement field = new TSLElement(currentIn, "field");
        field.setAttribute("name", (this.getClass().getName().equals("com.dexels.navajo.mapping.compiler.meta.ValueDefinition") ? name : ((ParameterDefinition) this).getField()));
        if (condition != null && !condition.equals("")) {
            field.setAttribute("condition", condition);
        }
        out.addChild(field);
        return field;
    } else {
        throw new MetaCompileException(filename, currentIn, "Unknown value tag for setter value: " + setterValue + ", tagname = " + currentIn.getName());
    }
}
Also used : XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 89 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class MapDefinition method generateCode.

/**
 * in: <map:sqlquery datasource=\"sportlinkkernel\"/>
 * out: <map object="com.dexels.navajo.adapter.SQLMap">
 *          <field name="datasource">
 *             <expression value="'sportlinkkernel'"/>
 *          </field>
 *      </map>
 * @param in
 * @param out
 * @throws MetaCompileException
 * @throws ClassNotFoundException
 */
public void generateCode(XMLElement in, XMLElement out, String filename) throws MetaCompileException, ClassNotFoundException {
    XMLElement map = null;
    if (in.getName().equals("map." + tagName)) {
        map = new TSLElement(in, "map");
        map.setAttribute("object", objectName);
        String condition = (String) in.getAttribute("condition");
        if (condition != null && !condition.equals("")) {
            map.setAttribute("condition", condition);
        }
        // Parse attributes using ValueDefinition.
        Iterator<String> attributes = in.enumerateAttributeNames();
        Set<String> required = new HashSet<>();
        // Get all 'automatic' parameters and determine required parameters.
        Iterator<ValueDefinition> auto = values.values().iterator();
        while (auto.hasNext()) {
            ValueDefinition pd = auto.next();
            if (pd.getRequired().equals("automatic")) {
                pd.generateCode(in, pd.getValue(), false, null, map, true, filename);
            } else if (pd.getRequired().equals("true")) {
                required.add(pd.getName());
            }
        }
        while (attributes.hasNext()) {
            String attribName = attributes.next();
            String attribValue = (String) in.getAttribute(attribName);
            ValueDefinition vd = getValueDefinition(attribName);
            if (vd != null) {
                vd.generateCode(in, attribValue, false, null, map, true, filename);
                required.remove(attribName);
            } else if (!attribName.equals("condition")) {
                throw new UnknownMapInitializationParameterException("map." + tagName, attribName, in, filename);
            }
        }
        // Check if all required parameters are present.
        if (required.size() > 0) {
            throw new MissingParameterException(required, tagName, in, filename);
        }
        out.addChild(map);
    }
    // Parse children tags.
    Vector<XMLElement> v = in.getChildren();
    for (int i = 0; i < v.size(); i++) {
        XMLElement child = v.get(i);
        // or <param type="array"><map ref="">
        if (child.getName().indexOf(".") != -1 && getValueDefinition(stripDot(child)) != null && getValueDefinition(stripDot(child)).getDirection().equals("out") && ((child.getChildren().size() > 0 && child.getFirstChild().getName().equals("map")) || (child.getParent().getName().equals("message") || child.getParent().getName().equals("property") || (child.getParent().getName().equals("param") && "array".equals(child.getParent().getAttribute("type")))))) {
            // Maybe an out ValueDefinition, map ref stuff...
            String field = stripDot(child);
            String filter = (String) child.getAttribute("filter");
            ValueDefinition vd = getValueDefinition(field);
            // It is either <field><map ref=""> or <message><map ref=""/> or <property><map ref=""/>
            MapDefinition md = myMetaData.getMapDefinition(vd.getMapType());
            if (md != null) {
                XMLElement out2 = vd.generateCode(child, field, false, filter, (map != null ? map : out), true, filename);
                md.generateCode(child, out2, filename);
            } else {
                throw new UnknownAdapterException(child.getName(), child, filename);
            }
        // Case II: a simple field construct.
        } else if (child.getName().indexOf(".") != -1 && getValueDefinition(stripDot(child)) != null) {
            generateFieldCode(child, (map != null ? map : out), filename, false);
        // Case III: a multiple-field aka method construct.
        } else if (child.getName().indexOf(".") != -1 && getMethodDefinition(stripDot(child)) != null) {
            generateFieldCode(child, (map != null ? map : out), filename, true);
        // Case IV: ?
        // } else if ( child.getName().equals("map." + tagName ) ) {
        // generateCode(child, ( map != null ? map : out ), filename );
        // Case V: a new map initialization construct.
        } else if (child.getName().startsWith("map.")) {
            MapDefinition md = myMetaData.getMapDefinition(child.getName().substring(4));
            if (md == null) {
                throw new MetaCompileException(filename, child, "Could not find map definition for: " + child.getName().substring(4));
            }
            if (md.abstractMap) {
                throw new MetaCompileException(filename, child, "Illegal declaration of abstract adapter: " + md.tagName);
            }
            md.generateCode(child, (map != null ? map : out), filename);
        } else if (!(child.getName().equals("message") || child.getName().equals("loop") || child.getName().equals("antimessage") || child.getName().equals("defines") || child.getName().equals("define") || child.getName().equals("property") || child.getName().equals("field") || child.getName().equals("comment") || child.getName().equals("debug") || child.getName().equals("log") || child.getName().equals("param") || child.getName().equals("include") || child.getName().equals("inject") || child.getName().equals("break") || child.getName().equals("required") || child.getName().equals("request") || child.getName().equals("response") || child.getName().equals("running") || child.getName().equals("option") || child.getName().equals("expression") || child.getName().equals("value") || child.getName().equals("condition") || child.getName().equals("map") || child.getName().equals("methods") || child.getName().equals("method") || child.getName().equals("validations") || child.getName().equals("operations") || child.getName().equals("operation") || child.getName().equals("synchronized") || child.getName().equals("block") || child.getName().equals("finally") || child.getName().equals("check"))) {
            throw new MetaCompileException(filename, child, "Unknown tag/method <" + child.getName() + "/> encountered");
        } else {
            // Copy it.
            XMLElement copy = new TSLElement(child, child.getName());
            if (map != null) {
                map.addChild(copy);
            } else {
                out.addChild(copy);
            }
            Iterator<String> allAttribs = child.enumerateAttributeNames();
            while (allAttribs.hasNext()) {
                String name = allAttribs.next();
                String value = (String) child.getAttribute(name);
                copy.setAttribute(name, value);
            }
            // Copy text node, if it exists.
            if (child.getContent() != null) {
                copy.setContent(child.getContent());
            }
            generateCode(child, copy, filename);
        }
    }
}
Also used : XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) HashSet(java.util.HashSet)

Example 90 with XMLElement

use of com.dexels.navajo.document.nanoimpl.XMLElement in project navajo by Dexels.

the class MapMetaData method parse.

public void parse(Reader br, String scriptName, Writer sw) throws IOException, MetaCompileException, ClassNotFoundException {
    XMLElement in = new CaseSensitiveXMLElement();
    in.parseFromReader(br);
    br.close();
    parse(in, scriptName, sw);
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Aggregations

XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)120 CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)109 MapTag (com.dexels.navajo.document.navascript.tags.MapTag)12 IOException (java.io.IOException)12 NS3Compatible (com.dexels.navajo.document.navascript.tags.NS3Compatible)10 ArrayList (java.util.ArrayList)8 ParamTag (com.dexels.navajo.document.navascript.tags.ParamTag)7 InputStreamReader (java.io.InputStreamReader)7 HashMap (java.util.HashMap)7 APIException (com.dexels.navajo.article.APIException)6 ExpressionTag (com.dexels.navajo.document.navascript.tags.ExpressionTag)5 FieldTag (com.dexels.navajo.document.navascript.tags.FieldTag)5 FileInputStream (java.io.FileInputStream)5 FileReader (java.io.FileReader)5 Property (com.dexels.navajo.document.Property)4 IncludeTag (com.dexels.navajo.document.navascript.tags.IncludeTag)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 File (java.io.File)4 Message (com.dexels.navajo.document.Message)3 BlockTag (com.dexels.navajo.document.navascript.tags.BlockTag)3