Repository: camel Updated Branches: refs/heads/master cfab63a58 -> 5aae60e44
Moving dependencies to class level attributes to reduce number of parameters in methods. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f4d3ab25 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f4d3ab25 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f4d3ab25 Branch: refs/heads/master Commit: f4d3ab259a95af4b7f7a6913a75b690c867c2488 Parents: 785efef Author: nkukhar <[email protected]> Authored: Sat Mar 7 18:11:48 2015 -0800 Committer: Claus Ibsen <[email protected]> Committed: Sun Mar 8 08:51:38 2015 +0100 ---------------------------------------------------------------------- .../java/org/apache/camel/maven/Constants.java | 2 +- .../camel/maven/DocumentationEnricher.java | 38 +++++++++++--------- .../java/org/apache/camel/maven/DomFinder.java | 13 +++++-- .../maven/EipDocumentationEnricherMojo.java | 24 ++++++------- 4 files changed, 43 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java index e6e3fbe..ebfd846 100644 --- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java +++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/Constants.java @@ -38,5 +38,5 @@ public final class Constants { public static final String DESCRIPTION_ATTRIBUTE_NAME = "description"; public static final String MODEL_ATTRIBUTE_NAME = "model"; - private Constants() {} + private Constants() { } } http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java index c7054e6..6e2db2c 100644 --- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java +++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DocumentationEnricher.java @@ -16,68 +16,74 @@ */ package org.apache.camel.maven; -import org.apache.camel.util.JsonSchemaHelper; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.lang.WordUtils; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + import org.w3c.dom.CDATASection; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Map; +import org.apache.camel.util.JsonSchemaHelper; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.WordUtils; /** * Enriches xml document with documentation from json files. */ public class DocumentationEnricher { + private final Document document; + + public DocumentationEnricher(Document document) { + this.document = document; + } - public void enrichTopLevelElementsDocumentation(Document document, NodeList elements, Map<String, File> jsonFiles) throws IOException { + public void enrichTopLevelElementsDocumentation(NodeList elements, Map<String, File> jsonFiles) throws IOException { for (int i = 0; i < elements.getLength(); i++) { Element item = (Element) elements.item(i); String name = item.getAttribute(Constants.NAME_ATTRIBUTE_NAME); if (jsonFiles.containsKey(name)) { - addElementDocumentation(document, item, jsonFiles.get(name)); + addElementDocumentation(item, jsonFiles.get(name)); } } } - public void enrichTypeAttributesDocumentation(Document document, NodeList attributeElements, File jsonFile) throws IOException { + public void enrichTypeAttributesDocumentation(NodeList attributeElements, File jsonFile) throws IOException { for (int j = 0; j < attributeElements.getLength(); j++) { Element item = (Element) attributeElements.item(j); - addAttributeDocumentation(item, jsonFile, document); + addAttributeDocumentation(item, jsonFile); } } - private void addElementDocumentation(Document document, Element item, File jsonFile) throws IOException { + private void addElementDocumentation(Element item, File jsonFile) throws IOException { List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema(Constants.MODEL_ATTRIBUTE_NAME, PackageHelper.fileToString(jsonFile), false); for (Map<String, String> row : rows) { if (row.containsKey(Constants.DESCRIPTION_ATTRIBUTE_NAME)) { String descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME); - addDocumentation(document, item, descriptionText); + addDocumentation(item, descriptionText); break; } } } - private void addAttributeDocumentation(Element item, File jsonFile, Document document) throws IOException { + private void addAttributeDocumentation(Element item, File jsonFile) throws IOException { List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema(Constants.PROPERTIES_ATTRIBUTE_NAME, PackageHelper.fileToString(jsonFile), true); for (Map<String, String> row : rows) { if (item.getAttribute(Constants.NAME_ATTRIBUTE_NAME) .equals(row.get(Constants.NAME_ATTRIBUTE_NAME))) { String descriptionText = row.get(Constants.DESCRIPTION_ATTRIBUTE_NAME); if (descriptionText != null) { - addDocumentation(document, item, descriptionText); + addDocumentation(item, descriptionText); break; } } } } - private void addDocumentation(Document document, Element item, String textContent) { + private void addDocumentation(Element item, String textContent) { Element annotation = document.createElement(Constants.XS_ANNOTATION_ELEMENT_NAME); Element documentation = document.createElement(Constants.XS_DOCUMENTATION_ELEMENT_NAME); documentation.setAttribute("xml:lang", "en"); http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java index 5c4fe47..64b4a20 100644 --- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java +++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/DomFinder.java @@ -27,19 +27,26 @@ import org.w3c.dom.NodeList; * Finds xml elements where documentation can be added. */ public class DomFinder { + private final Document document; + private final XPath xPath; - public NodeList findElementsAndTypes(Document document, XPath xPath) throws XPathExpressionException { + public DomFinder(Document document, XPath xPath) { + this.document = document; + this.xPath = xPath; + } + + public NodeList findElementsAndTypes() throws XPathExpressionException { return (NodeList) xPath.compile("/xs:schema/xs:element") .evaluate(document, XPathConstants.NODESET); } - public NodeList findAttributesElements(Document document, XPath xPath, String name) throws XPathExpressionException { + public NodeList findAttributesElements(String name) throws XPathExpressionException { return (NodeList) xPath.compile( "/xs:schema/xs:complexType[@name='" + name + "']//xs:attribute") .evaluate(document, XPathConstants.NODESET); } - public String findBaseType(Document document, XPath xPath, String name) throws XPathExpressionException { + public String findBaseType(String name) throws XPathExpressionException { return (String) xPath.compile( "/xs:schema/xs:complexType[@name='" + name + "']//xs:extension/@base") .evaluate(document, XPathConstants.STRING); http://git-wip-us.apache.org/repos/asf/camel/blob/f4d3ab25/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java index aebd0b1..db6ae1f 100644 --- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java +++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java @@ -81,14 +81,14 @@ public class EipDocumentationEnricherMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { Set<String> injectedTypes = new HashSet<String>(); File rootDir = new File(camelCoreDir, Constants.PATH_TO_MODEL_DIR); - DomFinder domFinder = new DomFinder(); - DocumentationEnricher documentationEnricher = new DocumentationEnricher(); - Map<String, File> jsonFiles = PackageHelper.findJsonFiles(rootDir); - XPath xPath = buildXPath(new CamelSpringNamespace()); Document document = buildNamespaceAwareDocument(inputCamelSchemaFile); + XPath xPath = buildXPath(new CamelSpringNamespace()); + DomFinder domFinder = new DomFinder(document, xPath); + DocumentationEnricher documentationEnricher = new DocumentationEnricher(document); + Map<String, File> jsonFiles = PackageHelper.findJsonFiles(rootDir); try { - NodeList elementsAndTypes = domFinder.findElementsAndTypes(document, xPath); - documentationEnricher.enrichTopLevelElementsDocumentation(document, elementsAndTypes, jsonFiles); + NodeList elementsAndTypes = domFinder.findElementsAndTypes(); + documentationEnricher.enrichTopLevelElementsDocumentation(elementsAndTypes, jsonFiles); Map<String, String> typeToNameMap = buildTypeToNameMap(elementsAndTypes); for (Map.Entry<String, String> entry : typeToNameMap.entrySet()) { String elementType = entry.getKey(); @@ -97,8 +97,6 @@ public class EipDocumentationEnricherMojo extends AbstractMojo { injectAttributesDocumentation(domFinder, documentationEnricher, jsonFiles.get(elementName), - xPath, - document, elementType, injectedTypes); } @@ -119,18 +117,16 @@ public class EipDocumentationEnricherMojo extends AbstractMojo { private void injectAttributesDocumentation(DomFinder domFinder, DocumentationEnricher documentationEnricher, File jsonFile, - XPath xPath, - Document document, String type, Set<String> injectedTypes) throws XPathExpressionException, IOException { - NodeList attributeElements = domFinder.findAttributesElements(document, xPath, type); + NodeList attributeElements = domFinder.findAttributesElements(type); if (attributeElements.getLength() > 0) { - documentationEnricher.enrichTypeAttributesDocumentation(document, attributeElements, jsonFile); + documentationEnricher.enrichTypeAttributesDocumentation(attributeElements, jsonFile); injectedTypes.add(type); - String baseType = domFinder.findBaseType(document, xPath, type); + String baseType = domFinder.findBaseType(type); baseType = truncateTypeNamespace(baseType); if (baseType != null && !injectedTypes.contains(baseType)) { - injectAttributesDocumentation(domFinder, documentationEnricher, jsonFile, xPath, document, baseType, injectedTypes); + injectAttributesDocumentation(domFinder, documentationEnricher, jsonFile, baseType, injectedTypes); } } }
