use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class LanguageConfigurationProvider method lookUpDocument.
private Document lookUpDocument() {
Document doc = null;
URL url = null;
if (configuration == null) {
throw new ConfigurationException("Missing default values configuration");
}
String defaults = configuration.getDefaultLanguage();
String fileName;
if (defaults == null) {
fileName = "default-config.xml";
} else {
fileName = "META-INF/walkmod/walkmod-" + defaults + "-" + suffixFileName;
}
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("Walkmod configuration parsed");
}
return doc;
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadWriter.
public void loadWriter(Element child, ChainConfig ac) {
if ("writer".equals(child.getNodeName())) {
WriterConfig wc = new WriterConfigImpl();
String path = child.getAttribute("path");
if ("".equals(path)) {
throw new ConfigurationException("Invalid writer definition: " + "A path attribute must be specified");
}
wc.setPath(path);
String type = child.getAttribute("type");
if ("".equals(type)) {
wc.setType(null);
} else {
wc.setType(type);
}
NodeList childs = child.getChildNodes();
if (childs != null) {
int max = childs.getLength();
List<String> excludes = new LinkedList<String>();
List<String> includes = new LinkedList<String>();
for (int i = 0; i < max; i++) {
Node n = childs.item(i);
String nodeName = n.getNodeName();
if ("exclude".equals(nodeName)) {
Element exclude = (Element) n;
excludes.add(exclude.getAttribute("wildcard"));
} else if ("include".equals(nodeName)) {
Element include = (Element) n;
includes.add(include.getAttribute("wildcard"));
} else if (!"param".equals(nodeName)) {
throw new ConfigurationException("Invalid writer definition. Only exclude or include tags are supported");
}
}
if (!excludes.isEmpty()) {
String[] excludesArray = new String[excludes.size()];
int j = 0;
for (String exclude : excludes) {
excludesArray[j] = exclude;
j++;
}
wc.setExcludes(excludesArray);
}
if (!includes.isEmpty()) {
String[] includesArray = new String[includes.size()];
int j = 0;
for (String include : includes) {
includesArray[j] = include;
j++;
}
wc.setIncludes(includesArray);
}
}
wc.setParams(getParams(child));
ac.setWriterConfig(wc);
}
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadWalkerConfig.
public void loadWalkerConfig(Element element, ChainConfig ac) {
NodeList children;
Node walkerNode = element;
if ("walker".equals(walkerNode.getNodeName())) {
WalkerConfig wc = new WalkerConfigImpl();
String type = ((Element) walkerNode).getAttribute("type");
if ("".equals(type)) {
wc.setType(null);
} else {
wc.setType(type);
}
wc.setParams(getParams((Element) walkerNode));
wc.setRootNamespace(((Element) walkerNode).getAttribute("root-namespace"));
children = walkerNode.getChildNodes();
if (children.getLength() > 3) {
throw new ConfigurationException("Invalid walker definition in the " + "architecture" + ac.getName() + ". Please, verify the dtd");
}
int max = children.getLength();
int transformationIndex = wc.getParams().size();
if (transformationIndex < max) {
final String nodeName = children.item(transformationIndex).getNodeName();
if (("parser").equals(nodeName)) {
loadParserConfig((Element) children.item(transformationIndex), wc);
transformationIndex = 1;
} else {
wc.setParserConfig(new ParserConfigImpl());
}
} else {
wc.setParserConfig(new ParserConfigImpl());
}
if (transformationIndex < max) {
loadTransformationConfigs((Element) children.item(transformationIndex), wc);
}
ac.setWalkerConfig(wc);
} else {
throw new ConfigurationException("Invalid architecture definition. " + "A walker element must be defined in the architecture element " + ac.getName());
}
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadChains.
public void loadChains() throws ConfigurationException {
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 (childNode instanceof Element) {
Element child = (Element) childNode;
final String nodeName = child.getNodeName();
if ("chain".equals(nodeName)) {
ChainConfig ac = new ChainConfigImpl();
if ("".equals(child.getAttribute("name"))) {
if (i == 0) {
ac.setName("chain_" + (i + 1));
} else {
ac.setName("chain_" + (i + 1));
}
} else {
ac.setName(child.getAttribute("name"));
}
NodeList childrenModel = child.getChildNodes();
ac.setParameters(getParams(child));
int index = 0;
if ("reader".equals(childrenModel.item(index).getNodeName())) {
loadReaderConfig((Element) childrenModel.item(index), ac);
index++;
} else {
addDefaultReaderConfig(ac);
}
if (index >= childrenModel.getLength()) {
throw new ConfigurationException("Invalid architecture definition for the " + "element" + ac.getName());
}
if ("walker".equals(childrenModel.item(index).getNodeName())) {
loadWalkerConfig((Element) childrenModel.item(index), ac);
index++;
} else if ("transformation".equals(childrenModel.item(index).getNodeName())) {
addDefaultWalker(ac, child);
} else {
throw new ConfigurationException("Invalid transformation chain. A walker or at least one transformation must be specified");
}
if (index > childrenModel.getLength()) {
throw new ConfigurationException("Invalid architecture definition for the " + "element" + ac.getName());
}
boolean found = false;
while (index < childrenModel.getLength() && !found) {
if ("writer".equals(childrenModel.item(index).getNodeName())) {
found = true;
loadWriter((Element) childrenModel.item(index), ac);
}
index++;
}
if (!found) {
addDefaultWriterConfig(ac);
}
configuration.addChainConfig(ac);
} else if ("transformation".equals(nodeName)) {
ChainConfig ac = new ChainConfigImpl();
ac.setName("default");
List<TransformationConfig> transformationConfigs = getTransformationItems(rootElement, true);
WalkerConfig wc = new WalkerConfigImpl();
wc.setType(null);
wc.setParserConfig(new ParserConfigImpl());
wc.setTransformations(transformationConfigs);
addDefaultReaderConfig(ac);
ac.setWalkerConfig(wc);
addDefaultWriterConfig(ac);
configuration.addChainConfig(ac);
i = i + transformationConfigs.size() - 1;
}
}
}
LOG.debug("Transformation chains loaded");
}
use of org.walkmod.conf.ConfigurationException in project walkmod-core by walkmod.
the class PluginsConfigurationProviderTest method testInvalidPlugins.
@Test
public void testInvalidPlugins() {
IvyConfigurationProvider provider = new IvyConfigurationProvider();
Configuration conf = new ConfigurationImpl();
provider.init(conf);
PluginConfig pc = new PluginConfigImpl();
pc.setGroupId("foo");
pc.setArtifactId("bar");
pc.setVersion("10");
conf.setPlugins(new LinkedList());
conf.getPlugins().add(pc);
Exception exception = null;
try {
provider.load();
} catch (ConfigurationException e) {
exception = e;
}
Assert.assertNotNull(exception);
}
Aggregations