Search in sources :

Example 1 with MapMetaData

use of com.dexels.navajo.mapping.compiler.meta.MapMetaData in project navajo by Dexels.

the class TslPreCompiler method getAllDependencies.

public void getAllDependencies(File script, String scriptFolder, List<Dependency> deps, String scriptTenant) throws XPathExpressionException, UserException {
    Document tslDoc = null;
    InputStream is = null;
    try {
        if (script.getAbsolutePath().endsWith(".ns")) {
            // Check for NS3 type script
            NS3ToNSXML ns3toxml = new NS3ToNSXML();
            ns3toxml.initialize();
            String content = ns3toxml.read(script.getAbsolutePath());
            InputStream metais = ns3toxml.parseNavascript(content);
            MapMetaData mmd = MapMetaData.getInstance();
            String intermed = mmd.parse(script.getAbsolutePath(), metais);
            metais.close();
            is = new ByteArrayInputStream(intermed.getBytes());
        } else if (MapMetaData.isMetaScript(script.getAbsolutePath())) {
            // Check for navascript type script
            MapMetaData mmd = MapMetaData.getInstance();
            InputStream metais = inputStreamReader.getResource(script.getAbsolutePath());
            String intermed = mmd.parse(script.getAbsolutePath(), metais);
            metais.close();
            is = new ByteArrayInputStream(intermed.getBytes());
        } else {
            // Normal tsl type script
            is = inputStreamReader.getResource(script.getAbsolutePath());
        }
        tslDoc = XMLDocumentUtils.createDocument(is, false);
    } catch (Exception e) {
        throw new UserException(-1, "Exception on pre-compiling script: " + script, e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                logger.error("Error: ", e);
            }
        }
    }
    getAllDependencies(script.getAbsolutePath(), scriptTenant, scriptFolder, deps, tslDoc);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NS3ToNSXML(com.dexels.navajo.mapping.compiler.navascript.NS3ToNSXML) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) Document(org.w3c.dom.Document) MapMetaData(com.dexels.navajo.mapping.compiler.meta.MapMetaData) XPathExpressionException(javax.xml.xpath.XPathExpressionException) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException)

Example 2 with MapMetaData

use of com.dexels.navajo.mapping.compiler.meta.MapMetaData in project navajo by Dexels.

the class GenerateXSD method generateXSD.

public String generateXSD() throws Exception {
    CaseSensitiveXMLElement xml = new CaseSensitiveXMLElement();
    InputStreamReader fis = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("basenavascript.xsd"));
    xml.parseFromReader(fis);
    fis.close();
    MapMetaData mmd = MapMetaData.getInstance();
    Set<String> maps = mmd.getMapDefinitions();
    Iterator<String> all = maps.iterator();
    while (all.hasNext()) {
        String mappie = all.next();
        if (!mappie.equals("__empty__")) {
            XMLElement x = createAdapterXSD(mappie, xml);
            xml.addChild(x);
        }
    }
    ArrayList<XMLElement> tags = new ArrayList<XMLElement>();
    findTags(xml, "adapters:insertedadapters", tags);
    for (int i = 0; i < tags.size(); i++) {
        XMLElement x = tags.get(i);
        XMLElement parent = x.getParent();
        // <xs:element ref="map.sqlquery"/>
        all = maps.iterator();
        while (all.hasNext()) {
            String mappie = all.next();
            if (!mappie.equals("__empty__")) {
                CaseSensitiveXMLElement replace = new CaseSensitiveXMLElement("xs:element");
                replace.setAttribute("ref", "map." + mappie);
                parent.addChild(replace);
            }
        }
        parent.removeChild(x);
    }
    StringWriter sb = new StringWriter();
    xml.write(sb);
    return sb.toString();
}
Also used : CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) InputStreamReader(java.io.InputStreamReader) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) MapMetaData(com.dexels.navajo.mapping.compiler.meta.MapMetaData) CaseSensitiveXMLElement(com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement) XMLElement(com.dexels.navajo.document.nanoimpl.XMLElement)

Example 3 with MapMetaData

use of com.dexels.navajo.mapping.compiler.meta.MapMetaData in project navajo by Dexels.

the class TslCompiler method compileScript.

public void compileScript(String script, String scriptPath, String workingPath, String packagePath, Writer outputWriter, List<Dependency> deps, String tenant, boolean hasTenantSpecificScript, boolean forceTenant) throws SystemException, SkipCompilationException {
    final String extension = ".xml";
    String fullScriptPath = scriptPath + "/" + packagePath + "/" + script + extension;
    String ns3ScriptPath = scriptPath + "/" + packagePath + "/" + script + ".ns";
    List<String> inheritedScripts = new ArrayList<>();
    List<String> extendEntities = new ArrayList<>();
    InputStream is = null;
    boolean isNavascript = false;
    try {
        if (new File(ns3ScriptPath).exists()) {
            NS3ToNSXML ns3toxml = new NS3ToNSXML();
            ns3toxml.initialize();
            scriptType = "navascript";
            String content = ns3toxml.read(ns3ScriptPath);
            InputStream metais = ns3toxml.parseNavascript(content);
            MapMetaData mmd = MapMetaData.getInstance();
            String intermed = mmd.parse(fullScriptPath, metais);
            metais.close();
            is = new ByteArrayInputStream(intermed.getBytes());
            isNavascript = true;
        } else if (MapMetaData.isMetaScript(fullScriptPath)) {
            // Check for metascript.
            scriptType = "navascript";
            MapMetaData mmd = MapMetaData.getInstance();
            InputStream metais = navajoIOConfig.getScript(packagePath + "/" + script, tenant, extension);
            String intermed = mmd.parse(fullScriptPath, metais);
            metais.close();
            is = new ByteArrayInputStream(intermed.getBytes());
        } else {
            is = navajoIOConfig.getScript(packagePath + "/" + script, tenant, extension);
        }
        if (!isNavascript) {
            // NS3 does NOT support inheritance at this moment.
            InputStream sis = navajoIOConfig.getScript(packagePath + "/" + script, tenant, extension);
            logger.debug("Getting script: {}/{}", packagePath, script);
            if (ScriptInheritance.containsInject(sis)) {
                // Inheritance preprocessor before compiling.
                InputStream ais = null;
                ais = ScriptInheritance.inherit(is, scriptPath, inheritedScripts);
                is.close();
                is = ais;
            }
            sis.close();
        }
        for (int i = 0; i < inheritedScripts.size(); i++) {
            File inheritedFile = new File(fetchScriptFileName(scriptPath + "/" + inheritedScripts.get(i)));
            addDependency("dependentObjects.add( new InheritDependency( Long.valueOf(\"" + IncludeDependency.getFileTimeStamp(inheritedFile) + "\"), \"" + inheritedScripts.get(i) + "\"));\n", "INHERIT" + inheritedScripts.get(i));
        }
        compileScript(is, packagePath, script, scriptPath, outputWriter, deps, tenant, forceTenant);
    } catch (SkipCompilationException e) {
        throw e;
    } catch (Exception e) {
        throw new SystemException(-1, "Error while generating Java code for script: " + script, e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) MapMetaData(com.dexels.navajo.mapping.compiler.meta.MapMetaData) UserException(com.dexels.navajo.script.api.UserException) TransformerException(javax.xml.transform.TransformerException) MappingException(com.dexels.navajo.script.api.MappingException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) ParseException(com.dexels.navajo.parser.compiled.ParseException) KeywordException(com.dexels.navajo.mapping.compiler.meta.KeywordException) MetaCompileException(com.dexels.navajo.mapping.compiler.meta.MetaCompileException) IOException(java.io.IOException) SystemException(com.dexels.navajo.script.api.SystemException) CompilationException(com.dexels.navajo.script.api.CompilationException) SystemException(com.dexels.navajo.script.api.SystemException) ByteArrayInputStream(java.io.ByteArrayInputStream) NS3ToNSXML(com.dexels.navajo.mapping.compiler.navascript.NS3ToNSXML) File(java.io.File)

Aggregations

MapMetaData (com.dexels.navajo.mapping.compiler.meta.MapMetaData)3 NS3ToNSXML (com.dexels.navajo.mapping.compiler.navascript.NS3ToNSXML)2 UserException (com.dexels.navajo.script.api.UserException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 CaseSensitiveXMLElement (com.dexels.navajo.document.nanoimpl.CaseSensitiveXMLElement)1 XMLElement (com.dexels.navajo.document.nanoimpl.XMLElement)1 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)1 KeywordException (com.dexels.navajo.mapping.compiler.meta.KeywordException)1 MetaCompileException (com.dexels.navajo.mapping.compiler.meta.MetaCompileException)1 ParseException (com.dexels.navajo.parser.compiled.ParseException)1 CompilationException (com.dexels.navajo.script.api.CompilationException)1 MappingException (com.dexels.navajo.script.api.MappingException)1 SystemException (com.dexels.navajo.script.api.SystemException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 StringWriter (java.io.StringWriter)1