Repository: camel Updated Branches: refs/heads/master 3f8df7fca -> 6ff4e76b9
Fixed camel-src and archetype Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6ff4e76b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6ff4e76b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6ff4e76b Branch: refs/heads/master Commit: 6ff4e76b96cdc37d378632d59b54123c1362cc46 Parents: 3f8df7f Author: Claus Ibsen <[email protected]> Authored: Thu Aug 6 10:00:46 2015 +0200 Committer: Claus Ibsen <[email protected]> Committed: Thu Aug 6 10:00:46 2015 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/scr/ScrHelper.java | 121 +++++++++++++++++++ .../apache/camel/scr/internal/ScrHelper.java | 121 ------------------- .../src/test/java/__className__Test.java | 6 +- 3 files changed, 124 insertions(+), 124 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/6ff4e76b/components/camel-scr/src/main/java/org/apache/camel/scr/ScrHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-scr/src/main/java/org/apache/camel/scr/ScrHelper.java b/components/camel-scr/src/main/java/org/apache/camel/scr/ScrHelper.java new file mode 100644 index 0000000..2918965 --- /dev/null +++ b/components/camel-scr/src/main/java/org/apache/camel/scr/ScrHelper.java @@ -0,0 +1,121 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.scr; + +import java.io.File; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import javax.xml.XMLConstants; +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Helper class. + */ +public final class ScrHelper { + + private static final Logger LOG = LoggerFactory.getLogger(ScrHelper.class); + + private ScrHelper() { + } + + public static Map<String, String> getScrProperties(String componentName) throws Exception { + return getScrProperties(String.format("target/classes/OSGI-INF/%s.xml", componentName), componentName); + } + + 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 ScrNamespaceContext(dom, xPath)); + + String propertyListExpression = String.format("/components/scr:component[@name='%s']/property", componentName); + XPathExpression propertyList = xPath.compile(propertyListExpression); + XPathExpression propertyName = xPath.compile("@name"); + XPathExpression propertyValue = xPath.compile("@value"); + NodeList nodes = (NodeList) propertyList.evaluate(dom, XPathConstants.NODESET); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + result.put((String) propertyName.evaluate(node, XPathConstants.STRING), (String) propertyValue.evaluate(node, XPathConstants.STRING)); + } + return result; + } + + private static Document readXML(File xml) throws Exception { + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + builderFactory.setNamespaceAware(true); + DocumentBuilder builder = builderFactory.newDocumentBuilder(); + 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; + } + } + +} + http://git-wip-us.apache.org/repos/asf/camel/blob/6ff4e76b/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 deleted file mode 100644 index 3d5842b..0000000 --- a/components/camel-scr/src/main/java/org/apache/camel/scr/internal/ScrHelper.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.scr.internal; - -import java.io.File; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Helper class. - */ -public final class ScrHelper { - - private static final Logger LOG = LoggerFactory.getLogger(ScrHelper.class); - - private ScrHelper() { - } - - public static Map<String, String> getScrProperties(String componentName) throws Exception { - return getScrProperties(String.format("target/classes/OSGI-INF/%s.xml", componentName), componentName); - } - - 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 ScrNamespaceContext(dom, xPath)); - - String propertyListExpression = String.format("/components/scr:component[@name='%s']/property", componentName); - XPathExpression propertyList = xPath.compile(propertyListExpression); - XPathExpression propertyName = xPath.compile("@name"); - XPathExpression propertyValue = xPath.compile("@value"); - NodeList nodes = (NodeList) propertyList.evaluate(dom, XPathConstants.NODESET); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - result.put((String) propertyName.evaluate(node, XPathConstants.STRING), (String) propertyValue.evaluate(node, XPathConstants.STRING)); - } - return result; - } - - private static Document readXML(File xml) throws Exception { - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - builderFactory.setNamespaceAware(true); - DocumentBuilder builder = builderFactory.newDocumentBuilder(); - 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; - } - } - -} - http://git-wip-us.apache.org/repos/asf/camel/blob/6ff4e76b/tooling/archetypes/camel-archetype-scr/src/main/resources/archetype-resources/src/test/java/__className__Test.java ---------------------------------------------------------------------- diff --git a/tooling/archetypes/camel-archetype-scr/src/main/resources/archetype-resources/src/test/java/__className__Test.java b/tooling/archetypes/camel-archetype-scr/src/main/resources/archetype-resources/src/test/java/__className__Test.java index 65c0127..dd5c67e 100644 --- a/tooling/archetypes/camel-archetype-scr/src/main/resources/archetype-resources/src/test/java/__className__Test.java +++ b/tooling/archetypes/camel-archetype-scr/src/main/resources/archetype-resources/src/test/java/__className__Test.java @@ -21,12 +21,12 @@ package ${package}; import java.util.List; -import org.apache.camel.scr.internal.ScrHelper; +import org.apache.camel.CamelContext; import org.apache.camel.builder.AdviceWithRouteBuilder; import org.apache.camel.component.mock.MockComponent; import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.model.ModelCamelContext; import org.apache.camel.model.RouteDefinition; +import org.apache.camel.scr.ScrHelper; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -46,7 +46,7 @@ public class ${className}Test { public TestName testName = new TestName(); ${className} integration; - ModelCamelContext context; + CamelContext context; @Before public void setUp() throws Exception {
