You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2009/10/07 12:53:40 UTC
svn commit: r822657 [1/2] - in /camel/trunk: components/
components/camel-blueprint/ components/camel-blueprint/src/
components/camel-blueprint/src/main/
components/camel-blueprint/src/main/java/
components/camel-blueprint/src/main/java/org/ components...
Author: gnodet
Date: Wed Oct 7 10:53:39 2009
New Revision: 822657
URL: http://svn.apache.org/viewvc?rev=822657&view=rev
Log:
CAMEL-2022: initial blueprint support
Added:
camel/trunk/components/camel-blueprint/
camel/trunk/components/camel-blueprint/pom.xml
camel/trunk/components/camel-blueprint/src/
camel/trunk/components/camel-blueprint/src/main/
camel/trunk/components/camel-blueprint/src/main/java/
camel/trunk/components/camel-blueprint/src/main/java/org/
camel/trunk/components/camel-blueprint/src/main/java/org/apache/
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelConsumerTemplateFactoryBean.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelEndpointFactoryBean.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelJMXAgentDefinition.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProducerTemplateFactoryBean.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProxyFactoryDefinition.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelServiceExporterDefinition.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/package-info.java
camel/trunk/components/camel-blueprint/src/main/resources/
camel/trunk/components/camel-blueprint/src/main/resources/OSGI-INF/
camel/trunk/components/camel-blueprint/src/main/resources/OSGI-INF/blueprint/
camel/trunk/components/camel-blueprint/src/main/resources/OSGI-INF/blueprint/camel-blueprint.xml
camel/trunk/components/camel-blueprint/src/main/resources/org/
camel/trunk/components/camel-blueprint/src/main/resources/org/apache/
camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/
camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/
camel/trunk/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index
camel/trunk/components/camel-blueprint/src/test/
camel/trunk/components/camel-blueprint/src/test/java/
camel/trunk/components/camel-blueprint/src/test/java/org/
camel/trunk/components/camel-blueprint/src/test/java/org/apache/
camel/trunk/components/camel-blueprint/src/test/java/org/apache/camel/
camel/trunk/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/
camel/trunk/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
camel/trunk/components/camel-blueprint/src/test/resources/
camel/trunk/components/camel-blueprint/src/test/resources/test.xml
Modified:
camel/trunk/components/pom.xml
camel/trunk/parent/pom.xml
Added: camel/trunk/components/camel-blueprint/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/pom.xml?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/pom.xml (added)
+++ camel/trunk/components/camel-blueprint/pom.xml Wed Oct 7 10:53:39 2009
@@ -0,0 +1,323 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>2.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-blueprint</artifactId>
+ <name>Camel :: Blueprint</name>
+ <description>Camel Blueprint support</description>
+ <packaging>bundle</packaging>
+
+ <properties>
+ <camel.osgi.import>
+ !org.apache.camel.blueprint.*,
+ !javax.xml.bind.annotation.adapters,
+ org.apache.camel.*;${camel.osgi.import.strict.version},
+ *
+ </camel.osgi.import>
+ <camel.osgi.export>
+ org.apache.camel.blueprint*;${camel.osgi.version}
+ </camel.osgi.export>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.blueprint</groupId>
+ <artifactId>aries-blueprint</artifactId>
+ <version>1.0.0-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <repositories>
+ <!-- for maven jaxb plugin -->
+ <repository>
+ <id>java.net</id>
+ <name>java.net Maven Repository</name>
+ <url>http://download.java.net/maven/1</url>
+ <!--<url>https://maven-repository.dev.java.net/nonav/repository</url>-->
+ <layout>legacy</layout>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>open.iona.m2</id>
+ <name>IONA Open Source Community Release Repository</name>
+ <url>http://repo.open.iona.com/maven2</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </pluginRepository>
+ </pluginRepositories>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>target/schema</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+
+ <plugins>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <childDelegation>false</childDelegation>
+ <useFile>true</useFile>
+ <forkMode>pertest</forkMode>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ <excludes>
+ <!-- TODO FIXME ASAP -->
+ <exclude>**/XXXTest.*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>process-sources</id>
+ <phase>process-sources</phase>
+ <configuration>
+ <tasks>
+ <taskdef name="schemagen" classname="com.sun.tools.jxc.SchemaGenTask" classpathref="maven.plugin.classpath"/>
+
+ <echo>Copying to code together for the XSD generation</echo>
+ <mkdir dir="${project.build.directory}/schema-src"/>
+ <mkdir dir="${project.build.directory}/schema"/>
+ <copy todir="${project.build.directory}/schema-src">
+ <fileset dir="${basedir}/src/main/java">
+ <include name="org/apache/camel/blueprint/Camel*.java"/>
+ <include name="org/apache/camel/blueprint/package-info.java"/>
+ </fileset>
+ <fileset dir="${basedir}/../../camel-core/src/main/java">
+ <include name="org/apache/camel/model/**/*.java"/>
+ <include name="org/apache/camel/ExchangePattern.java"/>
+ <include name="org/apache/camel/LoggingLevel.java"/>
+ <include name="org/apache/camel/ManagementStatisticsLevel.java"/>
+ <include name="**/package-info.java"/>
+ </fileset>
+ </copy>
+
+ <echo>Generating XSD schema</echo>
+ <schemagen srcdir="${project.build.directory}/schema-src" destdir="${project.build.directory}/schema">
+ <schema namespace="http://camel.apache.org/schema/spring" file="camel-blueprint.xsd"/>
+ <classpath refid="maven.compile.classpath"/>
+ </schemagen>
+ <replace file="${project.build.directory}/schema/camel-blueprint.xsd"
+ token="http://camel.apache.org/schema/spring" value="http://camel.apache.org/schema/blueprint"/>
+
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <execution>
+ <id>package</id>
+ <phase>package</phase>
+ <configuration>
+ <tasks>
+ <echo>Deleting unwanted resources from the test-jar</echo>
+ <delete file="${project.build.directory}/test-classes/log4j.properties" verbose="true"/>
+ <delete file="${project.build.directory}/test-classes/META-INF/spring/*" verbose="true"/>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- generate the attached tests jar -->
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <!-- TODO: this doesn't work - if ever we can figure out the maven ninja to get it working -->
+ <!-- TODO: we can zap the Ant package phase stuff above -->
+ <excludes>
+ <exclude>**/*/log4j.properties</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>${project.build.directory}/schema/camel-blueprint.xsd</file>
+ <type>xsd</type>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-blueprint</artifactId>
+ <version>${pom.version}</version>
+ <type>jar</type>
+ <overWrite>false</overWrite>
+ <outputDirectory>${project.build.directory}/schema</outputDirectory>
+ <includes>camel-blueprint.xsd</includes>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>release</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>package</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ <link>http://java.sun.com/javaee/5/docs/api/</link>
+ </links>
+ <stylesheetfile>${basedir}/../../etc/css/stylesheet.css</stylesheetfile>
+ <linksource>true</linksource>
+ <source>1.5</source>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ <link>http://java.sun.com/javaee/5/docs/api/</link>
+ <link>http://camel.apache.org/maven/camel-core/apidocs/</link>
+ </links>
+ <stylesheetfile>${basedir}/../../etc/css/stylesheet.css</stylesheetfile>
+ <linksource>true</linksource>
+ <maxmemory>256m</maxmemory>
+ <source>1.5</source>
+
+ <groups>
+ <group>
+ <title>Camel Blueprint Classes</title>
+ <packages>org.apache.camel.blueprint</packages>
+ </group>
+ </groups>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+</project>
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/BlueprintCamelContext.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,62 @@
+/**
+ * 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.blueprint;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class BlueprintCamelContext extends DefaultCamelContext {
+
+ private static final transient Log LOG = LogFactory.getLog(BlueprintCamelContext.class);
+
+ private boolean shouldStartContext = ObjectHelper.getSystemProperty("shouldStartContext", Boolean.TRUE);
+
+ public void init() throws Exception {
+ maybeStart();
+ }
+
+ private void maybeStart() throws Exception {
+ if (!getShouldStartContext()) {
+ LOG.info("Not starting Apache Camel as property ShouldStartContext is false");
+ return;
+ }
+
+ if (!isStarted() && !isStarting()) {
+ // Make sure we will not get into the endless loop of calling star
+ LOG.info("Starting Apache Camel as property ShouldStartContext is true");
+ start();
+ } else {
+ // ignore as Camel is already started
+ LOG.trace("Ignoring maybeStart() as Apache Camel is already started");
+ }
+ }
+
+ public void destroy() throws Exception {
+ stop();
+ }
+
+ public void setShouldStartContext(boolean shouldStartContext) {
+ this.shouldStartContext = shouldStartContext;
+ }
+
+ public boolean getShouldStartContext() {
+ return shouldStartContext;
+ }
+
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelConsumerTemplateFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelConsumerTemplateFactoryBean.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelConsumerTemplateFactoryBean.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelConsumerTemplateFactoryBean.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,69 @@
+/**
+ * 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.blueprint;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.impl.DefaultConsumerTemplate;
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * A factory for creating a new {@link org.apache.camel.ConsumerTemplate}
+ * instance with a minimum of XML
+ *
+ * @version $Revision: 800340 $
+ */
+@XmlRootElement(name = "consumerTemplate")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelConsumerTemplateFactoryBean extends IdentifiedType implements CamelContextAware {
+ @XmlTransient
+ private CamelContext camelContext;
+
+ public void afterPropertiesSet() throws Exception {
+ if (camelContext == null) {
+ throw new IllegalArgumentException("A CamelContext must be injected!");
+ }
+ }
+
+ public Object getObject() throws Exception {
+ return new DefaultConsumerTemplate(getCamelContext());
+ }
+
+ public Class getObjectType() {
+ return DefaultConsumerTemplate.class;
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+}
\ No newline at end of file
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,877 @@
+/**
+ * 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.blueprint;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelException;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.ErrorHandlerBuilderRef;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.scan.PatternBasedPackageScanFilter;
+import org.apache.camel.management.DefaultManagementAgent;
+import org.apache.camel.management.DefaultManagementLifecycleStrategy;
+import org.apache.camel.management.DefaultManagementStrategy;
+import org.apache.camel.management.ManagedManagementStrategy;
+import org.apache.camel.model.FromDefinition;
+import org.apache.camel.model.IdentifiedType;
+import org.apache.camel.model.InterceptDefinition;
+import org.apache.camel.model.InterceptFromDefinition;
+import org.apache.camel.model.InterceptSendToEndpointDefinition;
+import org.apache.camel.model.OnCompletionDefinition;
+import org.apache.camel.model.OnExceptionDefinition;
+import org.apache.camel.model.PackageScanDefinition;
+import org.apache.camel.model.PolicyDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RouteBuilderDefinition;
+import org.apache.camel.model.RouteContainer;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.TransactedDefinition;
+import org.apache.camel.model.config.PropertiesDefinition;
+import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.processor.interceptor.Delayer;
+import org.apache.camel.processor.interceptor.HandleFault;
+import org.apache.camel.processor.interceptor.TraceFormatter;
+import org.apache.camel.processor.interceptor.Tracer;
+import org.apache.camel.spi.ClassResolver;
+import org.apache.camel.spi.EventFactory;
+import org.apache.camel.spi.EventNotifier;
+import org.apache.camel.spi.FactoryFinderResolver;
+import org.apache.camel.spi.InflightRepository;
+import org.apache.camel.spi.InterceptStrategy;
+import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.apache.camel.spi.Registry;
+import org.apache.camel.util.EndpointHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A bean to create and initialize a {@link BlueprintCamelContext}
+ * and install routes either explicitly configured in
+ * Blueprint XML or found by searching the classpath for Java classes which extend
+ * {@link RouteBuilder} using the nested {@link #setPackages(String[])}.
+ *
+ * @version $Revision: 813776 $
+ */
+@XmlRootElement(name = "camelContext")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelContextFactoryBean extends IdentifiedType implements RouteContainer {
+ private static final Log LOG = LogFactory.getLog(CamelContextFactoryBean.class);
+
+ @XmlAttribute(required = false)
+ private Boolean trace;
+ @XmlAttribute(required = false)
+ private Boolean streamCache = Boolean.FALSE;
+ @XmlAttribute(required = false)
+ private Long delayer;
+ @XmlAttribute(required = false)
+ private Boolean handleFault;
+ @XmlAttribute(required = false)
+ private String errorHandlerRef;
+ @XmlAttribute(required = false)
+ private Boolean shouldStartContext = Boolean.TRUE;
+ @XmlElement(name = "properties", required = false)
+ private PropertiesDefinition properties;
+ @XmlElement(name = "package", required = false)
+ private String[] packages = {};
+ @XmlElement(name = "packageScan", type = PackageScanDefinition.class, required = false)
+ private PackageScanDefinition packageScan;
+ @XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class, required = false)
+ private CamelJMXAgentDefinition camelJMXAgent;
+ @XmlElements({
+// @XmlElement(name = "beanPostProcessor", type = CamelBeanPostProcessor.class, required = false),
+ @XmlElement(name = "template", type = CamelProducerTemplateFactoryBean.class, required = false),
+ @XmlElement(name = "consumerTemplate", type = CamelConsumerTemplateFactoryBean.class, required = false),
+ @XmlElement(name = "proxy", type = CamelProxyFactoryDefinition.class, required = false),
+ @XmlElement(name = "export", type = CamelServiceExporterDefinition.class, required = false)})
+ private List beans;
+ @XmlElement(name = "routeBuilder", required = false)
+ private List<RouteBuilderDefinition> builderRefs = new ArrayList<RouteBuilderDefinition>();
+ @XmlElement(name = "endpoint", required = false)
+ private List<CamelEndpointFactoryBean> endpoints;
+ @XmlElement(name = "dataFormats", required = false)
+ private DataFormatsDefinition dataFormats;
+ @XmlElement(name = "onException", required = false)
+ private List<OnExceptionDefinition> onExceptions = new ArrayList<OnExceptionDefinition>();
+ @XmlElement(name = "onCompletion", required = false)
+ private List<OnCompletionDefinition> onCompletions = new ArrayList<OnCompletionDefinition>();
+ @XmlElement(name = "intercept", required = false)
+ private List<InterceptDefinition> intercepts = new ArrayList<InterceptDefinition>();
+ @XmlElement(name = "interceptFrom", required = false)
+ private List<InterceptFromDefinition> interceptFroms = new ArrayList<InterceptFromDefinition>();
+ @XmlElement(name = "interceptSendToEndpoint", required = false)
+ private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<InterceptSendToEndpointDefinition>();
+ @XmlElement(name = "route", required = false)
+ private List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
+ @XmlTransient
+ private BlueprintCamelContext context;
+ @XmlTransient
+ private RouteBuilder routeBuilder;
+ @XmlTransient
+ private List<RoutesBuilder> additionalBuilders = new ArrayList<RoutesBuilder>();
+// @XmlTransient
+// private ApplicationContext applicationContext;
+ @XmlTransient
+ private ClassLoader contextClassLoaderOnStart;
+// @XmlTransient
+// private BeanPostProcessor beanPostProcessor;
+
+ public CamelContextFactoryBean() {
+ // Lets keep track of the class loader for when we actually do start things up
+ contextClassLoaderOnStart = Thread.currentThread().getContextClassLoader();
+ }
+
+ public Object getObject() throws Exception {
+ return getContext();
+ }
+
+ public Class getObjectType() {
+ return BlueprintCamelContext.class;
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public ClassLoader getContextClassLoaderOnStart() {
+ return contextClassLoaderOnStart;
+ }
+
+ public List<RoutesBuilder> getAdditionalBuilders() {
+ return additionalBuilders;
+ }
+
+ public void init() throws Exception {
+ if (properties != null) {
+ getContext().setProperties(properties.asMap());
+ }
+
+ // setup JMX agent at first
+ initJMXAgent();
+
+ // set the resolvers first
+ PackageScanClassResolver packageResolver = getBeanForType(PackageScanClassResolver.class);
+ if (packageResolver != null) {
+ LOG.info("Using custom PackageScanClassResolver: " + packageResolver);
+ getContext().setPackageScanClassResolver(packageResolver);
+ }
+ ClassResolver classResolver = getBeanForType(ClassResolver.class);
+ if (classResolver != null) {
+ LOG.info("Using custom ClassResolver: " + classResolver);
+ getContext().setClassResolver(classResolver);
+ }
+ FactoryFinderResolver factoryFinderResolver = getBeanForType(FactoryFinderResolver.class);
+ if (factoryFinderResolver != null) {
+ LOG.info("Using custom FactoryFinderResolver: " + factoryFinderResolver);
+ getContext().setFactoryFinderResolver(factoryFinderResolver);
+ }
+
+ // set the strategy if defined
+ Registry registry = getBeanForType(Registry.class);
+ if (registry != null) {
+ LOG.info("Using custom Registry: " + registry);
+ getContext().setRegistry(registry);
+ }
+
+ Tracer tracer = getBeanForType(Tracer.class);
+ if (tracer != null) {
+ // use formatter if there is a TraceFormatter bean defined
+ TraceFormatter formatter = getBeanForType(TraceFormatter.class);
+ if (formatter != null) {
+ tracer.setFormatter(formatter);
+ }
+ LOG.info("Using custom Tracer: " + tracer);
+ getContext().addInterceptStrategy(tracer);
+ }
+
+ HandleFault handleFault = getBeanForType(HandleFault.class);
+ if (handleFault != null) {
+ LOG.info("Using custom HandleFault: " + handleFault);
+ getContext().addInterceptStrategy(handleFault);
+ }
+
+ Delayer delayer = getBeanForType(Delayer.class);
+ if (delayer != null) {
+ LOG.info("Using custom Delayer: " + delayer);
+ getContext().addInterceptStrategy(delayer);
+ }
+
+ InflightRepository inflightRepository = getBeanForType(InflightRepository.class);
+ if (delayer != null) {
+ LOG.info("Using custom InflightRepository: " + inflightRepository);
+ getContext().setInflightRepository(inflightRepository);
+ }
+
+ ManagementStrategy managementStrategy = getBeanForType(ManagementStrategy.class);
+ if (managementStrategy != null) {
+ LOG.info("Using custom ManagementStrategy: " + managementStrategy);
+ getContext().setManagementStrategy(managementStrategy);
+ }
+
+ EventFactory eventFactory = getBeanForType(EventFactory.class);
+ if (eventFactory != null) {
+ LOG.info("Using custom EventFactory: " + eventFactory);
+ getContext().getManagementStrategy().setEventFactory(eventFactory);
+ }
+
+ EventNotifier eventNotifier = getBeanForType(EventNotifier.class);
+ if (eventNotifier != null) {
+ LOG.info("Using custom EventNotifier: " + eventNotifier);
+ getContext().getManagementStrategy().setEventNotifier(eventNotifier);
+ }
+
+ // add global interceptors
+ Map<String, InterceptStrategy> interceptStrategies = getContext().getRegistry().lookupByType(InterceptStrategy.class);
+ if (interceptStrategies != null && !interceptStrategies.isEmpty()) {
+ for (String id : interceptStrategies.keySet()) {
+ InterceptStrategy strategy = interceptStrategies.get(id);
+ // do not add if already added, for instance a tracer that is also an InterceptStrategy class
+ if (!getContext().getInterceptStrategies().contains(strategy)) {
+ LOG.info("Using custom intercept strategy with id: " + id + " and implementation: " + strategy);
+ getContext().addInterceptStrategy(strategy);
+ }
+ }
+ }
+
+ // set the lifecycle strategy if defined
+ Map<String, LifecycleStrategy> lifecycleStrategies = getContext().getRegistry().lookupByType(LifecycleStrategy.class);
+ if (lifecycleStrategies != null && !lifecycleStrategies.isEmpty()) {
+ for (String id : lifecycleStrategies.keySet()) {
+ LifecycleStrategy strategy = lifecycleStrategies.get(id);
+ // do not add if already added, for instance a tracer that is also an InterceptStrategy class
+ if (!getContext().getLifecycleStrategies().contains(strategy)) {
+ LOG.info("Using custom lifecycle strategy with id: " + id + " and implementation: " + strategy);
+ getContext().addLifecycleStrategy(strategy);
+ }
+ }
+ }
+
+ // Set the application context and camelContext for the beanPostProcessor
+// if (beanPostProcessor != null) {
+// if (beanPostProcessor instanceof ApplicationContextAware) {
+// ((ApplicationContextAware)beanPostProcessor).setApplicationContext(applicationContext);
+// }
+// if (beanPostProcessor instanceof CamelBeanPostProcessor) {
+// ((CamelBeanPostProcessor)beanPostProcessor).setCamelContext(getContext());
+// }
+// }
+
+ // do special preparation for some concepts such as interceptors and policies
+ // this is needed as JAXB does not build excaclty the same model definition as Spring DSL would do
+ // using route builders. So we have here a little custom code to fix the JAXB gaps
+ for (RouteDefinition route : routes) {
+ // interceptors should be first
+ initInterceptors(route);
+ // then on completion
+ initOnCompletions(route);
+ // then polices
+ initPolicies(route);
+ // and last on exception
+ initOnExceptions(route);
+ }
+
+ if (dataFormats != null) {
+ getContext().setDataFormats(dataFormats.asMap());
+ }
+
+ // lets force any lazy creation
+ getContext().addRouteDefinitions(routes);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Found JAXB created routes: " + getRoutes());
+ }
+ findRouteBuilders();
+ installRoutes();
+ }
+
+ private void initOnExceptions(RouteDefinition route) {
+ List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
+ List<ProcessorDefinition<?>> exceptionHandlers = new ArrayList<ProcessorDefinition<?>>();
+
+ // add global on exceptions if any
+ if (onExceptions != null && !onExceptions.isEmpty()) {
+ // on exceptions must be added at top, so the route flow is correct as
+ // on exceptions should be the first outputs
+ route.getOutputs().addAll(0, onExceptions);
+ }
+
+ for (ProcessorDefinition output : route.getOutputs()) {
+ // split into on exception and regular outputs
+ if (output instanceof OnExceptionDefinition) {
+ exceptionHandlers.add(output);
+ } else {
+ outputs.add(output);
+ }
+ }
+
+ // clearing the outputs
+ route.clearOutput();
+
+ // add exception handlers as top children
+ route.getOutputs().addAll(exceptionHandlers);
+
+ // and the remaining outputs
+ route.getOutputs().addAll(outputs);
+ }
+
+ private void initInterceptors(RouteDefinition route) {
+
+ // configure intercept
+ for (InterceptDefinition intercept : getIntercepts()) {
+ intercept.afterPropertiesSet();
+ // add as first output so intercept is handled before the actual route and that gives
+ // us the needed head start to init and be able to intercept all the remaining processing steps
+ route.getOutputs().add(0, intercept);
+ }
+
+ // configure intercept from
+ for (InterceptFromDefinition intercept : getInterceptFroms()) {
+
+ // should we only apply interceptor for a given endpoint uri
+ boolean match = true;
+ if (intercept.getUri() != null) {
+ match = false;
+ for (FromDefinition input : route.getInputs()) {
+ if (EndpointHelper.matchEndpoint(input.getUri(), intercept.getUri())) {
+ match = true;
+ break;
+ }
+ }
+ }
+
+ if (match) {
+ intercept.afterPropertiesSet();
+ // add as first output so intercept is handled before the acutal route and that gives
+ // us the needed head start to init and be able to intercept all the remaining processing steps
+ route.getOutputs().add(0, intercept);
+ }
+ }
+
+ // configure intercept send to endpoint
+ for (InterceptSendToEndpointDefinition intercept : getInterceptSendToEndpoints()) {
+ intercept.afterPropertiesSet();
+ // add as first output so intercept is handled before the acutal route and that gives
+ // us the needed head start to init and be able to intercept all the remaining processing steps
+ route.getOutputs().add(0, intercept);
+ }
+
+ }
+
+ private void initOnCompletions(RouteDefinition route) {
+ // only add global onCompletion if there are no route alredy
+ boolean hasRouteScope = false;
+ for (ProcessorDefinition out : route.getOutputs()) {
+ if (out instanceof OnCompletionDefinition) {
+ hasRouteScope = true;
+ break;
+ }
+ }
+ // only add global onCompletion if we do *not* have any route onCompletion defined in the route
+ // add onCompletion *after* intercept, as its important intercept is first
+ if (!hasRouteScope) {
+ int index = 0;
+ for (int i = 0; i < route.getOutputs().size(); i++) {
+ index = i;
+ ProcessorDefinition out = route.getOutputs().get(i);
+ if (out instanceof InterceptDefinition || out instanceof InterceptSendToEndpointDefinition) {
+ continue;
+ } else {
+ // we found the spot
+ break;
+ }
+ }
+ route.getOutputs().addAll(index, getOnCompletions());
+ }
+ }
+
+ private void initPolicies(RouteDefinition route) {
+ // setup the policies as JAXB yet again have not created a correct model for us
+ List<ProcessorDefinition> types = route.getOutputs();
+
+ // we need two types as transacted cannot extend policy due JAXB limitations
+ PolicyDefinition policy = null;
+ TransactedDefinition transacted = null;
+
+ // add to correct type
+ for (ProcessorDefinition type : types) {
+ if (type instanceof PolicyDefinition) {
+ policy = (PolicyDefinition) type;
+ } else if (type instanceof TransactedDefinition) {
+ transacted = (TransactedDefinition) type;
+ } else if (policy != null) {
+ // the outputs should be moved to the policy
+ policy.addOutput(type);
+ } else if (transacted != null) {
+ // the outputs should be moved to the transacted policy
+ transacted.addOutput(type);
+ }
+ }
+
+ // did we find a policy if so replace it as the only output on the route
+ if (policy != null) {
+ route.clearOutput();
+ route.addOutput(policy);
+ } else if (transacted != null) {
+ route.clearOutput();
+ route.addOutput(transacted);
+ }
+ }
+
+ private void initJMXAgent() throws Exception {
+ if (camelJMXAgent != null && camelJMXAgent.isDisabled()) {
+ LOG.info("JMXAgent disabled");
+ // clear the existing lifecycle strategies define by the DefaultCamelContext constructor
+ getContext().getLifecycleStrategies().clear();
+ // no need to add a lifecycle strategy as we do not need one as JMX is disabled
+ getContext().setManagementStrategy(new DefaultManagementStrategy());
+ } else if (camelJMXAgent != null) {
+ LOG.info("JMXAgent enabled: " + camelJMXAgent);
+ DefaultManagementAgent agent = new DefaultManagementAgent();
+ agent.setConnectorPort(camelJMXAgent.getConnectorPort());
+ agent.setCreateConnector(camelJMXAgent.isCreateConnector());
+ agent.setMBeanObjectDomainName(camelJMXAgent.getMbeanObjectDomainName());
+ agent.setMBeanServerDefaultDomain(camelJMXAgent.getMbeanServerDefaultDomain());
+ agent.setRegistryPort(camelJMXAgent.getRegistryPort());
+ agent.setServiceUrlPath(camelJMXAgent.getServiceUrlPath());
+ agent.setUsePlatformMBeanServer(camelJMXAgent.isUsePlatformMBeanServer());
+ agent.setOnlyRegisterProcessorWithCustomId(camelJMXAgent.getOnlyRegisterProcessorWithCustomId());
+
+ ManagementStrategy managementStrategy = new ManagedManagementStrategy(agent);
+ getContext().setManagementStrategy(managementStrategy);
+
+ // clear the existing lifecycle strategies define by the DefaultCamelContext constructor
+ getContext().getLifecycleStrategies().clear();
+ getContext().addLifecycleStrategy(new DefaultManagementLifecycleStrategy(getContext()));
+ // set additional configuration from camelJMXAgent
+ getContext().getManagementStrategy().onlyManageProcessorWithCustomId(camelJMXAgent.getOnlyRegisterProcessorWithCustomId());
+ getContext().getManagementStrategy().setSatisticsLevel(camelJMXAgent.getStatisticsLevel());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> T getBeanForType(Class<T> clazz) {
+ T bean = null;
+// String[] names = getApplicationContext().getBeanNamesForType(clazz, true, true);
+// if (names.length == 1) {
+// bean = (T) getApplicationContext().getBean(names[0], clazz);
+// }
+// if (bean == null) {
+// ApplicationContext parentContext = getApplicationContext().getParent();
+// if (parentContext != null) {
+// names = parentContext.getBeanNamesForType(clazz, true, true);
+// if (names.length == 1) {
+// bean = (T) parentContext.getBean(names[0], clazz);
+// }
+// }
+// }
+ return bean;
+ }
+
+ public void destroy() throws Exception {
+ getContext().stop();
+ }
+
+// public void onApplicationEvent(ApplicationEvent event) {
+// if (context != null) {
+// // let the spring camel context handle the events
+// context.onApplicationEvent(event);
+// } else {
+// if (LOG.isDebugEnabled()) {
+// LOG.debug("Publishing spring-event: " + event);
+// }
+//
+// if (event instanceof ContextRefreshedEvent) {
+// // now lets start the CamelContext so that all its possible
+// // dependencies are initialized
+// try {
+// LOG.debug("Starting the context now!");
+// getContext().start();
+// } catch (Exception e) {
+// throw wrapRuntimeCamelException(e);
+// }
+// }
+// }
+// }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public BlueprintCamelContext getContext() throws Exception {
+ if (context == null) {
+ context = createContext();
+ }
+ return context;
+ }
+
+ public void setContext(BlueprintCamelContext context) {
+ this.context = context;
+ }
+
+ public List<RouteDefinition> getRoutes() {
+ return routes;
+ }
+
+ public void setRoutes(List<RouteDefinition> routes) {
+ this.routes = routes;
+ }
+
+ public List<InterceptDefinition> getIntercepts() {
+ return intercepts;
+ }
+
+ public void setIntercepts(List<InterceptDefinition> intercepts) {
+ this.intercepts = intercepts;
+ }
+
+ public List<InterceptFromDefinition> getInterceptFroms() {
+ return interceptFroms;
+ }
+
+ public void setInterceptFroms(List<InterceptFromDefinition> interceptFroms) {
+ this.interceptFroms = interceptFroms;
+ }
+
+ public List<InterceptSendToEndpointDefinition> getInterceptSendToEndpoints() {
+ return interceptSendToEndpoints;
+ }
+
+ public void setInterceptSendToEndpoints(List<InterceptSendToEndpointDefinition> interceptSendToEndpoints) {
+ this.interceptSendToEndpoints = interceptSendToEndpoints;
+ }
+
+ public RouteBuilder getRouteBuilder() {
+ return routeBuilder;
+ }
+
+ /**
+ * Set a single {@link RouteBuilder} to be used to create the default routes
+ * on startup
+ */
+ public void setRouteBuilder(RouteBuilder routeBuilder) {
+ this.routeBuilder = routeBuilder;
+ }
+
+ /**
+ * Set a collection of {@link RouteBuilder} instances to be used to create
+ * the default routes on startup
+ */
+ public void setRouteBuilders(RouteBuilder[] builders) {
+ additionalBuilders.addAll(Arrays.asList(builders));
+ }
+
+// public ApplicationContext getApplicationContext() {
+// if (applicationContext == null) {
+// throw new IllegalArgumentException("No applicationContext has been injected!");
+// }
+// return applicationContext;
+// }
+//
+// public void setApplicationContext(ApplicationContext applicationContext) {
+// this.applicationContext = applicationContext;
+// }
+
+ public PropertiesDefinition getProperties() {
+ return properties;
+ }
+
+ public void setProperties(PropertiesDefinition properties) {
+ this.properties = properties;
+ }
+
+ /**
+ * @deprecated replaced by {@link #getPackageScan()}
+ */
+ @Deprecated
+ public String[] getPackages() {
+ return packages;
+ }
+
+ /**
+ * Sets the package names to be recursively searched for Java classes which
+ * extend {@link RouteBuilder} to be auto-wired up to the
+ * {@link BlueprintCamelContext} as a route. Note that classes are excluded if
+ * they are specifically configured in the spring.xml
+ *
+ * @deprecated replaced by {@link #setPackageScan(org.apache.camel.model.PackageScanDefinition)}
+ * @param packages the package names which are recursively searched
+ */
+ @Deprecated
+ public void setPackages(String[] packages) {
+ this.packages = packages;
+ }
+
+ public PackageScanDefinition getPackageScan() {
+ return packageScan;
+ }
+
+ /**
+ * Sets the package scanning information. Package scanning allows for the
+ * automatic discovery of certain camel classes at runtime for inclusion
+ * e.g. {@link RouteBuilder} implementations
+ *
+ * @param packageScan the package scan
+ */
+ public void setPackageScan(PackageScanDefinition packageScan) {
+ this.packageScan = packageScan;
+ }
+
+// public void setBeanPostProcessor(BeanPostProcessor postProcessor) {
+// this.beanPostProcessor = postProcessor;
+// }
+//
+// public BeanPostProcessor getBeanPostProcessor() {
+// return beanPostProcessor;
+// }
+
+ public void setCamelJMXAgent(CamelJMXAgentDefinition agent) {
+ camelJMXAgent = agent;
+ }
+
+ public Boolean getTrace() {
+ return trace;
+ }
+
+ public void setTrace(Boolean trace) {
+ this.trace = trace;
+ }
+
+ public Boolean getStreamCache() {
+ return streamCache;
+ }
+
+ public void setStreamCache(Boolean streamCache) {
+ this.streamCache = streamCache;
+ }
+
+ public Long getDelayer() {
+ return delayer;
+ }
+
+ public void setDelayer(Long delayer) {
+ this.delayer = delayer;
+ }
+
+ public Boolean getHandleFault() {
+ return handleFault;
+ }
+
+ public void setHandleFault(Boolean handleFault) {
+ this.handleFault = handleFault;
+ }
+
+ public CamelJMXAgentDefinition getCamelJMXAgent() {
+ return camelJMXAgent;
+ }
+
+ public List<RouteBuilderDefinition> getBuilderRefs() {
+ return builderRefs;
+ }
+
+ public void setBuilderRefs(List<RouteBuilderDefinition> builderRefs) {
+ this.builderRefs = builderRefs;
+ }
+
+ public String getErrorHandlerRef() {
+ return errorHandlerRef;
+ }
+
+ /**
+ * Sets the name of the error handler object used to default the error handling strategy
+ *
+ * @param errorHandlerRef the Spring bean ref of the error handler
+ */
+ public void setErrorHandlerRef(String errorHandlerRef) {
+ this.errorHandlerRef = errorHandlerRef;
+ }
+
+ public Boolean getShouldStartContext() {
+ return shouldStartContext;
+ }
+
+ public void setShouldStartContext(Boolean shouldStartContext) {
+ this.shouldStartContext = shouldStartContext;
+ }
+
+ public void setDataFormats(DataFormatsDefinition dataFormats) {
+ this.dataFormats = dataFormats;
+ }
+
+ public DataFormatsDefinition getDataFormats() {
+ return dataFormats;
+ }
+
+ public void setOnExceptions(List<OnExceptionDefinition> onExceptions) {
+ this.onExceptions = onExceptions;
+ }
+
+ public List<OnExceptionDefinition> getOnExceptions() {
+ return onExceptions;
+ }
+
+ public List<OnCompletionDefinition> getOnCompletions() {
+ return onCompletions;
+ }
+
+ public void setOnCompletions(List<OnCompletionDefinition> onCompletions) {
+ this.onCompletions = onCompletions;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Create the context
+ */
+ protected BlueprintCamelContext createContext() {
+ BlueprintCamelContext ctx = new BlueprintCamelContext();
+// BlueprintCamelContext ctx = new BlueprintCamelContext(getApplicationContext());
+ ctx.setName(getId());
+ if (streamCache != null) {
+ ctx.setStreamCaching(streamCache);
+ }
+ if (trace != null) {
+ ctx.setTracing(trace);
+ }
+ if (delayer != null) {
+ ctx.setDelayer(delayer);
+ }
+ if (handleFault != null) {
+ ctx.setHandleFault(handleFault);
+ }
+ if (errorHandlerRef != null) {
+ ctx.setErrorHandlerBuilder(new ErrorHandlerBuilderRef(errorHandlerRef));
+ }
+
+ if (shouldStartContext != null) {
+ ctx.setShouldStartContext(shouldStartContext);
+ }
+
+ return ctx;
+ }
+
+ /**
+ * Strategy to install all available routes into the context
+ */
+ @SuppressWarnings("unchecked")
+ protected void installRoutes() throws Exception {
+ List<RouteBuilder> builders = new ArrayList<RouteBuilder>();
+
+ if (routeBuilder != null) {
+ builders.add(routeBuilder);
+ }
+
+ // lets add route builders added from references
+ if (builderRefs != null) {
+ for (RouteBuilderDefinition builderRef : builderRefs) {
+ RouteBuilder builder = builderRef.createRouteBuilder(getContext());
+ if (builder != null) {
+ builders.add(builder);
+ } else {
+ // support to get the route here
+ RoutesBuilder routes = builderRef.createRoutes(getContext());
+ if (routes != null) {
+ additionalBuilders.add(routes);
+ } else {
+ // Throw the exception that we can't find any build here
+ throw new CamelException("Cannot find any routes with this RouteBuilder reference: " + builderRef);
+ }
+ }
+
+ }
+ }
+
+ // install already configured routes
+ for (RoutesBuilder routeBuilder : additionalBuilders) {
+ getContext().addRoutes(routeBuilder);
+ }
+
+ // install builders
+ for (RouteBuilder builder : builders) {
+// if (beanPostProcessor != null) {
+ // Inject the annotated resource
+// beanPostProcessor.postProcessBeforeInitialization(builder, builder.toString());
+// }
+ getContext().addRoutes(builder);
+ }
+ }
+
+ /**
+ * Strategy method to try find {@link RouteBuilder} instances on the classpath
+ */
+ protected void findRouteBuilders() throws Exception {
+ PackageScanClassResolver resolver = getContext().getPackageScanClassResolver();
+ addPackageElementContentsToScanDefinition();
+
+ PackageScanDefinition packageScanDef = getPackageScan();
+ if (packageScanDef != null && packageScanDef.getPackages().size() > 0) {
+ // use package scan filter
+ PatternBasedPackageScanFilter filter = new PatternBasedPackageScanFilter();
+ filter.addIncludePatterns(packageScanDef.getIncludes());
+ filter.addExcludePatterns(packageScanDef.getExcludes());
+ resolver.addFilter(filter);
+
+ String[] normalized = normalizePackages(packageScanDef.getPackages());
+// RouteBuilderFinder finder = new RouteBuilderFinder(getContext(), normalized, getContextClassLoaderOnStart(),
+// getBeanPostProcessor(), getContext().getPackageScanClassResolver());
+// finder.appendBuilders(getAdditionalBuilders());
+ }
+ }
+
+ private void addPackageElementContentsToScanDefinition() {
+ PackageScanDefinition packageScanDef = getPackageScan();
+
+ if (getPackages() != null && getPackages().length > 0) {
+ LOG.warn("Using a packages element to specify packages to search has been deprecated. Please use a packageScan element instead.");
+ if (packageScanDef == null) {
+ packageScanDef = new PackageScanDefinition();
+ setPackageScan(packageScanDef);
+ }
+
+ for (String pkg : getPackages()) {
+ packageScanDef.getPackages().add(pkg);
+ }
+ }
+ }
+
+ private String[] normalizePackages(List<String> unnormalized) {
+ List<String> packages = new ArrayList<String>();
+ for (String name : unnormalized) {
+ name = ObjectHelper.normalizeClassName(name);
+ if (ObjectHelper.isNotEmpty(name)) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Using package: " + name + " to scan for RouteBuilder classes");
+ }
+ packages.add(name);
+ }
+ }
+ return packages.toArray(new String[packages.size()]);
+ }
+
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelEndpointFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelEndpointFactoryBean.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelEndpointFactoryBean.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelEndpointFactoryBean.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,112 @@
+/**
+ * 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.blueprint;
+
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Endpoint;
+import org.apache.camel.NoSuchEndpointException;
+import org.apache.camel.model.IdentifiedType;
+import static org.apache.camel.util.ObjectHelper.notNull;
+
+/**
+ * A factory which instantiates {@link Endpoint} objects
+ *
+ * @version $Revision: 759657 $
+ */
+@XmlRootElement(name = "endpoint")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelEndpointFactoryBean extends IdentifiedType implements CamelContextAware {
+ @XmlAttribute
+ private String uri;
+ @XmlTransient
+ private CamelContext context;
+ @XmlTransient
+ private Endpoint endpoint;
+ @XmlTransient
+ private boolean singleton;
+
+ public Object getObject() throws Exception {
+ if (endpoint == null) {
+ endpoint = createEndpoint();
+ }
+ return endpoint;
+ }
+
+ public Class getObjectType() {
+ return Endpoint.class;
+ }
+
+ public boolean isSingleton() {
+ return singleton;
+ }
+
+ public CamelContext getCamelContext() {
+ return context;
+ }
+
+ /**
+ * Sets the context to use to resolve endpoints
+ *
+ * @param context the context used to resolve endpoints
+ */
+ public void setCamelContext(CamelContext context) {
+ this.context = context;
+ }
+
+ public Endpoint getEndpoint() {
+ return endpoint;
+ }
+
+ public void setEndpoint(Endpoint endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public void setSingleton(boolean singleton) {
+ this.singleton = singleton;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * Sets the URI to use to resolve the endpoint
+ *
+ * @param uri the URI used to set the endpoint
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ protected Endpoint createEndpoint() {
+ notNull(context, "context");
+ notNull(uri, "uri");
+ Endpoint endpoint = context.getEndpoint(uri);
+ if (endpoint == null) {
+ throw new NoSuchEndpointException(uri);
+ }
+ return endpoint;
+ }
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelJMXAgentDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelJMXAgentDefinition.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelJMXAgentDefinition.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelJMXAgentDefinition.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,206 @@
+/**
+ * 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.blueprint;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.ManagementStatisticsLevel;
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The JAXB type class for the configuration of jmxAgent
+ *
+ * @version $Revision: 812099 $
+ */
+@XmlRootElement(name = "jmxAgent")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelJMXAgentDefinition extends IdentifiedType {
+
+ /**
+ * Disable JMI (default false)
+ */
+ @XmlAttribute(required = false)
+ private Boolean disabled = Boolean.FALSE;
+
+ /**
+ * Only register processor if a custom id was defined for it.
+ */
+ @XmlAttribute(required = false)
+ private Boolean onlyRegisterProcessorWithCustomId = Boolean.FALSE;
+
+ /**
+ * RMI connector registry port (default 1099)
+ */
+ @XmlAttribute(required = false)
+ private Integer registryPort;
+
+ /**
+ * RMI connector server port (default -1 not used)
+ */
+ @XmlAttribute(required = false)
+ private Integer connectorPort;
+
+ /**
+ * MBean server default domain name (default org.apache.camel)
+ */
+ @XmlAttribute(required = false)
+ private String mbeanServerDefaultDomain;
+
+ /**
+ * MBean object domain name (default org.apache.camel)
+ */
+ @XmlAttribute(required = false)
+ private String mbeanObjectDomainName;
+
+ /**
+ * JMX Service URL path (default /jmxrmi)
+ */
+ @XmlAttribute(required = false)
+ private String serviceUrlPath;
+
+ /**
+ * A flag that indicates whether the agent should be created
+ */
+ @XmlAttribute(required = false)
+ private Boolean createConnector = Boolean.TRUE;
+
+ /**
+ * A flag that indicates whether the platform mbean server should be used
+ */
+ @XmlAttribute(required = false)
+ private Boolean usePlatformMBeanServer = Boolean.TRUE;
+
+ /**
+ * Level of granularity for performance statistics enabled
+ */
+ @XmlAttribute(required = false)
+ private ManagementStatisticsLevel statisticsLevel = ManagementStatisticsLevel.All;
+
+ public Integer getConnectorPort() {
+ return connectorPort;
+ }
+
+ public void setConnectorPort(Integer value) {
+ connectorPort = value;
+ }
+
+ public Integer getRegistryPort() {
+ return registryPort;
+ }
+
+ public void setRegistryPort(Integer value) {
+ registryPort = value;
+ }
+
+ public String getMbeanServerDefaultDomain() {
+ return mbeanServerDefaultDomain;
+ }
+
+ public void setMbeanServerDefaultDomain(String value) {
+ mbeanServerDefaultDomain = value;
+ }
+
+ public String getMbeanObjectDomainName() {
+ return mbeanObjectDomainName;
+ }
+
+ public void setMbeanObjectDomainName(String value) {
+ mbeanObjectDomainName = value;
+ }
+
+ public String getServiceUrlPath() {
+ return serviceUrlPath;
+ }
+
+ public void setServiceUrlPath(String value) {
+ serviceUrlPath = value;
+ }
+
+ public Boolean isCreateConnector() {
+ return createConnector;
+ }
+
+ public void setCreateConnector(Boolean value) {
+ createConnector = value != null ? value : Boolean.FALSE;
+ }
+
+ public Boolean isUsePlatformMBeanServer() {
+ return usePlatformMBeanServer;
+ }
+
+ public void setUsePlatformMBeanServer(Boolean value) {
+ usePlatformMBeanServer = value != null ? value : Boolean.FALSE;
+ }
+
+ public Boolean getOnlyRegisterProcessorWithCustomId() {
+ return onlyRegisterProcessorWithCustomId;
+ }
+
+ public void setOnlyRegisterProcessorWithCustomId(Boolean onlyRegisterProcessorWithCustomId) {
+ this.onlyRegisterProcessorWithCustomId = onlyRegisterProcessorWithCustomId;
+ }
+
+ public Boolean isDisabled() {
+ return disabled;
+ }
+
+ public void setDisabled(Boolean value) {
+ disabled = value != null ? value : Boolean.FALSE;
+ }
+
+ public ManagementStatisticsLevel getStatisticsLevel() {
+ return statisticsLevel;
+ }
+
+ public void setStatisticsLevel(ManagementStatisticsLevel statisticsLevel) {
+ this.statisticsLevel = statisticsLevel;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("CamelJMXAgent[");
+ sb.append("usePlatformMBeanServer=").append(usePlatformMBeanServer);
+ if (createConnector != null) {
+ sb.append(", createConnector=").append(createConnector);
+ }
+ if (connectorPort != null) {
+ sb.append(", connectorPort=").append(connectorPort);
+ }
+ if (registryPort != null) {
+ sb.append(", registryPort=").append(registryPort);
+ }
+ if (serviceUrlPath != null) {
+ sb.append(", serviceUrlPath=").append(serviceUrlPath);
+ }
+ if (mbeanServerDefaultDomain != null) {
+ sb.append(", mbeanServerDefaultDomain=").append(mbeanServerDefaultDomain);
+ }
+ if (mbeanObjectDomainName != null) {
+ sb.append(", mbeanObjectDomainName=").append(mbeanObjectDomainName);
+ }
+ if (statisticsLevel != null) {
+ sb.append(", statisticsLevel=").append(statisticsLevel);
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProducerTemplateFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProducerTemplateFactoryBean.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProducerTemplateFactoryBean.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProducerTemplateFactoryBean.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,93 @@
+/**
+ * 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.blueprint;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultProducerTemplate;
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * A factory for creating a new {@link org.apache.camel.ProducerTemplate}
+ * instance with a minimum of XML
+ *
+ * @version $Revision: 800340 $
+ */
+@XmlRootElement(name = "template")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelProducerTemplateFactoryBean extends IdentifiedType implements CamelContextAware {
+ @XmlAttribute(required = false)
+ private String defaultEndpoint;
+ @XmlTransient
+ private CamelContext camelContext;
+
+ public void afterPropertiesSet() throws Exception {
+ if (camelContext == null) {
+ throw new IllegalArgumentException("A CamelContext must be injected!");
+ }
+ }
+
+ public Object getObject() throws Exception {
+ CamelContext context = getCamelContext();
+ if (defaultEndpoint != null) {
+ Endpoint endpoint = context.getEndpoint(defaultEndpoint);
+ if (endpoint == null) {
+ throw new IllegalArgumentException("No endpoint found for URI: " + defaultEndpoint);
+ } else {
+ return new DefaultProducerTemplate(context, endpoint);
+ }
+ }
+ return new DefaultProducerTemplate(context);
+ }
+
+ public Class getObjectType() {
+ return DefaultProducerTemplate.class;
+ }
+
+ public boolean isSingleton() {
+ return false;
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ public String getDefaultEndpoint() {
+ return defaultEndpoint;
+ }
+
+ /**
+ * Sets the default endpoint URI used by default for sending message
+ * exchanges
+ */
+ public void setDefaultEndpoint(String defaultEndpoint) {
+ this.defaultEndpoint = defaultEndpoint;
+ }
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProxyFactoryDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProxyFactoryDefinition.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProxyFactoryDefinition.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelProxyFactoryDefinition.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,36 @@
+/**
+ * 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.blueprint;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The <proxy> tag element.
+ *
+ * @version $Revision: 750806 $
+*/ // to fudge the XSD generation
+@XmlRootElement(name = "proxy")
+public class CamelProxyFactoryDefinition extends IdentifiedType {
+ @XmlAttribute
+ private String serviceUrl;
+ @XmlAttribute
+ private Class serviceInterface;
+
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelServiceExporterDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelServiceExporterDefinition.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelServiceExporterDefinition.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelServiceExporterDefinition.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,37 @@
+/**
+ * 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.blueprint;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The <export> tag element.
+ *
+ * @version $Revision: 750806 $
+*/
+@XmlRootElement(name = "export")
+public class CamelServiceExporterDefinition extends IdentifiedType {
+ @XmlAttribute
+ private String uri;
+ @XmlAttribute
+ private String serviceRef;
+ @XmlAttribute
+ private Class serviceInterface;
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,177 @@
+/**
+ * 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.blueprint.handler;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+import javax.xml.bind.Binder;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.aries.blueprint.NamespaceHandler;
+import org.apache.aries.blueprint.ParserContext;
+import org.apache.aries.blueprint.mutable.MutableBeanMetadata;
+import org.apache.aries.blueprint.mutable.MutablePassThroughMetadata;
+import org.apache.camel.blueprint.BlueprintCamelContext;
+import org.apache.camel.blueprint.CamelContextFactoryBean;
+import org.apache.camel.util.ObjectHelper;
+import org.osgi.service.blueprint.container.ComponentDefinitionException;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.Metadata;
+
+public class CamelNamespaceHandler implements NamespaceHandler {
+
+ private static final String CAMEL_CONTEXT = "camelContext";
+
+ private static final String SPRING_NS = "http://camel.apache.org/schema/spring";
+ private static final String BLUEPRINT_NS = "http://camel.apache.org/schema/blueprint";
+
+ private JAXBContext jaxbContext;
+
+ public static void renameNamespaceRecursive(Node node) {
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ Document doc = node.getOwnerDocument();
+ if (((Element) node).getNamespaceURI().equals(BLUEPRINT_NS)) {
+ doc.renameNode(node, SPRING_NS, node.getNodeName());
+ }
+ }
+ NodeList list = node.getChildNodes();
+ for (int i = 0; i < list.getLength(); ++i) {
+ renameNamespaceRecursive(list.item(i));
+ }
+ }
+
+ public URL getSchemaLocation(String namespace) {
+ return getClass().getClassLoader().getResource("camel-blueprint.xsd");
+ }
+
+ public Set<Class> getManagedClasses() {
+ return new HashSet<Class>(Arrays.asList(
+ BlueprintCamelContext.class
+ ));
+ }
+
+ public Metadata parse(Element element, ParserContext context) {
+ renameNamespaceRecursive(element);
+ if (element.getNodeName().equals(CAMEL_CONTEXT)) {
+ // Find the id, generate one if needed
+ String contextId = element.getAttribute("id");
+ if (ObjectHelper.isEmpty(contextId)) {
+ contextId = "camelContext";
+ element.setAttribute("id", contextId);
+ }
+
+ // now lets parse the routes with JAXB
+ Binder<Node> binder;
+ try {
+ binder = getJaxbContext().createBinder();
+ } catch (JAXBException e) {
+ throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ }
+ Object value = parseUsingJaxb(element, context, binder);
+ if (!(value instanceof CamelContextFactoryBean)) {
+ throw new ComponentDefinitionException("Expected an instance of " + CamelContextFactoryBean.class);
+ }
+
+ MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
+ factory.setId(".camelBlueprint.passThrough." + contextId);
+ factory.setObject(new PassThroughCallable<Object>(value));
+
+ MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
+ factory2.setId(".camelBlueprint.factory." + contextId);
+ factory2.setFactoryComponent(factory);
+ factory2.setFactoryMethod("call");
+ factory2.setInitMethod("init");
+ factory2.setDestroyMethod("destroy");
+
+ MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
+ ctx.setId(contextId);
+ ctx.setFactoryComponent(factory2);
+ ctx.setFactoryMethod("getContext");
+ ctx.setInitMethod("init");
+ ctx.setDestroyMethod("destroy");
+
+ return ctx;
+ }
+ return null;
+ }
+
+ public ComponentMetadata decorate(Node node, ComponentMetadata component, ParserContext context) {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ protected Object parseUsingJaxb(Element element, ParserContext parserContext, Binder<Node> binder) {
+ try {
+ return binder.unmarshal(element);
+ } catch (JAXBException e) {
+ throw new ComponentDefinitionException("Failed to parse JAXB element: " + e, e);
+ }
+ }
+
+ public JAXBContext getJaxbContext() throws JAXBException {
+ if (jaxbContext == null) {
+ jaxbContext = createJaxbContext();
+ }
+ return jaxbContext;
+ }
+
+ protected JAXBContext createJaxbContext() throws JAXBException {
+ StringBuilder packages = new StringBuilder();
+ for (Class cl : getJaxbPackages()) {
+ if (packages.length() > 0) {
+ packages.append(":");
+ }
+ packages.append(cl.getName().substring(0, cl.getName().lastIndexOf('.')));
+ }
+ return JAXBContext.newInstance(packages.toString(), getClass().getClassLoader());
+ }
+
+ protected Set<Class> getJaxbPackages() {
+ Set<Class> classes = new HashSet<Class>();
+ classes.add(CamelContextFactoryBean.class);
+ classes.add(org.apache.camel.ExchangePattern.class);
+ classes.add(org.apache.camel.model.RouteDefinition.class);
+ classes.add(org.apache.camel.model.config.StreamResequencerConfig.class);
+ classes.add(org.apache.camel.model.dataformat.DataFormatsDefinition.class);
+ classes.add(org.apache.camel.model.language.ExpressionDefinition.class);
+ classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class);
+ return classes;
+ }
+
+ public static class PassThroughCallable<T> implements Callable<T> {
+
+ private T value;
+
+ public PassThroughCallable(T value) {
+ this.value = value;
+ }
+
+ public T call() throws Exception {
+ return value;
+ }
+ }
+
+}
Added: camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/package-info.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/package-info.java?rev=822657&view=auto
==============================================================================
--- camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/package-info.java (added)
+++ camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/package-info.java Wed Oct 7 10:53:39 2009
@@ -0,0 +1,18 @@
+/**
+ * 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.
+ */
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://camel.apache.org/schema/spring", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.camel.blueprint;