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);
}
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);
}
}
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);
}
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();
}
Aggregations