You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/01 00:37:29 UTC
svn commit: r418401 [11/32] - in /incubator/openjpa/trunk: openjpa-lib/
openjpa-lib/src/main/java/org/apache/openjpa/lib/ant/
openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/
openjpa-lib/src/main/java/org/apache/openjpa/lib/jdbc/ openjpa-lib/src/...
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Options.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -15,285 +12,247 @@
*/
package org.apache.openjpa.lib.util;
+import java.lang.reflect.*;
+import java.util.*;
import org.apache.commons.collections.*;
import org.apache.commons.lang.*;
import org.apache.commons.lang.exception.*;
-
import serp.util.*;
-import java.lang.reflect.*;
-
-import java.util.*;
-
-
/**
- * <p>A specialization of the {@link Properties} map type with the added
- * abilities to read application options from the command line and to
- * use bean patterns to set an object's properties via command-line the
- * stored mappings.</p>
- *
- * <p>A typical use pattern for this class is to construct a new instance
- * in the <code>main</code> method, then call {@link #setFromCmdLine} with the
- * given args. Next, an instanceof the class being invoked is created, and
- * {@link #setInto} is called with that instance as a parameter. With this
- * pattern, the user can configure any bean properties of the class, or even
- * properties of classes reachable from the class, through the command
- * line.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * A specialization of the {@link Properties} map type with the added
+ * abilities to read application options from the command line and to
+ * use bean patterns to set an object's properties via command-line the
+ * stored mappings.
+ * A typical use pattern for this class is to construct a new instance
+ * in the <code>main</code> method, then call {@link #setFromCmdLine} with the
+ * given args. Next, an instanceof the class being invoked is created, and
+ * {@link #setInto} is called with that instance as a parameter. With this
+ * pattern, the user can configure any bean properties of the class, or even
+ * properties of classes reachable from the class, through the command line.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public class Options extends TypedProperties {
// maps primitive types to the appropriate wrapper class and default value
private static Object[][] _primWrappers = new Object[][] {
- { boolean.class, Boolean.class, Boolean.FALSE },
- { byte.class, Byte.class, new Byte((byte) 0) },
- { char.class, Character.class, new Character((char) 0) },
- { double.class, Double.class, new Double(0D) },
- { float.class, Float.class, new Float(0F) },
- { int.class, Integer.class, new Integer(0) },
- { long.class, Long.class, new Long(0L) },
- { short.class, Short.class, new Short((short) 0) },
- };
+ { boolean.class, Boolean.class, Boolean.FALSE },
+ { byte.class, Byte.class, new Byte((byte) 0) },
+ { char.class, Character.class, new Character((char) 0) },
+ { double.class, Double.class, new Double(0D) },
+ { float.class, Float.class, new Float(0F) },
+ { int.class, Integer.class, new Integer(0) },
+ { long.class, Long.class, new Long(0L) },
+ { short.class, Short.class, new Short((short) 0) }, };
/**
- * Default constructor.
+ * Default constructor.
*/
public Options() {
super();
}
/**
- * Construct the options instance with the given set of defaults.
- *
- * @see Properties#Properties(Properties)
+ * Construct the options instance with the given set of defaults.
+ *
+ * @see Properties#Properties(Properties)
*/
public Options(Properties defaults) {
super(defaults);
}
/**
- * Parses the given argument list into flag/value pairs, which are stored
- * as properties. Flags that are present without values are given
- * the value "true". If any flag is found for which there is already
- * a mapping present, the existing mapping will be overwritten.
- * Flags should be of the form:<br />
- * <code>java Foo -flag1 value1 -flag2 value2 ... arg1 arg2 ...</code>
- *
- * @param args the command-line arguments
- * @return all arguments in the original array beyond the
- * flag/value pair list
- * @author Patrick Linskey
+ * Parses the given argument list into flag/value pairs, which are stored
+ * as properties. Flags that are present without values are given
+ * the value "true". If any flag is found for which there is already
+ * a mapping present, the existing mapping will be overwritten.
+ * Flags should be of the form:<br />
+ * <code>java Foo -flag1 value1 -flag2 value2 ... arg1 arg2 ...</code>
+ *
+ * @param args the command-line arguments
+ * @return all arguments in the original array beyond the
+ * flag/value pair list
+ * @author Patrick Linskey
*/
public String[] setFromCmdLine(String[] args) {
- if ((args == null) || (args.length == 0)) {
+ if (args == null || args.length == 0)
return args;
- }
String key = null;
String value = null;
List remainder = new LinkedList();
-
- for (int i = 0; i < (args.length + 1); i++) {
- if ((i == args.length) || args[i].startsWith("-")) {
+ for (int i = 0; i < args.length + 1; i++) {
+ if (i == args.length || args[i].startsWith("-")) {
key = trimQuote(key);
-
if (key != null) {
- if ((value != null) && (value.length() > 0)) {
+ if (value != null && value.length() > 0)
setProperty(key, trimQuote(value));
- } else {
+ else
setProperty(key, "true");
- }
}
- if (i == args.length) {
+ if (i == args.length)
break;
- } else {
+ else {
key = args[i].substring(1);
value = null;
}
} else if (key != null) {
setProperty(key, trimQuote(args[i]));
key = null;
- } else {
+ } else
remainder.add(args[i]);
- }
}
- return (String[]) remainder.toArray(new String[remainder.size()]);
+ return(String[]) remainder.toArray(new String[remainder.size()]);
}
/**
- * This method uses reflection to set all the properties in the given
- * object that are named by the keys in this map. For a given key 'foo',
- * the algorithm will look for a 'setFoo' method in the given instance.
- * For a given key 'foo.bar', the algorithm will first look for a
- * 'getFoo' method in the given instance, then will recurse on the return
- * value of that method, now looking for the 'bar' property. This allows
- * the setting of nested object properties. If in the above example the
- * 'getFoo' method is not present or returns null, the algorithm will
- * look for a 'setFoo' method; if found it will constrct a new instance
- * of the correct type, set it using the 'setFoo' method, then recurse on
- * it as above. Property names can be nested in this way to an arbitrary
- * depth. For setter methods that take multiple parameters, the value
- * mapped to the key can use the ',' as an argument separator character.
- * If not enough values are present for a given method after splitting
- * the string on ',', the remaining arguments will receive default
- * values. All arguments are converted from string form to the
- * correct type if possible (i.e. if the type is primitive,
- * java.lang.Clas, or has a constructor that takes a single string
- * argument). Examples:
- * <ul>
- * <li>Map Entry: <code>"age"->"12"</code><br />
- * Resultant method call: <code>obj.setAge (12)</code></li>
- * <li>Map Entry: <code>"range"->"1,20"</code><br />
- * Resultant method call: <code>obj.setRange (1, 20)</code></li>
- * <li>Map Entry: <code>"range"->"10"</code><br />
- * Resultant method call: <code>obj.setRange (10, 10)</code></li>
- * <li>Map Entry: <code>"brother.name"->"Bob"</code><br />
- * Resultant method call: <code>obj.getBrother ().setName ("Bob")
- * <code></li>
- * </ul>
- *
+ * This method uses reflection to set all the properties in the given
+ * object that are named by the keys in this map. For a given key 'foo',
+ * the algorithm will look for a 'setFoo' method in the given instance.
+ * For a given key 'foo.bar', the algorithm will first look for a
+ * 'getFoo' method in the given instance, then will recurse on the return
+ * value of that method, now looking for the 'bar' property. This allows
+ * the setting of nested object properties. If in the above example the
+ * 'getFoo' method is not present or returns null, the algorithm will
+ * look for a 'setFoo' method; if found it will constrct a new instance
+ * of the correct type, set it using the 'setFoo' method, then recurse on
+ * it as above. Property names can be nested in this way to an arbitrary
+ * depth. For setter methods that take multiple parameters, the value
+ * mapped to the key can use the ',' as an argument separator character.
+ * If not enough values are present for a given method after splitting
+ * the string on ',', the remaining arguments will receive default
+ * values. All arguments are converted from string form to the
+ * correct type if possible(i.e. if the type is primitive,
+ * java.lang.Clas, or has a constructor that takes a single string
+ * argument). Examples:
+ * <ul>
+ * <li>Map Entry: <code>"age"->"12"</code><br />
+ * Resultant method call: <code>obj.setAge(12)</code></li>
+ * <li>Map Entry: <code>"range"->"1,20"</code><br />
+ * Resultant method call: <code>obj.setRange(1, 20)</code></li>
+ * <li>Map Entry: <code>"range"->"10"</code><br />
+ * Resultant method call: <code>obj.setRange(10, 10)</code></li>
+ * <li>Map Entry: <code>"brother.name"->"Bob"</code><br />
+ * Resultant method call: <code>obj.getBrother().setName("Bob")
+ * <code></li>
+ * </ul>
* Any keys present in the map for which there is no
- * corresponding property in the given object will be ignored,
- * and will be returned in the {@link Map} returned by this
- * method.
- *
- * @return a {@link Map} of key-value pairs in this object
- * for which no setters could be found.
- * @throws RuntimeException on parse error
+ * corresponding property in the given object will be ignored,
+ * and will be returned in the {@link Map} returned by this method.
+ *
+ * @return a {@link Map} of key-value pairs in this object
+ * for which no setters could be found.
+ * @throws RuntimeException on parse error
*/
public Map setInto(Object obj) {
- // set all defaults that have no explicit value
+ // set all defaults that have no explicit value
Map.Entry entry = null;
-
if (defaults != null) {
for (Iterator itr = defaults.entrySet().iterator(); itr.hasNext();) {
entry = (Map.Entry) itr.next();
-
- if (!containsKey(entry.getKey())) {
+ if (!containsKey(entry.getKey()))
setInto(obj, entry);
- }
}
}
// set from main map
Map invalidEntries = null;
Map.Entry e;
-
for (Iterator itr = entrySet().iterator(); itr.hasNext();) {
e = (Map.Entry) itr.next();
-
if (!setInto(obj, e)) {
- if (invalidEntries == null) {
+ if (invalidEntries == null)
invalidEntries = new HashMap();
- }
-
invalidEntries.put(e.getKey(), e.getValue());
}
}
- return (invalidEntries == null) ? Collections.EMPTY_MAP : invalidEntries;
+ return(invalidEntries == null) ? Collections.EMPTY_MAP : invalidEntries;
}
/**
- * Sets the property named by the key of the given entry in the
- * given object.
- *
- * @return <code>true</code> if the set succeeded, or
- * <code>false</code> if no method could be found for
- * this property.
+ * Sets the property named by the key of the given entry in the
+ * given object.
+ *
+ * @return <code>true</code> if the set succeeded, or
+ * <code>false</code> if no method could be found for this property.
*/
private boolean setInto(Object obj, Map.Entry entry) {
- if (entry.getKey() == null) {
+ if (entry.getKey() == null)
return false;
- }
try {
// look for matching parameter of object
Object[] match = new Object[] { obj, null };
-
- if (!matchOptionToMember(entry.getKey().toString(), match)) {
+ if (!matchOptionToMember(entry.getKey().toString(), match))
return false;
- }
Class[] type = getType(match[1]);
Object[] values = new Object[type.length];
String[] strValues;
-
- if (entry.getValue() == null) {
+ if (entry.getValue() == null)
strValues = new String[1];
- } else if (values.length == 1) {
+ else if (values.length == 1)
strValues = new String[] { entry.getValue().toString() };
- } else {
+ else
strValues = Strings.split(entry.getValue().toString(), ",", 0);
- }
// convert the string values into parameter values, if not
// enough string values repeat last one for rest
for (int i = 0; i < strValues.length; i++)
values[i] = stringToObject(strValues[i].trim(), type[i]);
-
for (int i = strValues.length; i < values.length; i++)
values[i] = getDefaultValue(type[i]);
// invoke the setter / set the field
invoke(match[0], match[1], values);
-
return true;
} catch (Throwable t) {
- throw new ParseException(obj + "." + entry.getKey() + " = " +
- entry.getValue(), t);
+ throw new ParseException(obj + "." + entry.getKey()
+ + " = " + entry.getValue(), t);
}
}
/**
- * Removes leading and trailing single quotes from the given String,
- * if any.
- */
+ * Removes leading and trailing single quotes from the given String, if any.
+ */
private static String trimQuote(String val) {
- if ((val != null) && val.startsWith("'") && val.endsWith("'")) {
+ if (val != null && val.startsWith("'") && val.endsWith("'"))
return val.substring(1, val.length() - 1);
- }
-
return val;
}
/**
- * Finds all the options that can be set on the provided class. This does
- * not look for path-traversal expressions.
- *
- * @param type The class for which available options should be listed.
- * @return The available option names in <code>type</code>. The
- * names will have initial caps. They will be ordered
- * alphabetically.
+ * Finds all the options that can be set on the provided class. This does
+ * not look for path-traversal expressions.
+ *
+ * @param type The class for which available options should be listed.
+ * @return The available option names in <code>type</code>. The
+ * names will have initial caps. They will be ordered alphabetically.
*/
public static Collection findOptionsFor(Class type) {
Collection names = new TreeSet();
-
// look for a setter method matching the key
Method[] meths = type.getMethods();
Class[] params;
-
for (int i = 0; i < meths.length; i++) {
if (meths[i].getName().startsWith("set")) {
params = meths[i].getParameterTypes();
-
- if (params.length == 0) {
+ if (params.length == 0)
continue;
- }
-
- if (params[0].isArray()) {
+ if (params[0].isArray())
continue;
- }
- names.add(StringUtils.capitalize(meths[i].getName().substring(3)));
+ names.add(StringUtils.capitalize(
+ meths[i].getName().substring(3)));
}
}
// check for public fields
Field[] fields = type.getFields();
-
for (int i = 0; i < fields.length; i++)
names.add(StringUtils.capitalize(fields[i].getName()));
@@ -301,27 +260,25 @@
}
/**
- * Matches a key to an object/setter pair.
- *
- * @param key the key given at the command line; may be of the form
- * 'foo.bar' to signify the 'bar' property of the
- * 'foo' owned object
- * @param match an array of length 2, where the first index is set
- * to the object to retrieve the setter for
- * @return true if a match was made, false otherwise; additionally,
- * the first index of the match array will be set to
- * the matching object and the second index will be
- * set to the setter method or public field for the
- * property named by the key
+ * Matches a key to an object/setter pair.
+ *
+ * @param key the key given at the command line; may be of the form
+ * 'foo.bar' to signify the 'bar' property of the 'foo' owned object
+ * @param match an array of length 2, where the first index is set
+ * to the object to retrieve the setter for
+ * @return true if a match was made, false otherwise; additionally,
+ * the first index of the match array will be set to
+ * the matching object and the second index will be
+ * set to the setter method or public field for the
+ * property named by the key
*/
private static boolean matchOptionToMember(String key, Object[] match)
throws Exception {
- if ((key == null) || (key.length() == 0)) {
+ if (key == null || key.length() == 0)
return false;
- }
// unfortunately we can't use bean properties for setters; any
- // setter with more than 1 arg is ignored; calc setter and getter
+ // setter with more than 1 arg is ignored; calc setter and getter
// name to look for
String[] find = Strings.split(key, ".", 2);
String base = StringUtils.capitalise(find[0]);
@@ -334,157 +291,124 @@
Method setMeth = null;
Method getMeth = null;
Class[] params;
-
for (int i = 0; i < meths.length; i++) {
if (meths[i].getName().equals(set)) {
params = meths[i].getParameterTypes();
-
- if (params.length == 0) {
+ if (params.length == 0)
continue;
- }
-
- if (params[0].isArray()) {
+ if (params[0].isArray())
continue;
- }
// use this method if we haven't found any other setter, if
// it has less parameters than any other setter, or if it uses
// string parameters
- if (setMeth == null) {
+ if (setMeth == null)
setMeth = meths[i];
- } else if (params.length < setMeth.getParameterTypes().length) {
+ else if (params.length < setMeth.getParameterTypes().length)
setMeth = meths[i];
- } else if ((params.length == setMeth.getParameterTypes().length) &&
- (params[0] == String.class)) {
+ else if (params.length == setMeth.getParameterTypes().length
+ && params[0] == String.class)
setMeth = meths[i];
- }
- } else if (meths[i].getName().equals(get)) {
+ } else if (meths[i].getName().equals(get))
getMeth = meths[i];
- }
}
// if no methods found, check for public field
Member setter = setMeth;
Member getter = getMeth;
-
if (setter == null) {
Field[] fields = type.getFields();
String uncapBase = StringUtils.uncapitalise(find[0]);
-
for (int i = 0; i < fields.length; i++) {
- if (fields[i].getName().equals(base) ||
- fields[i].getName().equals(uncapBase)) {
+ if (fields[i].getName().equals(base)
+ || fields[i].getName().equals(uncapBase)) {
setter = fields[i];
getter = fields[i];
-
break;
}
}
}
// if no way to access property, give up
- if ((setter == null) && (getter == null)) {
+ if (setter == null && getter == null)
return false;
- }
// recurse on inner object with remainder of key?
if (find.length > 1) {
Object inner = null;
-
- if (getter != null) {
+ if (getter != null)
inner = invoke(match[0], getter, null);
- }
- // if no getter or current inner is null, try to create a new
+ // if no getter or current inner is null, try to create a new
// inner instance and set it in object
- if ((inner == null) && (setter != null)) {
+ if (inner == null && setter != null) {
Class innerType = getType(setter)[0];
inner = innerType.newInstance();
invoke(match[0], setter, new Object[] { inner });
}
-
match[0] = inner;
-
return matchOptionToMember(find[1], match);
}
// got match; find setter for property
match[1] = setter;
-
return match[1] != null;
}
/**
- * Return the types of the parameters needed to set the given member.
+ * Return the types of the parameters needed to set the given member.
*/
private static Class[] getType(Object member) {
- if (member instanceof Method) {
- return ((Method) member).getParameterTypes();
- }
-
+ if (member instanceof Method)
+ return((Method) member).getParameterTypes();
return new Class[] { ((Field) member).getType() };
}
/**
- * Set the given member to the given value(s).
+ * Set the given member to the given value(s).
*/
private static Object invoke(Object target, Object member, Object[] values)
throws Exception {
- if (member instanceof Method) {
- return ((Method) member).invoke(target, values);
- }
-
- if ((values == null) || (values.length == 0)) {
- return ((Field) member).get(target);
- }
-
+ if (member instanceof Method)
+ return((Method) member).invoke(target, values);
+ if (values == null || values.length == 0)
+ return((Field) member).get(target);
((Field) member).set(target, values[0]);
-
return null;
}
/**
- * Converts the given string into an object of the given type, or its
- * wrapper type if it is primitive.
+ * Converts the given string into an object of the given type, or its
+ * wrapper type if it is primitive.
*/
- private Object stringToObject(String str, Class type)
- throws Exception {
+ private Object stringToObject(String str, Class type) throws Exception {
// special case for null and for strings
- if ((str == null) || (type == String.class)) {
+ if (str == null || type == String.class)
return str;
- }
// special case for creating Class instances
- if (type == Class.class) {
+ if (type == Class.class)
return Class.forName(str, false, getClass().getClassLoader());
- }
// special case for numeric types that end in .0; strip the decimal
// places because it can kill int, short, long parsing
- if (type.isPrimitive() || Number.class.isAssignableFrom(type)) {
- if ((str.length() > 2) && str.endsWith(".0")) {
+ if (type.isPrimitive() || Number.class.isAssignableFrom(type))
+ if (str.length() > 2 && str.endsWith(".0"))
str = str.substring(0, str.length() - 2);
- }
- }
// for primitives, recurse on wrapper type
- if (type.isPrimitive()) {
+ if (type.isPrimitive())
for (int i = 0; i < _primWrappers.length; i++)
- if (type == _primWrappers[i][0]) {
+ if (type == _primWrappers[i][0])
return stringToObject(str, (Class) _primWrappers[i][1]);
- }
- }
// look for a string constructor
Exception err = null;
-
try {
- Constructor cons = type.getConstructor(new Class[] { String.class });
-
- if ((type == Boolean.class) && "t".equalsIgnoreCase(str)) {
+ Constructor cons = type.getConstructor
+ (new Class[] { String.class });
+ if (type == Boolean.class && "t".equalsIgnoreCase(str))
str = "true";
- }
-
return cons.newInstance(new Object[] { str });
} catch (Exception e) {
err = e;
@@ -493,219 +417,178 @@
// special case: the arg value is a subtype name and a new instance
// of that type should be set as the object
Class subType = null;
-
try {
subType = Class.forName(str);
} catch (Exception e) {
throw err;
}
-
- if (!type.isAssignableFrom(subType)) {
+ if (!type.isAssignableFrom(subType))
throw err;
- }
-
return subType.newInstance();
}
/**
- * Returns the default value for the given parameter type.
+ * Returns the default value for the given parameter type.
*/
private Object getDefaultValue(Class type) {
for (int i = 0; i < _primWrappers.length; i++)
- if (_primWrappers[i][0] == type) {
+ if (_primWrappers[i][0] == type)
return _primWrappers[i][2];
- }
return null;
}
/**
- * Specialization of {@link #getBooleanProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link #getBooleanProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public boolean getBooleanProperty(String key, String key2, boolean def) {
String val = getProperty(key);
-
- if (val == null) {
+ if (val == null)
val = getProperty(key2);
- }
-
- if (val == null) {
+ if (val == null)
return def;
- }
-
return "t".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val);
}
/**
- * Specialization of {@link TypedProperties#getFloatProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#getFloatProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public float getFloatProperty(String key, String key2, float def) {
String val = getProperty(key);
-
- if (val == null) {
+ if (val == null)
val = getProperty(key2);
- }
-
- return (val == null) ? def : Float.parseFloat(val);
+ return(val == null) ? def : Float.parseFloat(val);
}
/**
- * Specialization of {@link TypedProperties#getDoubleProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#getDoubleProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public double getDoubleProperty(String key, String key2, double def) {
String val = getProperty(key);
-
- if (val == null) {
+ if (val == null)
val = getProperty(key2);
- }
-
- return (val == null) ? def : Double.parseDouble(val);
+ return(val == null) ? def : Double.parseDouble(val);
}
/**
- * Specialization of {@link TypedProperties#getLongProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#getLongProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public long getLongProperty(String key, String key2, long def) {
String val = getProperty(key);
-
- if (val == null) {
+ if (val == null)
val = getProperty(key2);
- }
-
- return (val == null) ? def : Long.parseLong(val);
+ return(val == null) ? def : Long.parseLong(val);
}
/**
- * Specialization of {@link TypedProperties#getIntProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#getIntProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public int getIntProperty(String key, String key2, int def) {
String val = getProperty(key);
-
- if (val == null) {
+ if (val == null)
val = getProperty(key2);
- }
-
- return (val == null) ? def : Integer.parseInt(val);
+ return(val == null) ? def : Integer.parseInt(val);
}
/**
- * Specialization of {@link Properties#getProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link Properties#getProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public String getProperty(String key, String key2, String def) {
String val = getProperty(key);
-
- return (val == null) ? getProperty(key2, def) : val;
+ return(val == null) ? getProperty(key2, def) : val;
}
/**
- * Specialization of {@link TypedProperties#removeBooleanProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#removeBooleanProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public boolean removeBooleanProperty(String key, String key2, boolean def) {
String val = removeProperty(key);
-
- if (val == null) {
+ if (val == null)
val = removeProperty(key2);
- } else {
+ else
removeProperty(key2);
- }
-
- if (val == null) {
+ if (val == null)
return def;
- }
-
return "t".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val);
}
/**
- * Specialization of {@link TypedProperties#removeFloatProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#removeFloatProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public float removeFloatProperty(String key, String key2, float def) {
String val = removeProperty(key);
-
- if (val == null) {
+ if (val == null)
val = removeProperty(key2);
- } else {
+ else
removeProperty(key2);
- }
-
- return (val == null) ? def : Float.parseFloat(val);
+ return(val == null) ? def : Float.parseFloat(val);
}
/**
- * Specialization of {@link TypedProperties#removeDoubleProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#removeDoubleProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public double removeDoubleProperty(String key, String key2, double def) {
String val = removeProperty(key);
-
- if (val == null) {
+ if (val == null)
val = removeProperty(key2);
- } else {
+ else
removeProperty(key2);
- }
-
- return (val == null) ? def : Double.parseDouble(val);
+ return(val == null) ? def : Double.parseDouble(val);
}
/**
- * Specialization of {@link TypedProperties#removeLongProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#removeLongProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public long removeLongProperty(String key, String key2, long def) {
String val = removeProperty(key);
-
- if (val == null) {
+ if (val == null)
val = removeProperty(key2);
- } else {
+ else
removeProperty(key2);
- }
-
- return (val == null) ? def : Long.parseLong(val);
+ return(val == null) ? def : Long.parseLong(val);
}
/**
- * Specialization of {@link TypedProperties#removeIntProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link TypedProperties#removeIntProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public int removeIntProperty(String key, String key2, int def) {
String val = removeProperty(key);
-
- if (val == null) {
+ if (val == null)
val = removeProperty(key2);
- } else {
+ else
removeProperty(key2);
- }
-
- return (val == null) ? def : Integer.parseInt(val);
+ return(val == null) ? def : Integer.parseInt(val);
}
/**
- * Specialization of {@link Properties#removeProperty} to allow
- * a value to appear under either of two keys; useful for short and
- * long versions of command-line flags.
+ * Specialization of {@link Properties#removeProperty} to allow
+ * a value to appear under either of two keys; useful for short and
+ * long versions of command-line flags.
*/
public String removeProperty(String key, String key2, String def) {
String val = removeProperty(key);
-
- return (val == null) ? removeProperty(key2, def) : val;
+ return(val == null) ? removeProperty(key2, def) : val;
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParameterTemplate.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParameterTemplate.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParameterTemplate.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParameterTemplate.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -16,228 +13,206 @@
package org.apache.openjpa.lib.util;
import java.io.*;
-
import java.util.*;
-
/**
- * <p>A template that allows parameter substitutions. Parameters should be
- * placed in the template in the form ${param-name}. Use the
- * {@link #setParameter} method to set the parameter values, which will be
- * substituted into the template on calls to {@link #write} and
- * {@link #toString}. If a parameter is encountered that hasn't been set, then
- * the parameter key is used to lookup the corresponding System property.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * A template that allows parameter substitutions. Parameters should be
+ * placed in the template in the form ${param-name}. Use the
+ * {@link #setParameter} method to set the parameter values, which will be
+ * substituted into the template on calls to {@link #write} and
+ * {@link #toString}. If a parameter is encountered that hasn't been set, then
+ * the parameter key is used to lookup the corresponding System property.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public class ParameterTemplate {
private static final String SEP = System.getProperty("line.separator");
+
private final StringBuffer _buf = new StringBuffer();
private final Map _params = new HashMap();
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(String value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(boolean value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(char value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(double value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(float value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(int value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(long value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(short value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(Object value) {
_buf.append(value);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(InputStream in) throws IOException {
return append(new InputStreamReader(in));
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(Reader reader) throws IOException {
BufferedReader buf = new BufferedReader(reader);
String line;
-
while ((line = buf.readLine()) != null)
_buf.append(line).append(SEP);
-
return this;
}
/**
- * Add the given value to the internal template.
+ * Add the given value to the internal template.
*/
public ParameterTemplate append(File file) throws IOException {
FileReader reader = new FileReader(file);
-
try {
return append(reader);
- } finally {
- try {
- reader.close();
- } catch (IOException ioe) {
- }
+ }
+ finally {
+ try { reader.close(); } catch (IOException ioe) {}
}
}
/**
- * Return true if the given parameter has been given a value.
+ * Return true if the given parameter has been given a value.
*/
public boolean hasParameter(String name) {
return _params.containsKey(name);
}
/**
- * Return the value set for the given parameter.
+ * Return the value set for the given parameter.
*/
public Object getParameter(String name) {
return _params.get(name);
}
/**
- * Set the value for the given parameter.
+ * Set the value for the given parameter.
*/
public Object setParameter(String name, Object val) {
return _params.put(name, val);
}
/**
- * Set the values for all the parameters in the given map.
+ * Set the values for all the parameters in the given map.
*/
public void setParameters(Map params) {
_params.putAll(params);
}
/**
- * Clear the recorded parameter values.
+ * Clear the recorded parameter values.
*/
public void clearParameters() {
_params.clear();
}
/**
- * Return a copy of the internal value template with all parameters
- * substituted with their current values.
+ * Return a copy of the internal value template with all parameters
+ * substituted with their current values.
*/
public String toString() {
- if ((_buf.length() == 0) || _params.isEmpty()) {
+ if (_buf.length() == 0 || _params.isEmpty())
return _buf.toString();
- }
StringBuffer copy = new StringBuffer();
StringBuffer param = null;
- char ch;
- char last = 0;
-
+ char ch, last = 0;
for (int i = 0; i < _buf.length(); i++) {
ch = _buf.charAt(i);
-
- if ((last == '$') && (ch == '{')) {
+ if (last == '$' && ch == '{') {
copy.deleteCharAt(copy.length() - 1);
param = new StringBuffer();
- } else if ((ch == '}') && (param != null)) {
- if (_params.containsKey(param.toString())) {
+ } else if (ch == '}' && param != null) {
+ if (_params.containsKey(param.toString()))
copy.append(_params.get(param.toString()));
- } else {
+ else
copy.append(System.getProperty(param.toString()));
- }
-
param = null;
- } else if (param != null) {
+ } else if (param != null)
param.append(ch);
- } else {
+ else
copy.append(ch);
- }
last = ch;
}
-
return copy.toString();
}
/**
- * Write the internal value template with all parameters
- * substituted with their current values.
+ * Write the internal value template with all parameters
+ * substituted with their current values.
*/
public void write(OutputStream out) throws IOException {
write(new OutputStreamWriter(out));
}
/**
- * Write the internal value template with all parameters
- * substituted with their current values.
+ * Write the internal value template with all parameters
+ * substituted with their current values.
*/
public void write(Writer writer) throws IOException {
writer.write(toString());
@@ -245,19 +220,16 @@
}
/**
- * Write the internal value template with all parameters
- * substituted with their current values.
+ * Write the internal value template with all parameters
+ * substituted with their current values.
*/
public void write(File file) throws IOException {
FileWriter writer = new FileWriter(file);
-
try {
write(writer);
- } finally {
- try {
- writer.close();
- } catch (IOException ioe) {
- }
+ }
+ finally {
+ try { writer.close(); } catch (IOException ioe) {}
}
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ParseException.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -17,13 +14,13 @@
import org.apache.commons.lang.exception.*;
-
/**
- * <p>Exception type for parse errors.</p>
- *
- * @author Abe White
- * @since 4.0
- * @nojavadoc */
+ * Exception type for parse errors.
+ *
+ * @author Abe White
+ * @since 4.0
+ * @nojavadoc
+ */
public class ParseException extends NestableRuntimeException {
public ParseException() {
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -16,19 +13,18 @@
package org.apache.openjpa.lib.util;
import java.io.*;
-
import java.lang.ref.*;
-
import java.util.*;
-
/**
- * <p>Map in which the key, value, or both may be weak/soft references.</p>
- *
- * @author Abe White
- * @since 4.0
- * @nojavadoc */
-public class ReferenceHashMap extends org.apache.commons.collections.map.ReferenceMap
+ * Map in which the key, value, or both may be weak/soft references.
+ *
+ * @author Abe White
+ * @since 4.0
+ * @nojavadoc
+ */
+public class ReferenceHashMap
+ extends org.apache.commons.collections.map.ReferenceMap
implements ReferenceMap, SizedMap {
private int _maxSize = Integer.MAX_VALUE;
@@ -43,18 +39,16 @@
}
/**
- * Concver our reference constants to Apache's.
+ * Concver our reference constants to Apache's.
*/
private static int toReferenceConstant(int type) {
switch (type) {
case ReferenceMap.HARD:
- return org.apache.commons.collections.map.ReferenceMap.HARD;
-
+ return org.apache.commons.collections.map.ReferenceMap. HARD;
case ReferenceMap.SOFT:
- return org.apache.commons.collections.map.ReferenceMap.SOFT;
-
+ return org.apache.commons.collections.map.ReferenceMap. SOFT;
default:
- return org.apache.commons.collections.map.ReferenceMap.WEAK;
+ return org.apache.commons.collections.map.ReferenceMap. WEAK;
}
}
@@ -64,10 +58,8 @@
public void setMaxSize(int maxSize) {
_maxSize = (maxSize < 0) ? Integer.MAX_VALUE : maxSize;
-
- if (_maxSize != Integer.MAX_VALUE) {
+ if (_maxSize != Integer.MAX_VALUE)
removeOverflow(_maxSize);
- }
}
public boolean isFull() {
@@ -88,11 +80,10 @@
}
/**
- * Remove any entries over max size.
+ * Remove any entries over max size.
*/
private void removeOverflow(int maxSize) {
Object key;
-
while (size() > maxSize) {
key = keySet().iterator().next();
overflowRemoved(key, remove(key));
@@ -101,10 +92,8 @@
protected void addMapping(int hashIndex, int hashCode, Object key,
Object value) {
- if (_maxSize != Integer.MAX_VALUE) {
+ if (_maxSize != Integer.MAX_VALUE)
removeOverflow(_maxSize - 1);
- }
-
super.addMapping(hashIndex, hashCode, key, value);
}
@@ -119,67 +108,53 @@
int index = hashIndex(ref.hashCode(), data.length);
AccessibleEntry entry = (AccessibleEntry) data[index];
AccessibleEntry prev = null;
- Object key = null;
- Object value = null;
-
+ Object key = null, value = null;
while (entry != null) {
if (purge(entry, ref)) {
- if (isHard(keyType)) {
+ if (isHard(keyType))
key = entry.key();
- } else if (isHard(valueType)) {
+ else if (isHard(valueType))
value = entry.value();
- }
- if (prev == null) {
+ if (prev == null)
data[index] = entry.nextEntry();
- } else {
+ else
prev.setNextEntry(entry.nextEntry());
- }
-
size--;
-
break;
}
-
prev = entry;
entry = entry.nextEntry();
}
- if (key != null) {
+ if (key != null)
valueExpired(key);
- } else if (value != null) {
+ else if (value != null)
keyExpired(value);
- }
}
/**
- * See the code for <code>ReferenceMap.ReferenceEntry.purge</code>.
+ * See the code for <code>ReferenceMap.ReferenceEntry.purge</code>.
*/
private boolean purge(AccessibleEntry entry, Reference ref) {
- boolean match = (!isHard(keyType) && (entry.key() == ref)) ||
- (!isHard(valueType) && (entry.value() == ref));
-
+ boolean match = (!isHard(keyType) && entry.key() == ref)
+ || (!isHard(valueType) && entry.value() == ref);
if (match) {
- if (!isHard(keyType)) {
+ if (!isHard(keyType))
((Reference) entry.key()).clear();
- }
-
- if (!isHard(valueType)) {
+ if (!isHard(valueType))
((Reference) entry.value()).clear();
- } else if (purgeValues) {
+ else if (purgeValues)
entry.nullValue();
- }
}
-
return match;
}
private static boolean isHard(int type) {
- return type == org.apache.commons.collections.map.ReferenceMap.HARD;
+ return type == org.apache.commons.collections.map. ReferenceMap.HARD;
}
- protected void doWriteObject(ObjectOutputStream out)
- throws IOException {
+ protected void doWriteObject(ObjectOutputStream out) throws IOException {
out.writeInt(_maxSize);
super.doWriteObject(out);
}
@@ -191,13 +166,13 @@
}
/**
- * Extension of the base entry type that allows our outer class to access
- * protected state.
+ * Extension of the base entry type that allows our outer class to access
+ * protected state.
*/
private static class AccessibleEntry extends ReferenceEntry {
- public AccessibleEntry(
- org.apache.commons.collections.map.AbstractReferenceMap map,
- HashEntry next, int hashCode, Object key, Object value) {
+ public AccessibleEntry(org.apache.commons.collections.map.
+ AbstractReferenceMap map, HashEntry next,
+ int hashCode, Object key, Object value) {
super(map, next, hashCode, key, value);
}
@@ -214,7 +189,7 @@
}
public AccessibleEntry nextEntry() {
- return (AccessibleEntry) next;
+ return(AccessibleEntry) next;
}
public void setNextEntry(AccessibleEntry next) {
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashSet.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -15,50 +12,50 @@
*/
package org.apache.openjpa.lib.util;
-import org.apache.commons.collections.set.*;
-
import java.io.*;
-
import java.util.*;
-
+import org.apache.commons.collections.set.*;
/**
- * <p>A set whose values may be stored as weak or soft references.</p>
- *
- * @author Abe White
- * @nojavadoc */
+ * A set whose values may be stored as weak or soft references.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
public class ReferenceHashSet implements Set, Serializable {
/**
- * Hard reference marker.
- */
+ * Hard reference marker.
+ */
public static final int HARD = 0;
/**
- * Soft reference marker.
- */
+ * Soft reference marker.
+ */
public static final int SOFT = 1;
/**
- * Weak reference marker.
+ * Weak reference marker.
*/
public static final int WEAK = 2;
+
private static final Object DUMMY_VAL = new Object();
+
private final Set _set;
/**
- * Construct a set with the given reference type.
+ * Construct a set with the given reference type.
*/
public ReferenceHashSet(int refType) {
- if (refType == HARD) {
+ if (refType == HARD)
_set = new HashSet();
- } else {
- int mapRefType = (refType == WEAK)
- ? org.apache.commons.collections.map.ReferenceMap.WEAK
- : org.apache.commons.collections.map.ReferenceMap.SOFT;
- _set = MapBackedSet.decorate(new org.apache.commons.collections.map.ReferenceMap(
- mapRefType,
- org.apache.commons.collections.map.ReferenceMap.HARD),
- DUMMY_VAL);
+ else {
+ int mapRefType = (refType == WEAK) ? org.apache.commons.
+ collections.map.ReferenceMap.WEAK : org.apache.
+ commons.collections.map.ReferenceMap.SOFT;
+ _set = MapBackedSet.decorate(new org.apache.commons.
+ collections.map.ReferenceMap(mapRefType,
+ org.apache.commons.collections.map.
+ ReferenceMap.HARD), DUMMY_VAL);
}
}
@@ -119,14 +116,10 @@
}
public boolean equals(Object obj) {
- if (this == obj) {
+ if (this == obj)
return true;
- }
-
- if (obj instanceof ReferenceHashSet) {
+ if (obj instanceof ReferenceHashSet)
obj = ((ReferenceHashSet) obj)._set;
- }
-
return _set.equals(obj);
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceMap.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -17,12 +14,11 @@
import java.util.*;
-
/**
- * <p>A {@link Map} type that can hold its keys, values, or both with
- * weak or soft references.</p>
- *
- * @author Abe White
+ * A {@link Map} type that can hold its keys, values, or both with
+ * weak or soft references.
+ *
+ * @author Abe White
*/
public interface ReferenceMap extends Map {
public static final int HARD = 0;
@@ -30,21 +26,21 @@
public static final int SOFT = 2;
/**
- * Purge stale entries.
+ * Purge stale entries.
*/
public void removeExpired();
/**
- * Overridable callback for when a key reference expires.
- *
- * @param value the value for the expired key
+ * Overridable callback for when a key reference expires.
+ *
+ * @param value the value for the expired key
*/
public void keyExpired(Object value);
/**
- * Overridable callback for when a value reference expires.
- *
- * @param key the key for the expired value
+ * Overridable callback for when a value reference expires.
+ *
+ * @param key the key for the expired value
*/
public void valueExpired(Object key);
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ResourceBundleProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ResourceBundleProvider.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ResourceBundleProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ResourceBundleProvider.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -17,18 +14,18 @@
import java.util.*;
-
/**
- * <p>A simple mechanism for looking up ResourceBundle instances
- * across different potential sources.</p>
- *
- * @author Stephen Kim
+ * A simple mechanism for looking up ResourceBundle instances
+ * across different potential sources.
+ *
+ * @author Stephen Kim
*/
interface ResourceBundleProvider {
/**
- * Find a ResourceBundle with the given name, locale, and class loader
- * (which may be null).
+ * Find a ResourceBundle with the given name, locale, and class loader
+ * (which may be null).
*/
public ResourceBundle findResource(String name, Locale locale,
ClassLoader loader);
}
+
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/Services.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -16,27 +13,22 @@
package org.apache.openjpa.lib.util;
import java.io.*;
-
import java.net.*;
-
import java.util.*;
-
/**
- * <p>Utility classes to locate services, as defined in the <a
+ * Utility classes to locate services, as defined in the <a
* href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html
* #Service%20Provider">Jar File Specification</a>. Most of the methods in this
* class can also be found in the <em>sun.misc.Service</em> class, but since
- * it is undocumented, we cannot rely on its API.</p>
- *
- * <p>Service location for a specified interface is done by searching for the
+ * it is undocumented, we cannot rely on its API.
+ * Service location for a specified interface is done by searching for the
* resource <em>/META-INF/services/</em><i>service.class.name</i>, and
- * loading the resource.</p>
- *
- * <p>Methods in this class that do not declare exceptions will never throw
+ * loading the resource.
+ * Methods in this class that do not declare exceptions will never throw
* Runtime exceptions: exceptions are silently swallowed and empty array values
- * are returned.</p>
- *
+ * are returned.
+ *
* @author Marc Prud'hommeaux
* @nojavadoc
*/
@@ -62,7 +54,7 @@
/**
* Return an array of Strings of class names of all known service
- * implementors of the specified class name (as resolved by the current
+ * implementors of the specified class name(as resolved by the current
* thread's context class loader).
*/
public static String[] getImplementors(String serviceName) {
@@ -76,18 +68,17 @@
*/
public static String[] getImplementors(String serviceName,
ClassLoader loader) {
- if (loader == null) {
+ if (loader == null)
loader = Thread.currentThread().getContextClassLoader();
- }
try {
Set resourceList = new TreeSet();
Enumeration resources = loader.getResources(PREFIX + serviceName);
-
while (resources.hasMoreElements())
addResources((URL) resources.nextElement(), resourceList);
- return (String[]) resourceList.toArray(new String[resourceList.size()]);
+ return(String[]) resourceList.toArray(new String[resourceList
+ .size()]);
} catch (Exception e) {
// silently swallow all exceptions.
return new String[0];
@@ -99,34 +90,30 @@
* Set. Class names are separated by lines. Lines starting with '#' are
* ignored.
*/
- private static void addResources(URL url, Set set)
- throws IOException {
+ private static void addResources(URL url, Set set) throws IOException {
InputStream in = url.openConnection().getInputStream();
try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(
+ in));
String line;
-
while ((line = reader.readLine()) != null) {
- if (line.trim().startsWith("#") || (line.trim().length() == 0)) {
+ if (line.trim().startsWith("#")
+ || line.trim().length() == 0)
continue;
- }
StringTokenizer tok = new StringTokenizer(line, "# \t");
-
if (tok.hasMoreTokens()) {
String next = tok.nextToken();
-
if (next != null) {
next = next.trim();
-
- if ((next.length() > 0) && !next.startsWith("#")) {
+ if (next.length() > 0 && !next.startsWith("#"))
set.add(next);
- }
}
}
}
- } finally {
+ }
+ finally {
try {
in.close();
} catch (IOException ioe) {
@@ -146,7 +133,7 @@
/**
* Return an array of Class objects of all known service implementors of the
- * specified class name (as resolved by the current thread's context class
+ * specified class name(as resolved by the current thread's context class
* loader).
*/
public static Class[] getImplementorClasses(String serviceName) {
@@ -166,43 +153,35 @@
/**
* Return an array of Class objects of all known service implementors of the
* specified class name, as resolved by the specified {@link ClassLoader}.
- *
+ *
* @param skipMissing if true, then ignore classes that cannot be loaded by
* the classloader; otherwise, resolution failures will throw a
* {@link ClassNotFoundException}.
*/
public static Class[] getImplementorClasses(String serviceName,
ClassLoader loader, boolean skipMissing) throws ClassNotFoundException {
- if (loader == null) {
+ if (loader == null)
loader = Thread.currentThread().getContextClassLoader();
- }
String[] names = getImplementors(serviceName, loader);
-
- if (names == null) {
+ if (names == null)
return new Class[0];
- }
List classes = new ArrayList(names.length);
-
for (int i = 0; i < names.length; i++) {
try {
classes.add(Class.forName(names[i], false, loader));
} catch (ClassNotFoundException e) {
- if (!skipMissing) {
+ if (!skipMissing)
throw e;
- }
} catch (UnsupportedClassVersionError ecve) {
- if (!skipMissing) {
+ if (!skipMissing)
throw ecve;
- }
} catch (LinkageError le) {
- if (!skipMissing) {
+ if (!skipMissing)
throw le;
- }
}
}
-
- return (Class[]) classes.toArray(new Class[classes.size()]);
+ return(Class[]) classes.toArray(new Class[classes.size()]);
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleRegex.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleRegex.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleRegex.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleRegex.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -15,18 +12,16 @@
*/
package org.apache.openjpa.lib.util;
-
/**
- * <p>Allows for simple regex style testing of strings. The wildcard '.'
- * is used to represent any single character, while '.*' is used to represent
- * any series of 0 or more characters.</p>
- *
- * <p>Examples:<br />
- * <code>
- * SimpleRegex re = new SimpleRegex ("the qu.ck .* dog", true);
- * boolean matches = re.matches ("The quick fox jumped over the lazy dog");
- * </code></p>
- * @nojavadoc */
+ * Allows for simple regex style testing of strings. The wildcard '.'
+ * is used to represent any single character, while '.*' is used to represent
+ * any series of 0 or more characters.
+ * Examples:<br />
+ * <code> SimpleRegex re = new SimpleRegex("the qu.ck .* dog", true);
+ * boolean matches = re.matches("The quick fox jumped over the lazy dog");
+ * </code>
+ * @nojavadoc
+ */
public class SimpleRegex {
private final String expr;
private final boolean caseInsensitive;
@@ -36,27 +31,24 @@
// If we're case insensitive, toLowerCase the expr. We'll toLowerCase
// each target, too, in the matches call.
- if (caseInsensitive) {
+ if (caseInsensitive)
this.expr = expr.toLowerCase();
- } else {
+ else
this.expr = expr;
- }
}
public boolean matches(String target) {
// If we're case insensitive, toLowerCase the target
- if (caseInsensitive) {
+ if (caseInsensitive)
target = target.toLowerCase();
- }
- // By default, we are not position independent ("mobile"). We only
+ // By default, we are not position independent("mobile"). We only
// become position independent once we hit our first ".*".
boolean mobile = false;
// Find occurrences of ".*" in the expression.
int exprPos = 0;
int targetPos = 0;
-
while (true) {
// Find the next occurrence of ".*"
int star = expr.indexOf(".*", exprPos);
@@ -66,11 +58,10 @@
if (star == exprPos) {
mobile = true;
exprPos += 2;
-
continue;
}
// If there are no more ".*"s, then we're effectively no longer
- // position independent (assuming we even were before), since
+ // position independent(assuming we even were before), since
// we must match the end of the string
else if (star == -1) {
int len = expr.length() - exprPos;
@@ -80,74 +71,61 @@
// match. If we're mobile, then the length doesn't have to
// be the same as long as the remainder of the expression
// is equal to the end of the target
- if (!mobile && (targetPos != (target.length() - len))) {
+ if (!mobile && targetPos != target.length() - len)
return false;
- }
// Match the end of the target to the remainder of the
// expression
int match = indexOf(target, target.length() - len, exprPos,
- len, true);
-
- if (match != -1) {
+ len, true);
+ if (match != -1)
return true;
- }
-
return false;
}
// Match the fragment of the expression to the target
- int match = indexOf(target, targetPos, exprPos, star - exprPos,
- !mobile);
-
- if (match == -1) {
+ int match = indexOf(target, targetPos, exprPos,
+ star - exprPos, !mobile);
+ if (match == -1)
return false;
- }
-
- targetPos = (match + star) - exprPos;
+ targetPos = match + star - exprPos;
exprPos = star + 2;
mobile = true;
}
}
/**
- * Match a section of target to a fragment of the expression.
- * If we're only to match the beginning of the target, beginOnly
- * will be true, otherwise we can match anymore in the target (starting
- * at the targetStart position). A "." in the expression matches any
- * character.
+ * Match a section of target to a fragment of the expression.
+ * If we're only to match the beginning of the target, beginOnly
+ * will be true, otherwise we can match anymore in the target(starting
+ * at the targetStart position). A "." in the expression matches any
+ * character.
*/
- private int indexOf(String target, int targetStart, int exprStart,
- int exprLength, boolean beginOnly) {
+ private int indexOf(String target, int targetStart,
+ int exprStart, int exprLength, boolean beginOnly) {
// Run through the target seeing if there is a match
- while ((target.length() - targetStart) >= exprLength) {
+ while (target.length() - targetStart >= exprLength) {
// Assume success. If there isn't a match we'll break out
boolean found = true;
-
for (int i = 0; i < exprLength; i++) {
// "." in the expr matches any character in the target
- if ((expr.charAt(exprStart + i) != '.') &&
- (expr.charAt(exprStart + i) != target.charAt(targetStart +
- i))) {
+ if (expr.charAt(exprStart + i) != '.' &&
+ expr.charAt(exprStart + i) !=
+ target.charAt(targetStart + i)) {
found = false;
-
break;
}
}
-
- if (found) {
+ if (found)
return targetStart;
- }
- // If we're position dependent (beginOnly == true), then don't
+ // If we're position dependent(beginOnly == true), then don't
// continue the search
- if (beginOnly) {
+ if (beginOnly)
return -1;
- }
targetStart++;
}
-
return -1;
}
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleResourceBundleProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleResourceBundleProvider.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleResourceBundleProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SimpleResourceBundleProvider.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -17,18 +14,16 @@
import java.util.*;
-
/**
- * <p>{@link ResourceBundleProvider} that uses Java's built-in resource
- * bundle lookup methods.</p>
- *
- * @author Abe White
+ * {@link ResourceBundleProvider} that uses Java's built-in resource
+ * bundle lookup methods.
+ *
+ * @author Abe White
*/
class SimpleResourceBundleProvider implements ResourceBundleProvider {
public ResourceBundle findResource(String name, Locale locale,
ClassLoader loader) {
ResourceBundle bundle = null;
-
if (loader != null) {
try {
bundle = ResourceBundle.getBundle(name, locale, loader);
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SizedMap.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SizedMap.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SizedMap.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/SizedMap.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -17,32 +14,30 @@
import java.util.*;
-
/**
- * <p>A {@link Map} type that maintains a maximum size, automatically
- * removing entries when the maximum is exceeded.</p>
- *
- * @author Abe White
+ * A {@link Map} type that maintains a maximum size, automatically
+ * removing entries when the maximum is exceeded.
+ *
+ * @author Abe White
*/
public interface SizedMap extends Map {
/**
- * The maximum number of entries, or Integer.MAX_VALUE for no limit.
+ * The maximum number of entries, or Integer.MAX_VALUE for no limit.
*/
public int getMaxSize();
/**
- * The maximum number of entries, or Integer.MAX_VALUE for no limit.
+ * The maximum number of entries, or Integer.MAX_VALUE for no limit.
*/
public void setMaxSize(int max);
/**
- * Whether the map is full.
+ * Whether the map is full.
*/
public boolean isFull();
/**
- * Overridable callback for when an overflow entry is automatically
- * removed.
+ * Overridable callback for when an overflow entry is automatically removed.
*/
public void overflowRemoved(Object key, Object value);
}
Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StreamResourceBundleProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StreamResourceBundleProvider.java?rev=418401&r1=418400&r2=418401&view=diff
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StreamResourceBundleProvider.java (original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StreamResourceBundleProvider.java Fri Jun 30 15:37:18 2006
@@ -1,13 +1,10 @@
/*
* Copyright 2006 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed 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
+ * 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
@@ -16,40 +13,32 @@
package org.apache.openjpa.lib.util;
import java.io.*;
-
import java.util.*;
-
/**
- * <p>{@link ResourceBundleProvider} that uses the
- * {@link ClassLoader#getResourceAsStream} method to load resources.
- * Created for use under WSAD.</p>
- *
- * @author Stephen Kim
+ * {@link ResourceBundleProvider} that uses the
+ * {@link ClassLoader#getResourceAsStream} method to load resources.
+ * Created for use under WSAD.
+ *
+ * @author Stephen Kim
*/
class StreamResourceBundleProvider implements ResourceBundleProvider {
public ResourceBundle findResource(String name, Locale locale,
ClassLoader loader) {
String rsrc = name.replace('.', '/') + ".properties";
-
- if (loader == null) {
+ if (loader == null)
loader = Thread.currentThread().getContextClassLoader();
- }
InputStream in = loader.getResourceAsStream(rsrc);
-
if (in != null) {
try {
return new PropertyResourceBundle(in);
} catch (Exception e) {
- } finally {
- try {
- in.close();
- } catch (IOException ioe) {
- }
+ }
+ finally {
+ try { in.close(); } catch (IOException ioe) {}
}
}
-
return null;
}
}