Updated Branches:
  refs/heads/camel-2.11.x 499fb0319 -> 73a72ded0
  refs/heads/camel-2.12.x 1605177b1 -> 766e39294
  refs/heads/master 8270ae3a0 -> 985284fb8


CAMEL-6790: Fixed camel-blueprint refresh issue can cause namespace handler to 
not trigger.


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

Branch: refs/heads/master
Commit: 985284fb8be9a0de0bb451a14f90300e86c5d98e
Parents: 8270ae3
Author: Claus Ibsen <davscl...@apache.org>
Authored: Sat Sep 28 14:57:44 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Sat Sep 28 14:57:44 2013 +0200

----------------------------------------------------------------------
 .../handler/CamelNamespaceHandler.java          | 51 +++++++++++---------
 .../camel/blueprint/BlueprintJaxbTest.java      |  2 +-
 2 files changed, 29 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/985284fb/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git 
a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
 
b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
index 9ec79ff..fe726e8 100644
--- 
a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
+++ 
b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
@@ -105,29 +105,29 @@ import static 
org.osgi.service.blueprint.reflect.ServiceReferenceMetadata.AVAILA
  */
 public class CamelNamespaceHandler implements NamespaceHandler {
 
+    public static final String BLUEPRINT_NS = 
"http://camel.apache.org/schema/blueprint";;
+    public static final String SPRING_NS = 
"http://camel.apache.org/schema/spring";;
+
     private static final String CAMEL_CONTEXT = "camelContext";
     private static final String ROUTE_CONTEXT = "routeContext";
     private static final String KEY_STORE_PARAMETERS = "keyStoreParameters";
     private static final String SECURE_RANDOM_PARAMETERS = 
"secureRandomParameters";
     private static final String SSL_CONTEXT_PARAMETERS = 
"sslContextParameters";
 
-    private static final String BLUEPRINT_NS = 
"http://camel.apache.org/schema/blueprint";;
-    private static final String SPRING_NS = 
"http://camel.apache.org/schema/spring";;
-
     private static final Logger LOG = 
LoggerFactory.getLogger(CamelNamespaceHandler.class);
 
     private JAXBContext jaxbContext;
 
-    public static void renameNamespaceRecursive(Node node) {
+    public static void renameNamespaceRecursive(Node node, String 
fromNamespace, String toNamespace) {
         if (node.getNodeType() == Node.ELEMENT_NODE) {
             Document doc = node.getOwnerDocument();
-            if (node.getNamespaceURI().equals(BLUEPRINT_NS)) {
-                doc.renameNode(node, SPRING_NS, node.getLocalName());
+            if (node.getNamespaceURI().equals(fromNamespace)) {
+                doc.renameNode(node, toNamespace, node.getLocalName());
             }
         }
         NodeList list = node.getChildNodes();
         for (int i = 0; i < list.getLength(); ++i) {
-            renameNamespaceRecursive(list.item(i));
+            renameNamespaceRecursive(list.item(i), fromNamespace, toNamespace);
         }
     }
 
@@ -143,23 +143,28 @@ public class CamelNamespaceHandler implements 
NamespaceHandler {
     public Metadata parse(Element element, ParserContext context) {
         LOG.trace("Parsing element {}", element);
 
-        // make sure namespace is blueprint
-        renameNamespaceRecursive(element);
+        try {
+            // as the camel-core model namespace is Spring we need to rename 
from blueprint to spring
+            renameNamespaceRecursive(element, BLUEPRINT_NS, SPRING_NS);
 
-        if (element.getLocalName().equals(CAMEL_CONTEXT)) {
-            return parseCamelContextNode(element, context);
-        }
-        if (element.getLocalName().equals(ROUTE_CONTEXT)) {
-            return parseRouteContextNode(element, context);
-        }
-        if (element.getLocalName().equals(KEY_STORE_PARAMETERS)) {
-            return parseKeyStoreParametersNode(element, context);
-        }
-        if (element.getLocalName().equals(SECURE_RANDOM_PARAMETERS)) {
-            return parseSecureRandomParametersNode(element, context);
-        }
-        if (element.getLocalName().equals(SSL_CONTEXT_PARAMETERS)) {
-            return parseSSLContextParametersNode(element, context);
+            if (element.getLocalName().equals(CAMEL_CONTEXT)) {
+                return parseCamelContextNode(element, context);
+            }
+            if (element.getLocalName().equals(ROUTE_CONTEXT)) {
+                return parseRouteContextNode(element, context);
+            }
+            if (element.getLocalName().equals(KEY_STORE_PARAMETERS)) {
+                return parseKeyStoreParametersNode(element, context);
+            }
+            if (element.getLocalName().equals(SECURE_RANDOM_PARAMETERS)) {
+                return parseSecureRandomParametersNode(element, context);
+            }
+            if (element.getLocalName().equals(SSL_CONTEXT_PARAMETERS)) {
+                return parseSSLContextParametersNode(element, context);
+            }
+        } finally {
+            // make sure to rename back so we leave the DOM as-is
+            renameNamespaceRecursive(element, SPRING_NS, BLUEPRINT_NS);
         }
 
         return null;

http://git-wip-us.apache.org/repos/asf/camel/blob/985284fb/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
 
b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
index 76ab285..9ea5abc 100644
--- 
a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
+++ 
b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
@@ -52,7 +52,7 @@ public class BlueprintJaxbTest {
                 break;
             }
         }
-        CamelNamespaceHandler.renameNamespaceRecursive(elem);
+        CamelNamespaceHandler.renameNamespaceRecursive(elem, 
CamelNamespaceHandler.BLUEPRINT_NS, CamelNamespaceHandler.SPRING_NS);
 
         JAXBContext context = 
JAXBContext.newInstance("org.apache.camel.blueprint:"
                                                         + 
"org.apache.camel:org.apache.camel.model:"

Reply via email to