camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r567621 - in /activemq/camel/trunk: ./ apache-camel/ apache-camel/src/main/descriptors/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/util/ components/ components/camel-atom/ components/camel-atom...
Date Mon, 20 Aug 2007 09:30:18 GMT
Author: jstrachan
Date: Mon Aug 20 02:30:16 2007
New Revision: 567621

URL: http://svn.apache.org/viewvc?rev=567621&view=rev
Log:
initial spike of an atom component using Apache Abdera

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java
  (with props)
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultScheduledPollConsumer.java
  (with props)
    activemq/camel/trunk/components/camel-atom/
    activemq/camel/trunk/components/camel-atom/pom.xml   (with props)
    activemq/camel/trunk/components/camel-atom/src/
    activemq/camel/trunk/components/camel-atom/src/main/
    activemq/camel/trunk/components/camel-atom/src/main/java/
    activemq/camel/trunk/components/camel-atom/src/main/java/org/
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
  (with props)
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomEndpoint.java
  (with props)
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomPollingConsumer.java
  (with props)
    activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomProducer.java
  (with props)
    activemq/camel/trunk/components/camel-atom/src/main/resources/
    activemq/camel/trunk/components/camel-atom/src/main/resources/META-INF/
    activemq/camel/trunk/components/camel-atom/src/test/
    activemq/camel/trunk/components/camel-atom/src/test/java/
    activemq/camel/trunk/components/camel-atom/src/test/resources/
    activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties   (with
props)
Modified:
    activemq/camel/trunk/apache-camel/pom.xml
    activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml
    activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    activemq/camel/trunk/components/pom.xml
    activemq/camel/trunk/pom.xml

Modified: activemq/camel/trunk/apache-camel/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/pom.xml?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/pom.xml (original)
+++ activemq/camel/trunk/apache-camel/pom.xml Mon Aug 20 02:30:16 2007
@@ -40,6 +40,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.camel</groupId>
+      <artifactId>camel-atom</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
       <artifactId>camel-bam</artifactId>
     </dependency>
     <dependency>

Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml (original)
+++ activemq/camel/trunk/apache-camel/src/main/descriptors/unix-bin.xml Mon Aug 20 02:30:16
2007
@@ -41,10 +41,18 @@
         <exclude>**/*.i*</exclude>
         <exclude>**/target/</exclude>
         <exclude>**/target/*</exclude>
+        <exclude>**/*.ser</exclude>
+        <exclude>**/*.log</exclude>
       </excludes>
       <lineEnding>unix</lineEnding>
     </fileSet>
 
+    <!-- copy the manual docs -->
+    <fileSet>
+      <directory>${basedir}/../tooling/camel-manual/target/site/manual/</directory>
+      <outputDirectory>/doc/manual</outputDirectory>
+    </fileSet>
+
     <!-- copy the website docs -->
     <fileSet>
       <directory>${basedir}/target/website</directory>
@@ -69,6 +77,7 @@
       <scope>runtime</scope>
       <includes>
         <include>org.apache.camel:camel-activemq</include>
+        <include>org.apache.camel:camel-atom</include>
         <include>org.apache.camel:camel-bam</include>
         <include>org.apache.camel:camel-core</include>
         <include>org.apache.camel:camel-cxf</include>

Modified: activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml (original)
+++ activemq/camel/trunk/apache-camel/src/main/descriptors/windows-bin.xml Mon Aug 20 02:30:16
2007
@@ -38,6 +38,12 @@
       <outputDirectory>/doc/website</outputDirectory>
     </fileSet>
 
+    <!-- copy the manual docs -->
+    <fileSet>
+      <directory>${basedir}/../tooling/camel-manual/target/site/manual/</directory>
+      <outputDirectory>/doc/manual</outputDirectory>
+    </fileSet>
+
     <!-- copy the examples -->
     <fileSet>
       <directory>../examples</directory>
@@ -47,6 +53,8 @@
         <exclude>**/*.i*</exclude>
         <exclude>**/target/</exclude>
         <exclude>**/target/*</exclude>
+        <exclude>**/*.ser</exclude>
+        <exclude>**/*.log</exclude>
       </excludes>
       <lineEnding>dos</lineEnding>
     </fileSet>
@@ -75,6 +83,7 @@
       <scope>runtime</scope>
       <includes>
         <include>org.apache.camel:camel-activemq</include>
+        <include>org.apache.camel:camel-atom</include>
         <include>org.apache.camel:camel-bam</include>
         <include>org.apache.camel:camel-core</include>
         <include>org.apache.camel:camel-cxf</include>

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingConsumer.java
Mon Aug 20 02:30:16 2007
@@ -16,18 +16,19 @@
  */
 package org.apache.camel.impl;
 
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
-
 import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
 import org.apache.camel.Processor;
 import org.apache.camel.processor.Logger;
 import org.apache.camel.spi.ExceptionHandler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
 
 /**
  * A default implementation of the {@link PollingConsumer} which uses the normal

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java
Mon Aug 20 02:30:16 2007
@@ -0,0 +1,43 @@
+/**
+ *
+ * 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.impl;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Component;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+
+/**
+ * A base class for an endpoint which the default consumer mode is to use a {@link PollingConsumer}
+ *
+ * @version $Revision: 1.1 $
+ */
+public abstract class DefaultPollingEndpoint<E extends Exchange> extends ScheduledPollEndpoint<E>
 {
+
+    protected DefaultPollingEndpoint(String endpointUri, Component component) {
+        super(endpointUri, component);
+    }
+
+    public Consumer<E> createConsumer(Processor processor) throws Exception {
+        DefaultScheduledPollConsumer result = new DefaultScheduledPollConsumer(this, processor);
+        configureConsumer(result);
+        return result;
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultPollingEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultScheduledPollConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultScheduledPollConsumer.java?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultScheduledPollConsumer.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultScheduledPollConsumer.java
Mon Aug 20 02:30:16 2007
@@ -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.impl;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Processor;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+/**
+ * A default implementation of an event driven {@link Consumer} which uses the {@link PollingConsumer}
+ *
+ * @version $Revision: 1.1 $
+ */
+public class DefaultScheduledPollConsumer<E extends Exchange> extends ScheduledPollConsumer<E>
{
+    private PollingConsumer<E> pollingConsumer;
+
+    public DefaultScheduledPollConsumer(DefaultEndpoint<E> defaultEndpoint, Processor
processor) {
+        super(defaultEndpoint, processor);
+    }
+
+    public DefaultScheduledPollConsumer(Endpoint<E> endpoint, Processor processor,
ScheduledExecutorService executor) {
+        super(endpoint, processor, executor);
+    }
+
+    protected void poll() throws Exception {
+        while (true) {
+            E exchange = pollingConsumer.receiveNoWait();
+            if (exchange == null) {
+                break;
+            }
+            getProcessor().process(exchange);
+        }
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        pollingConsumer = getEndpoint().createPollingConsumer();
+        super.doStart();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+        if (pollingConsumer != null) {
+            pollingConsumer.stop();
+        }
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultScheduledPollConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ScheduledPollEndpoint.java
Mon Aug 20 02:30:16 2007
@@ -16,12 +16,13 @@
  */
 package org.apache.camel.impl;
 
-import java.util.Map;
-
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.util.IntrospectionSupport;
+
+import java.util.Map;
 
 /**
  * A base class for {@link Endpoint} which creates a {@link ScheduledPollConsumer}

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ExchangeHelper.java
Mon Aug 20 02:30:16 2007
@@ -35,7 +35,27 @@
      */
     private ExchangeHelper() {        
     }
-    
+
+    /**
+     * Extracts the exchange property of the given name and type; if it is not present then
the
+     * default value will be used
+     *
+     * @param exchange the message exchange
+     * @param propertyName the name of the property on the exchange
+     * @param type the expected type of the property
+     * @param defaultValue the default value to be used if the property name does not exist
or could not be
+     * converted to the given type
+     * @return the property value as the given type or the defaultValue if it could not be
found or converted
+     */
+    public static <T> T getExchangeProperty(Exchange exchange, String propertyName,
Class<T> type, T defaultValue) {
+        T answer = exchange.getProperty(propertyName, type);
+        if (answer == null) {
+            return defaultValue;
+        }
+        return answer;
+    }
+
+
     /**
      * Attempts to resolve the endpoint for the given value
      * 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
Mon Aug 20 02:30:16 2007
@@ -30,6 +30,9 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.io.OutputStream;
+import java.io.Closeable;
+import java.io.IOException;
 
 /**
  * A number of useful helper methods for working with Objects
@@ -388,5 +391,23 @@
             }
         }
         return false;
+    }
+
+    /**
+     * Closes the given resource if it is available, logging any closing exceptions to the
given log
+     *
+     * @param closeable the object to close
+     * @param name the name of the resource
+     * @param log the log to use when reporting closure warnings
+     */
+    public static void close(Closeable closeable, String name, Log log) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            }
+            catch (IOException e) {
+                log.warn("Could not close " + name + ". Reason: "+ e, e);
+            }
+        }
     }
 }

Added: activemq/camel/trunk/components/camel-atom/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/pom.xml?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/pom.xml (added)
+++ activemq/camel/trunk/components/camel-atom/pom.xml Mon Aug 20 02:30:16 2007
@@ -0,0 +1,48 @@
+<?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>1.1-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-atom</artifactId>
+  <name>Camel :: Atom</name>
+  <description>Camel Atom support</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+    </dependency>
+      <dependency>
+      <groupId>org.apache.abdera</groupId>
+        <artifactId>abdera-extensions</artifactId>
+      <version>0.2.0-incubating</version>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Propchange: activemq/camel/trunk/components/camel-atom/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
(added)
+++ activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
Mon Aug 20 02:30:16 2007
@@ -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.component.atom;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.IntrospectionSupport;
+
+import java.util.Map;
+
+/**
+ * An <a href="http://activemq.apache.org/camel/atom.html">Atom Component</a>.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class AtomComponent extends DefaultComponent {
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
+        AtomEndpoint answer = new AtomEndpoint(uri, this, remaining);
+        IntrospectionSupport.setProperties(answer, parameters);
+        return answer;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomComponent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomEndpoint.java?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomEndpoint.java
(added)
+++ activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomEndpoint.java
Mon Aug 20 02:30:16 2007
@@ -0,0 +1,111 @@
+/**
+ *
+ * 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.atom;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.parser.Parser;
+import org.apache.abdera.util.iri.IRISyntaxException;
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.DefaultPollingEndpoint;
+
+import java.io.BufferedOutputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+
+/**
+ * An <a href="http://activemq.apache.org/camel/atom.html">Atom Endpoint</a>.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class AtomEndpoint extends DefaultPollingEndpoint {
+    private Factory atomFactory;
+    private String atomUri;
+
+    public AtomEndpoint(String endpointUri, AtomComponent component, String atomUri) {
+        super(endpointUri, component);
+        this.atomUri = atomUri;
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+
+    public Exchange createExchange() {
+        return new DefaultExchange(getContext());
+    }
+
+    public Producer createProducer() throws Exception {
+        return new AtomProducer(this);
+    }
+
+    @Override
+    public PollingConsumer createPollingConsumer() throws Exception {
+        return new AtomPollingConsumer(this);
+    }
+
+    public Document<Feed> parseDocument() throws IRISyntaxException, IOException {
+        String uri = getAtomUri();
+        InputStream in = new URL(uri).openStream();
+        return createAtomParser().parse(in, uri);
+    }
+
+    public OutputStream createProducerOutputStream() throws FileNotFoundException {
+        return new BufferedOutputStream(new FileOutputStream(getAtomUri()));
+    }
+
+    // Properties
+    //-------------------------------------------------------------------------
+    public Factory getAtomFactory() {
+        if (atomFactory == null) {
+            atomFactory = createAtomFactory();
+        }
+        return atomFactory;
+    }
+
+    public void setAtomFactory(Factory atomFactory) {
+        this.atomFactory = atomFactory;
+    }
+
+    public String getAtomUri() {
+        return atomUri;
+    }
+
+    public void setAtomUri(String atomUri) {
+        this.atomUri = atomUri;
+    }
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+    protected Factory createAtomFactory() {
+        return Abdera.getNewFactory();
+    }
+
+    protected Parser createAtomParser() {
+        return Abdera.getNewParser();
+    }
+}

Propchange: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomEndpoint.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomPollingConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomPollingConsumer.java?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomPollingConsumer.java
(added)
+++ activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomPollingConsumer.java
Mon Aug 20 02:30:16 2007
@@ -0,0 +1,68 @@
+/**
+ *
+ * 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.atom;
+
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.util.iri.IRISyntaxException;
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.PollingConsumerSupport;
+
+import java.io.IOException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class AtomPollingConsumer extends PollingConsumerSupport {
+    private final AtomEndpoint endpoint;
+
+    public AtomPollingConsumer(AtomEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    protected void doStart() throws Exception {
+    }
+
+    protected void doStop() throws Exception {
+    }
+
+    public Exchange receiveNoWait() {
+        try {
+            Document<Feed> document = endpoint.parseDocument();
+            Exchange exchange = endpoint.createExchange();
+            exchange.getIn().setBody(document);
+            return exchange;
+        }
+        catch (IRISyntaxException e) {
+            throw new RuntimeCamelException(e);
+        }
+        catch (IOException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
+
+    public Exchange receive() {
+        return receiveNoWait();
+    }
+
+    public Exchange receive(long timeout) {
+        return receiveNoWait();
+    }
+}

Propchange: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomPollingConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomProducer.java?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomProducer.java
(added)
+++ activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomProducer.java
Mon Aug 20 02:30:16 2007
@@ -0,0 +1,85 @@
+/**
+ *
+ * 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.atom;
+
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+import org.apache.abdera.util.iri.IRISyntaxException;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import static org.apache.camel.util.ExchangeHelper.getExchangeProperty;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.util.Date;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class AtomProducer extends DefaultProducer {
+    private static final transient Log LOG = LogFactory.getLog(AtomProducer.class);
+    private final AtomEndpoint endpoint;
+
+    public AtomProducer(AtomEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        Document<Feed> document = getDocument(exchange);
+
+        // now lets write the document...
+        OutputStream out = endpoint.createProducerOutputStream();
+        try {
+            document.writeTo(out);
+        }
+        finally {
+            ObjectHelper.close(out, "Atom document output stream", LOG);
+        }
+    }
+
+    protected Document<Feed> getDocument(Exchange exchange) throws IRISyntaxException,
IOException {
+        Document<Feed> document = endpoint.parseDocument();
+        Feed root = document.getRoot();
+        Entry entry = root.addEntry();
+        entry.setPublished(org.apache.camel.util.ExchangeHelper.getExchangeProperty(exchange,
"org.apache.camel.atom.published", Date.class, new Date()));
+
+        String id = exchange.getProperty("org.apache.camel.atom.id", String.class);
+        if (id != null) {
+            entry.setId(id);
+        }
+        String content = exchange.getProperty("org.apache.camel.atom.content", String.class);
+        if (content != null) {
+            entry.setContent(content);
+        }
+        String summary = exchange.getProperty("org.apache.camel.atom.summary", String.class);
+        if (summary != null) {
+            entry.setSummary(summary);
+        }
+        String title = exchange.getProperty("org.apache.camel.atom.title", String.class);
+        if (title != null) {
+            entry.setTitle(title);
+        }
+        // TODO categories, authors etc
+        return document;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties?rev=567621&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties (added)
+++ activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties Mon Aug
20 02:30:16 2007
@@ -0,0 +1,16 @@
+
+#
+# The logging properties used for eclipse testing, We want to see debug output on the console.
+#
+log4j.rootLogger=INFO, out
+
+#log4j.logger.org.apache.activemq=DEBUG
+
+#log4j.logger.org.apache.camel=DEBUG
+log4j.logger.org.apache.camel.impl.converter=INFO
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n

Propchange: activemq/camel/trunk/components/camel-atom/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/pom.xml?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/components/pom.xml (original)
+++ activemq/camel/trunk/components/pom.xml Mon Aug 20 02:30:16 2007
@@ -35,6 +35,7 @@
 
   <modules>
     <module>camel-activemq</module>
+    <module>camel-atom</module>
     <module>camel-bam</module>
     <module>camel-cxf</module>
     <module>camel-ftp</module>

Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?rev=567621&r1=567620&r2=567621&view=diff
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Mon Aug 20 02:30:16 2007
@@ -176,6 +176,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.camel</groupId>
+        <artifactId>camel-atom</artifactId>
+        <version>${camel-version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.camel</groupId>
         <artifactId>camel-bam</artifactId>
         <version>${camel-version}</version>
       </dependency>



Mime
View raw message