use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class PluginsConfigurationProvider method lookUpDocument.
private Document lookUpDocument() {
Document doc = null;
URL url = null;
if (configuration == null) {
throw new ConfigurationException("Missing default values configuration");
}
File f = new File(fileName);
if (f.exists()) {
try {
url = f.toURI().toURL();
} catch (MalformedURLException e) {
throw new ConfigurationException("Unable to load " + fileName, e);
}
}
if (url == null) {
url = configuration.getClassLoader().getResource(fileName);
}
InputStream is = null;
if (url == null) {
if (errorIfMissing) {
throw new ConfigurationException("Could not open files of the name " + fileName);
} else {
LOG.info("Unable to locate default values configuration of the name " + f.getName() + ", skipping");
return doc;
}
}
try {
is = url.openStream();
InputSource in = new InputSource(is);
in.setSystemId(url.toString());
doc = DomHelper.parse(in, dtdMappings);
} catch (Exception e) {
throw new ConfigurationException("Unable to load " + fileName, e);
} finally {
try {
is.close();
} catch (IOException e) {
LOG.error("Unable to close input stream", e);
}
}
if (doc != null) {
LOG.debug("Default Walkmod plugins configuration parsed");
}
return doc;
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadPlugins.
private void loadPlugins() {
Element rootElement = document.getDocumentElement();
NodeList children = rootElement.getChildNodes();
int childSize = children.getLength();
for (int i = 0; i < childSize; i++) {
Node childNode = children.item(i);
if ("plugins".equals(childNode.getNodeName())) {
Element child = (Element) childNode;
Collection<PluginConfig> plugins = new LinkedList<PluginConfig>();
configuration.setPlugins(plugins);
NodeList pluginNodes = child.getChildNodes();
int pluginSize = pluginNodes.getLength();
for (int j = 0; j < pluginSize; j++) {
Node pluginNode = pluginNodes.item(j);
if ("plugin".equals(pluginNode.getNodeName())) {
Element pluginElement = (Element) pluginNode;
PluginConfig pc = new PluginConfigImpl();
String groupId = pluginElement.getAttribute("groupId");
String artifactId = pluginElement.getAttribute("artifactId");
String version = pluginElement.getAttribute("version");
if (groupId == null) {
throw new ConfigurationException("Invalid plugin definition. A groupId is necessary.");
}
if (artifactId == null) {
throw new ConfigurationException("Invalid plugin definition. A artifactId is necessary.");
}
if (version == null) {
throw new ConfigurationException("Invalid plugin definition. A version is necessary.");
}
pc.setGroupId(groupId);
pc.setArtifactId(artifactId);
pc.setVersion(version);
plugins.add(pc);
}
}
}
}
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadDocument.
/**
* Load the XML configuration on memory as a DOM structure with SAX.
* Additional information about elements location is added. Non valid DTDs
* or XML structures are detected.
*
* @param file
* XML configuration
* @return XML tree
*/
private Document loadDocument(String file) {
Document doc = null;
URL url = null;
File f = new File(file);
if (f.exists()) {
try {
url = f.toURI().toURL();
} catch (MalformedURLException e) {
throw new ConfigurationException("Unable to load " + file, e);
}
}
if (url == null) {
url = ClassLoader.getSystemResource(file);
}
InputStream is = null;
if (url == null) {
if (errorIfMissing) {
throw new ConfigurationException("Could not open files of the name " + file);
} else {
LOG.info("Unable to locate configuration files of the name " + file + ", skipping");
return doc;
}
}
try {
is = url.openStream();
InputSource in = new InputSource(is);
in.setSystemId(url.toString());
doc = DomHelper.parse(in, dtdMappings);
} catch (Exception e) {
throw new ConfigurationException("Unable to load " + file, e);
} finally {
try {
is.close();
} catch (IOException e) {
LOG.error("Unable to close input stream", e);
}
}
if (doc != null) {
LOG.debug("Wallmod configuration parsed");
}
return doc;
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class XMLConfigurationProvider method getTransformationItems.
public List<TransformationConfig> getTransformationItems(Element element, boolean exceptionsEnabled) {
List<TransformationConfig> transformationConfigs = new LinkedList<TransformationConfig>();
NodeList transfNodes = element.getChildNodes();
for (int j = 0; j < transfNodes.getLength(); j++) {
element = (Element) transfNodes.item(j);
if ("transformation".equals(element.getNodeName())) {
TransformationConfig tc = new TransformationConfigImpl();
String name = element.getAttribute("name");
String visitor = element.getAttribute("type");
String isMergeable = element.getAttribute("isMergeable");
String mergePolicy = element.getAttribute("merge-policy");
if ("".equals(visitor)) {
throw new ConfigurationException("Invalid transformation definition: A " + "type attribute must be specified");
}
if ("".equals(name)) {
name = null;
}
tc.setName(name);
tc.setType(visitor);
tc.setParameters(getParams(element));
if (isMergeable != null && !("".equals(isMergeable))) {
tc.isMergeable(Boolean.parseBoolean(isMergeable));
}
if (!"".equals(mergePolicy.trim())) {
tc.isMergeable(true);
tc.setMergePolicy(mergePolicy);
}
transformationConfigs.add(tc);
}
}
return transformationConfigs;
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class DynamicModulesConfigurationProvider method load.
@Override
public void load() throws ConfigurationException {
DummyConfigurationProvider dummy = new DummyConfigurationProvider();
dummy.init(configuration);
try {
configuration.runInitializers(dummy);
} catch (Exception e) {
throw new ConfigurationException("Error running initializers", e);
}
List<String> modules = configuration.getModules();
if (modules != null && !modules.isEmpty()) {
configuration.getChainConfigs().clear();
}
}
Aggregations