Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java
 Thu Apr 24 10:49:03 2008
@@ -1,200 +1,200 @@
-/*
- *
- * 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.qpid.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Iterator;
-import java.util.Properties;
-
-/**
- * PropertiesHelper defines some static methods which are useful when working 
with properties
- * files.
- *
- * <p><table id="crc"><caption>CRC Card</caption>
- * <tr><th> Responsibilities <th> Collaborations
- * <tr><td> Read properties from an input stream
- * <tr><td> Read properties from a file
- * <tr><td> Read properties from a URL
- * <tr><td> Read properties given a path to a file
- * <tr><td> Trim any whitespace from property values
- * </table>
- */
-public class PropertiesUtils
-{
-    /** Used for logging. */
-    private static final Logger log = 
LoggerFactory.getLogger(PropertiesUtils.class);
-
-    /**
-     * Get properties from an input stream.
-     *
-     * @param is The input stream.
-     *
-     * @return The properties loaded from the input stream.
-     *
-     * @throws IOException If the is an I/O error reading from the stream.
-     */
-    public static Properties getProperties(InputStream is) throws IOException
-    {
-        log.debug("getProperties(InputStream): called");
-
-        // Create properties object laoded from input stream
-        Properties properties = new Properties();
-
-        properties.load(is);
-
-        return properties;
-    }
-
-    /**
-     * Get properties from a file.
-     *
-     * @param file The file.
-     *
-     * @return The properties loaded from the file.
-     *
-     * @throws IOException If there is an I/O error reading from the file.
-     */
-    public static Properties getProperties(File file) throws IOException
-    {
-        log.debug("getProperties(File): called");
-
-        // Open the file as an input stream
-        InputStream is = new FileInputStream(file);
-
-        // Create properties object loaded from the stream
-        Properties properties = getProperties(is);
-
-        // Close the file
-        is.close();
-
-        return properties;
-    }
-
-    /**
-     * Get properties from a url.
-     *
-     * @param url The URL.
-     *
-     * @return The properties loaded from the url.
-     *
-     * @throws IOException If there is an I/O error reading from the URL.
-     */
-    public static Properties getProperties(URL url) throws IOException
-    {
-        log.debug("getProperties(URL): called");
-
-        // Open the URL as an input stream
-        InputStream is = url.openStream();
-
-        // Create properties object loaded from the stream
-        Properties properties = getProperties(is);
-
-        // Close the url
-        is.close();
-
-        return properties;
-    }
-
-    /**
-     * Get properties from a path name. The path name may refer to either a 
file or a URL.
-     *
-     * @param pathname The path name.
-     *
-     * @return The properties loaded from the file or URL.
-     *
-     * @throws IOException If there is an I/O error reading from the URL or 
file named by the path.
-     */
-    public static Properties getProperties(String pathname) throws IOException
-    {
-        log.debug("getProperties(String): called");
-
-        // Check that the path is not null
-        if (pathname == null)
-        {
-            return null;
-        }
-
-        // Check if the path is a URL
-        if (isURL(pathname))
-        {
-            // The path is a URL
-            return getProperties(new URL(pathname));
-        }
-        else
-        {
-            // Assume the path is a file name
-            return getProperties(new File(pathname));
-        }
-    }
-
-    /**
-     * Trims whitespace from property values. This method returns a new set of 
properties
-     * the same as the properties specified as an argument but with any white 
space removed by
-     * the [EMAIL PROTECTED] java.lang.String#trim} method.
-     *
-     * @param properties The properties to trim whitespace from.
-     *
-     * @return The white space trimmed properties.
-     */
-    public static Properties trim(Properties properties)
-    {
-        Properties trimmedProperties = new Properties();
-
-        // Loop over all the properties
-        for (Iterator i = properties.keySet().iterator(); i.hasNext();)
-        {
-            String next = (String) i.next();
-            String nextValue = properties.getProperty(next);
-
-            // Trim the value if it is not null
-            if (nextValue != null)
-            {
-                nextValue.trim();
-            }
-
-            // Store the trimmed value in the trimmed properties
-            trimmedProperties.setProperty(next, nextValue);
-        }
-
-        return trimmedProperties;
-    }
-
-    /**
-     * Helper method. Guesses whether a string is a URL or not. A String is 
considered to be a url if it begins with
-     * http:, ftp:, or uucp:.
-     *
-     * @param name The string to test for being a URL.
-     *
-     * @return True if the string is a URL and false if not.
-     */
-    private static boolean isURL(String name)
-    {
-        return (name.toLowerCase().startsWith("http:") || 
name.toLowerCase().startsWith("ftp:")
-                || name.toLowerCase().startsWith("uucp:"));
-    }
-}
+/*
+ *
+ * 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.qpid.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Properties;
+
+/**
+ * PropertiesHelper defines some static methods which are useful when working 
with properties
+ * files.
+ *
+ * <p><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Read properties from an input stream
+ * <tr><td> Read properties from a file
+ * <tr><td> Read properties from a URL
+ * <tr><td> Read properties given a path to a file
+ * <tr><td> Trim any whitespace from property values
+ * </table>
+ */
+public class PropertiesUtils
+{
+    /** Used for logging. */
+    private static final Logger log = 
LoggerFactory.getLogger(PropertiesUtils.class);
+
+    /**
+     * Get properties from an input stream.
+     *
+     * @param is The input stream.
+     *
+     * @return The properties loaded from the input stream.
+     *
+     * @throws IOException If the is an I/O error reading from the stream.
+     */
+    public static Properties getProperties(InputStream is) throws IOException
+    {
+        log.debug("getProperties(InputStream): called");
+
+        // Create properties object laoded from input stream
+        Properties properties = new Properties();
+
+        properties.load(is);
+
+        return properties;
+    }
+
+    /**
+     * Get properties from a file.
+     *
+     * @param file The file.
+     *
+     * @return The properties loaded from the file.
+     *
+     * @throws IOException If there is an I/O error reading from the file.
+     */
+    public static Properties getProperties(File file) throws IOException
+    {
+        log.debug("getProperties(File): called");
+
+        // Open the file as an input stream
+        InputStream is = new FileInputStream(file);
+
+        // Create properties object loaded from the stream
+        Properties properties = getProperties(is);
+
+        // Close the file
+        is.close();
+
+        return properties;
+    }
+
+    /**
+     * Get properties from a url.
+     *
+     * @param url The URL.
+     *
+     * @return The properties loaded from the url.
+     *
+     * @throws IOException If there is an I/O error reading from the URL.
+     */
+    public static Properties getProperties(URL url) throws IOException
+    {
+        log.debug("getProperties(URL): called");
+
+        // Open the URL as an input stream
+        InputStream is = url.openStream();
+
+        // Create properties object loaded from the stream
+        Properties properties = getProperties(is);
+
+        // Close the url
+        is.close();
+
+        return properties;
+    }
+
+    /**
+     * Get properties from a path name. The path name may refer to either a 
file or a URL.
+     *
+     * @param pathname The path name.
+     *
+     * @return The properties loaded from the file or URL.
+     *
+     * @throws IOException If there is an I/O error reading from the URL or 
file named by the path.
+     */
+    public static Properties getProperties(String pathname) throws IOException
+    {
+        log.debug("getProperties(String): called");
+
+        // Check that the path is not null
+        if (pathname == null)
+        {
+            return null;
+        }
+
+        // Check if the path is a URL
+        if (isURL(pathname))
+        {
+            // The path is a URL
+            return getProperties(new URL(pathname));
+        }
+        else
+        {
+            // Assume the path is a file name
+            return getProperties(new File(pathname));
+        }
+    }
+
+    /**
+     * Trims whitespace from property values. This method returns a new set of 
properties
+     * the same as the properties specified as an argument but with any white 
space removed by
+     * the [EMAIL PROTECTED] java.lang.String#trim} method.
+     *
+     * @param properties The properties to trim whitespace from.
+     *
+     * @return The white space trimmed properties.
+     */
+    public static Properties trim(Properties properties)
+    {
+        Properties trimmedProperties = new Properties();
+
+        // Loop over all the properties
+        for (Iterator i = properties.keySet().iterator(); i.hasNext();)
+        {
+            String next = (String) i.next();
+            String nextValue = properties.getProperty(next);
+
+            // Trim the value if it is not null
+            if (nextValue != null)
+            {
+                nextValue.trim();
+            }
+
+            // Store the trimmed value in the trimmed properties
+            trimmedProperties.setProperty(next, nextValue);
+        }
+
+        return trimmedProperties;
+    }
+
+    /**
+     * Helper method. Guesses whether a string is a URL or not. A String is 
considered to be a url if it begins with
+     * http:, ftp:, or uucp:.
+     *
+     * @param name The string to test for being a URL.
+     *
+     * @return True if the string is a URL and false if not.
+     */
+    private static boolean isURL(String name)
+    {
+        return (name.toLowerCase().startsWith("http:") || 
name.toLowerCase().startsWith("ftp:")
+                || name.toLowerCase().startsWith("uucp:"));
+    }
+}

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/PropertiesUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtils.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtils.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtils.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtils.java
 Thu Apr 24 10:49:03 2008
@@ -1,228 +1,228 @@
-/*
- *
- * 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.qpid.util;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-/**
- * Provides helper methods for operating on classes and methods using 
reflection. Reflection methods tend to return
- * a lot of checked exception so writing code to use them can be tedious and 
harder to read, especially when such errors
- * are not expected to occur. This class always works with [EMAIL PROTECTED] 
ReflectionUtilsException}, which is a runtime exception,
- * to wrap the checked exceptions raised by the standard Java reflection 
methods. Code using it does not normally
- * expect these errors to occur, usually does not have a recovery mechanism 
for them when they do, but is cleaner,
- * quicker to write and easier to read in the majority of cases.
- *
- * <p/><table id="crc"><caption>CRC Card</caption>
- * <tr><th> Responsibilities <th> Collaborations
- * <tr><td> Look up Classes by name.
- * <tr><td> Instantiate Classes by no-arg constructor.
- * </table>
- */
-public class ReflectionUtils
-{
-    /**
-    * Gets the Class object for a named class.
-    *
-    * @param className The class to get the Class object for.
-    *
-    * @return The Class object for the named class.
-    */
-    public static Class<?> forName(String className)
-    {
-        try
-        {
-            return Class.forName(className);
-        }
-        catch (ClassNotFoundException e)
-        {
-            throw new ReflectionUtilsException("ClassNotFoundException whilst 
finding class.", e);
-        }
-    }
-
-    /**
-     * Creates an instance of a Class, instantiated through its no-args 
constructor.
-     *
-     * @param cls The Class to instantiate.
-     * @param <T> The Class type.
-     *
-     * @return An instance of the class.
-     */
-    public static <T> T newInstance(Class<? extends T> cls)
-    {
-        try
-        {
-            return cls.newInstance();
-        }
-        catch (InstantiationException e)
-        {
-            throw new ReflectionUtilsException("InstantiationException whilst 
instantiating class.", e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new ReflectionUtilsException("IllegalAccessException whilst 
instantiating class.", e);
-        }
-    }
-
-    /**
-     * Calls a named method on an object with a specified set of parameters, 
any Java access modifier are overridden.
-     *
-     * @param o            The object to call.
-     * @param method       The method name to call.
-     * @param params       The parameters to pass.
-     * @param paramClasses The argument types.
-     *
-     * @return The return value from the method call.
-     */
-    public static Object callMethodOverridingIllegalAccess(Object o, String 
method, Object[] params, Class[] paramClasses)
-    {
-        // Get the objects class.
-        Class cls = o.getClass();
-
-        // Get the classes of the parameters.
-        /*Class[] paramClasses = new Class[params.length];
-
-        for (int i = 0; i < params.length; i++)
-        {
-            paramClasses[i] = params[i].getClass();
-        }*/
-
-        try
-        {
-            // Try to find the matching method on the class.
-            Method m = cls.getDeclaredMethod(method, paramClasses);
-
-            // Make it accessible.
-            m.setAccessible(true);
-
-            // Invoke it with the parameters.
-            return m.invoke(o, params);
-        }
-        catch (NoSuchMethodException e)
-        {
-            throw new ReflectionUtilsException("NoSuchMethodException.", e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new ReflectionUtilsException("IllegalAccessException.", e);
-        }
-        catch (InvocationTargetException e)
-        {
-            throw new ReflectionUtilsException("InvocationTargetException", e);
-        }
-    }
-
-    /**
-     * Calls a named method on an object with a specified set of parameters.
-     *
-     * @param o      The object to call.
-     * @param method The method name to call.
-     * @param params The parameters to pass.
-     *
-     * @return The return value from the method call.
-     */
-    public static Object callMethod(Object o, String method, Object[] params)
-    {
-        // Get the objects class.
-        Class cls = o.getClass();
-
-        // Get the classes of the parameters.
-        Class[] paramClasses = new Class[params.length];
-
-        for (int i = 0; i < params.length; i++)
-        {
-            paramClasses[i] = params[i].getClass();
-        }
-
-        try
-        {
-            // Try to find the matching method on the class.
-            Method m = cls.getMethod(method, paramClasses);
-
-            // Invoke it with the parameters.
-            return m.invoke(o, params);
-        }
-        catch (NoSuchMethodException e)
-        {
-            throw new ReflectionUtilsException("NoSuchMethodException.", e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new ReflectionUtilsException("IllegalAccessException", e);
-        }
-        catch (InvocationTargetException e)
-        {
-            throw new ReflectionUtilsException("InvocationTargetException", e);
-        }
-    }
-
-    /**
-     * Calls a constuctor witht the specified arguments.
-     *
-     * @param constructor The constructor.
-     * @param args        The arguments.
-     * @param <T>         The Class type.
-     *
-     * @return An instance of the class that the constructor is for.
-     */
-    public static <T> T newInstance(Constructor<T> constructor, Object[] args)
-    {
-        try
-        {
-            return constructor.newInstance(args);
-        }
-        catch (InstantiationException e)
-        {
-            throw new ReflectionUtilsException("InstantiationException", e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new ReflectionUtilsException("IllegalAccessException", e);
-        }
-        catch (InvocationTargetException e)
-        {
-            throw new ReflectionUtilsException("InvocationTargetException", e);
-        }
-    }
-
-    /**
-     * Gets the constructor of a class that takes the specified set of 
arguments if any matches. If no matching
-     * constructor is found then a runtime exception is raised.
-     *
-     * @param cls  The class to get a constructor from.
-     * @param args The arguments to match.
-     * @param <T>  The class type.
-     *
-     * @return The constructor.
-     */
-    public static <T> Constructor<T> getConstructor(Class<T> cls, Class[] args)
-    {
-        try
-        {
-            return cls.getConstructor(args);
-        }
-        catch (NoSuchMethodException e)
-        {
-            throw new ReflectionUtilsException("NoSuchMethodException", e);
-        }
-    }
-}
+/*
+ *
+ * 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.qpid.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * Provides helper methods for operating on classes and methods using 
reflection. Reflection methods tend to return
+ * a lot of checked exception so writing code to use them can be tedious and 
harder to read, especially when such errors
+ * are not expected to occur. This class always works with [EMAIL PROTECTED] 
ReflectionUtilsException}, which is a runtime exception,
+ * to wrap the checked exceptions raised by the standard Java reflection 
methods. Code using it does not normally
+ * expect these errors to occur, usually does not have a recovery mechanism 
for them when they do, but is cleaner,
+ * quicker to write and easier to read in the majority of cases.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Look up Classes by name.
+ * <tr><td> Instantiate Classes by no-arg constructor.
+ * </table>
+ */
+public class ReflectionUtils
+{
+    /**
+    * Gets the Class object for a named class.
+    *
+    * @param className The class to get the Class object for.
+    *
+    * @return The Class object for the named class.
+    */
+    public static Class<?> forName(String className)
+    {
+        try
+        {
+            return Class.forName(className);
+        }
+        catch (ClassNotFoundException e)
+        {
+            throw new ReflectionUtilsException("ClassNotFoundException whilst 
finding class.", e);
+        }
+    }
+
+    /**
+     * Creates an instance of a Class, instantiated through its no-args 
constructor.
+     *
+     * @param cls The Class to instantiate.
+     * @param <T> The Class type.
+     *
+     * @return An instance of the class.
+     */
+    public static <T> T newInstance(Class<? extends T> cls)
+    {
+        try
+        {
+            return cls.newInstance();
+        }
+        catch (InstantiationException e)
+        {
+            throw new ReflectionUtilsException("InstantiationException whilst 
instantiating class.", e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new ReflectionUtilsException("IllegalAccessException whilst 
instantiating class.", e);
+        }
+    }
+
+    /**
+     * Calls a named method on an object with a specified set of parameters, 
any Java access modifier are overridden.
+     *
+     * @param o            The object to call.
+     * @param method       The method name to call.
+     * @param params       The parameters to pass.
+     * @param paramClasses The argument types.
+     *
+     * @return The return value from the method call.
+     */
+    public static Object callMethodOverridingIllegalAccess(Object o, String 
method, Object[] params, Class[] paramClasses)
+    {
+        // Get the objects class.
+        Class cls = o.getClass();
+
+        // Get the classes of the parameters.
+        /*Class[] paramClasses = new Class[params.length];
+
+        for (int i = 0; i < params.length; i++)
+        {
+            paramClasses[i] = params[i].getClass();
+        }*/
+
+        try
+        {
+            // Try to find the matching method on the class.
+            Method m = cls.getDeclaredMethod(method, paramClasses);
+
+            // Make it accessible.
+            m.setAccessible(true);
+
+            // Invoke it with the parameters.
+            return m.invoke(o, params);
+        }
+        catch (NoSuchMethodException e)
+        {
+            throw new ReflectionUtilsException("NoSuchMethodException.", e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new ReflectionUtilsException("IllegalAccessException.", e);
+        }
+        catch (InvocationTargetException e)
+        {
+            throw new ReflectionUtilsException("InvocationTargetException", e);
+        }
+    }
+
+    /**
+     * Calls a named method on an object with a specified set of parameters.
+     *
+     * @param o      The object to call.
+     * @param method The method name to call.
+     * @param params The parameters to pass.
+     *
+     * @return The return value from the method call.
+     */
+    public static Object callMethod(Object o, String method, Object[] params)
+    {
+        // Get the objects class.
+        Class cls = o.getClass();
+
+        // Get the classes of the parameters.
+        Class[] paramClasses = new Class[params.length];
+
+        for (int i = 0; i < params.length; i++)
+        {
+            paramClasses[i] = params[i].getClass();
+        }
+
+        try
+        {
+            // Try to find the matching method on the class.
+            Method m = cls.getMethod(method, paramClasses);
+
+            // Invoke it with the parameters.
+            return m.invoke(o, params);
+        }
+        catch (NoSuchMethodException e)
+        {
+            throw new ReflectionUtilsException("NoSuchMethodException.", e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new ReflectionUtilsException("IllegalAccessException", e);
+        }
+        catch (InvocationTargetException e)
+        {
+            throw new ReflectionUtilsException("InvocationTargetException", e);
+        }
+    }
+
+    /**
+     * Calls a constuctor witht the specified arguments.
+     *
+     * @param constructor The constructor.
+     * @param args        The arguments.
+     * @param <T>         The Class type.
+     *
+     * @return An instance of the class that the constructor is for.
+     */
+    public static <T> T newInstance(Constructor<T> constructor, Object[] args)
+    {
+        try
+        {
+            return constructor.newInstance(args);
+        }
+        catch (InstantiationException e)
+        {
+            throw new ReflectionUtilsException("InstantiationException", e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new ReflectionUtilsException("IllegalAccessException", e);
+        }
+        catch (InvocationTargetException e)
+        {
+            throw new ReflectionUtilsException("InvocationTargetException", e);
+        }
+    }
+
+    /**
+     * Gets the constructor of a class that takes the specified set of 
arguments if any matches. If no matching
+     * constructor is found then a runtime exception is raised.
+     *
+     * @param cls  The class to get a constructor from.
+     * @param args The arguments to match.
+     * @param <T>  The class type.
+     *
+     * @return The constructor.
+     */
+    public static <T> Constructor<T> getConstructor(Class<T> cls, Class[] args)
+    {
+        try
+        {
+            return cls.getConstructor(args);
+        }
+        catch (NoSuchMethodException e)
+        {
+            throw new ReflectionUtilsException("NoSuchMethodException", e);
+        }
+    }
+}

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtilsException.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtilsException.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtilsException.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtilsException.java
 Thu Apr 24 10:49:03 2008
@@ -1,44 +1,44 @@
-/*
- *
- * 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.qpid.util;
-
-/**
- * Wraps a checked exception that occurs when [EMAIL PROTECTED] 
ReflectionUtils} encounters checked exceptions using standard
- * Java reflection methods.
- *
- * <p/><table id="crc"><caption>CRC Card</caption>
- * <tr><th> Responsibilities <th> Collaborations
- * <tr><td> Wrap a checked reflection exception.
- * </table>
- */
-public class ReflectionUtilsException extends RuntimeException
-{
-    /**
-     * Creates a runtime reflection exception, from a checked one.
-     *
-     * @param message The message.
-     * @param cause   The causing exception.
-     */
-    public ReflectionUtilsException(String message, Throwable cause)
-    {
-        super(message, cause);
-    }
-}
+/*
+ *
+ * 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.qpid.util;
+
+/**
+ * Wraps a checked exception that occurs when [EMAIL PROTECTED] 
ReflectionUtils} encounters checked exceptions using standard
+ * Java reflection methods.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Wrap a checked reflection exception.
+ * </table>
+ */
+public class ReflectionUtilsException extends RuntimeException
+{
+    /**
+     * Creates a runtime reflection exception, from a checked one.
+     *
+     * @param message The message.
+     * @param cause   The causing exception.
+     */
+    public ReflectionUtilsException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+}

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/ReflectionUtilsException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/Serial.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/AlreadyUnblockedException.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/AlreadyUnblockedException.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/AlreadyUnblockedException.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/AlreadyUnblockedException.java
 Thu Apr 24 10:49:03 2008
@@ -1,13 +1,13 @@
-package org.apache.qpid.util.concurrent;
-
-/**
- * Used to signal that a data element and its producer cannot be requeued or 
sent an error message when using a
- * [EMAIL PROTECTED] BatchSynchQueue} because the producer has already been 
unblocked by an unblocking take on the queue.
- *
- * <p/><table id="crc"><caption>CRC Card</caption>
- * <tr><th> Responsibilities <th> Collaborations
- * <tr><td> Signal that an unblocking take has already occurred.
- * </table>
- */
-public class AlreadyUnblockedException extends RuntimeException
-{ }
+package org.apache.qpid.util.concurrent;
+
+/**
+ * Used to signal that a data element and its producer cannot be requeued or 
sent an error message when using a
+ * [EMAIL PROTECTED] BatchSynchQueue} because the producer has already been 
unblocked by an unblocking take on the queue.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Signal that an unblocking take has already occurred.
+ * </table>
+ */
+public class AlreadyUnblockedException extends RuntimeException
+{ }

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/AlreadyUnblockedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/BatchSynchQueue.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/BatchSynchQueue.java?rev=651325&r1=651324&r2=651325&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/BatchSynchQueue.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/BatchSynchQueue.java
 Thu Apr 24 10:49:03 2008
@@ -1,101 +1,101 @@
-package org.apache.qpid.util.concurrent;
-
-import java.util.Collection;
-import java.util.concurrent.BlockingQueue;
-
-/**
- * BatchSynchQueue is an abstraction of the classic producer/consumer buffer 
pattern for thread interaction. In this
- * pattern threads can deposit data onto a buffer whilst other threads take 
data from the buffer and perform usefull
- * work with it. A BatchSynchQueue adds to this the possibility that producers 
can be blocked until their data is
- * consumed or until a consumer chooses to release the producer some time 
after consuming the data from the queue.
- *
- * <p>There are a number of possible advantages to using this technique when 
compared with having the producers
- * processing their own data:
- *
- * <ul>
- * <li>Data may be deposited asynchronously in the buffer allowing the 
producers to continue running.</li>
- * <li>Data may be deposited synchronously in the buffer so that producers 
wait until their data has been processed
- *     before being allowed to continue.</li>
- * <li>Variable rates of production/consumption can be smoothed over by the 
buffer as it provides space in memory to
- *     hold data between production and consumption.</li>
- * <li>Consumers may be able to batch data as they consume it leading to more 
efficient consumption over
- *     individual data item consumption where latency associated with the 
consume operation can be ammortized.
- *     For example, it may be possibly to ammortize the cost of a disk seek 
over many producers.</li>
- * <li>Data from seperate threads can be combined together in the buffer, 
providing a convenient way of spreading work
- *     amongst many workers and gathering the results together again.</li>
- * <li>Different types of queue can be used to hold the buffer, resulting in 
different processing orders. For example,
- *     lifo, fifo, priority heap, etc.</li>
- * </ul>
- *
- * <p/>The asynchronous type of producer/consumer buffers is already well 
supported by the java.util.concurrent package
- * (in Java 5) and there is also a synchronous queue implementation available 
there too. This interface extends the
- * blocking queue with some more methods for controlling a synchronous 
blocking queue. In particular it adds additional
- * take methods that can be used to take data from a queue without releasing 
producers, so that consumers have an
- * opportunity to confirm correct processing of the data before producers are 
released. It also adds a put method with
- * exceptions so that consumers can signal exception cases back to producers 
where there are errors in the data.
- *
- * <p/>This type of queue is usefull in situations where consumers can obtain 
an efficiency gain by batching data
- * from many threads but where synchronous handling of that data is neccessary 
because producers need to know that
- * their data has been processed before they continue. For example, sending a 
bundle of messages together, or writing
- * many records to disk at once, may result in improved performance but the 
originators of the messages or disk records
- * need confirmation that their data has really been sent or saved to disk.
- *
- * <p/>The consumer can put an element back onto the queue or send an error 
message to the elements producer using the
- * [EMAIL PROTECTED] SynchRecord} interface.
- *
- * <p/>The [EMAIL PROTECTED] #take()}, [EMAIL PROTECTED] 
#drainTo(java.util.Collection<? super E>)}  and
- * [EMAIL PROTECTED] #drainTo(java.util.Collection<? super E>, int)} methods 
from [EMAIL PROTECTED] BlockingQueue} should behave as if they
- * have been called with unblock set to false. That is they take elements from 
the queue but leave the producers
- * blocked. These methods do not return collections of [EMAIL PROTECTED] 
SynchRecord}s so they do not supply an interface through
- * which errors or re-queuings can be applied. If these methods are used then 
the consumer must succesfully process
- * all the records it takes.
- *
- * <p/>The [EMAIL PROTECTED] #put} method should silently swallow any 
exceptions that consumers attempt to return to the caller.
- * In order to handle exceptions the [EMAIL PROTECTED] #tryPut} method must be 
used.
- *
- * <p/><table id="crc"><caption>CRC Card</caption>
- * <tr><th> Responsibilities <th> Collaborations
- * <tr><td> Handle synchronous puts, with possible exceptions.
- * <tr><td> Allow consumers to take many records from a queue in a batch.
- * <tr><td> Allow consumers to decide when to unblock synchronous producers.
- * </table>
- */
-public interface BatchSynchQueue<E> extends BlockingQueue<E>
-{
-    /**
-     * Tries a synchronous put into the queue. If a consumer encounters an 
exception condition whilst processing the
-     * data that is put, then this is returned to the caller wrapped inside a 
[EMAIL PROTECTED] SynchException}.
-     *
-     * @param e The data element to put into the queue.
-     *
-     * @throws InterruptedException If the thread is interrupted whilst 
waiting to write to the queue or whilst waiting
-     *                              on its entry in the queue being consumed.
-     * @throws SynchException       If a consumer encounters an error whilst 
processing the data element.
-     */
-    public void tryPut(E e) throws InterruptedException, SynchException;
-
-    /**
-     * Takes all available data items from the queue or blocks until some 
become available. The returned items
-     * are wrapped in a [EMAIL PROTECTED] SynchRecord} which provides an 
interface to requeue them or send errors to their
-     * producers, where the producers are still blocked.
-     *
-     * @param c       The collection to drain the data items into.
-     * @param unblock If set to <tt>true</tt> the producers for the taken 
items will be immediately unblocked.
-     *
-     * @return A count of the number of elements that were drained from the 
queue.
-     */
-    public SynchRef drainTo(Collection<SynchRecord<E>> c, boolean unblock);
-
-    /**
-     * Takes up to maxElements available data items from the queue or blocks 
until some become available. The returned
-     * items are wrapped in a [EMAIL PROTECTED] SynchRecord} which provides an 
interface to requeue them or send errors to their
-     * producers, where the producers are still blocked.
-     *
-     * @param c           The collection to drain the data items into.
-     * @param maxElements The maximum number of elements to drain.
-     * @param unblock     If set to <tt>true</tt> the producers for the taken 
items will be immediately unblocked.
-     *
-     * @return A count of the number of elements that were drained from the 
queue.
-     */
-    public SynchRef drainTo(Collection<SynchRecord<E>> c, int maxElements, 
boolean unblock);
-}
+package org.apache.qpid.util.concurrent;
+
+import java.util.Collection;
+import java.util.concurrent.BlockingQueue;
+
+/**
+ * BatchSynchQueue is an abstraction of the classic producer/consumer buffer 
pattern for thread interaction. In this
+ * pattern threads can deposit data onto a buffer whilst other threads take 
data from the buffer and perform usefull
+ * work with it. A BatchSynchQueue adds to this the possibility that producers 
can be blocked until their data is
+ * consumed or until a consumer chooses to release the producer some time 
after consuming the data from the queue.
+ *
+ * <p>There are a number of possible advantages to using this technique when 
compared with having the producers
+ * processing their own data:
+ *
+ * <ul>
+ * <li>Data may be deposited asynchronously in the buffer allowing the 
producers to continue running.</li>
+ * <li>Data may be deposited synchronously in the buffer so that producers 
wait until their data has been processed
+ *     before being allowed to continue.</li>
+ * <li>Variable rates of production/consumption can be smoothed over by the 
buffer as it provides space in memory to
+ *     hold data between production and consumption.</li>
+ * <li>Consumers may be able to batch data as they consume it leading to more 
efficient consumption over
+ *     individual data item consumption where latency associated with the 
consume operation can be ammortized.
+ *     For example, it may be possibly to ammortize the cost of a disk seek 
over many producers.</li>
+ * <li>Data from seperate threads can be combined together in the buffer, 
providing a convenient way of spreading work
+ *     amongst many workers and gathering the results together again.</li>
+ * <li>Different types of queue can be used to hold the buffer, resulting in 
different processing orders. For example,
+ *     lifo, fifo, priority heap, etc.</li>
+ * </ul>
+ *
+ * <p/>The asynchronous type of producer/consumer buffers is already well 
supported by the java.util.concurrent package
+ * (in Java 5) and there is also a synchronous queue implementation available 
there too. This interface extends the
+ * blocking queue with some more methods for controlling a synchronous 
blocking queue. In particular it adds additional
+ * take methods that can be used to take data from a queue without releasing 
producers, so that consumers have an
+ * opportunity to confirm correct processing of the data before producers are 
released. It also adds a put method with
+ * exceptions so that consumers can signal exception cases back to producers 
where there are errors in the data.
+ *
+ * <p/>This type of queue is usefull in situations where consumers can obtain 
an efficiency gain by batching data
+ * from many threads but where synchronous handling of that data is neccessary 
because producers need to know that
+ * their data has been processed before they continue. For example, sending a 
bundle of messages together, or writing
+ * many records to disk at once, may result in improved performance but the 
originators of the messages or disk records
+ * need confirmation that their data has really been sent or saved to disk.
+ *
+ * <p/>The consumer can put an element back onto the queue or send an error 
message to the elements producer using the
+ * [EMAIL PROTECTED] SynchRecord} interface.
+ *
+ * <p/>The [EMAIL PROTECTED] #take()}, [EMAIL PROTECTED] 
#drainTo(java.util.Collection<? super E>)}  and
+ * [EMAIL PROTECTED] #drainTo(java.util.Collection<? super E>, int)} methods 
from [EMAIL PROTECTED] BlockingQueue} should behave as if they
+ * have been called with unblock set to false. That is they take elements from 
the queue but leave the producers
+ * blocked. These methods do not return collections of [EMAIL PROTECTED] 
SynchRecord}s so they do not supply an interface through
+ * which errors or re-queuings can be applied. If these methods are used then 
the consumer must succesfully process
+ * all the records it takes.
+ *
+ * <p/>The [EMAIL PROTECTED] #put} method should silently swallow any 
exceptions that consumers attempt to return to the caller.
+ * In order to handle exceptions the [EMAIL PROTECTED] #tryPut} method must be 
used.
+ *
+ * <p/><table id="crc"><caption>CRC Card</caption>
+ * <tr><th> Responsibilities <th> Collaborations
+ * <tr><td> Handle synchronous puts, with possible exceptions.
+ * <tr><td> Allow consumers to take many records from a queue in a batch.
+ * <tr><td> Allow consumers to decide when to unblock synchronous producers.
+ * </table>
+ */
+public interface BatchSynchQueue<E> extends BlockingQueue<E>
+{
+    /**
+     * Tries a synchronous put into the queue. If a consumer encounters an 
exception condition whilst processing the
+     * data that is put, then this is returned to the caller wrapped inside a 
[EMAIL PROTECTED] SynchException}.
+     *
+     * @param e The data element to put into the queue.
+     *
+     * @throws InterruptedException If the thread is interrupted whilst 
waiting to write to the queue or whilst waiting
+     *                              on its entry in the queue being consumed.
+     * @throws SynchException       If a consumer encounters an error whilst 
processing the data element.
+     */
+    public void tryPut(E e) throws InterruptedException, SynchException;
+
+    /**
+     * Takes all available data items from the queue or blocks until some 
become available. The returned items
+     * are wrapped in a [EMAIL PROTECTED] SynchRecord} which provides an 
interface to requeue them or send errors to their
+     * producers, where the producers are still blocked.
+     *
+     * @param c       The collection to drain the data items into.
+     * @param unblock If set to <tt>true</tt> the producers for the taken 
items will be immediately unblocked.
+     *
+     * @return A count of the number of elements that were drained from the 
queue.
+     */
+    public SynchRef drainTo(Collection<SynchRecord<E>> c, boolean unblock);
+
+    /**
+     * Takes up to maxElements available data items from the queue or blocks 
until some become available. The returned
+     * items are wrapped in a [EMAIL PROTECTED] SynchRecord} which provides an 
interface to requeue them or send errors to their
+     * producers, where the producers are still blocked.
+     *
+     * @param c           The collection to drain the data items into.
+     * @param maxElements The maximum number of elements to drain.
+     * @param unblock     If set to <tt>true</tt> the producers for the taken 
items will be immediately unblocked.
+     *
+     * @return A count of the number of elements that were drained from the 
queue.
+     */
+    public SynchRef drainTo(Collection<SynchRecord<E>> c, int maxElements, 
boolean unblock);
+}

Propchange: 
incubator/qpid/trunk/qpid/java/common/src/main/java/org/apache/qpid/util/concurrent/BatchSynchQueue.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to