Search in sources :

Example 61 with XMLElement

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

the class ScriptCompiler method addProperty.

private void addProperty(final String key, final String type, final String value, final XMLElement xe) {
    XMLElement property = new CaseSensitiveXMLElement("property");
    xe.addChild(property);
    property.setAttribute("name", key);
    property.setAttribute("type", type);
    property.setAttribute("value", value);
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 62 with XMLElement

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

the class ScriptCompiler method generateEntityDs.

private void generateEntityDs(String packagePath, String script, String compiledDate, List<Dependency> dependencies, Set<String> dependentResources) throws IOException {
    String fullName;
    if (packagePath.equals("")) {
        fullName = script;
    } else {
        fullName = packagePath + "/" + script;
    }
    String entityName = fullName.substring(fullName.indexOf('/') + 1).replaceAll("/", ".");
    String symbolicName = rpcNameFromScriptPath(fullName).replaceAll("/", ".");
    XMLElement xe = new CaseSensitiveXMLElement("scr:component");
    xe.setAttribute("xmlns:scr", "http://www.osgi.org/xmlns/scr/v1.1.0");
    xe.setAttribute("immediate", "true");
    xe.setAttribute("name", "navajo.entities." + symbolicName);
    xe.setAttribute("activate", "activate");
    xe.setAttribute("deactivate", "deactivate");
    xe.setAttribute("enabled", "true");
    XMLElement implementation = new CaseSensitiveXMLElement("implementation");
    xe.addChild(implementation);
    implementation.setAttribute("class", "com.dexels.navajo.enterprise.entity.Entity");
    XMLElement service = new CaseSensitiveXMLElement("service");
    xe.addChild(service);
    XMLElement provide = new CaseSensitiveXMLElement("provide");
    service.addChild(provide);
    provide.setAttribute("interface", "com.dexels.navajo.enterprise.entity.Entity");
    addProperty("entity.name", "String", entityName, xe);
    addProperty("service.name", "String", fullName, xe);
    addProperty("entity.message", "String", script, xe);
    XMLElement refMan = new CaseSensitiveXMLElement("reference");
    refMan.setAttribute("bind", "setEntityManager");
    refMan.setAttribute("unbind", "clearEntityManager");
    refMan.setAttribute("policy", "dynamic");
    refMan.setAttribute("cardinality", "1..1");
    refMan.setAttribute("interface", "com.dexels.navajo.enterprise.entity.EntityManager");
    refMan.setAttribute("name", "EntityManager");
    xe.addChild(refMan);
    XMLElement refScript = new CaseSensitiveXMLElement("reference");
    refScript.setAttribute("cardinality", "1..1");
    refScript.setAttribute("bind", "setCompiledScript");
    refScript.setAttribute("unbind", "clearCompiledScript");
    refScript.setAttribute("interface", "com.dexels.navajo.script.api.CompiledScriptFactory");
    refScript.setAttribute("name", "CompiledScript");
    String target1 = "component.name=" + symbolicName.replace("/", ".");
    String target2 = "navajo.compileddate=" + compiledDate;
    refScript.setAttribute("target", "(&(" + target1 + ")(" + target2 + "))");
    xe.addChild(refScript);
    for (int i = 0; i < dependencies.size(); i++) {
        Dependency d = dependencies.get(i);
        if (d instanceof ExtendDependency) {
            String extendedEntity = d.getId().replaceAll("/", ".");
            XMLElement depref = new CaseSensitiveXMLElement("reference");
            depref.setAttribute("name", "SuperEntity" + i);
            depref.setAttribute("policy", "static");
            depref.setAttribute("cardinality", "1..1");
            depref.setAttribute("interface", "com.dexels.navajo.enterprise.entity.Entity");
            depref.setAttribute("target", "(entity.name=" + extendedEntity + ")");
            depref.setAttribute("bind", "addSuperEntity");
            depref.setAttribute("unbind", "removeSuperEntity");
            xe.addChild(depref);
        }
    }
    for (String resource : dependentResources) {
        XMLElement dep = new CaseSensitiveXMLElement("reference");
        dep.setAttribute("bind", "set" + resource);
        dep.setAttribute("unbind", "clear" + resource);
        dep.setAttribute("policy", "static");
        dep.setAttribute("cardinality", "1..1");
        dep.setAttribute("interface", "javax.sql.DataSource");
        dep.setAttribute("target", "(navajo.resource.name=" + resource + ")");
        xe.addChild(dep);
    }
    PrintWriter w = new PrintWriter(navajoIOConfig.getOutputWriter(navajoIOConfig.getCompiledScriptPath(), packagePath, "entity", ".xml"));
    w.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    xe.write(w);
    w.flush();
    w.close();
}
Also used : ExtendDependency(com.dexels.navajo.mapping.compiler.meta.ExtendDependency) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) ExtendDependency(com.dexels.navajo.mapping.compiler.meta.ExtendDependency) AdapterFieldDependency(com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency) IncludeDependency(com.dexels.navajo.mapping.compiler.meta.IncludeDependency) Dependency(com.dexels.navajo.script.api.Dependency) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) PrintWriter(java.io.PrintWriter)

Example 63 with XMLElement

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

the class JarFunctionFactory method readDefinitionFile.

@Override
public final void readDefinitionFile(Map<String, FunctionDefinition> fuds, ExtensionDefinition fd) {
    // Read config file.
    CaseSensitiveXMLElement xml = new CaseSensitiveXMLElement();
    try {
        InputStream fis = fd.getDefinitionAsStream();
        xml.parseFromStream(fis);
        fis.close();
        Vector<XMLElement> children = xml.getChildren();
        for (int i = 0; i < children.size(); i++) {
            // Get object, usage and description.
            XMLElement element = children.get(i);
            if (element.getName().equals("function")) {
                parseFunction(fuds, element);
            }
            if (element.getName().equals("map")) {
                parseAdapters(fuds, fd, element);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) InputStream(java.io.InputStream) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 64 with XMLElement

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

the class JarFunctionFactory method parseFunction.

public FunctionDefinition parseFunction(Map<String, FunctionDefinition> fuds, XMLElement element) {
    Vector<XMLElement> def = element.getChildren();
    String name = (String) element.getAttribute("name");
    String object = (String) element.getAttribute("class");
    String description = null;
    String inputParams = null;
    String resultParam = null;
    for (int j = 0; j < def.size(); j++) {
        if (def.get(j).getName().equals("description")) {
            description = def.get(j).getContent();
        }
        if (def.get(j).getName().equals("input")) {
            inputParams = def.get(j).getContent();
        }
        if (def.get(j).getName().equals("result")) {
            resultParam = def.get(j).getContent();
        }
    }
    if (name != null) {
        FunctionDefinition functionDefinition = new FunctionDefinition(object, description, inputParams, resultParam);
        functionDefinition.setXmlElement(element);
        fuds.put(name, functionDefinition);
        return functionDefinition;
    }
    return null;
}
Also used : FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 65 with XMLElement

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

the class MethodDefinition method generateCode.

public void generateCode(XMLElement in, XMLElement out, String filename) throws MetaCompileException {
    Map<Integer, XMLElement> orderedParameters = new TreeMap<>();
    String condition = (String) in.getAttribute("condition");
    // Create condition that always evaluates to true if an empty condition is specified.
    if (condition == null || condition.trim().equals("")) {
        condition = "true";
    }
    boolean hasCondition = false;
    String tempParamName = null;
    if (!condition.equals("true")) {
        // Generate a temp. param to evaluate the condition expression.
        XMLElement c = new TSLElement(in, "param");
        tempParamName = generateParamName();
        // Force absolute param name.
        c.setAttribute("name", Navajo.MESSAGE_SEPARATOR + tempParamName);
        XMLElement exp = new TSLElement(in, "expression");
        exp.setAttribute("value", condition);
        c.addChild(exp);
        out.addChild(c);
        hasCondition = true;
    }
    Iterator<String> attributes = in.enumerateAttributeNames();
    Set<String> required = new HashSet<>();
    // Get all 'automatic' parameters and determine required parameters.
    Iterator<ParameterDefinition> auto = parameters.values().iterator();
    while (auto.hasNext()) {
        ParameterDefinition pd = auto.next();
        if (pd.getRequired().equals("automatic")) {
            String setterValue = pd.getValue();
            if (in.getAttribute(pd.getName()) != null) {
                setterValue = (String) in.getAttribute(pd.getName());
            }
            XMLElement pdx = pd.generateCode(in, setterValue, false, (hasCondition ? "[/@" + tempParamName + "]" : null), out, false, filename);
            orderedParameters.put(pd.getOrder(), pdx);
        } else if (pd.getRequired().equals("true")) {
            required.add(pd.getName());
        }
    }
    while (attributes.hasNext()) {
        String attribName = attributes.next();
        String attribValue = (String) in.getAttribute(attribName);
        ParameterDefinition pd = parameters.get(attribName);
        if (pd == null && !attribName.equals("condition")) {
            throw new UnknownParameterException(getName(), attribName, in, filename);
        }
        if (pd != null && !pd.getRequired().equals("automatic")) {
            XMLElement pdx = pd.generateCode(in, attribValue, false, (hasCondition ? "[/@" + tempParamName + "]" : null), out, false, filename);
            orderedParameters.put(pd.getOrder(), pdx);
            required.remove(pd.getName());
        }
    }
    // Check if all required parameters are present.
    if (!required.isEmpty()) {
        throw new MissingParameterException(required, getName(), in, filename);
    }
    Iterator<XMLElement> iter = orderedParameters.values().iterator();
    while (iter.hasNext()) {
        XMLElement xe = iter.next();
        out.addChild(xe);
    }
}
Also used : XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

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