Search in sources :

Example 26 with CaseSensitiveXMLElement

use of com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement 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 27 with CaseSensitiveXMLElement

use of com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement 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 28 with CaseSensitiveXMLElement

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

the class TslMetaDataHandler method addScriptElement.

/**
 * @param x
 * @param element
 */
private void addScriptElement(XMLElement x, String element) {
    XMLElement xn = new CaseSensitiveXMLElement();
    xn.setName("script");
    x.addChild(xn);
    xn.setAttribute("name", element);
    addAdapters(xn, element);
    addCalls(xn, element);
    addCalledBy(xn, element);
    addIncludes(xn, element);
    addIncomingIncludes(xn, element);
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 29 with CaseSensitiveXMLElement

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

the class TslMetaDataHandler method addCalls.

private void addCalls(XMLElement xn, String element) {
    TreeSet<String> s = callsScriptMap.get(element);
    if (s == null) {
        return;
    }
    for (Iterator<String> iter = s.iterator(); iter.hasNext(); ) {
        String include = iter.next();
        XMLElement xnincl = new CaseSensitiveXMLElement();
        xnincl.setName("calls");
        xnincl.setAttribute("name", include);
        xn.addChild(xnincl);
    }
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 30 with CaseSensitiveXMLElement

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

the class TslMetaDataHandler method addIncomingIncludes.

/**
 * @param xn
 * @param element
 */
private void addIncomingIncludes(XMLElement xn, String element) {
    TreeSet<String> s = includedByScriptMap.get(element);
    if (s == null) {
        return;
    }
    for (Iterator<String> iter = s.iterator(); iter.hasNext(); ) {
        String include = iter.next();
        XMLElement xnincl = new CaseSensitiveXMLElement();
        xnincl.setName("includedby");
        xnincl.setAttribute("name", include);
        xn.addChild(xnincl);
    }
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Aggregations

CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)53 XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)49 IOException (java.io.IOException)10 InputStreamReader (java.io.InputStreamReader)7 FileReader (java.io.FileReader)5 HashMap (java.util.HashMap)5 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 APIException (com.dexels.navajo.article.APIException)2 Message (com.dexels.navajo.document.Message)2 Property (com.dexels.navajo.document.Property)2 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 PrintWriter (java.io.PrintWriter)2 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 XMLParseException (com.dexels.navajo.document.nanoimpl.XMLParseException)1 AdapterFieldDependency (com.dexels.navajo.mapping.compiler.meta.AdapterFieldDependency)1