Search in sources :

Example 1 with ParserAware

use of org.walkmod.walkers.ParserAware 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);
}
Also used : ChainWriter(org.walkmod.ChainWriter) ResourceModifier(org.walkmod.ResourceModifier) WalkModException(org.walkmod.exceptions.WalkModException) Configuration(org.walkmod.conf.entities.Configuration) TransformationConfig(org.walkmod.conf.entities.TransformationConfig) ParserAware(org.walkmod.walkers.ParserAware) ChainConfig(org.walkmod.conf.entities.ChainConfig) Parser(org.walkmod.walkers.Parser)

Aggregations

ChainWriter (org.walkmod.ChainWriter)1 ResourceModifier (org.walkmod.ResourceModifier)1 ChainConfig (org.walkmod.conf.entities.ChainConfig)1 Configuration (org.walkmod.conf.entities.Configuration)1 TransformationConfig (org.walkmod.conf.entities.TransformationConfig)1 WalkModException (org.walkmod.exceptions.WalkModException)1 Parser (org.walkmod.walkers.Parser)1 ParserAware (org.walkmod.walkers.ParserAware)1