use of org.walkmod.walkers.Parser in project walkmod-core by walkmod.
the class DefaultChainWalkerAdapter method prepare.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void prepare() throws WalkModException {
walker.setResource(getModel());
walker.setRootNamespace(config.getRootNamespace());
ChainWriter mw = ap.getChainWriter();
mw.setExcludes(config.getChainConfig().getWriterConfig().getExcludes());
mw.setIncludes(config.getChainConfig().getWriterConfig().getIncludes());
walker.setWriter(ap.getChainWriter());
walker.setChainConfig(config.getChainConfig());
ChainConfig ac = config.getChainConfig();
Object visitor;
Configuration c = ac.getConfiguration();
Parser parser = null;
String parserType = config.getParserConfig().getType();
if (parserType != null) {
Object parserInstance = c.getBean(parserType, config.getParserConfig().getParameters());
if (parserInstance != null) {
if (parserInstance instanceof Parser) {
parser = (Parser) parserInstance;
walker.setParser(parser);
} else {
throw new WalkModException("The parser " + parserType + " must implement " + Parser.class.getName());
}
} else {
throw new WalkModException("The parser " + parserType + " does not exist.");
}
}
Collection<TransformationConfig> cfgs = getTransformationConfig();
if (cfgs != null) {
for (TransformationConfig config : cfgs) {
setName(config.getName());
visitor = config.getVisitorInstance();
if (visitor == null || "".equals(config.getType())) {
visitor = c.getBean(config.getType(), config.getParameters());
}
if (visitor instanceof ResourceModifier) {
((ResourceModifier) visitor).setResource(getModel());
}
if (visitor instanceof ParserAware) {
((ParserAware) visitor).setParser(parser);
}
if (visitor != null) {
LOG.debug("setting chain[\"" + ac.getName() + "\"].transformation[\"" + getName() + "\"].walker = " + walker.getClass().getName());
LOG.debug("setting chain[\"" + ac.getName() + "\"].transformation[\"" + getName() + "\"].visitor = " + visitor.getClass().getName());
visitors.add(visitor);
} else {
walker = null;
visitor = null;
LOG.debug("Transformation[" + getName() + "] without walker and visitor");
}
}
}
walker.setVisitors(visitors);
wi.init(this);
}
Aggregations