You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ch...@apache.org on 2007/08/07 20:36:08 UTC
svn commit: r563607 [10/12] - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/ main/java/org/apache/camel/builder/
main/java/org/apache/camel/builder/xml/
main/java/org/apache/camel/component/bean/
main/java/org/apache/camel/compone...
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=563607&r1=563606&r2=563607
==============================================================================
--- 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 Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,11 +16,6 @@
*/
package org.apache.camel.util;
-import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.converter.ObjectConverter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -29,15 +24,26 @@
import java.util.Iterator;
import java.util.List;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.converter.ObjectConverter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* A number of useful helper methods for working with Objects
- *
+ *
* @version $Revision$
*/
public class ObjectHelper {
- private static final transient Log log = LogFactory.getLog(ObjectHelper.class);
+ private static final transient Log LOG = LogFactory.getLog(ObjectHelper.class);
/**
+ * Utility classes should not have a public constructor.
+ */
+ private ObjectHelper() {
+ }
+
+ /**
* A helper method for comparing objects for equality while handling nulls
*/
public static boolean equals(Object a, Object b) {
@@ -49,6 +55,7 @@
/**
* Returns true if the given object is equal to any of the expected value
+ *
* @param expression
* @param s
* @param s1
@@ -62,11 +69,10 @@
}
return false;
}
-
+
/**
* A helper method for performing an ordered comparsion on the objects
- * handling nulls and objects which do not
- * handle sorting gracefully
+ * handling nulls and objects which do not handle sorting gracefully
*/
public static int compare(Object a, Object b) {
if (a == b) {
@@ -79,10 +85,9 @@
return 1;
}
if (a instanceof Comparable) {
- Comparable comparable = (Comparable) a;
+ Comparable comparable = (Comparable)a;
return comparable.compareTo(b);
- }
- else {
+ } else {
int answer = a.getClass().getName().compareTo(b.getClass().getName());
if (answer == 0) {
answer = a.hashCode() - b.hashCode();
@@ -113,10 +118,11 @@
}
/**
- * Removes any starting characters on the given text which match the given character
- *
+ * Removes any starting characters on the given text which match the given
+ * character
+ *
* @param text the string
- * @param ch the initial characters to remove
+ * @param ch the initial characters to remove
* @return either the original string or the new substring
*/
public static String removeStartingCharacters(String text, char ch) {
@@ -135,10 +141,9 @@
*/
public static boolean contains(Object collectionOrArray, Object value) {
if (collectionOrArray instanceof Collection) {
- Collection collection = (Collection) collectionOrArray;
+ Collection collection = (Collection)collectionOrArray;
return collection.contains(value);
- }
- else {
+ } else {
Iterator iter = ObjectConverter.iterator(value);
while (iter.hasNext()) {
if (equals(value, iter.next())) {
@@ -150,20 +155,20 @@
}
/**
- * Returns the predicate matching boolean on a {@link List} result set
- * where if the first element is a boolean its value is used
- * otherwise this method returns true if the collection is not empty
- *
- * @returns true if the first element is a boolean and its value is true or if the list is non empty
+ * Returns the predicate matching boolean on a {@link List} result set where
+ * if the first element is a boolean its value is used otherwise this method
+ * returns true if the collection is not empty
+ *
+ * @returns true if the first element is a boolean and its value is true or
+ * if the list is non empty
*/
public static boolean matches(List list) {
if (!list.isEmpty()) {
Object value = list.get(0);
if (value instanceof Boolean) {
- Boolean flag = (Boolean) value;
+ Boolean flag = (Boolean)value;
return flag.booleanValue();
- }
- else {
+ } else {
// lets assume non-empty results are true
return true;
}
@@ -180,26 +185,30 @@
}
/**
- * A helper method to access a system property, catching any security exceptions
- *
- * @param name the name of the system property required
- * @param defaultValue the default value to use if the property is not available or a security exception prevents access
- * @return the system property value or the default value if the property is not available or security does not allow its access
+ * A helper method to access a system property, catching any security
+ * exceptions
+ *
+ * @param name the name of the system property required
+ * @param defaultValue the default value to use if the property is not
+ * available or a security exception prevents access
+ * @return the system property value or the default value if the property is
+ * not available or security does not allow its access
*/
public static String getSystemProperty(String name, String defaultValue) {
try {
return System.getProperty(name, defaultValue);
- }
- catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.debug("Caught security exception accessing system property: " + name + ". Reason: " + e, e);
+ } catch (Exception e) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Caught security exception accessing system property: " + name + ". Reason: " + e,
+ e);
}
return defaultValue;
}
}
/**
- * Returns the type name of the given type or null if the type variable is null
+ * Returns the type name of the given type or null if the type variable is
+ * null
*/
public static String name(Class type) {
return type != null ? type.getName() : null;
@@ -212,11 +221,10 @@
return name(value != null ? value.getClass() : null);
}
-
/**
- * Attempts to load the given class name using the thread context class loader
- * or the class loader used to load this class
- *
+ * 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
*/
@@ -225,10 +233,12 @@
}
/**
- * 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
+ * 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) {
@@ -236,13 +246,11 @@
if (contextClassLoader != null) {
try {
return contextClassLoader.loadClass(name);
- }
- catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
try {
return loader.loadClass(name);
- }
- catch (ClassNotFoundException e1) {
- log.debug("Could not find class: " + name + ". Reason: " + e);
+ } catch (ClassNotFoundException e1) {
+ LOG.debug("Could not find class: " + name + ". Reason: " + e);
}
}
}
@@ -252,32 +260,31 @@
/**
* A helper method to invoke a method via reflection and wrap any exceptions
* as {@link RuntimeCamelException} instances
- *
- * @param method the method to invoke
- * @param instance the object instance (or null for static methods)
+ *
+ * @param method the method to invoke
+ * @param instance the object instance (or null for static methods)
* @param parameters the parameters to the method
* @return the result of the method invocation
*/
public static Object invokeMethod(Method method, Object instance, Object... parameters) {
try {
return method.invoke(instance, parameters);
- }
- catch (IllegalAccessException e) {
+ } catch (IllegalAccessException e) {
throw new RuntimeCamelException(e);
- }
- catch (InvocationTargetException e) {
+ } catch (InvocationTargetException e) {
throw new RuntimeCamelException(e.getCause());
}
}
/**
* Returns a list of methods which are annotated with the given annotation
- *
- * @param type the type to reflect on
+ *
+ * @param type the type to reflect on
* @param annotationType the annotation type
* @return a list of the methods found
*/
- public static List<Method> findMethodsWithAnnotation(Class<?> type, Class<? extends Annotation> annotationType) {
+ public static List<Method> findMethodsWithAnnotation(Class<?> type,
+ Class<? extends Annotation> annotationType) {
List<Method> answer = new ArrayList<Method>();
do {
Method[] methods = type.getDeclaredMethods();
@@ -287,22 +294,20 @@
}
}
type = type.getSuperclass();
- }
- while (type != null);
+ } while (type != null);
return answer;
}
/**
* Turns the given object arrays into a meaningful string
- *
+ *
* @param objects an array of objects or null
* @return a meaningful string
*/
public static String asString(Object[] objects) {
if (objects == null) {
return "null";
- }
- else {
+ } else {
StringBuffer buffer = new StringBuffer("{");
int counter = 0;
for (Object object : objects) {
@@ -320,7 +325,8 @@
/**
* Returns true if a class is assignable from another class like the
* {@link Class#isAssignableFrom(Class)} method but which also includes
- * coercion between primitive types to deal with Java 5 primitive type wrapping
+ * coercion between primitive types to deal with Java 5 primitive type
+ * wrapping
*/
public static boolean isAssignableFrom(Class a, Class b) {
a = convertPrimitiveTypeToWrapperType(a);
@@ -329,30 +335,27 @@
}
/**
- * Converts primitive types such as int to its wrapper type like {@link Integeer}
+ * Converts primitive types such as int to its wrapper type like
+ * {@link Integeer}
*/
public static Class convertPrimitiveTypeToWrapperType(Class type) {
+ Class rc = type;
if (type.isPrimitive()) {
if (type == int.class) {
- return Integer.class;
- }
- else if (type == long.class) {
- return Long.class;
- }
- else if (type == double.class) {
- return Double.class;
- }
- else if (type == float.class) {
- return Float.class;
- }
- else if (type == short.class) {
- return Short.class;
- }
- else if (type == byte.class) {
- return Byte.class;
+ rc = Integer.class;
+ } else if (type == long.class) {
+ rc = Long.class;
+ } else if (type == double.class) {
+ rc = Double.class;
+ } else if (type == float.class) {
+ rc = Float.class;
+ } else if (type == short.class) {
+ rc = Short.class;
+ } else if (type == byte.class) {
+ rc = Byte.class;
}
}
- return type;
+ return rc;
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProducerCache.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProducerCache.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProducerCache.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProducerCache.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,6 +16,9 @@
*/
package org.apache.camel.util;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.FailedToCreateProducerException;
@@ -27,14 +29,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.HashMap;
-import java.util.Map;
-
/**
* @version $Revision$
*/
public class ProducerCache<E extends Exchange> extends ServiceSupport {
- private static final Log log = LogFactory.getLog(ProducerCache.class);
+ private static final Log LOG = LogFactory.getLog(ProducerCache.class);
private Map<String, Producer<E>> producers = new HashMap<String, Producer<E>>();
@@ -45,8 +44,7 @@
try {
answer = endpoint.createProducer();
answer.start();
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new FailedToCreateProducerException(endpoint, e);
}
producers.put(key, answer);
@@ -56,7 +54,7 @@
/**
* Sends the exchange to the given endpoint
- *
+ *
* @param endpoint the endpoint to send the exchange to
* @param exchange the exchange to send
*/
@@ -64,16 +62,17 @@
try {
Producer<E> producer = getProducer(endpoint);
producer.process(exchange);
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
/**
- * Sends an exchange to an endpoint using a supplied @{link Processor} to populate the exchange
- *
- * @param endpoint the endpoint to send the exchange to
+ * Sends an exchange to an endpoint using a supplied
+ *
+ * @{link Processor} to populate the exchange
+ *
+ * @param endpoint the endpoint to send the exchange to
* @param processor the transformer used to populate the new exchange
*/
public E send(Endpoint<E> endpoint, Processor processor) {
@@ -85,13 +84,12 @@
processor.process(exchange);
// now lets dispatch
- if (log.isDebugEnabled()) {
- log.debug(">>>> " + endpoint + " " + exchange);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(">>>> " + endpoint + " " + exchange);
}
producer.process(exchange);
return exchange;
- }
- catch (Exception e) {
+ } catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,121 +16,148 @@
*/
package org.apache.camel.util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.lang.annotation.Annotation;
-import java.util.Set;
-import java.util.HashSet;
+import java.net.URL;
+import java.net.URLDecoder;
import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
-import java.net.URL;
-import java.net.URLDecoder;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileInputStream;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
- * <p>ResolverUtil is used to locate classes that are available in the/a class path and meet
- * arbitrary conditions. The two most common conditions are that a class implements/extends
- * another class, or that is it annotated with a specific annotation. However, through the use
- * of the {@link Test} class it is possible to search using arbitrary conditions.</p>
- *
- * <p>A ClassLoader is used to locate all locations (directories and jar files) in the class
- * path that contain classes within certain packages, and then to load those classes and
- * check them. By default the ClassLoader returned by
- * {@code Thread.currentThread().getContextClassLoader()} is used, but this can be overridden
- * by calling {@link #setClassLoader(ClassLoader)} prior to invoking any of the {@code find()}
- * methods.</p>
- *
- * <p>General searches are initiated by calling the
- * {@link #find(ResolverUtil.Test, String)} ()} method and supplying
- * a package name and a Test instance. This will cause the named package <b>and all sub-packages</b>
- * to be scanned for classes that meet the test. There are also utility methods for the common
- * use cases of scanning multiple packages for extensions of particular classes, or classes
- * annotated with a specific annotation.</p>
- *
- * <p>The standard usage pattern for the ResolverUtil class is as follows:</p>
- *
- *<pre>
- *ResolverUtil<ActionBean> resolver = new ResolverUtil<ActionBean>();
- *resolver.findImplementation(ActionBean.class, pkg1, pkg2);
- *resolver.find(new CustomTest(), pkg1);
- *resolver.find(new CustomTest(), pkg2);
- *Collection<ActionBean> beans = resolver.getClasses();
- *</pre>
- *
+ * <p>
+ * ResolverUtil is used to locate classes that are available in the/a class path
+ * and meet arbitrary conditions. The two most common conditions are that a
+ * class implements/extends another class, or that is it annotated with a
+ * specific annotation. However, through the use of the {@link Test} class it is
+ * possible to search using arbitrary conditions.
+ * </p>
+ *
+ * <p>
+ * A ClassLoader is used to locate all locations (directories and jar files) in
+ * the class path that contain classes within certain packages, and then to load
+ * those classes and check them. By default the ClassLoader returned by
+ * {@code Thread.currentThread().getContextClassLoader()} is used, but this can
+ * be overridden by calling {@link #setClassLoader(ClassLoader)} prior to
+ * invoking any of the {@code find()} methods.
+ * </p>
+ *
+ * <p>
+ * General searches are initiated by calling the
+ * {@link #find(ResolverUtil.Test, String)} ()} method and supplying a package
+ * name and a Test instance. This will cause the named package <b>and all
+ * sub-packages</b> to be scanned for classes that meet the test. There are
+ * also utility methods for the common use cases of scanning multiple packages
+ * for extensions of particular classes, or classes annotated with a specific
+ * annotation.
+ * </p>
+ *
+ * <p>
+ * The standard usage pattern for the ResolverUtil class is as follows:
+ * </p>
+ *
+ * <pre>
+ * esolverUtil<ActionBean> resolver = new ResolverUtil<ActionBean>();
+ * esolver.findImplementation(ActionBean.class, pkg1, pkg2);
+ * esolver.find(new CustomTest(), pkg1);
+ * esolver.find(new CustomTest(), pkg2);
+ * ollection<ActionBean> beans = resolver.getClasses();
+ * </pre>
+ *
* @author Tim Fennell
*/
public class ResolverUtil<T> {
- private static final transient Log log = LogFactory.getLog(ResolverUtil.class);
+ private static final transient Log LOG = LogFactory.getLog(ResolverUtil.class);
/**
- * A simple interface that specifies how to test classes to determine if they
- * are to be included in the results produced by the ResolverUtil.
+ * A simple interface that specifies how to test classes to determine if
+ * they are to be included in the results produced by the ResolverUtil.
*/
public static interface Test {
/**
- * Will be called repeatedly with candidate classes. Must return True if a class
- * is to be included in the results, false otherwise.
+ * Will be called repeatedly with candidate classes. Must return True if
+ * a class is to be included in the results, false otherwise.
*/
boolean matches(Class type);
}
/**
- * A Test that checks to see if each class is assignable to the provided class. Note
- * that this test will match the parent type itself if it is presented for matching.
+ * A Test that checks to see if each class is assignable to the provided
+ * class. Note that this test will match the parent type itself if it is
+ * presented for matching.
*/
public static class IsA implements Test {
private Class parent;
- /** Constructs an IsA test using the supplied Class as the parent class/interface. */
- public IsA(Class parentType) { this.parent = parentType; }
+ /**
+ * Constructs an IsA test using the supplied Class as the parent
+ * class/interface.
+ */
+ public IsA(Class parentType) {
+ this.parent = parentType;
+ }
- /** Returns true if type is assignable to the parent type supplied in the constructor. */
+ /**
+ * Returns true if type is assignable to the parent type supplied in the
+ * constructor.
+ */
public boolean matches(Class type) {
return type != null && parent.isAssignableFrom(type);
}
- @Override public String toString() {
+ @Override
+ public String toString() {
return "is assignable to " + parent.getSimpleName();
}
}
/**
- * A Test that checks to see if each class is annotated with a specific annotation. If it
- * is, then the test returns true, otherwise false.
+ * A Test that checks to see if each class is annotated with a specific
+ * annotation. If it is, then the test returns true, otherwise false.
*/
public static class AnnotatedWith implements Test {
private Class<? extends Annotation> annotation;
/** Construts an AnnotatedWith test for the specified annotation type. */
- public AnnotatedWith(Class<? extends Annotation> annotation) { this.annotation = annotation; }
+ public AnnotatedWith(Class<? extends Annotation> annotation) {
+ this.annotation = annotation;
+ }
- /** Returns true if the type is annotated with the class provided to the constructor. */
+ /**
+ * Returns true if the type is annotated with the class provided to the
+ * constructor.
+ */
public boolean matches(Class type) {
return type != null && type.isAnnotationPresent(annotation);
}
- @Override public String toString() {
+ @Override
+ public String toString() {
return "annotated with @" + annotation.getSimpleName();
}
}
/** The set of matches being accumulated. */
- private Set<Class<? extends T>> matches = new HashSet<Class<?extends T>>();
+ private Set<Class<? extends T>> matches = new HashSet<Class<? extends T>>();
/**
- * The ClassLoader to use when looking for classes. If null then the ClassLoader returned
- * by Thread.currentThread().getContextClassLoader() will be used.
+ * The ClassLoader to use when looking for classes. If null then the
+ * ClassLoader returned by Thread.currentThread().getContextClassLoader()
+ * will be used.
*/
private ClassLoader classloader;
/**
- * Provides access to the classes discovered so far. If no calls have been made to
- * any of the {@code find()} methods, this set will be empty.
- *
+ * Provides access to the classes discovered so far. If no calls have been
+ * made to any of the {@code find()} methods, this set will be empty.
+ *
* @return the set of classes that have been discovered.
*/
public Set<Class<? extends T>> getClasses() {
@@ -139,9 +165,10 @@
}
/**
- * Returns the classloader that will be used for scanning for classes. If no explicit
- * ClassLoader has been set by the calling, the context class loader will be used.
- *
+ * Returns the classloader that will be used for scanning for classes. If no
+ * explicit ClassLoader has been set by the calling, the context class
+ * loader will be used.
+ *
* @return the ClassLoader that will be used to scan for classes
*/
public ClassLoader getClassLoader() {
@@ -149,24 +176,31 @@
}
/**
- * Sets an explicit ClassLoader that should be used when scanning for classes. If none
- * is set then the context classloader will be used.
- *
+ * Sets an explicit ClassLoader that should be used when scanning for
+ * classes. If none is set then the context classloader will be used.
+ *
* @param classloader a ClassLoader to use when scanning for classes
*/
- public void setClassLoader(ClassLoader classloader) { this.classloader = classloader; }
+ public void setClassLoader(ClassLoader classloader) {
+ this.classloader = classloader;
+ }
/**
- * Attempts to discover classes that are assignable to the type provided. In the case
- * that an interface is provided this method will collect implementations. In the case
- * of a non-interface class, subclasses will be collected. Accumulated classes can be
- * accessed by calling {@link #getClasses()}.
- *
- * @param parent the class of interface to find subclasses or implementations of
- * @param packageNames one or more package names to scan (including subpackages) for classes
+ * Attempts to discover classes that are assignable to the type provided. In
+ * the case that an interface is provided this method will collect
+ * implementations. In the case of a non-interface class, subclasses will be
+ * collected. Accumulated classes can be accessed by calling
+ * {@link #getClasses()}.
+ *
+ * @param parent the class of interface to find subclasses or
+ * implementations of
+ * @param packageNames one or more package names to scan (including
+ * subpackages) for classes
*/
public void findImplementations(Class parent, String... packageNames) {
- if (packageNames == null) return;
+ if (packageNames == null) {
+ return;
+ }
Test test = new IsA(parent);
for (String pkg : packageNames) {
@@ -175,14 +209,18 @@
}
/**
- * Attempts to discover classes that are annotated with to the annotation. Accumulated
- * classes can be accessed by calling {@link #getClasses()}.
- *
- * @param annotation the annotation that should be present on matching classes
- * @param packageNames one or more package names to scan (including subpackages) for classes
+ * Attempts to discover classes that are annotated with to the annotation.
+ * Accumulated classes can be accessed by calling {@link #getClasses()}.
+ *
+ * @param annotation the annotation that should be present on matching
+ * classes
+ * @param packageNames one or more package names to scan (including
+ * subpackages) for classes
*/
public void findAnnotated(Class<? extends Annotation> annotation, String... packageNames) {
- if (packageNames == null) return;
+ if (packageNames == null) {
+ return;
+ }
Test test = new AnnotatedWith(annotation);
for (String pkg : packageNames) {
@@ -191,14 +229,15 @@
}
/**
- * Scans for classes starting at the package provided and descending into subpackages.
- * Each class is offered up to the Test as it is discovered, and if the Test returns
- * true the class is retained. Accumulated classes can be fetched by calling
- * {@link #getClasses()}.
- *
- * @param test an instance of {@link Test} that will be used to filter classes
- * @param packageName the name of the package from which to start scanning for
- * classes, e.g. {@code net.sourceforge.stripes}
+ * Scans for classes starting at the package provided and descending into
+ * subpackages. Each class is offered up to the Test as it is discovered,
+ * and if the Test returns true the class is retained. Accumulated classes
+ * can be fetched by calling {@link #getClasses()}.
+ *
+ * @param test an instance of {@link Test} that will be used to filter
+ * classes
+ * @param packageName the name of the package from which to start scanning
+ * for classes, e.g. {@code net.sourceforge.stripes}
*/
public void find(Test test, String packageName) {
packageName = packageName.replace('.', '/');
@@ -207,9 +246,8 @@
try {
urls = loader.getResources(packageName);
- }
- catch (IOException ioe) {
- log.warn("Could not read package: " + packageName, ioe);
+ } catch (IOException ioe) {
+ LOG.warn("Could not read package: " + packageName, ioe);
return;
}
@@ -219,7 +257,7 @@
urlPath = URLDecoder.decode(urlPath, "UTF-8");
// If it's a file in a directory, trim the stupid file: spec
- if ( urlPath.startsWith("file:") ) {
+ if (urlPath.startsWith("file:")) {
urlPath = urlPath.substring(5);
}
@@ -228,32 +266,31 @@
urlPath = urlPath.substring(0, urlPath.indexOf('!'));
}
- log.debug("Scanning for classes in [" + urlPath + "] matching criteria: " + test);
+ LOG.debug("Scanning for classes in [" + urlPath + "] matching criteria: " + test);
File file = new File(urlPath);
- if ( file.isDirectory() ) {
+ if (file.isDirectory()) {
loadImplementationsInDirectory(test, packageName, file);
- }
- else {
+ } else {
loadImplementationsInJar(test, packageName, file);
}
- }
- catch (IOException ioe) {
- log.warn("could not read entries", ioe);
+ } catch (IOException ioe) {
+ LOG.warn("could not read entries", ioe);
}
}
}
-
/**
- * Finds matches in a physical directory on a filesystem. Examines all
- * files within a directory - if the File object is not a directory, and ends with <i>.class</i>
- * the file is loaded and tested to see if it is acceptable according to the Test. Operates
- * recursively to find classes within a folder structure matching the package structure.
- *
+ * Finds matches in a physical directory on a filesystem. Examines all files
+ * within a directory - if the File object is not a directory, and ends with
+ * <i>.class</i> the file is loaded and tested to see if it is acceptable
+ * according to the Test. Operates recursively to find classes within a
+ * folder structure matching the package structure.
+ *
* @param test a Test used to filter the classes that are discovered
- * @param parent the package name up to this directory in the package hierarchy. E.g. if
- * /classes is in the classpath and we wish to examine files in /classes/org/apache then
- * the values of <i>parent</i> would be <i>org/apache</i>
+ * @param parent the package name up to this directory in the package
+ * hierarchy. E.g. if /classes is in the classpath and we
+ * wish to examine files in /classes/org/apache then the
+ * values of <i>parent</i> would be <i>org/apache</i>
* @param location a File object representing a directory
*/
private void loadImplementationsInDirectory(Test test, String parent, File location) {
@@ -263,24 +300,24 @@
for (File file : files) {
builder = new StringBuilder(100);
builder.append(parent).append("/").append(file.getName());
- String packageOrClass = ( parent == null ? file.getName() : builder.toString() );
+ String packageOrClass = parent == null ? file.getName() : builder.toString();
if (file.isDirectory()) {
loadImplementationsInDirectory(test, packageOrClass, file);
- }
- else if (file.getName().endsWith(".class")) {
+ } else if (file.getName().endsWith(".class")) {
addIfMatching(test, packageOrClass);
}
}
}
/**
- * Finds matching classes within a jar files that contains a folder structure
- * matching the package structure. If the File is not a JarFile or does not exist a warning
- * will be logged, but no error will be raised.
- *
+ * Finds matching classes within a jar files that contains a folder
+ * structure matching the package structure. If the File is not a JarFile or
+ * does not exist a warning will be logged, but no error will be raised.
+ *
* @param test a Test used to filter the classes that are discovered
- * @param parent the parent package under which classes must be in order to be considered
+ * @param parent the parent package under which classes must be in order to
+ * be considered
* @param jarfile the jar file to be examined for classes
*/
private void loadImplementationsInJar(Test test, String parent, File jarfile) {
@@ -289,23 +326,23 @@
JarEntry entry;
JarInputStream jarStream = new JarInputStream(new FileInputStream(jarfile));
- while ( (entry = jarStream.getNextJarEntry() ) != null) {
+ while ((entry = jarStream.getNextJarEntry()) != null) {
String name = entry.getName();
if (!entry.isDirectory() && name.startsWith(parent) && name.endsWith(".class")) {
addIfMatching(test, name);
}
}
- }
- catch (IOException ioe) {
- log.error("Could not search jar file '" + jarfile + "' for classes matching criteria: " +
- test + "due to an IOException: " + ioe.getMessage());
+ } catch (IOException ioe) {
+ LOG.error("Could not search jar file '" + jarfile + "' for classes matching criteria: " + test
+ + "due to an IOException: " + ioe.getMessage());
}
}
/**
- * Add the class designated by the fully qualified class name provided to the set of
- * resolved classes if and only if it is approved by the Test supplied.
- *
+ * Add the class designated by the fully qualified class name provided to
+ * the set of resolved classes if and only if it is approved by the Test
+ * supplied.
+ *
* @param test the test used to determine if the class matches
* @param fqn the fully qualified name of a class
*/
@@ -313,16 +350,15 @@
try {
String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', '.');
ClassLoader loader = getClassLoader();
- log.trace("Checking to see if class " + externalName + " matches criteria [" + test+ "]");
+ LOG.trace("Checking to see if class " + externalName + " matches criteria [" + test + "]");
Class type = loader.loadClass(externalName);
- if (test.matches(type) ) {
- matches.add( (Class<T>) type);
+ if (test.matches(type)) {
+ matches.add((Class<T>)type);
}
- }
- catch (Throwable t) {
- log.warn("Could not examine class '"+ fqn + "' due to a " +
- t.getClass().getName()+ " with message: " + t.getMessage());
+ } catch (Throwable t) {
+ LOG.warn("Could not examine class '" + fqn + "' due to a " + t.getClass().getName()
+ + " with message: " + t.getMessage());
}
}
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ServiceHelper.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,28 +16,32 @@
*/
package org.apache.camel.util;
+import java.util.Collection;
+
import org.apache.camel.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.Collection;
-
/**
* A collection of helper methods for working with {@link Service} objects
- *
+ *
* @version $Revision$
*/
public class ServiceHelper {
- private static final transient Log log = LogFactory.getLog(ServiceHelper.class);
-
-
+ private static final transient Log LOG = LogFactory.getLog(ServiceHelper.class);
+
+ /**
+ * Utility classes should not have a public constructor.
+ */
+ private ServiceHelper() {
+ }
+
public static void startService(Object value) throws Exception {
if (value instanceof Service) {
- Service service = (Service) value;
+ Service service = (Service)value;
service.start();
- }
- else if (value instanceof Collection) {
- startServices((Collection) value);
+ } else if (value instanceof Collection) {
+ startServices((Collection)value);
}
}
@@ -57,7 +60,7 @@
public static void startServices(Collection services) throws Exception {
for (Object value : services) {
if (value instanceof Service) {
- Service service = (Service) value;
+ Service service = (Service)value;
service.start();
}
}
@@ -70,12 +73,11 @@
Exception firstException = null;
for (Object value : services) {
if (value instanceof Service) {
- Service service = (Service) value;
+ Service service = (Service)value;
try {
service.stop();
- }
- catch (Exception e) {
- log.debug("Caught exception shutting down: " + e, e);
+ } catch (Exception e) {
+ LOG.debug("Caught exception shutting down: " + e, e);
if (firstException == null) {
firstException = e;
}
@@ -89,15 +91,13 @@
public static void stopService(Object value) throws Exception {
if (value instanceof Service) {
- Service service = (Service) value;
+ Service service = (Service)value;
service.stop();
- }
- else if (value instanceof Collection) {
- stopServices((Collection) value);
+ } else if (value instanceof Collection) {
+ stopServices((Collection)value);
}
}
-
/**
* Stops all of the given services, throwing the first exception caught
*/
@@ -105,12 +105,11 @@
Exception firstException = null;
for (Object value : services) {
if (value instanceof Service) {
- Service service = (Service) value;
+ Service service = (Service)value;
try {
service.stop();
- }
- catch (Exception e) {
- log.debug("Caught exception shutting down: " + e, e);
+ } catch (Exception e) {
+ LOG.debug("Caught exception shutting down: " + e, e);
if (firstException == null) {
firstException = e;
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/Time.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/Time.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/Time.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/Time.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,18 +16,23 @@
*/
package org.apache.camel.util;
-import java.util.concurrent.TimeUnit;
import java.util.Date;
+import java.util.concurrent.TimeUnit;
/**
* A helper class for working with times in various units
- *
+ *
* @version $Revision: $
*/
public class Time {
private long number;
private TimeUnit timeUnit = TimeUnit.MILLISECONDS;
+ public Time(long number, TimeUnit timeUnit) {
+ this.number = number;
+ this.timeUnit = timeUnit;
+ }
+
public static Time millis(long value) {
return new Time(value, TimeUnit.MILLISECONDS);
}
@@ -54,11 +59,6 @@
public static Time days(long value) {
return new Time(daysAsSeconds(value), TimeUnit.MILLISECONDS);
- }
-
- public Time(long number, TimeUnit timeUnit) {
- this.number = number;
- this.timeUnit = timeUnit;
}
public long toMillis() {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/URISupport.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -33,12 +32,13 @@
*/
public class URISupport {
public static class CompositeData {
+ public String host;
+
String scheme;
String path;
URI components[];
Map parameters;
String fragment;
- public String host;
public URI[] getComponents() {
return components;
@@ -73,8 +73,7 @@
if (host != null && host.length() != 0) {
sb.append(host);
- }
- else {
+ } else {
sb.append('(');
for (int i = 0; i < components.length; i++) {
if (i != 0) {
@@ -112,16 +111,14 @@
String name = URLDecoder.decode(parameters[i].substring(0, p), "UTF-8");
String value = URLDecoder.decode(parameters[i].substring(p + 1), "UTF-8");
rc.put(name, value);
- }
- else {
+ } else {
rc.put(parameters[i], null);
}
}
}
return rc;
- }
- catch (UnsupportedEncodingException e) {
- throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
+ } catch (UnsupportedEncodingException e) {
+ throw (URISyntaxException)new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
}
}
@@ -132,12 +129,10 @@
int idx = schemeSpecificPart.lastIndexOf('?');
if (idx < 0) {
return Collections.EMPTY_MAP;
- }
- else {
+ } else {
query = schemeSpecificPart.substring(idx + 1);
}
- }
- else {
+ } else {
query = stripPrefix(query, "?");
}
return parseQuery(query);
@@ -154,7 +149,8 @@
* Creates a URI with the given query
*/
public static URI createURIWithQuery(URI uri, String query) throws URISyntaxException {
- return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), query, uri.getFragment());
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(),
+ query, uri.getFragment());
}
public static CompositeData parseComposite(URI uri) throws URISyntaxException {
@@ -195,8 +191,7 @@
p = ssp.lastIndexOf(")");
componentString = ssp.substring(intialParen + 1, p);
params = ssp.substring(p + 1).trim();
- }
- else {
+ } else {
componentString = ssp;
params = "";
}
@@ -213,8 +208,7 @@
rc.path = stripPrefix(params.substring(0, p), "/");
}
rc.parameters = parseQuery(params.substring(p + 1));
- }
- else {
+ } else {
if (params.length() > 0) {
rc.path = stripPrefix(params, "/");
}
@@ -234,18 +228,20 @@
char chars[] = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
switch (chars[i]) {
- case '(':
- depth++;
- break;
- case ')':
- depth--;
- break;
- case ',':
- if (depth == 0) {
- String s = str.substring(last, i);
- l.add(s);
- last = i + 1;
- }
+ case '(':
+ depth++;
+ break;
+ case ')':
+ depth--;
+ break;
+ case ',':
+ if (depth == 0) {
+ String s = str.substring(last, i);
+ l.add(s);
+ last = i + 1;
+ }
+ break;
+ default:
}
}
@@ -278,31 +274,28 @@
for (Iterator iter = options.keySet().iterator(); iter.hasNext();) {
if (first) {
first = false;
- }
- else {
+ } else {
rc.append("&");
}
- String key = (String) iter.next();
- String value = (String) options.get(key);
+ String key = (String)iter.next();
+ String value = (String)options.get(key);
rc.append(URLEncoder.encode(key, "UTF-8"));
rc.append("=");
rc.append(URLEncoder.encode(value, "UTF-8"));
}
return rc.toString();
- }
- else {
+ } else {
return "";
}
- }
- catch (UnsupportedEncodingException e) {
- throw (URISyntaxException) new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
+ } catch (UnsupportedEncodingException e) {
+ throw (URISyntaxException)new URISyntaxException(e.toString(), "Invalid encoding").initCause(e);
}
}
/**
* Creates a URI from the original URI and the remaining paramaters
- *
+ *
* @throws URISyntaxException
*/
public static URI createRemainingURI(URI originalURI, Map params) throws URISyntaxException {
@@ -313,8 +306,9 @@
return createURIWithQuery(originalURI, s);
}
- static public URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
- return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr.getPath(), bindAddr.getQuery(), bindAddr.getFragment());
+ public static URI changeScheme(URI bindAddr, String scheme) throws URISyntaxException {
+ return new URI(scheme, bindAddr.getUserInfo(), bindAddr.getHost(), bindAddr.getPort(), bindAddr
+ .getPath(), bindAddr.getQuery(), bindAddr.getFragment());
}
public static boolean checkParenthesis(String str) {
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -16,6 +15,7 @@
* limitations under the License.
*/
package org.apache.camel.util;
+
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.logging.Level;
@@ -27,81 +27,84 @@
public class UuidGenerator {
- private static final Logger log = Logger.getLogger(UuidGenerator.class.getName());
+ private static final Logger LOG = Logger.getLogger(UuidGenerator.class.getName());
private static final String UNIQUE_STUB;
private static int instanceCount;
private static String hostName;
private String seed;
private long sequence;
-
+
static {
String stub = "";
boolean canAccessSystemProps = true;
- try{
+ try {
SecurityManager sm = System.getSecurityManager();
- if(sm != null){
+ if (sm != null) {
sm.checkPropertiesAccess();
}
- }catch(SecurityException se){
+ } catch (SecurityException se) {
canAccessSystemProps = false;
}
-
- if ( canAccessSystemProps) {
+
+ if (canAccessSystemProps) {
try {
hostName = InetAddress.getLocalHost().getHostName();
ServerSocket ss = new ServerSocket(0);
- stub="/" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "/";
+ stub = "/" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "/";
Thread.sleep(100);
ss.close();
- }catch(Exception ioe){
- log.log(Level.WARNING, "could not generate unique stub",ioe);
+ } catch (Exception ioe) {
+ LOG.log(Level.WARNING, "could not generate unique stub", ioe);
}
- }else{
- hostName="localhost";
- stub = "-1-" +System.currentTimeMillis() +"-";
+ } else {
+ hostName = "localhost";
+ stub = "-1-" + System.currentTimeMillis() + "-";
}
UNIQUE_STUB = stub;
}
-
- /**
- * As we have to find the hostname as a side-affect of generating
- * a unique stub, we allow it's easy retrevial here
- * @return the local host name
- */
-
- public static String getHostName(){
- return hostName;
- }
-
+
/**
* Construct an IdGenerator
- *
+ *
*/
-
- public UuidGenerator(String prefix){
- synchronized(UNIQUE_STUB){
- this.seed = prefix + UNIQUE_STUB +(instanceCount++) +"-";
+
+ public UuidGenerator(String prefix) {
+ synchronized (UNIQUE_STUB) {
+ this.seed = prefix + UNIQUE_STUB + (instanceCount++) + "-";
}
}
-
- public UuidGenerator(){
+
+ public UuidGenerator() {
this("ID-" + hostName);
}
-
+
+ /**
+ * As we have to find the hostname as a side-affect of generating a unique
+ * stub, we allow it's easy retrevial here
+ *
+ * @return the local host name
+ */
+
+ public static String getHostName() {
+ return hostName;
+ }
+
/**
* Generate a unqiue id
+ *
* @return a unique id
*/
-
- public synchronized String generateId(){
+
+ public synchronized String generateId() {
return this.seed + (this.sequence++);
}
-
+
/**
* Generate a unique ID - that is friendly for a URL or file system
+ *
* @return a unique id
*/
- public String generateSanitizedId(){
+ public String generateSanitizedId() {
String result = generateId();
result = result.replace(':', '-');
result = result.replace('_', '-');
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/CamelInitialContextFactory.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -17,10 +17,11 @@
package org.apache.camel.util.jndi;
+import java.util.Hashtable;
+
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
-import java.util.Hashtable;
/**
* A factory of the Cameel InitialContext which allows a Map to be used to create a
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/JndiContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/JndiContext.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/JndiContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/jndi/JndiContext.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -16,70 +16,53 @@
*/
package org.apache.camel.util.jndi;
-import org.apache.camel.impl.ReflectionInjector;
-import org.apache.camel.spi.Injector;
-import org.apache.camel.util.IntrospectionSupport;
-import org.apache.camel.util.ObjectHelper;
-
-import javax.naming.*;
-import javax.naming.spi.NamingManager;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
+import javax.naming.Binding;
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.LinkRef;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.NotContextException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.Reference;
+import javax.naming.spi.NamingManager;
+
+import org.apache.camel.impl.ReflectionInjector;
+import org.apache.camel.spi.Injector;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+
/**
* A default JNDI context
- *
+ *
* @version $Revision: 1.2 $ $Date: 2005/08/27 03:52:39 $
*/
public class JndiContext implements Context, Serializable {
public static final String SEPARATOR = "/";
- private static final long serialVersionUID = -5754338187296859149L;
- protected static final NameParser nameParser = new NameParser() {
+ protected static final NameParser NAME_PARSER = new NameParser() {
public Name parse(String name) throws NamingException {
return new CompositeName(name);
}
};
- protected static Injector injector = new ReflectionInjector();
- private final Hashtable environment; // environment for this context
- private final Map bindings; // bindings at my level
- private final Map treeBindings; // all bindings under me
- private boolean frozen = false;
+ protected static final Injector INJETOR = new ReflectionInjector();
+ private static final long serialVersionUID = -5754338187296859149L;
+
+ private final Hashtable environment; // environment for this context
+ private final Map bindings; // bindings at my level
+ private final Map treeBindings; // all bindings under me
+ private boolean frozen;
private String nameInNamespace = "";
- /**
- * A helper method to create the JNDI bindings from the input environment properties
- * using $foo.class to point to a class name with $foo.* being properties set on the injected bean
- */
- public static Map createBindingsMapFromEnvironment(Hashtable env) {
- Map answer = new HashMap(env);
-
- for (Object object : env.entrySet()) {
- Map.Entry entry = (Map.Entry) object;
- Object key = entry.getKey();
- Object value = entry.getValue();
-
- if (key instanceof String && value instanceof String) {
- String keyText = (String) key;
- String valueText = (String) value;
- if (keyText.endsWith(".class")) {
- Class<?> type = ObjectHelper.loadClass(valueText);
- if (type != null) {
- String newEntry = keyText.substring(0, keyText.length() - ".class".length());
- Object bean = createBean(type, answer, newEntry + ".");
- if (bean != null) {
- answer.put(newEntry, bean);
- }
- }
- }
- }
- }
-
- return answer;
- }
-
public JndiContext() {
this(new Hashtable());
}
@@ -91,8 +74,7 @@
public JndiContext(Hashtable environment, Map bindings) {
if (environment == null) {
this.environment = new Hashtable();
- }
- else {
+ } else {
this.environment = new Hashtable(environment);
}
this.bindings = bindings;
@@ -114,6 +96,38 @@
this(clone, env);
this.nameInNamespace = nameInNamespace;
}
+
+ /**
+ * A helper method to create the JNDI bindings from the input environment
+ * properties using $foo.class to point to a class name with $foo.* being
+ * properties set on the injected bean
+ */
+ public static Map createBindingsMapFromEnvironment(Hashtable env) {
+ Map answer = new HashMap(env);
+
+ for (Object object : env.entrySet()) {
+ Map.Entry entry = (Map.Entry)object;
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+
+ if (key instanceof String && value instanceof String) {
+ String keyText = (String)key;
+ String valueText = (String)value;
+ if (keyText.endsWith(".class")) {
+ Class<?> type = ObjectHelper.loadClass(valueText);
+ if (type != null) {
+ String newEntry = keyText.substring(0, keyText.length() - ".class".length());
+ Object bean = createBean(type, answer, newEntry + ".");
+ if (bean != null) {
+ answer.put(newEntry, bean);
+ }
+ }
+ }
+ }
+ }
+
+ return answer;
+ }
public void freeze() {
frozen = true;
@@ -124,13 +138,15 @@
}
/**
- * internalBind is intended for use only during setup or possibly by suitably synchronized superclasses.
- * It binds every possible lookup into a map in each context. To do this, each context
- * strips off one name segment and if necessary creates a new context for it. Then it asks that context
- * to bind the remaining name. It returns a map containing all the bindings from the next context, plus
- * the context it just created (if it in fact created it). (the names are suitably extended by the segment
- * originally lopped off).
- *
+ * internalBind is intended for use only during setup or possibly by
+ * suitably synchronized superclasses. It binds every possible lookup into a
+ * map in each context. To do this, each context strips off one name segment
+ * and if necessary creates a new context for it. Then it asks that context
+ * to bind the remaining name. It returns a map containing all the bindings
+ * from the next context, plus the context it just created (if it in fact
+ * created it). (the names are suitably extended by the segment originally
+ * lopped off).
+ *
* @param name
* @param value
* @return
@@ -148,8 +164,7 @@
}
bindings.put(name, value);
newBindings.put(name, value);
- }
- else {
+ } else {
String segment = name.substring(0, pos);
assert segment != null;
assert !segment.equals("");
@@ -159,16 +174,15 @@
treeBindings.put(segment, o);
bindings.put(segment, o);
newBindings.put(segment, o);
- }
- else if (!(o instanceof JndiContext)) {
+ } else if (!(o instanceof JndiContext)) {
throw new NamingException("Something already bound where a subcontext should go");
}
- JndiContext defaultContext = (JndiContext) o;
+ JndiContext defaultContext = (JndiContext)o;
String remainder = name.substring(pos + 1);
Map subBindings = defaultContext.internalBind(remainder, value);
for (Iterator iterator = subBindings.entrySet().iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- String subName = segment + "/" + (String) entry.getKey();
+ Map.Entry entry = (Map.Entry)iterator.next();
+ String subName = segment + "/" + (String)entry.getKey();
Object bound = entry.getValue();
treeBindings.put(subName, bound);
newBindings.put(subName, bound);
@@ -186,7 +200,7 @@
}
public Hashtable getEnvironment() throws NamingException {
- return (Hashtable) environment.clone();
+ return (Hashtable)environment.clone();
}
public Object removeFromEnvironment(String propName) throws NamingException {
@@ -210,23 +224,20 @@
throw new NamingException("scheme " + scheme + " not recognized");
}
return ctx.lookup(name);
- }
- else {
+ } else {
// Split out the first name of the path
// and look for it in the bindings map.
CompositeName path = new CompositeName(name);
if (path.size() == 0) {
return this;
- }
- else {
+ } else {
String first = path.get(0);
Object value = bindings.get(first);
if (value == null) {
throw new NameNotFoundException(name);
- }
- else if (value instanceof Context && path.size() > 1) {
- Context subContext = (Context) value;
+ } else if (value instanceof Context && path.size() > 1) {
+ Context subContext = (Context)value;
value = subContext.lookup(path.getSuffix(1));
}
return value;
@@ -234,18 +245,16 @@
}
}
if (result instanceof LinkRef) {
- LinkRef ref = (LinkRef) result;
+ LinkRef ref = (LinkRef)result;
result = lookup(ref.getLinkName());
}
if (result instanceof Reference) {
try {
result = NamingManager.getObjectInstance(result, null, null, this.environment);
- }
- catch (NamingException e) {
+ } catch (NamingException e) {
throw e;
- }
- catch (Exception e) {
- throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
+ } catch (Exception e) {
+ throw (NamingException)new NamingException("could not look up : " + name).initCause(e);
}
}
if (result instanceof JndiContext) {
@@ -253,7 +262,7 @@
if (prefix.length() > 0) {
prefix = prefix + SEPARATOR;
}
- result = new JndiContext((JndiContext) result, environment, prefix + name);
+ result = new JndiContext((JndiContext)result, environment, prefix + name);
}
return result;
}
@@ -267,7 +276,7 @@
}
public Name composeName(Name name, Name prefix) throws NamingException {
- Name result = (Name) prefix.clone();
+ Name result = (Name)prefix.clone();
result.addAll(name);
return result;
}
@@ -282,11 +291,9 @@
Object o = lookup(name);
if (o == this) {
return new ListEnumeration();
- }
- else if (o instanceof Context) {
- return ((Context) o).list("");
- }
- else {
+ } else if (o instanceof Context) {
+ return ((Context)o).list("");
+ } else {
throw new NotContextException();
}
}
@@ -295,11 +302,9 @@
Object o = lookup(name);
if (o == this) {
return new ListBindingEnumeration();
- }
- else if (o instanceof Context) {
- return ((Context) o).listBindings("");
- }
- else {
+ } else if (o instanceof Context) {
+ return ((Context)o).listBindings("");
+ } else {
throw new NotContextException();
}
}
@@ -323,8 +328,7 @@
public void bind(String name, Object value) throws NamingException {
if (isFrozen()) {
throw new OperationNotSupportedException();
- }
- else {
+ } else {
internalBind(name, value);
}
}
@@ -354,11 +358,11 @@
}
public NameParser getNameParser(Name name) throws NamingException {
- return nameParser;
+ return NAME_PARSER;
}
public NameParser getNameParser(String name) throws NamingException {
- return nameParser;
+ return NAME_PARSER;
}
public void rebind(Name name, Object value) throws NamingException {
@@ -397,7 +401,7 @@
}
protected Map.Entry getNext() {
- return (Map.Entry) i.next();
+ return (Map.Entry)i.next();
}
public void close() throws NamingException {
@@ -414,7 +418,7 @@
public Object nextElement() {
Map.Entry entry = getNext();
- return new NameClassPair((String) entry.getKey(), entry.getValue().getClass().getName());
+ return new NameClassPair((String)entry.getKey(), entry.getValue().getClass().getName());
}
}
@@ -428,12 +432,12 @@
public Object nextElement() {
Map.Entry entry = getNext();
- return new Binding((String) entry.getKey(), entry.getValue());
+ return new Binding((String)entry.getKey(), entry.getValue());
}
}
protected static Object createBean(Class<?> type, Map properties, String prefix) {
- Object value = injector.newInstance(type);
+ Object value = INJETOR.newInstance(type);
IntrospectionSupport.setProperties(value, properties, prefix);
return value;
}
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/view/RouteDotGenerator.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,6 +16,11 @@
*/
package org.apache.camel.view;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.List;
+
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
@@ -25,19 +29,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.List;
-
/**
* A <a href="http://www.graphviz.org/">DOT</a> file creator plugin which
* creates a DOT file showing the current routes
- *
+ *
* @version $Revision: 523881 $
*/
public class RouteDotGenerator {
- private static final transient Log log = LogFactory.getLog(RouteDotGenerator.class);
+ private static final transient Log LOG = LogFactory.getLog(RouteDotGenerator.class);
private String file = "CamelRoutes.dot";
public String getFile() {
@@ -61,7 +60,8 @@
writer.println();
writer.println("label=\"Camel Container: " + context + "\"];");
writer.println();
- writer.println("node [style = \"rounded,filled\", fillcolor = yellow, fontname=\"Helvetica-Oblique\"];");
+ writer.println("node [style = \"rounded,filled\", fillcolor = yellow, "
+ + "fontname=\"Helvetica-Oblique\"];");
writer.println();
printRoutes(writer, context.getRoutes());
}
@@ -74,7 +74,7 @@
writer.print(r);
writer.print(" -> ");
if (r instanceof EventDrivenConsumerRoute) {
- EventDrivenConsumerRoute consumerRoute = (EventDrivenConsumerRoute) r;
+ EventDrivenConsumerRoute consumerRoute = (EventDrivenConsumerRoute)r;
Processor p = consumerRoute.getProcessor();
writer.println(p);
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/BodyAndHeaderConvertTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/BodyAndHeaderConvertTest.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/BodyAndHeaderConvertTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/BodyAndHeaderConvertTest.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -17,11 +16,13 @@
*/
package org.apache.camel;
-import junit.framework.TestCase;
-import org.apache.camel.impl.DefaultExchange;
-import org.apache.camel.impl.DefaultCamelContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultExchange;
/**
* @version $Revision$
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/ContextTestSupport.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -24,9 +23,9 @@
import org.apache.camel.util.jndi.JndiTest;
/**
- * A useful base class which creates a {@link CamelContext} with some routes along with a {@link CamelTemplate}
- * for use in the test case
- *
+ * A useful base class which creates a {@link CamelContext} with some routes
+ * along with a {@link CamelTemplate} for use in the test case
+ *
* @version $Revision: 1.1 $
*/
public abstract class ContextTestSupport extends TestSupport {
@@ -48,10 +47,9 @@
}
/**
- * Allows a service to be registered a separate lifecycle service to start and stop
- * the context; such as for Spring
- * when the ApplicationContext is started and stopped, rather than directly stopping the
- * CamelContext
+ * Allows a service to be registered a separate lifecycle service to start
+ * and stop the context; such as for Spring when the ApplicationContext is
+ * started and stopped, rather than directly stopping the CamelContext
*/
public void setCamelContextService(Service camelContextService) {
this.camelContextService = camelContextService;
@@ -66,15 +64,13 @@
RouteBuilder builder = createRouteBuilder();
log.debug("Using created route builder: " + builder);
context.addRoutes(builder);
- }
- else {
+ } else {
log.debug("Using route builder from the created context: " + context);
}
if (camelContextService != null) {
camelContextService.start();
- }
- else {
+ } else {
context.start();
}
@@ -87,8 +83,7 @@
template.stop();
if (camelContextService != null) {
camelContextService.stop();
- }
- else {
+ } else {
context.stop();
}
}
@@ -113,12 +108,11 @@
return resolveMandatoryEndpoint(context, uri, endpointType);
}
-
/**
* Sends a message to the given endpoint URI with the body value
- *
+ *
* @param endpointUri the URI of the endpoint to send to
- * @param body the body for the message
+ * @param body the body for the message
*/
protected void sendBody(String endpointUri, final Object body) {
template.send(endpointUri, new Processor() {
@@ -132,9 +126,9 @@
/**
* Sends messages to the given endpoint for each of the specified bodies
- *
+ *
* @param endpointUri the endpoint URI to send to
- * @param bodies the bodies to send, one per message
+ * @param bodies the bodies to send, one per message
*/
protected void sendBodies(String endpointUri, Object... bodies) {
for (Object body : bodies) {
@@ -150,28 +144,27 @@
}
/**
- * Asserts that the given language name and expression evaluates to the given value on a specific exchange
+ * Asserts that the given language name and expression evaluates to the
+ * given value on a specific exchange
*/
protected void assertExpression(Exchange exchange, String languageName, String expressionText, Object expectedValue) {
Language language = assertResolveLanguage(languageName);
Expression<Exchange> expression = language.createExpression(expressionText);
- assertNotNull("No Expression could be created for text: " + expressionText
- + " language: " + language, expression);
+ assertNotNull("No Expression could be created for text: " + expressionText + " language: " + language, expression);
assertExpression(expression, exchange, expectedValue);
}
-
/**
- * Asserts that the given language name and predicate expression evaluates to the expected value on the message exchange
+ * Asserts that the given language name and predicate expression evaluates
+ * to the expected value on the message exchange
*/
protected void assertPredicate(String languageName, String expressionText, Exchange exchange, boolean expected) {
Language language = assertResolveLanguage(languageName);
Predicate<Exchange> predicate = language.createPredicate(expressionText);
- assertNotNull("No Predicate could be created for text: " + expressionText
- + " language: " + language, predicate);
+ assertNotNull("No Predicate could be created for text: " + expressionText + " language: " + language, predicate);
assertPredicate(predicate, exchange, expected);
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/InjectorDefaultsToReflectionTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/InjectorDefaultsToReflectionTest.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/InjectorDefaultsToReflectionTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/InjectorDefaultsToReflectionTest.java Tue Aug 7 11:35:48 2007
@@ -1,5 +1,4 @@
/**
- *
* 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.
@@ -7,7 +6,7 @@
* (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
+ * 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,
@@ -28,11 +27,12 @@
* @version $Revision$
*/
public class InjectorDefaultsToReflectionTest extends TestCase {
- private static final transient Log log = LogFactory.getLog(InjectorDefaultsToReflectionTest.class);
+ private static final transient Log LOG = LogFactory.getLog(InjectorDefaultsToReflectionTest.class);
public void testInjectorIsReflectionByDefault() throws Exception {
Injector injector = new DefaultCamelContext().getInjector();
- assertTrue("Injector should be reflection based but was: " + injector, injector instanceof ReflectionInjector);
- log.debug("Found injector: " + injector);
+ assertTrue("Injector should be reflection based but was: " + injector,
+ injector instanceof ReflectionInjector);
+ LOG.debug("Found injector: " + injector);
}
}
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java?view=diff&rev=563607&r1=563606&r2=563607
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/LanguageTestSupport.java Tue Aug 7 11:35:48 2007
@@ -1,4 +1,4 @@
-/*
+/**
* 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.