camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r583494 - in /activemq/camel/trunk/camel-core/src/main: java/org/apache/camel/builder/ java/org/apache/camel/model/dataformat/ java/org/apache/camel/util/ resources/org/apache/camel/model/dataformat/
Date Wed, 10 Oct 2007 14:36:32 GMT
Author: jstrachan
Date: Wed Oct 10 07:36:31 2007
New Revision: 583494

URL: http://svn.apache.org/viewvc?rev=583494&view=rev
Log:
tidied up the configuration of the DataFormat instances from the DataFormatType along with
improving the support for ArtixDS in the DSL and XML configuration

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSContentType.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.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/IntrospectionSupport.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
    activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java?rev=583494&r1=583493&r2=583494&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DataTypeExpression.java
Wed Oct 10 07:36:31 2007
@@ -18,11 +18,12 @@
 package org.apache.camel.builder;
 
 import org.apache.camel.model.ProcessorType;
-import org.apache.camel.model.dataformat.JaxbDataFormat;
+import org.apache.camel.model.dataformat.ArtixDSContentType;
+import org.apache.camel.model.dataformat.ArtixDSDataFormat;
 import org.apache.camel.model.dataformat.DataFormatType;
+import org.apache.camel.model.dataformat.JaxbDataFormat;
 import org.apache.camel.model.dataformat.SerializationDataFormat;
 import org.apache.camel.model.dataformat.XMLBeansDataFormat;
-import org.apache.camel.model.dataformat.ArtixDSDataFormat;
 import org.apache.camel.spi.DataFormat;
 
 /**
@@ -79,6 +80,37 @@
      */
     public T artixDS() {
         return dataFormat(new ArtixDSDataFormat());
+    }
+
+    /**
+     * Uses the
+     * <a href="http://activemq.apache.org/camel/artix-data-services.html">Artix Data
Services</a>
+     * data format with the specified type of ComplexDataObject
+     * for marshalling and unmarshalling messages using the dataObject's default Source and
Sink.
+     */
+    public T artixDS(Class<?> dataObjectType) {
+        return dataFormat(new ArtixDSDataFormat(dataObjectType));
+    }
+
+
+    /**
+     * Uses the
+     * <a href="http://activemq.apache.org/camel/artix-data-services.html">Artix Data
Services</a>
+     * data format with the specified type of ComplexDataObject
+     * for marshalling and unmarshalling messages using the dataObject's default Source and
Sink.
+     */
+    public T artixDS(Class<?> elementType, ArtixDSContentType contentType) {
+        return dataFormat(new ArtixDSDataFormat(elementType, contentType));
+    }
+
+    /**
+     * Uses the
+     * <a href="http://activemq.apache.org/camel/artix-data-services.html">Artix Data
Services</a>
+     * data format with the specified content type
+     * for marshalling and unmarshalling messages
+     */
+    public T artixDS(ArtixDSContentType contentType) {
+        return dataFormat(new ArtixDSDataFormat(contentType));
     }
 
     private T dataFormat(DataFormatType dataFormatType) {

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSContentType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSContentType.java?rev=583494&view=auto
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSContentType.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSContentType.java
Wed Oct 10 07:36:31 2007
@@ -0,0 +1,28 @@
+/**
+ *
+ * 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.model.dataformat;
+
+import javax.xml.bind.annotation.XmlEnum;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@XmlEnum(String.class)
+public enum ArtixDSContentType {
+    Default, Auto, Binary, Text, Java, Xml, Sax, TagValuePair 
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSContentType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java?rev=583494&r1=583493&r2=583494&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/ArtixDSDataFormat.java
Wed Oct 10 07:36:31 2007
@@ -23,6 +23,7 @@
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.camel.spi.DataFormat;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * Represents the <a href="http://activemq.apache.org/camel/artix-data-services.html">Artix
Data Services</a>
@@ -33,20 +34,87 @@
 @XmlRootElement(name = "artixDS")
 @XmlAccessorType(XmlAccessType.FIELD)
 public class ArtixDSDataFormat extends DataFormatType {
-    @XmlAttribute
-    private String element;
-    @XmlAttribute
+    @XmlAttribute(required = false)
+    private String elementTypeName;
+    @XmlAttribute(required = false)
     private String format;
+    @XmlAttribute(required = false)
+    private Class<?> elementType;
+    @XmlAttribute(required = false)
+    private ArtixDSContentType contentType;
 
     public ArtixDSDataFormat() {
-        super("org.apache.camel.artix.ds.ArtixDSDataFormat");
+        super("org.apache.camel.artix.ds.ArtixDSFormat");
     }
 
-    public String getElement() {
-        return element;
+    public ArtixDSDataFormat(Class<?> elementType) {
+        this();
+        this.elementType = elementType;
     }
 
-    public void setElement(String element) {
-        this.element = element;
+    public ArtixDSDataFormat(Class<?> elementType, ArtixDSContentType contentType)
{
+        this();
+        this.elementType = elementType;
+        this.contentType = contentType;
+    }
+
+    public ArtixDSDataFormat(ArtixDSContentType contentType) {
+        this();
+        this.contentType = contentType;
+    }
+
+    // Properties
+    //-------------------------------------------------------------------------
+
+    public String getElementTypeName() {
+        return elementTypeName;
+    }
+
+    public void setElementTypeName(String elementTypeName) {
+        this.elementTypeName = elementTypeName;
+    }
+
+    public ArtixDSContentType getContentType() {
+        return contentType;
+    }
+
+    public void setContentType(ArtixDSContentType contentType) {
+        this.contentType = contentType;
+    }
+
+    public Class<?> getElementType() {
+        if (elementType == null) {
+            if (elementTypeName != null) {
+                elementType = ObjectHelper.loadClass(elementTypeName, getClass().getClassLoader());
+            }
+        }
+        return elementType;
+    }
+
+    public void setElementType(Class<?> elementType) {
+        this.elementType = elementType;
+    }
+
+    public String getFormat() {
+        return format;
+    }
+
+    public void setFormat(String format) {
+        this.format = format;
+    }
+
+    // Implementation methods
+    //-------------------------------------------------------------------------
+
+    @Override
+    protected void configureDataFormat(DataFormat dataFormat) {
+        Class<?> type = getElementType();
+        if (type != null) {
+            setProperty(dataFormat, "elementType", type);
+        }
+        ArtixDSContentType content = getContentType();
+        if (content != null) {
+            setProperty(dataFormat, "contentType", content);
+        }
     }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java?rev=583494&r1=583493&r2=583494&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/DataFormatType.java
Wed Oct 10 07:36:31 2007
@@ -25,6 +25,7 @@
 import org.apache.camel.impl.RouteContext;
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.IntrospectionSupport;
 
 /**
  * @version $Revision: 1.1 $
@@ -52,10 +53,14 @@
         if (dataFormat == null) {
             dataFormat = createDataFormat(routeContext);
             ObjectHelper.notNull(dataFormat, "dataFormat");
+            configureDataFormat(dataFormat);
         }
         return dataFormat;
     }
 
+    /**
+     * Factory method to create the data format instance
+     */
     protected DataFormat createDataFormat(RouteContext routeContext) {
         if (dataFormatTypeName != null) {
             Class type = ObjectHelper.loadClass(dataFormatTypeName, getClass().getClassLoader());
@@ -67,4 +72,22 @@
         return null;
     }
 
+    /**
+     * Allows derived classes to customize the data format
+     */
+    protected void configureDataFormat(DataFormat dataFormat) {
+    }
+
+    /**
+     * Sets a named property on the data format instance using introspection
+     */
+    protected void setProperty(DataFormat dataFormat, String name, Object value) {
+        try {
+            IntrospectionSupport.setProperty(dataFormat,name, value);
+        }
+        catch (Exception e) {
+            throw new IllegalArgumentException("Failed to set property " + name + " on "
+ dataFormat + ". Reason: " + e, e);
+        }
+
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java?rev=583494&r1=583493&r2=583494&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/dataformat/JaxbDataFormat.java
Wed Oct 10 07:36:31 2007
@@ -22,6 +22,7 @@
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 
+import org.apache.camel.converter.ObjectConverter;
 import org.apache.camel.spi.DataFormat;
 
 /**
@@ -50,5 +51,12 @@
 
     public void setPrettyPrint(Boolean prettyPrint) {
         this.prettyPrint = prettyPrint;
+    }
+
+    @Override
+    protected void configureDataFormat(DataFormat dataFormat) {
+        if (ObjectConverter.toBool(getPrettyPrint())) {
+            setProperty(dataFormat, "prettyPrint", Boolean.TRUE);
+        }
     }
 }

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=583494&r1=583493&r2=583494&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
Wed Oct 10 07:36:31 2007
@@ -250,4 +250,11 @@
         }
         map.put("camelContext", exchange.getContext());
     }
+
+    /**
+     * Returns the MIME content type on the input message or null if one is not defined
+     */
+    public static String getContentType(Exchange exchange) {
+       return exchange.getIn().getHeader("Content-Type", String.class);
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java?rev=583494&r1=583493&r2=583494&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
Wed Oct 10 07:36:31 2007
@@ -179,7 +179,7 @@
     public static boolean setProperty(TypeConverter typeConverter, Object target, String
name, Object value) throws Exception {
         try {
             Class clazz = target.getClass();
-            Method setter = findSetterMethod(typeConverter, clazz, name);
+            Method setter = findSetterMethod(typeConverter, clazz, name, value);
             if (setter == null) {
                 return false;
             }
@@ -244,7 +244,7 @@
         return null;
     }
 
-    private static Method findSetterMethod(TypeConverter typeConverter, Class clazz, String
name) {
+    private static Method findSetterMethod(TypeConverter typeConverter, Class clazz, String
name, Object value) {
         // Build the method name.
         name = "set" + ObjectHelper.capitalize(name);
         while (clazz != Object.class) {
@@ -253,7 +253,8 @@
                 Method method = methods[i];
                 Class params[] = method.getParameterTypes();
                 if (method.getName().equals(name) && params.length == 1) {
-                    if (typeConverter != null || isSettableType(params[0])) {
+                    Class paramType = params[0];
+                    if (typeConverter != null || isSettableType(paramType) || paramType.isInstance(value))
{
                         return method;
                     }
                 }

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=583494&r1=583493&r2=583494&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
Wed Oct 10 07:36:31 2007
@@ -459,4 +459,18 @@
             throw new RuntimeCamelException(e);
         }
     }
+
+    /**
+     * A helper method to create a new instance of a type using the default constructor arguments.
+     */
+    public static <T> T newInstance(Class<?> actualType, Class<T> expectedType)
{
+        try {
+            Object value = actualType.newInstance();
+            return cast(expectedType, value);
+        } catch (InstantiationException e) {
+            throw new RuntimeCamelException(e.getCause());
+        } catch (IllegalAccessException e) {
+            throw new RuntimeCamelException(e);
+        }
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index?rev=583494&r1=583493&r2=583494&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
(original)
+++ activemq/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/dataformat/jaxb.index
Wed Oct 10 07:36:31 2007
@@ -14,6 +14,7 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ------------------------------------------------------------------------
+ArtixDSContentType
 ArtixDSDataFormat
 DataFormatType
 JaxbDataFormat



Mime
View raw message