You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/01/14 07:56:00 UTC
svn commit: r1432813 - in /camel/trunk/components/camel-cxf-transport: ./
src/main/java/org/apache/camel/component/cxf/transport/blueprint/
src/main/resources/OSGI-INF/ src/main/resources/OSGI-INF/blueprint/
src/main/resources/schema/blueprint/
Author: ningjiang
Date: Mon Jan 14 06:56:00 2013
New Revision: 1432813
URL: http://svn.apache.org/viewvc?rev=1432813&view=rev
Log:
CAMEL-5933 Added blueprint support on camel-cxf-transport
Added:
camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/
camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/AbstractBeanDefinitionParser.java
camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelConduitDefinitionParser.java
camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelDestinationDefinitionParser.java
camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelTransportNameSpaceHandler.java
camel/trunk/components/camel-cxf-transport/src/main/resources/OSGI-INF/
camel/trunk/components/camel-cxf-transport/src/main/resources/OSGI-INF/blueprint/
camel/trunk/components/camel-cxf-transport/src/main/resources/OSGI-INF/blueprint/camel-transport.xml
camel/trunk/components/camel-cxf-transport/src/main/resources/schema/blueprint/
camel/trunk/components/camel-cxf-transport/src/main/resources/schema/blueprint/camel.xsd
Modified:
camel/trunk/components/camel-cxf-transport/pom.xml
Modified: camel/trunk/components/camel-cxf-transport/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/pom.xml?rev=1432813&r1=1432812&r2=1432813&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf-transport/pom.xml (original)
+++ camel/trunk/components/camel-cxf-transport/pom.xml Mon Jan 14 06:56:00 2013
@@ -44,6 +44,8 @@
${camel.osgi.import.defaults},
${camel.osgi.import.additional},
org.osgi.framework;resolution:=optional,
+ org.apache.aries.blueprint*;resolution:=optional,
+ org.osgi.service.blueprint*;resolution:=optional,
*
</camel.osgi.import>
@@ -77,6 +79,26 @@
<artifactId>spring-beans</artifactId>
</dependency>
+ <!-- OSGi, Blueprint -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-blueprint</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>org.apache.aries.blueprint</artifactId>
+ </dependency>
+
<!-- for testing -->
<dependency>
<groupId>org.apache.camel</groupId>
Added: camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/AbstractBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/AbstractBeanDefinitionParser.java?rev=1432813&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/AbstractBeanDefinitionParser.java (added)
+++ camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/AbstractBeanDefinitionParser.java Mon Jan 14 06:56:00 2013
@@ -0,0 +1,84 @@
+/**
+ * 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.component.cxf.transport.blueprint;
+
+import java.util.StringTokenizer;
+
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.configuration.blueprint.AbstractBPBeanDefinitionParser;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+
+
+public class AbstractBeanDefinitionParser extends AbstractBPBeanDefinitionParser {
+
+ public static String getIdOrName(Element elem) {
+ String id = elem.getAttribute("id");
+
+ if (null == id || "".equals(id)) {
+ String names = elem.getAttribute("name");
+ if (null != names) {
+ StringTokenizer st = new StringTokenizer(names, ",");
+ if (st.countTokens() > 0) {
+ id = st.nextToken();
+ }
+ }
+ }
+ return id;
+ }
+
+ public MutableBeanMetadata createBeanMetadata(Element element, ParserContext context, Class<?> runtimeClass) {
+ MutableBeanMetadata answer = context.createMetadata(MutableBeanMetadata.class);
+ answer.setRuntimeClass(runtimeClass);
+ if (!StringUtils.isEmpty(getIdOrName(element))) {
+ answer.setId(getIdOrName(element));
+ } else {
+ // TODO we may need to throw exception for it
+ answer.setId("camel.cxf.transport." + runtimeClass.getSimpleName() + "." + context.generateId());
+ }
+ return answer;
+ }
+
+ public Metadata parse(Element element, ParserContext context, Class<?> runtime) {
+ MutableBeanMetadata config = createBeanMetadata(element, context, runtime);
+ config.setScope(BeanMetadata.SCOPE_PROTOTYPE);
+ String camelContextId = "camelContext";
+ NamedNodeMap atts = element.getAttributes();
+ for (int i = 0; i < atts.getLength(); i++) {
+ Attr node = (Attr) atts.item(i);
+ String val = node.getValue();
+ //String pre = node.getPrefix();
+ String name = node.getLocalName();
+ if ("camelContext".equals(name)) {
+ camelContextId = val;
+ }
+ }
+ config.addDependsOn(camelContextId);
+ config.addProperty("camelContext", createRef(context, camelContextId));
+ return config;
+ }
+
+}
Added: camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelConduitDefinitionParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelConduitDefinitionParser.java?rev=1432813&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelConduitDefinitionParser.java (added)
+++ camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelConduitDefinitionParser.java Mon Jan 14 06:56:00 2013
@@ -0,0 +1,32 @@
+/**
+ * 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.component.cxf.transport.blueprint;
+
+import org.w3c.dom.Element;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.camel.component.cxf.transport.CamelConduit;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+
+
+public class CamelConduitDefinitionParser extends AbstractBeanDefinitionParser {
+ public Metadata parse(Element element, ParserContext context) {
+ return parse(element, context, CamelConduit.class);
+ }
+
+}
Added: camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelDestinationDefinitionParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelDestinationDefinitionParser.java?rev=1432813&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelDestinationDefinitionParser.java (added)
+++ camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelDestinationDefinitionParser.java Mon Jan 14 06:56:00 2013
@@ -0,0 +1,32 @@
+/**
+ * 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.component.cxf.transport.blueprint;
+
+import org.w3c.dom.Element;
+
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.camel.component.cxf.transport.CamelDestination;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+
+public class CamelDestinationDefinitionParser extends AbstractBeanDefinitionParser {
+ public Metadata parse(Element element, ParserContext context) {
+ return parse(element, context, CamelDestination.class);
+ }
+
+
+}
Added: camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelTransportNameSpaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelTransportNameSpaceHandler.java?rev=1432813&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelTransportNameSpaceHandler.java (added)
+++ camel/trunk/components/camel-cxf-transport/src/main/java/org/apache/camel/component/cxf/transport/blueprint/CamelTransportNameSpaceHandler.java Mon Jan 14 06:56:00 2013
@@ -0,0 +1,67 @@
+/**
+ * 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.component.cxf.transport.blueprint;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.ParserContext;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class CamelTransportNameSpaceHandler implements NamespaceHandler {
+ private static final Logger LOG = LoggerFactory.getLogger(CamelTransportNameSpaceHandler.class);
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata componentMetadata, ParserContext parserContext) {
+ return null;
+ }
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(CamelTransportNameSpaceHandler.class));
+ }
+
+ public URL getSchemaLocation(String s) {
+ return getClass().getClassLoader().getResource("schema/blueprint/camel.xsd");
+ }
+
+ @Override
+ public Metadata parse(Element element, ParserContext context) {
+ Metadata answer = null;
+ String s = element.getLocalName();
+ if ("conduit".equals(s)) {
+ LOG.debug("parsing the conduit element");
+ answer = new CamelConduitDefinitionParser().parse(element, context);
+ }
+ if ("destination".equals(s)) {
+ LOG.debug("parsing the detination element");
+ answer = new CamelDestinationDefinitionParser().parse(element, context);
+ }
+ return answer;
+ }
+
+}
Added: camel/trunk/components/camel-cxf-transport/src/main/resources/OSGI-INF/blueprint/camel-transport.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/main/resources/OSGI-INF/blueprint/camel-transport.xml?rev=1432813&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/main/resources/OSGI-INF/blueprint/camel-transport.xml (added)
+++ camel/trunk/components/camel-cxf-transport/src/main/resources/OSGI-INF/blueprint/camel-transport.xml Mon Jan 14 06:56:00 2013
@@ -0,0 +1,29 @@
+<!--
+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.
+-->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <service interface="org.apache.aries.blueprint.NamespaceHandler">
+ <service-properties>
+ <entry key="osgi.service.blueprint.namespace" value="http://cxf.apache.org/transports/camel/blueprint"/>
+ </service-properties>
+ <bean class="org.apache.camel.component.cxf.transport.blueprint.CamelTransportNameSpaceHandler"/>
+ </service>
+</blueprint>
\ No newline at end of file
Added: camel/trunk/components/camel-cxf-transport/src/main/resources/schema/blueprint/camel.xsd
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf-transport/src/main/resources/schema/blueprint/camel.xsd?rev=1432813&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf-transport/src/main/resources/schema/blueprint/camel.xsd (added)
+++ camel/trunk/components/camel-cxf-transport/src/main/resources/schema/blueprint/camel.xsd Mon Jan 14 06:56:00 2013
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:camel="http://cxf.apache.org/transports/camel"
+ xmlns:beans="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:cxf-beans="http://cxf.apache.org/configuration/beans"
+ xmlns:camel-blueprint="http://camel.apache.org/schema/blueprint"
+ targetNamespace="http://cxf.apache.org/transports/camel/blueprint"
+ elementFormDefault="qualified" attributeFormDefault="unqualified"
+ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <xsd:import namespace="http://www.osgi.org/xmlns/blueprint/v1.0.0" schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"/>
+ <xsd:import namespace="http://cxf.apache.org/configuration/beans" schemaLocation="http://cxf.apache.org/schemas/configuration/cxf-beans.xsd"/>
+
+ <xsd:element name="destination">
+ <xsd:complexType>
+ <xsd:complexContent>
+ <xsd:extension base="beans:Tcomponent"/>
+ <!-- here we need to specify the CamelContext reference -->
+ <xsd:attribute name="camelContext" type="xsd:string" />
+ </xsd:complexContent>
+ </xsd:complexType>
+ </xsd:element>
+
+ <xsd:element name="conduit">
+ <xsd:complexType>
+ <xsd:complexContent>
+ <xsd:extension base="beans:Tcomponent"/>
+ <!-- here we need to specify the CamelContext reference -->
+ <xsd:attribute name="camelContext" type="xsd:string" />
+ </xsd:complexContent>
+ </xsd:complexType>
+ </xsd:element>
+
+
+</xsd:schema>