Example usage for org.apache.commons.digester WithDefaultsRulesWrapper WithDefaultsRulesWrapper

List of usage examples for org.apache.commons.digester WithDefaultsRulesWrapper WithDefaultsRulesWrapper

Introduction

In this page you can find the example usage for org.apache.commons.digester WithDefaultsRulesWrapper WithDefaultsRulesWrapper.

Prototype

public WithDefaultsRulesWrapper(Rules wrappedRules) 

Source Link

Document

Base constructor.

Usage

From source file:org.xchain.framework.digester.AnnotationRuleSet.java

public void addRuleInstances(Digester digester) {
    // log what we are attempting to do.

    // set up the namespace in the digester.
    digester.setNamespaceAware(true);/*from  ww w .  j  a v a  2s .c om*/

    // add the place holder rule used to pass mappings when there is not an element to pass them on...
    // TODO: add code for the place holder command.

    LifecycleContext lifecycleContext = Lifecycle.getLifecycleContext();

    for (NamespaceContext namespaceContext : lifecycleContext.getNamespaceContextMap().values()) {
        digester.setRuleNamespaceURI(namespaceContext.getNamespaceUri());

        for (Class classObject : namespaceContext.getCatalogList()) {
            // for catalogs that we find, we need to add a create rule, a properties rule, a set next rule, and a registration rule.
            addRulesForCatalog(digester, classObject, lifecycleContext);
        }

        for (Class classObject : namespaceContext.getCommandList()) {
            // for commands that we find, we need to add a create rule, a properties rule, a set next rule, and a registration rule.
            addRulesForCommand(digester, lifecycleContext, systemId, classObject);
        }
    }

    WithDefaultsRulesWrapper defaults = new WithDefaultsRulesWrapper(digester.getRules());
    defaults.addDefault(new UnknownElementRule());
    digester.setRules(defaults);
}

From source file:org.xchain.tools.monitoring.MonitoringMojo.java

private void mergeWarMonitoringInfo(MonitoringInfo monitoringInfo, File file) throws MojoExecutionException {
    JarFile artifactJar = null;/*from  www. j  a v a 2 s.  c  om*/
    JarEntry monitoringInfoEntry = null;
    InputStream in = null;
    try {
        getLog().info("Getting monitoring info from file " + file.toString());
        artifactJar = new JarFile(file);
        monitoringInfoEntry = artifactJar.getJarEntry("WEB-INF/classes/META-INF/monitoring-info.xml");
        if (monitoringInfoEntry != null) {
            in = artifactJar.getInputStream(monitoringInfoEntry);

            // digest the xml file and get all of the entries.
            Digester digester = new Digester();
            digester.push(monitoringInfo);
            digester.addRuleSet(new MonitoringInfoRuleSet());
            WithDefaultsRulesWrapper wrapper = new WithDefaultsRulesWrapper(digester.getRules());
            wrapper.addDefault(new LoggingRule());
            digester.setRules(wrapper);
            digester.parse(in);
        } else {
            getLog().info("Monitoring info file not found in " + file.toString());
        }
    } catch (SAXException se) {
        throw new MojoExecutionException("Could not parse a monitoring-info.xml file.", se);
    } catch (IOException ioe) {
        throw new MojoExecutionException("Could not open jar file.", ioe);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ioe) {
                getLog().warn("Could not close a jar entry input stream.", ioe);
            }
        }
        try {
            artifactJar.close();
        } catch (IOException ioe) {
            getLog().warn("Could not close a jar.", ioe);
        }
    }
}