activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r525122 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel: CamelContext.java NoTypeConversionAvailableException.java impl/DefaultCamelContext.java util/ObjectHelper.java
Date Tue, 03 Apr 2007 09:53:50 GMT
Author: jstrachan
Date: Tue Apr  3 02:53:49 2007
New Revision: 525122

URL: http://svn.apache.org/viewvc?view=rev&rev=525122
Log:
added a helper exception & some methods also exposed the Injector on CamelContext

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
  (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?view=diff&rev=525122&r1=525121&r2=525122
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Tue Apr
 3 02:53:49 2007
@@ -18,6 +18,7 @@
 package org.apache.camel;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.converter.Injector;
 
 import java.util.Collection;
 import java.util.List;
@@ -29,7 +30,7 @@
  *
  * @version $Revision$
  */
-public interface CamelContext {
+public interface CamelContext extends Service {
 
     // Component Management Methods
     //-----------------------------------------------------------------------
@@ -37,9 +38,9 @@
     /**
      * Adds a component to the container.
      */
-    public void addComponent(String componentName, Component component);
+    void addComponent(String componentName, Component component);
 
-    public Component getComponent(String componentName);
+    Component getComponent(String componentName);
 
     /**
      * Removes a previously added component.
@@ -47,7 +48,7 @@
      * @param componentName
      * @return the previously added component or null if it had not been previously added.
      */
-    public Component removeComponent(String componentName);
+    Component removeComponent(String componentName);
 
     /**
      * Gets the a previously added component by name or lazily creates the component
@@ -57,7 +58,7 @@
      * @param factory       used to create a new component instance if the component was
not previously added.
      * @return
      */
-    public Component getOrCreateComponent(String componentName, Callable<Component>
factory);
+    Component getOrCreateComponent(String componentName, Callable<Component> factory);
 
     // Endpoint Management Methods
     //-----------------------------------------------------------------------
@@ -65,17 +66,17 @@
     /**
      * Resolves the given URI to an endpoint
      */
-    public Endpoint resolveEndpoint(String uri);
+    Endpoint resolveEndpoint(String uri);
 
     /**
      * Activates all the starting endpoints in that were added as routes.
      */
-    public void activateEndpoints() throws Exception;
+    void activateEndpoints() throws Exception;
 
     /**
      * Deactivates all the starting endpoints in that were added as routes.
      */
-    public void deactivateEndpoints() throws Exception;
+    void deactivateEndpoints() throws Exception;
 
     /**
      * Returns the collection of all active endpoints currently registered
@@ -84,21 +85,29 @@
 
     // Route Management Methods
     //-----------------------------------------------------------------------
-    public List<Route> getRoutes();
+    List<Route> getRoutes();
 
-    public void setRoutes(List<Route> routes);
+    void setRoutes(List<Route> routes);
 
-    public void addRoutes(List<Route> routes);
+    void addRoutes(List<Route> routes);
 
-    public void addRoutes(RouteBuilder builder) throws Exception;
+    void addRoutes(RouteBuilder builder) throws Exception;
 
-    public void addRoutes(RouteFactory factory) throws Exception;
+    void addRoutes(RouteFactory factory) throws Exception;
 
     // Properties
     //-----------------------------------------------------------------------
-    public EndpointResolver getEndpointResolver();
+    EndpointResolver getEndpointResolver();
 
-    public ExchangeConverter getExchangeConverter();
+    ExchangeConverter getExchangeConverter();
 
-    public TypeConverter getTypeConverter();
+    /**
+     * Returns the type converter used to coerce types from one type to another
+     */
+    TypeConverter getTypeConverter();
+
+    /**
+     * Returns the injector used to instantiate objects by type
+     */
+    Injector getInjector();
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java?view=auto&rev=525122
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
Tue Apr  3 02:53:49 2007
@@ -0,0 +1,52 @@
+/**
+ *
+ * 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;
+
+/**
+ * An exception thrown if a value could not be converted to the required type
+ *
+ * @version $Revision$
+ */
+public class NoTypeConversionAvailableException extends RuntimeCamelException {
+    private final Object value;
+    private final Class type;
+
+    public NoTypeConversionAvailableException(Object value, Class type) {
+        super("No converter available to convert value: " + value + " to the required type:
" + type.getName());
+        this.value = value;
+        this.type = type;
+    }
+
+    /**
+     * Returns the value which could not be converted
+     *
+     * @return the value that could not be converted
+     */
+    public Object getValue() {
+        return value;
+    }
+
+    /**
+     * Returns the required type
+     *
+     * @return the required type
+     */
+    public Class getType() {
+        return type;
+    }
+}

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

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=525122&r1=525121&r2=525122
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
Tue Apr  3 02:53:49 2007
@@ -44,7 +44,7 @@
  * @version $Revision: 520517 $
  * @org.apache.xbean.XBean element="container" rootElement="true"
  */
-public class DefaultCamelContext implements CamelContext, Service {
+public class DefaultCamelContext extends ServiceSupport implements CamelContext, Service
{
     private static final transient Log log = LogFactory.getLog(DefaultCamelContext.class);
     private Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
     private Map<String, Component> components = new HashMap<String, Component>();
@@ -121,16 +121,6 @@
 
     // Endpoint Management Methods
     //-----------------------------------------------------------------------
-    public void start() throws Exception {
-        activateEndpoints();
-    }
-
-    public void stop() throws Exception {
-        deactivateEndpoints();
-    }
-
-    // Endpoint Management Methods
-    //-----------------------------------------------------------------------
 
     public Collection<Endpoint> getEndpoints() {
         synchronized (endpoints) {
@@ -290,6 +280,14 @@
 
     // Implementation methods
     //-----------------------------------------------------------------------
+
+    protected void doStart() throws Exception {
+        activateEndpoints();
+    }
+
+    protected void doStop() throws Exception {
+        deactivateEndpoints();
+    }
 
     /**
      * Lazily create a default implementation

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?view=diff&rev=525122&r1=525121&r2=525122
==============================================================================
--- 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
Tue Apr  3 02:53:49 2007
@@ -137,4 +137,40 @@
     public static String name(Class type) {
         return type != null ? type.getName() : null;
     }
+
+    /**
+     * Attempts to load the given class name using the thread context class loader
+     * or the class loader used to load this class
+     *
+     * @param name the name of the class to load
+     * @return the class or null if it could not be loaded
+     */
+    public static Class<?> loadClass(String name) {
+        return loadClass(name, ObjectHelper.class.getClassLoader());
+    }
+    
+    /**
+     * Attempts to load the given class name using the thread context class loader or the
given class loader
+     *
+     * @param name the name of the class to load
+     * @param loader the class loader to use after the thread context class loader
+     * @return the class or null if it could not be loaded
+     */
+    public static Class<?> loadClass(String name, ClassLoader loader) {
+        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        if (contextClassLoader != null) {
+            try {
+                return contextClassLoader.loadClass(name);
+            }
+            catch (ClassNotFoundException e) {
+                try {
+                    return loader.loadClass(name);
+                }
+                catch (ClassNotFoundException e1) {
+                    log.debug("Could not find class: " + name + ". Reason: " + e);
+                }
+            }
+        }
+        return null;
+    }
 }



Mime
View raw message