Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 875F7D6F7 for ; Mon, 22 Oct 2012 08:53:16 +0000 (UTC) Received: (qmail 24439 invoked by uid 500); 22 Oct 2012 08:53:15 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 24338 invoked by uid 500); 22 Oct 2012 08:53:13 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 24307 invoked by uid 99); 22 Oct 2012 08:53:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Oct 2012 08:53:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Oct 2012 08:53:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F20E623888E4; Mon, 22 Oct 2012 08:52:23 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@camel.apache.org From: davsclaus@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121022085223.F20E623888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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