Search in sources :

Example 46 with XMLElement

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

the class TslMetaDataHandler method getScriptMetadata.

public XMLElement getScriptMetadata(String scriptName) {
    XMLElement x = new CaseSensitiveXMLElement();
    x.setName("metadata");
    addScriptElement(x, scriptName);
    return x;
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 47 with XMLElement

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

the class OsgiFunctionFactory method getAllFunctionElements.

@SuppressWarnings("rawtypes")
@Override
public List<XMLElement> getAllFunctionElements(String interfaceClass, String propertyKey) {
    List<XMLElement> result = new ArrayList<>();
    BundleContext context = Version.getDefaultBundleContext();
    try {
        ServiceReference[] refs = context.getServiceReferences(interfaceClass, null);
        if (refs == null) {
            logger.warn("Service enumeration failed class: {}", interfaceClass);
            return null;
        }
        for (ServiceReference serviceReference : refs) {
            Object o = serviceReference.getProperty(propertyKey);
            FunctionDefinition fd = (FunctionDefinition) o;
            XMLElement xe = fd.getXmlElement();
            if (xe != null) {
                result.add(xe);
            }
        }
    } catch (InvalidSyntaxException e) {
        logger.error("Error: ", e);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 48 with XMLElement

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

the class OsgiFunctionFactory method getAllAdapterElements.

@SuppressWarnings("rawtypes")
@Override
public // TODO not ok, seems to return function elements
List<XMLElement> getAllAdapterElements(String interfaceClass, String propertyKey) {
    List<XMLElement> result = new ArrayList<>();
    BundleContext context = Version.getDefaultBundleContext();
    try {
        ServiceReference[] refs = context.getServiceReferences(interfaceClass, null);
        if (refs == null) {
            logger.warn("Service enumeration failed class: {}", interfaceClass);
            return null;
        }
        for (ServiceReference serviceReference : refs) {
            Object o = serviceReference.getProperty(propertyKey);
            FunctionDefinition fd = (FunctionDefinition) o;
            XMLElement xe = fd.getXmlElement();
            if (xe != null) {
                result.add(xe);
            }
        }
    } catch (InvalidSyntaxException e) {
        logger.error("Error: ", e);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 49 with XMLElement

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

the class TagMap method setInsert.

public void setInsert(Binary b) throws UserException {
    insert = b;
    String insertChild = new String(b.getData());
    XMLElement xe = new CaseSensitiveXMLElement(true);
    try {
        xe.parseFromReader(new StringReader(insertChild));
    } catch (IOException ex) {
        logger.error("XML parse problem: ", ex);
    }
    // get child based on childName set
    TagMap child = getChild();
    child.setChild(TagMap.parseXMLElement(xe, this.compact));
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) StringReader(java.io.StringReader) IOException(java.io.IOException) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 50 with XMLElement

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

the class ScriptCompiler method generateDs.

private String generateDs(String packagePath, String script, List<Dependency> dependencies, Set<String> dependentResources) throws IOException {
    String fullName;
    String compiledDate = "" + Long.valueOf(new Date().getTime());
    if (packagePath.equals("")) {
        fullName = script;
    } else {
        fullName = packagePath + "/" + script;
    }
    String javaPackagePath;
    if ("".equals(packagePath)) {
        javaPackagePath = "defaultPackage";
    } else {
        javaPackagePath = packagePath.replaceAll("/", ".");
    }
    String tenant = tenantFromScriptPath(fullName);
    if (tenant == null) {
        tenant = getTentantSpecificDependency(dependencies);
    }
    String symbolicName = rpcNameFromScriptPath(fullName).replaceAll("/", ".");
    boolean hasTenantSpecificFile = tenant != null;
    XMLElement xe = new CaseSensitiveXMLElement("scr:component");
    xe.setAttribute("xmlns:scr", "http://www.osgi.org/xmlns/scr/v1.1.0");
    xe.setAttribute("immediate", "true");
    if (tenant != null) {
        xe.setAttribute("name", symbolicName + "_" + tenant);
    } else {
        xe.setAttribute("name", symbolicName);
    }
    xe.setAttribute("activate", "activate");
    xe.setAttribute("deactivate", "deactivate");
    xe.setAttribute("configuration-policy", "optional");
    XMLElement implementation = new CaseSensitiveXMLElement("implementation");
    xe.addChild(implementation);
    implementation.setAttribute("class", javaPackagePath + "." + script + "Factory");
    XMLElement service = new CaseSensitiveXMLElement("service");
    xe.addChild(service);
    XMLElement provide = new CaseSensitiveXMLElement("provide");
    service.addChild(provide);
    provide.setAttribute("interface", CompiledScriptFactory.class.getName());
    addProperty("navajo.scriptName", "String", symbolicName, xe);
    addProperty("navajo.compileddate", "String", compiledDate, xe);
    if (hasTenantSpecificFile) {
        addProperty("navajo.tenant", "String", tenant, xe);
        addProperty("service.ranking", "Integer", "1000", xe);
    } else {
        addProperty("service.ranking", "Integer", "0", xe);
        addProperty("navajo.tenant", "String", "default", xe);
    }
    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, script, ".xml"));
    w.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    xe.write(w);
    w.flush();
    w.close();
    return compiledDate;
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) CompiledScriptFactory(com.dexels.navajo.script.api.CompiledScriptFactory) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

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