Package org.jibeframework.core.app.config

Source Code of org.jibeframework.core.app.config.ConfigurationConfigFactoryWorker

/**
*
*/
package org.jibeframework.core.app.config;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.dom4j.Element;
import org.dom4j.io.XMLWriter;
import org.jibeframework.core.JibeRuntimeException;

class ConfigurationConfigFactoryWorker implements FactoryWorker {

  public String getType() {
    return "configuration";
  }

  public ConfigElement produce(Element el) {
    ConfigurationConfig cc = new ConfigurationConfig();
    cc.setId(el.attributeValue("id"));
    cc.setCondition(el.attributeValue("condition"));
    cc.setReplace(Boolean.parseBoolean(el.attributeValue("replace")));
    StringWriter w = new StringWriter();
    XMLWriter x = new XMLWriter(w);
    try {
      x.write(el);
    } catch (IOException e) {
    }
    XMLConfiguration xmlConfig = new XMLConfiguration();
    try {
      xmlConfig.load(new StringReader(w.toString()));
    } catch (ConfigurationException e) {
      throw new JibeRuntimeException(e);
    }
    xmlConfig.setExpressionEngine(new XPathExpressionEngine());
    cc.setConfiguration(xmlConfig);
    return cc;
  }

}
TOP

Related Classes of org.jibeframework.core.app.config.ConfigurationConfigFactoryWorker

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.