camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: Fixed CS
Date Mon, 02 Mar 2015 10:03:39 GMT
Repository: camel
Updated Branches:
  refs/heads/master 1ba5a6bc3 -> 5bd1f5af7


Fixed CS


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5bd1f5af
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5bd1f5af
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5bd1f5af

Branch: refs/heads/master
Commit: 5bd1f5af713d85d8194ada65a0c44145ef73df54
Parents: 1ba5a6b
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Mar 2 11:04:51 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Mon Mar 2 11:04:51 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/scr/internal/ScrHelper.java    | 76 +++++++++++---------
 1 file changed, 42 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5bd1f5af/components/camel-scr/src/main/java/org/apache/camel/scr/internal/ScrHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-scr/src/main/java/org/apache/camel/scr/internal/ScrHelper.java
b/components/camel-scr/src/main/java/org/apache/camel/scr/internal/ScrHelper.java
index f6a3d8d..3d5842b 100644
--- a/components/camel-scr/src/main/java/org/apache/camel/scr/internal/ScrHelper.java
+++ b/components/camel-scr/src/main/java/org/apache/camel/scr/internal/ScrHelper.java
@@ -37,9 +37,6 @@ import org.w3c.dom.NodeList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-// CHECKSTYLE:OFF
-// turn off checkstyle as it fails internally
-
 /**
  * Helper class.
  */
@@ -56,38 +53,10 @@ public final class ScrHelper {
 
     public static Map<String, String> getScrProperties(String xmlLocation, String componentName)
throws Exception {
         Map<String, String> result = new HashMap<String, String>();
+
         final Document dom = readXML(new File(xmlLocation));
         final XPath xPath = XPathFactory.newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI,
"com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", null).newXPath();
-        xPath.setNamespaceContext(new NamespaceContext() {
-            @Override
-            public String getNamespaceURI(String prefix) {
-                switch (prefix) {
-                    case "scr":
-                        try {
-                            XPathExpression scrNamespace = xPath.compile("/*/namespace::*[name()='scr']");
-                            Node node = (Node) scrNamespace.evaluate(dom, XPathConstants.NODE);
-                            return node.getNodeValue();
-                        } catch (XPathExpressionException e) {
-                            // ignore
-                            LOG.debug("Error evaluating xpath to obtain namespace prefix.
This exception is ignored and using namespace: http://www.osgi.org/xmlns/scr/v1.1.0", e);
-                        }
-                        return "http://www.osgi.org/xmlns/scr/v1.1.0";
-                    default:
-                        // noop
-                }
-                return XMLConstants.NULL_NS_URI;
-            }
-
-            @Override
-            public String getPrefix(String namespaceURI) {
-                return null;
-            }
-
-            @Override
-            public Iterator<String> getPrefixes(String namespaceURI) {
-                return null;
-            }
-        });
+        xPath.setNamespaceContext(new ScrNamespaceContext(dom, xPath));
 
         String propertyListExpression = String.format("/components/scr:component[@name='%s']/property",
componentName);
         XPathExpression propertyList = xPath.compile(propertyListExpression);
@@ -108,6 +77,45 @@ public final class ScrHelper {
         return builder.parse(xml);
     }
 
+    private static final class ScrNamespaceContext implements NamespaceContext {
+
+        private final Document dom;
+        private final XPath xPath;
+
+        private ScrNamespaceContext(Document dom, XPath xPath) {
+            this.dom = dom;
+            this.xPath = xPath;
+        }
+
+        @Override
+        public String getNamespaceURI(String prefix) {
+            switch (prefix) {
+            case "scr":
+                try {
+                    XPathExpression scrNamespace = xPath.compile("/*/namespace::*[name()='scr']");
+                    Node node = (Node) scrNamespace.evaluate(dom, XPathConstants.NODE);
+                    return node.getNodeValue();
+                } catch (XPathExpressionException e) {
+                    // ignore
+                    LOG.debug("Error evaluating xpath to obtain namespace prefix. This exception
is ignored and using namespace: http://www.osgi.org/xmlns/scr/v1.1.0", e);
+                }
+                return "http://www.osgi.org/xmlns/scr/v1.1.0";
+            default:
+                // noop
+            }
+            return XMLConstants.NULL_NS_URI;
+        }
+
+        @Override
+        public String getPrefix(String namespaceURI) {
+            return null;
+        }
+
+        @Override
+        public Iterator<String> getPrefixes(String namespaceURI) {
+            return null;
+        }
+    }
+
 }
-// CHECKSTYLE:ON
 


Mime
View raw message