Search in sources :

Example 11 with WalkModException

use of org.walkmod.exceptions.WalkModException in project walkmod-core by walkmod.

the class DefaultChainAdapter method prepare.

@Override
public void prepare() throws WalkModException {
    setName(ac.getName());
    ReaderConfig readerConfig = ac.getReaderConfig();
    WriterConfig writerConfig = ac.getWriterConfig();
    String modelName = readerConfig.getPath();
    String modelType = readerConfig.getType();
    ChainReader reader = readerConfig.getModelReader();
    if (reader == null) {
        try {
            reader = (ChainReader) ac.getConfiguration().getBean(modelType, readerConfig.getParameters());
        } catch (Exception e2) {
            throw new WalkModException("The model " + modelName + ", whose type is " + modelType + "in the architecture " + getName() + " cannot be loaded ", e2);
        }
    }
    readerConfig.setModelReader(reader);
    reader.setPath(readerConfig.getPath());
    reader.setExcludes(readerConfig.getExcludes());
    reader.setIncludes(readerConfig.getIncludes());
    try {
        setResource(reader.read());
        LOG.debug("Model " + modelName + " loaded");
    } catch (Exception e2) {
        throw new WalkModException("The model " + modelName + ", whose type is " + modelType + "in the architecture " + getName() + " cannot be read ", e2);
    }
    WalkerConfig wc = ac.getWalkerConfig();
    ChainWalkerAdapter wa = new DefaultChainWalkerAdapter();
    setWalkerAdapter(wa);
    ChainWalker walker = wc.getWalker();
    if (walker == null) {
        walker = (ChainWalker) ac.getConfiguration().getBean(wc.getType(), wc.getParams());
    }
    wc.setWalker(walker);
    wa.setWalker(walker);
    wa.setWalkerConfig(wc);
    wa.setArchitectureProxy(this);
    wa.setWalkerInvocation(new DefaultChainWalkerInvocation());
    ChainWriter writer = writerConfig.getModelWriter();
    if (writer == null) {
        try {
            writer = (ChainWriter) ac.getConfiguration().getBean(writerConfig.getType(), writerConfig.getParams());
        } catch (Exception e2) {
            throw new WalkModException("The writer " + ", whose type is " + writerConfig.getType() + "in the architecture " + getName() + " cannot be read ", e2);
        }
    }
    writerConfig.setModelWriter(writer);
    writer.setPath(writerConfig.getPath());
    setChainWriter(writer);
    wa.prepare();
    ai.init(this);
}
Also used : ChainWalker(org.walkmod.ChainWalker) ChainWriter(org.walkmod.ChainWriter) WalkModException(org.walkmod.exceptions.WalkModException) ChainReader(org.walkmod.ChainReader) WalkerConfig(org.walkmod.conf.entities.WalkerConfig) ReaderConfig(org.walkmod.conf.entities.ReaderConfig) ChainWalkerAdapter(org.walkmod.ChainWalkerAdapter) WalkModException(org.walkmod.exceptions.WalkModException) WriterConfig(org.walkmod.conf.entities.WriterConfig)

Example 12 with WalkModException

use of org.walkmod.exceptions.WalkModException in project walkmod-core by walkmod.

the class ScriptingQueryEngine method resolve.

@Override
public Object resolve(Object context, String query) {
    if (context == null) {
        context = rootNode;
    }
    bindings.put("node", context);
    bindings.put("root", rootNode);
    bindings.put("context", this.context);
    try {
        if (query == null) {
            return null;
        }
        if (includes != null) {
            for (String include : includes) {
                URI uri = this.context.getResource(include);
                if (uri != null) {
                    String aux = includeExpression(uri.getPath()) + "\n";
                    query = aux + query;
                }
            }
        }
        return engine.eval(query, bindings);
    } catch (ScriptException e) {
        log.error("The query: [" + query + "] has an error");
        throw new WalkModException(e);
    }
}
Also used : ScriptException(javax.script.ScriptException) WalkModException(org.walkmod.exceptions.WalkModException) URI(java.net.URI)

Example 13 with WalkModException

use of org.walkmod.exceptions.WalkModException in project walkmod-core by walkmod.

the class ScriptProcessor method initialize.

public void initialize(VisitorContext context, Object node) {
    if (engine == null) {
        ScriptEngineManager factory = new ScriptEngineManager(context.getClassLoader());
        engine = factory.getEngineByName(language);
        if (engine instanceof GroovyScriptEngineImpl) {
            ((GroovyScriptEngineImpl) engine).setClassLoader(new GroovyClassLoader(context.getClassLoader(), new CompilerConfiguration()));
        }
    }
    if (queryEngine == null) {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("language", "groovy");
        List<String> includes = new LinkedList<String>();
        includes.add("query.alias.groovy");
        parameters.put("includes", includes);
        Object bean = context.getBean("org.walkmod.query.ScriptingQueryEngine", parameters);
        if (bean != null) {
            if (bean instanceof QueryEngine) {
                queryEngine = (QueryEngine) bean;
            }
        } else {
            throw new WalkModException("Query Engine not found");
        }
    }
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("node", node);
    queryEngine.initialize(context, params);
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GroovyScriptEngineImpl(org.codehaus.groovy.jsr223.GroovyScriptEngineImpl) WalkModException(org.walkmod.exceptions.WalkModException) HashMap(java.util.HashMap) ScriptEngineManager(javax.script.ScriptEngineManager) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) QueryEngine(org.walkmod.query.QueryEngine) LinkedList(java.util.LinkedList)

Example 14 with WalkModException

use of org.walkmod.exceptions.WalkModException in project walkmod-core by walkmod.

the class DomHelper method parse.

/**
 * Creates a W3C Document that remembers the location of each element in the
 * source file. The location of element nodes can then be retrieved using
 * the {@link #getLocationObject(Element)} method.
 *
 * @param inputSource
 *            the inputSource to read the document from
 * @param dtdMappings
 *            a map of DTD names and public ids
 * @return Document
 */
public static Document parse(InputSource inputSource, Map<String, String> dtdMappings) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating((dtdMappings != null));
    factory.setNamespaceAware(true);
    SAXParser parser = null;
    try {
        parser = factory.newSAXParser();
    } catch (Exception ex) {
        throw new WalkModException("Unable to create SAX parser", ex);
    }
    DOMBuilder builder = new DOMBuilder();
    ContentHandler locationHandler = new LocationAttributes.Pipe(builder);
    try {
        parser.parse(inputSource, new StartHandler(locationHandler, dtdMappings));
    } catch (Exception ex) {
        throw new WalkModException(ex);
    }
    return builder.getDocument();
}
Also used : WalkModException(org.walkmod.exceptions.WalkModException) SAXParser(javax.xml.parsers.SAXParser) WalkModException(org.walkmod.exceptions.WalkModException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) ContentHandler(org.xml.sax.ContentHandler) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

WalkModException (org.walkmod.exceptions.WalkModException)14 LinkedList (java.util.LinkedList)4 File (java.io.File)3 DateFormat (java.text.DateFormat)3 DecimalFormat (java.text.DecimalFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 ChainConfig (org.walkmod.conf.entities.ChainConfig)3 Configuration (org.walkmod.conf.entities.Configuration)3 IOException (java.io.IOException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 ScriptException (javax.script.ScriptException)2 ChainAdapter (org.walkmod.ChainAdapter)2 ChainWalker (org.walkmod.ChainWalker)2 ChainWriter (org.walkmod.ChainWriter)2 ConfigurationProvider (org.walkmod.conf.ConfigurationProvider)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)1