camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r752137 - in /camel/branches/camel-1.x: ./ components/camel-osgi/ components/camel-osgi/src/main/java/org/apache/camel/osgi/ components/camel-osgi/src/test/java/org/apache/camel/osgi/ components/camel-osgi/src/test/resources/ components/cam...
Date Tue, 10 Mar 2009 15:22:07 GMT
Author: ningjiang
Date: Tue Mar 10 15:21:30 2009
New Revision: 752137

URL: http://svn.apache.org/viewvc?rev=752137&view=rev
Log:
Merged revisions 752117 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r752117 | ningjiang | 2009-03-10 22:19:37 +0800 (Tue, 10 Mar 2009) | 1 line
  
  CAMEL-1443 fixed the script languages resolver issue in OSGi environment
........

Added:
    camel/branches/camel-1.x/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiLanguageResolverTest.java
      - copied unchanged from r752117, camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/osgi/OsgiLanguageResolverTest.java
    camel/branches/camel-1.x/components/camel-osgi/src/test/resources/META-INF/services/org/apache/camel/language/resolver/
      - copied from r752117, camel/trunk/components/camel-osgi/src/test/resources/META-INF/services/org/apache/camel/language/resolver/
    camel/branches/camel-1.x/components/camel-osgi/src/test/resources/META-INF/services/org/apache/camel/language/resolver/default
      - copied unchanged from r752117, camel/trunk/components/camel-osgi/src/test/resources/META-INF/services/org/apache/camel/language/resolver/default
Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/components/camel-osgi/pom.xml
    camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java
    camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiLanguageResolver.java
    camel/branches/camel-1.x/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelMockBundle.java
    camel/branches/camel-1.x/components/camel-osgi/src/test/resources/log4j.properties

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar 10 15:21:30 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749956,750017,750334,750761,750796,752068
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749956,750017,750334,750761,750796,752068,752117

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/components/camel-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-osgi/pom.xml?rev=752137&r1=752136&r2=752137&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-osgi/pom.xml (original)
+++ camel/branches/camel-1.x/components/camel-osgi/pom.xml Tue Mar 10 15:21:30 2009
@@ -92,6 +92,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-script</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.springframework.osgi</groupId>
       <artifactId>spring-osgi-mock</artifactId>
       <scope>test</scope>

Modified: camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java?rev=752137&r1=752136&r2=752137&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java
(original)
+++ camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java
Tue Mar 10 15:21:30 2009
@@ -43,10 +43,13 @@
     public static final String META_INF_TYPE_CONVERTER = "META-INF/services/org/apache/camel/TypeConverter";
     public static final String META_INF_COMPONENT = "META-INF/services/org/apache/camel/component/";
     public static final String META_INF_LANGUAGE = "META-INF/services/org/apache/camel/language/";
+    public static final String META_INF_LANGUAGE_RESOLVER = "META-INF/services/org/apache/camel/language/resolver/";
+    
     private static final transient Log LOG = LogFactory.getLog(Activator.class);    
     private static final Map<String, ComponentEntry> COMPONENTS = new HashMap<String,
ComponentEntry>();
     private static final Map<URL, TypeConverterEntry> TYPE_CONVERTERS = new HashMap<URL,
TypeConverterEntry>();
     private static final Map<String, ComponentEntry> LANGUAGES = new HashMap<String,
ComponentEntry>();
+    private static final Map<String, ComponentEntry> LANGUAGE_RESOLVERS = new HashMap<String,
ComponentEntry>();
     private static Bundle bundle;
     
     private class ComponentEntry {
@@ -105,6 +108,7 @@
     protected void mayBeAddComponentAndLanguageFor(Bundle bundle) {        
         addComponentEntry(META_INF_COMPONENT, bundle, COMPONENTS);
         addComponentEntry(META_INF_LANGUAGE, bundle, LANGUAGES);
+        addComponentEntry(META_INF_LANGUAGE_RESOLVER, bundle, LANGUAGE_RESOLVERS);
     }
     
     protected synchronized void mayBeAddTypeConverterFor(Bundle bundle) {
@@ -130,7 +134,8 @@
 
     protected void mayBeRemoveComponentAndLanguageFor(Bundle bundle) {
         removeComponentEntry(bundle, COMPONENTS);
-        removeComponentEntry(bundle, LANGUAGES);        
+        removeComponentEntry(bundle, LANGUAGES);
+        removeComponentEntry(bundle, LANGUAGE_RESOLVERS);
     }
     
     protected void removeComponentEntry(Bundle bundle, Map<String, ComponentEntry>
entries) {
@@ -252,13 +257,17 @@
         return getClassFromEntries(name, LANGUAGES);
     }
     
+    public static synchronized Class getLanguageResolver(String name) throws Exception {
+        return getClassFromEntries(name, LANGUAGE_RESOLVERS);
+    }
+    
     protected static synchronized Class getClassFromEntries(String name, Map<String, ComponentEntry>
entries) throws Exception {
         ComponentEntry entry = entries.get(name);
         if (entry == null) {
             return null;
         }
         if (entry.type == null) {
-            URL url = entry.bundle.getEntry(entry.path);
+            URL url = entry.bundle.getEntry(entry.path);            
             if (LOG.isDebugEnabled()) {
                 LOG.debug("The entry " + name + "'s url is" + url);
             }

Modified: camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiLanguageResolver.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiLanguageResolver.java?rev=752137&r1=752136&r2=752137&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiLanguageResolver.java
(original)
+++ camel/branches/camel-1.x/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiLanguageResolver.java
Tue Mar 10 15:21:30 2009
@@ -18,6 +18,8 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
+import org.apache.camel.NoFactoryAvailableException;
+import org.apache.camel.NoSuchLanguageException;
 import org.apache.camel.spi.Language;
 import org.apache.camel.spi.LanguageResolver;
 import org.apache.commons.logging.Log;
@@ -49,19 +51,46 @@
         } catch (Throwable e) {
             throw new IllegalArgumentException("Invalid URI, no Language registered for scheme
: " + name, e);
         }
-        if (type == null) {
-            return null;
-        }
-        if (Language.class.isAssignableFrom(type)) {
-            return (Language)context.getInjector().newInstance(type);
+        if (type != null) {
+            if (Language.class.isAssignableFrom(type)) {
+                return (Language)context.getInjector().newInstance(type);
+            } else {
+                throw new IllegalArgumentException("Type is not a Lanaguage implementation.
Found: "
+                                                   + type.getName());
+            }
         } else {
-            throw new IllegalArgumentException("Type is not a Lanaguage implementation. Found:
"
-                                               + type.getName());
+            return noSpecificLanguageFound(name, context);
         }
     }
+    
+    protected Language noSpecificLanguageFound(String name, CamelContext context) {
+        Class type = null;
+        try {
+            type = getLanaguageResolver("default");
+        } catch (NoFactoryAvailableException e) {
+            // ignore
+        } catch (Throwable e) {
+            throw new IllegalArgumentException("Invalid URI, no Language registered for scheme:
" + name, e);
+        }
+        if (type != null) {
+            if (LanguageResolver.class.isAssignableFrom(type)) {
+                LanguageResolver resolver = (LanguageResolver)context.getInjector().newInstance(type);
+                return resolver.resolveLanguage(name, context);
+            } else {
+                throw new IllegalArgumentException("Type is not a LanguageResolver implementation.
Found: " + type.getName());
+            }
+        }
+        throw new NoSuchLanguageException(name);
+    }
+
+    
 
     protected Class getLanaguage(String name) throws Exception {
         return Activator.getLanguage(name);
     }
+    
+    protected Class getLanaguageResolver(String name) throws Exception {
+        return Activator.getLanguageResolver(name);
+    }
 
 }

Modified: camel/branches/camel-1.x/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelMockBundle.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelMockBundle.java?rev=752137&r1=752136&r2=752137&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelMockBundle.java
(original)
+++ camel/branches/camel-1.x/components/camel-osgi/src/test/java/org/apache/camel/osgi/CamelMockBundle.java
Tue Mar 10 15:21:30 2009
@@ -72,6 +72,10 @@
             String[] entries = new String[] {"bean_test", "file_test"};
             result = getListEnumeration(Activator.META_INF_LANGUAGE, entries);
         }
+        if (Activator.META_INF_LANGUAGE_RESOLVER.equals(path)) {
+            String[] entries = new String[] {"default"};
+            result = getListEnumeration(Activator.META_INF_LANGUAGE_RESOLVER, entries);
+        }
 
         return result;
     }

Modified: camel/branches/camel-1.x/components/camel-osgi/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-osgi/src/test/resources/log4j.properties?rev=752137&r1=752136&r2=752137&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-osgi/src/test/resources/log4j.properties (original)
+++ camel/branches/camel-1.x/components/camel-osgi/src/test/resources/log4j.properties Tue
Mar 10 15:21:30 2009
@@ -21,7 +21,7 @@
 log4j.rootLogger=INFO, file
 
 # uncomment the following to enable camel debugging
-#log4j.logger.org.apache.camel=DEBUG
+log4j.logger.org.apache.camel=DEBUG
 
 # CONSOLE appender not used by default
 log4j.appender.out=org.apache.log4j.ConsoleAppender
@@ -33,4 +33,4 @@
 log4j.appender.file=org.apache.log4j.FileAppender
 log4j.appender.file.layout=org.apache.log4j.PatternLayout
 log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-log4j.appender.file.file=target/camel-ognl-test.log
\ No newline at end of file
+log4j.appender.file.file=target/camel-osgi-test.log
\ No newline at end of file



Mime
View raw message