camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1400806 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/DefaultCamelContext.java test/java/org/apache/camel/impl/DataFormatContextAwareTest.java test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java
Date Mon, 22 Oct 2012 08:52:23 GMT
Author: davsclaus
Date: Mon Oct 22 08:52:23 2012
New Revision: 1400806

URL: http://svn.apache.org/viewvc?rev=1400806&view=rev
Log:
CAMEL-5726: Langauge and DataFormat now supports CamelContextAware

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
  (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1400806&r1=1400805&r2=1400806&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Mon
Oct 22 08:52:23 2012
@@ -993,6 +993,12 @@ public class DefaultCamelContext extends
 
             // language not known or not singleton, then use resolver
             answer = getLanguageResolver().resolveLanguage(language, this);
+
+            // inject CamelContext if aware
+            if (answer != null && answer instanceof CamelContextAware) {
+                ((CamelContextAware) answer).setCamelContext(this);
+            }
+
             if (answer != null) {
                 languages.put(language, answer);
             }
@@ -2405,7 +2411,14 @@ public class DefaultCamelContext extends
     }
 
     public DataFormat resolveDataFormat(String name) {
-        return dataFormatResolver.resolveDataFormat(name, this);
+        DataFormat answer = dataFormatResolver.resolveDataFormat(name, this);
+
+        // inject CamelContext if aware
+        if (answer != null && answer instanceof CamelContextAware) {
+            ((CamelContextAware) answer).setCamelContext(this);
+        }
+
+        return answer;
     }
 
     public DataFormatDefinition resolveDataFormatDefinition(String name) {

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java?rev=1400806&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
Mon Oct 22 08:52:23 2012
@@ -0,0 +1,71 @@
+/**
+ * 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 java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.DataFormat;
+
+/**
+ *
+ */
+public class DataFormatContextAwareTest extends ContextTestSupport {
+
+    private MyDataFormat my = new MyDataFormat();
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("my", my);
+        return jndi;
+    }
+
+    public void testLanguageCamelContextAware() throws Exception {
+        DataFormat df = context.resolveDataFormat("my");
+        assertNotNull(df);
+
+        MyDataFormat me = assertIsInstanceOf(MyDataFormat.class, df);
+        assertNotNull(me.getCamelContext());
+    }
+
+    private static class MyDataFormat implements DataFormat, CamelContextAware {
+
+        private CamelContext camelContext;
+
+        public CamelContext getCamelContext() {
+            return camelContext;
+        }
+
+        public void setCamelContext(CamelContext camelContext) {
+            this.camelContext = camelContext;
+        }
+
+        @Override
+        public void marshal(Exchange exchange, Object graph, OutputStream stream) throws
Exception {
+        }
+
+        @Override
+        public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
+            return null;
+        }
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DataFormatContextAwareTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java?rev=1400806&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java
Mon Oct 22 08:52:23 2012
@@ -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.impl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Expression;
+import org.apache.camel.Predicate;
+import org.apache.camel.spi.Language;
+
+/**
+ *
+ */
+public class LanguageCamelContextAwareTest extends ContextTestSupport {
+
+    private MyLanguage my = new MyLanguage();
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("my", my);
+        return jndi;
+    }
+
+    public void testLanguageCamelContextAware() throws Exception {
+        Language lan = context.resolveLanguage("my");
+        assertNotNull(lan);
+
+        MyLanguage me = assertIsInstanceOf(MyLanguage.class, lan);
+        assertNotNull(me.getCamelContext());
+    }
+
+    private static class MyLanguage implements Language, CamelContextAware {
+
+        private CamelContext camelContext;
+
+        public CamelContext getCamelContext() {
+            return camelContext;
+        }
+
+        public void setCamelContext(CamelContext camelContext) {
+            this.camelContext = camelContext;
+        }
+
+        public Predicate createPredicate(String expression) {
+            return null;
+        }
+
+        public Expression createExpression(String expression) {
+            return null;
+        }
+
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/LanguageCamelContextAwareTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message