use of org.walkmod.conf.entities.ReaderConfig in project walkmod-core by walkmod.
the class XMLConfigurationProvider method loadReaderConfig.
public void loadReaderConfig(Element element, ChainConfig ac) throws ConfigurationException {
ReaderConfig readerConfig = new ReaderConfig();
if ("reader".equals(element.getNodeName())) {
if ("".equals(element.getAttribute("path"))) {
throw new ConfigurationException("Invalid reader definition: " + "A path attribute must be specified");
}
readerConfig.setPath(element.getAttribute("path"));
if ("".equals(element.getAttribute("type"))) {
readerConfig.setType(null);
} else {
readerConfig.setType(element.getAttribute("type"));
}
readerConfig.setParameters(getParams(element));
NodeList childs = element.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 {
throw new ConfigurationException("Invalid reader 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++;
}
readerConfig.setExcludes(excludesArray);
}
if (!includes.isEmpty()) {
String[] includesArray = new String[includes.size()];
int j = 0;
for (String include : includes) {
includesArray[j] = include;
j++;
}
readerConfig.setIncludes(includesArray);
}
}
} else {
throw new ConfigurationException("Invalid architecture definition. " + "A reader element must be defined in the architecture element " + ac.getName());
}
ac.setReaderConfig(readerConfig);
}
use of org.walkmod.conf.entities.ReaderConfig in project walkmod-core by walkmod.
the class AddIncludesOrExcludesXMLAction method doAction.
@Override
public void doAction() throws Exception {
Document document = provider.getDocument();
Element rootElement = document.getDocumentElement();
NodeList children = rootElement.getChildNodes();
int childSize = children.getLength();
boolean chainFound = false;
boolean containsChains = false;
if (chain == null) {
chain = "default";
}
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();
String writerPath = "src/main/java";
if ("chain".equals(nodeName)) {
containsChains = true;
String name = child.getAttribute("name");
if (name.equals(chain)) {
chainFound = true;
NodeList chainChildren = child.getChildNodes();
int chainChildrenSize = chainChildren.getLength();
boolean existsReader = false;
boolean existsWriter = false;
for (int j = 0; j < chainChildrenSize; j++) {
Node chainChild = chainChildren.item(j);
if (chainChild instanceof Element) {
Element elementChain = (Element) chainChild;
String elementName = elementChain.getNodeName();
if (elementName.equals("reader") && setToReader) {
existsReader = true;
updateElement(elementChain);
writerPath = elementChain.getAttribute("path");
} else if (elementName.equals("writer") && setToWriter) {
existsWriter = true;
updateElement(elementChain);
}
}
}
if (!existsReader && setToReader) {
Element reader = document.createElement("reader");
reader.setAttribute("path", "src/main/java");
updateElement(reader);
if (chainChildrenSize == 0) {
child.appendChild(reader);
} else {
child.insertBefore(reader, chainChildren.item(0));
}
}
if (!existsWriter && setToWriter) {
Element writer = document.createElement("writer");
writer.setAttribute("path", writerPath);
updateElement(writer);
child.appendChild(writer);
}
}
}
}
}
if (!chainFound) {
ChainConfig chainCfg = null;
if (!containsChains) {
Configuration configuration = new ConfigurationImpl();
provider.setConfiguration(configuration);
// we write specifically a default chain, and
// afterwards, we
// add the requested one.
provider.loadChains();
Collection<ChainConfig> chainCfgs = configuration.getChainConfigs();
chainCfg = chainCfgs.iterator().next();
NodeList child = rootElement.getChildNodes();
int limit = child.getLength();
for (int i = 0; i < limit; i++) {
Node item = child.item(i);
if (item instanceof Element) {
Element auxElem = (Element) item;
if (auxElem.getNodeName().equals("transformation")) {
rootElement.removeChild(auxElem);
}
}
}
if (!chain.equals("default")) {
rootElement.appendChild(createChainElement(chainCfg));
chainCfg = new ChainConfigImpl();
chainCfg.setName(chain);
provider.addDefaultReaderConfig(chainCfg);
provider.addDefaultWriterConfig(chainCfg);
provider.addDefaultWalker(chainCfg);
}
} else {
chainCfg = new ChainConfigImpl();
chainCfg.setName(chain);
provider.addDefaultReaderConfig(chainCfg);
provider.addDefaultWriterConfig(chainCfg);
provider.addDefaultWalker(chainCfg);
}
if (setToReader) {
ReaderConfig rcfg = chainCfg.getReaderConfig();
String[] aux = new String[includes.size()];
rcfg.setIncludes(includes.toArray(aux));
chainCfg.setReaderConfig(rcfg);
}
if (setToWriter) {
WriterConfig wcfg = chainCfg.getWriterConfig();
String[] aux = new String[includes.size()];
wcfg.setIncludes(includes.toArray(aux));
chainCfg.setWriterConfig(wcfg);
}
rootElement.appendChild(createChainElement(chainCfg));
}
provider.persist();
}
use of org.walkmod.conf.entities.ReaderConfig in project walkmod-core by walkmod.
the class LanguageConfigurationProvider method updateNulls.
private void updateNulls() {
Collection<ChainConfig> ccs = configuration.getChainConfigs();
Element rootElement = document.getDocumentElement();
if (ccs != null) {
for (ChainConfig cc : ccs) {
ReaderConfig rc = cc.getReaderConfig();
if (rc.getType() == null) {
rc.setType(rootElement.getAttribute("reader"));
}
if (rc.getPath() == null) {
rc.setPath(rootElement.getAttribute("path"));
}
WriterConfig wc = cc.getWriterConfig();
if (wc.getType() == null) {
wc.setType(rootElement.getAttribute("writer"));
}
if (wc.getPath() == null) {
wc.setPath(rootElement.getAttribute("path"));
}
WalkerConfig walkc = cc.getWalkerConfig();
if (walkc.getType() == null) {
walkc.setType(rootElement.getAttribute("walker"));
}
if (walkc.getParserConfig().getType() == null) {
if (!"".equals(rootElement.getAttribute("parser"))) {
walkc.getParserConfig().setType(rootElement.getAttribute("parser"));
}
}
List<TransformationConfig> transformations = walkc.getTransformations();
if (transformations != null) {
for (TransformationConfig tc : transformations) {
if (tc.isMergeable()) {
if (tc.getMergePolicy() == null) {
tc.setMergePolicy(DEFAULT_MERGE_ENGINE_NAME);
}
}
}
}
wc.setPatcherType(rootElement.getAttribute("patcher"));
}
}
}
use of org.walkmod.conf.entities.ReaderConfig in project walkmod-core by walkmod.
the class AddChainYMLAction method doAction.
@Override
public void doAction(JsonNode chainsNode) throws Exception {
ArrayNode chainsList = null;
ObjectMapper mapper = provider.getObjectMapper();
if (chainsNode != null) {
if (!chainsNode.has("chains")) {
chainsList = new ArrayNode(mapper.getNodeFactory());
if (chainsNode.isObject()) {
ObjectNode aux = (ObjectNode) chainsNode;
aux.set("chains", chainsList);
} else {
throw new TransformerException("The root element is not a JSON node");
}
} else {
JsonNode aux = chainsNode.get("chains");
if (aux.isArray()) {
chainsList = (ArrayNode) chainsNode.get("chains");
} else {
throw new TransformerException("The plugins element is not a valid array");
}
}
}
ObjectNode chainNode = new ObjectNode(mapper.getNodeFactory());
ReaderConfig readerCfg = chainCfg.getReaderConfig();
if (readerCfg != null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
ObjectNode readerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("reader", readerNode);
populateWriterReader(readerNode, readerCfg.getPath(), readerCfg.getType(), readerCfg.getIncludes(), readerCfg.getExcludes(), readerCfg.getParameters());
} else {
provider.addDefaultReaderConfig(chainCfg);
}
WalkerConfig walkerCfg = chainCfg.getWalkerConfig();
if (walkerCfg != null) {
ObjectNode walkerNode = null;
String type = walkerCfg.getType();
if (type != null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
walkerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("walker", walkerNode);
walkerNode.set("type", new TextNode(type));
}
Map<String, Object> wparams = walkerCfg.getParams();
if (wparams != null && !wparams.isEmpty()) {
if (walkerNode == null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
walkerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("walker", walkerNode);
}
populateParams(walkerNode, wparams);
}
String rootNamespace = walkerCfg.getRootNamespace();
if (rootNamespace != null) {
if (walkerNode == null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
walkerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("walker", walkerNode);
}
walkerNode.set("root-namespace", new TextNode(rootNamespace));
}
List<TransformationConfig> transformationList = walkerCfg.getTransformations();
if (transformationList != null && !transformationList.isEmpty()) {
ArrayNode transformationListNode = new ArrayNode(mapper.getNodeFactory());
if (walkerNode == null) {
if (chainsNode == null) {
ObjectNode aux = new ObjectNode(mapper.getNodeFactory());
aux.set("transformations", transformationListNode);
chainsNode = aux;
} else {
chainNode.set("transformations", transformationListNode);
}
} else {
walkerNode.set("transformations", transformationListNode);
}
for (TransformationConfig transCfg : transformationList) {
ObjectNode transformationNode = new ObjectNode(mapper.getNodeFactory());
transformationListNode.add(transformationNode);
createTransformation(transformationNode, transCfg);
}
}
}
WriterConfig writerCfg = chainCfg.getWriterConfig();
if (writerCfg != null) {
if (chainsNode == null) {
chainsNode = new ObjectNode(mapper.getNodeFactory());
ObjectNode aux = (ObjectNode) chainsNode;
chainsList = new ArrayNode(mapper.getNodeFactory());
aux.set("chains", chainsList);
}
ObjectNode writerNode = new ObjectNode(mapper.getNodeFactory());
chainNode.set("writer", writerNode);
populateWriterReader(writerNode, writerCfg.getPath(), writerCfg.getType(), writerCfg.getIncludes(), writerCfg.getExcludes(), writerCfg.getParams());
} else {
provider.addDefaultWriterConfig(chainCfg);
}
if (chainsList != null) {
int beforePos = -1;
if (before != null) {
Iterator<JsonNode> it = chainsList.iterator();
int i = 0;
while (it.hasNext() && beforePos == -1) {
JsonNode next = it.next();
if (next.get("name").equals(before)) {
beforePos = i;
}
i++;
}
}
if (beforePos == -1) {
chainsList.add(chainNode);
} else {
chainsList.insert(beforePos, chainNode);
}
}
if (readerCfg != null || walkerCfg != null || writerCfg != null) {
provider.write(chainsNode);
}
}
use of org.walkmod.conf.entities.ReaderConfig in project walkmod-core by walkmod.
the class ChainConfigImpl method setPath.
@Override
public void setPath(String path) {
if (model == null) {
setReaderConfig(new ReaderConfig());
}
model.setPath(path);
if (writerConfig == null) {
setWriterConfig(new WriterConfigImpl());
}
writerConfig.setPath(path);
}
Aggregations