Code cleanup remove compiler warnings

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@708580 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2008-10-28 14:15:01 +00:00
parent b9476a8ae8
commit 995c6a4acc
36 changed files with 234 additions and 197 deletions

View File

@ -167,7 +167,7 @@ public abstract class AbstractCFMetaDataFactory
}
public boolean store(ClassMetaData[] metas, QueryMetaData[] queries,
SequenceMetaData[] seqs, int mode, Map output) {
SequenceMetaData[] seqs, int mode, Map<File,String> output) {
if (mode == MODE_NONE)
return true;
if (isMappingOnlyFactory() && (mode & MODE_MAPPING) == 0)
@ -338,14 +338,14 @@ public abstract class AbstractCFMetaDataFactory
for (int i = 0; i < cls.length; i++)
ser.removeMetaData(pr.getMetaData(cls[i], envLoader,
false));
serialize(ser, null, ser.PRETTY);
serialize(ser, null, Serializer.PRETTY);
}
if (qqs != null && !qqs.isEmpty()) {
ser = newSerializer();
ser.setMode(MODE_QUERY);
for (int i = 0; i < qqs.size(); i++)
ser.addQueryMetaData((QueryMetaData) qqs.get(i));
serialize(ser, null, ser.PRETTY);
serialize(ser, null, Serializer.PRETTY);
}
return true;
}
@ -473,7 +473,8 @@ public abstract class AbstractCFMetaDataFactory
/**
* Tell the given serialier to write its metadatas.
*/
protected void serialize(MetaDataSerializer ser, Map output, int flags) {
protected void serialize(MetaDataSerializer ser, Map<File, String> output,
int flags) {
try {
if (output == null)
ser.serialize(flags);

View File

@ -84,7 +84,7 @@ public abstract class AbstractMetaDataFactory
}
public boolean store(ClassMetaData[] metas, QueryMetaData[] queries,
SequenceMetaData[] seqs, int mode, Map output) {
SequenceMetaData[] seqs, int mode, Map<File, String> output) {
return false;
}

View File

@ -87,7 +87,7 @@ public interface MetaDataFactory
* @return false if this factory is unable to store metadata
*/
public boolean store(ClassMetaData[] metas, QueryMetaData[] queries,
SequenceMetaData[] seqs, int mode, Map output);
SequenceMetaData[] seqs, int mode, Map<File, String> output);
/**
* Drop the metadata for the given classes in the given mode(s).

View File

@ -22,7 +22,6 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.sql.DataSource;
@ -36,7 +35,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public class DecoratingDataSource extends DelegatingDataSource {
private List _decorators = new CopyOnWriteArrayList();
private List<ConnectionDecorator> _decorators =
new CopyOnWriteArrayList<ConnectionDecorator>();
/**
* Constructor. Supply wrapped data source.
@ -49,7 +49,7 @@ public class DecoratingDataSource extends DelegatingDataSource {
* Return a read-only list of connection decorators in the order they were
* added.
*/
public Collection getDecorators() {
public Collection<ConnectionDecorator> getDecorators() {
return Collections.unmodifiableCollection(_decorators);
}
@ -64,7 +64,7 @@ public class DecoratingDataSource extends DelegatingDataSource {
/**
* Add multiple connection decorators efficiently.
*/
public void addDecorators(Collection decorators) {
public void addDecorators(Collection<ConnectionDecorator> decorators) {
if (decorators != null)
_decorators.addAll(decorators);
}
@ -95,9 +95,9 @@ public class DecoratingDataSource extends DelegatingDataSource {
}
private Connection decorate(Connection conn) throws SQLException {
if (!_decorators.isEmpty())
for (Iterator itr = _decorators.iterator(); itr.hasNext();)
conn = ((ConnectionDecorator) itr.next()).decorate(conn);
for(ConnectionDecorator decorator : _decorators) {
conn = decorator.decorate(conn);
}
return conn;
}
}

View File

@ -336,6 +336,9 @@ public class DelegatingCallableStatement
_stmnt.setAsciiStream(i1, is, i2);
}
/**
* @deprecated
*/
public void setUnicodeStream(int i1, InputStream is, int i2)
throws SQLException {
_stmnt.setUnicodeStream(i1, is, i2);
@ -509,6 +512,10 @@ public class DelegatingCallableStatement
return _stmnt.getDouble(i);
}
/**
* @deprecated use <code>getBigDecimal(int parameterIndex)</code> or
* <code>getBigDecimal(String parameterName)</code>
*/
public BigDecimal getBigDecimal(int a, int b) throws SQLException {
return _stmnt.getBigDecimal(a, b);
}
@ -537,7 +544,7 @@ public class DelegatingCallableStatement
return _stmnt.getBigDecimal(i);
}
public Object getObject(int i, Map m) throws SQLException {
public Object getObject(int i, Map<String,Class<?>> m) throws SQLException {
return _stmnt.getObject(i, m);
}
@ -760,7 +767,7 @@ public class DelegatingCallableStatement
throw new UnsupportedOperationException();
}
public Object getObject(String a, Map b) throws SQLException {
public Object getObject(String a, Map<String, Class<?>>b) throws SQLException {
throw new UnsupportedOperationException();
}

View File

@ -63,7 +63,7 @@ public class DelegatingConnection implements Connection, Closeable {
private static final Localizer _loc = Localizer.forPackage
(DelegatingConnection.class);
private static final Map _jdbc3;
private static final Map<Object, Method> _jdbc3;
static {
boolean jdbc3 = false;
@ -76,7 +76,7 @@ public class DelegatingConnection implements Connection, Closeable {
}
if (jdbc3) {
_jdbc3 = new HashMap();
_jdbc3 = new HashMap<Object,Method>();
_jdbc3.put(SET_SAVEPOINT, m);
} else
_jdbc3 = null;
@ -331,11 +331,11 @@ public class DelegatingConnection implements Connection, Closeable {
return stmnt;
}
public Map getTypeMap() throws SQLException {
public Map<String, Class<?>> getTypeMap() throws SQLException {
return _conn.getTypeMap();
}
public void setTypeMap(Map map) throws SQLException {
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
_conn.setTypeMap(map);
}
@ -578,7 +578,7 @@ public class DelegatingConnection implements Connection, Closeable {
}
private static Method createJDBC3Method(Object key, String name,
Class[] args) {
Class<?>[] args) {
try {
Method m = Connection.class.getMethod(name, args);
_jdbc3.put(key, m);

View File

@ -330,6 +330,9 @@ public class DelegatingPreparedStatement
_stmnt.setAsciiStream(i1, is, i2);
}
/**
* @deprecated
*/
public void setUnicodeStream(int i1, InputStream is, int i2)
throws SQLException {
_stmnt.setUnicodeStream(i1, is, i2);

View File

@ -146,6 +146,7 @@ public class DelegatingResultSet implements ResultSet, Closeable {
return _rs.getDouble(a);
}
@Deprecated
public BigDecimal getBigDecimal(int a, int b) throws SQLException {
return _rs.getBigDecimal(a, b);
}
@ -170,6 +171,7 @@ public class DelegatingResultSet implements ResultSet, Closeable {
return _rs.getAsciiStream(a);
}
@Deprecated
public InputStream getUnicodeStream(int a) throws SQLException {
return _rs.getUnicodeStream(a);
}
@ -210,6 +212,7 @@ public class DelegatingResultSet implements ResultSet, Closeable {
return _rs.getDouble(a);
}
@Deprecated
public BigDecimal getBigDecimal(String a, int b) throws SQLException {
return _rs.getBigDecimal(a, b);
}
@ -234,6 +237,7 @@ public class DelegatingResultSet implements ResultSet, Closeable {
return _rs.getAsciiStream(a);
}
@Deprecated
public InputStream getUnicodeStream(String a) throws SQLException {
return _rs.getUnicodeStream(a);
}
@ -568,7 +572,7 @@ public class DelegatingResultSet implements ResultSet, Closeable {
return _stmnt;
}
public Object getObject(int a, Map b) throws SQLException {
public Object getObject(int a, Map<String, Class<?>> b) throws SQLException {
return _rs.getObject(a, b);
}
@ -588,7 +592,7 @@ public class DelegatingResultSet implements ResultSet, Closeable {
return _rs.getArray(a);
}
public Object getObject(String a, Map b) throws SQLException {
public Object getObject(String a, Map<String, Class<?>> b) throws SQLException {
return _rs.getObject(a, b);
}

View File

@ -29,6 +29,7 @@ import java.util.EventObject;
* @author Abe White
* @see JDBCListener
*/
@SuppressWarnings("serial")
public class JDBCEvent extends EventObject {
/**

View File

@ -32,6 +32,7 @@ import org.apache.openjpa.lib.util.concurrent.AbstractConcurrentEventManager;
* @author Abe White
* @nojavadoc
*/
@SuppressWarnings("serial")
public class JDBCEventConnectionDecorator extends AbstractConcurrentEventManager
implements ConnectionDecorator {

View File

@ -893,8 +893,8 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
extends DelegatingPreparedStatement {
private final String _sql;
private List _params = null;
private List _paramBatch = null;
private List<String> _params = null;
private List<List<String>> _paramBatch = null;
public LoggingPreparedStatement(PreparedStatement stmnt, String sql)
throws SQLException {
@ -1025,7 +1025,7 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
// set the current params to the saved values
if (index < _paramBatch.size())
_params = (List) _paramBatch.get(index);
_params = (List<String>) _paramBatch.get(index);
}
}
err = wrap(se, LoggingPreparedStatement.this);
@ -1138,6 +1138,7 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
super.setAsciiStream(i1, is, i2);
}
@Deprecated
public void setUnicodeStream(int i1, InputStream is, int i2)
throws SQLException {
setLogParameter(i1, "InputStream", is);
@ -1181,10 +1182,12 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
if (shouldTrackParameters()) {
// make sure our list is initialized
if (_paramBatch == null)
_paramBatch = new ArrayList();
_paramBatch = new ArrayList<List<String>>();
// copy parameters since they will be re-used
if (_params != null)
_paramBatch.add(new ArrayList(_params));
if (_params != null) {
List<String> copyParms = new ArrayList<String>(_params);
_paramBatch.add(copyParms);
}
else
_paramBatch.add(null);
}
@ -1258,7 +1261,8 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
StringBuffer paramBuf = null;
if (_params != null && !_params.isEmpty()) {
paramBuf = new StringBuffer();
for (Iterator itr = _params.iterator(); itr.hasNext();) {
for (Iterator<String> itr = _params.iterator(); itr
.hasNext();) {
paramBuf.append(itr.next());
if (itr.hasNext())
paramBuf.append(", ");
@ -1327,7 +1331,7 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
private void setLogParameter(int index, String val) {
if (_params == null)
_params = new ArrayList();
_params = new ArrayList<String>();
while (_params.size() < index)
_params.add(null);
if (val.length() > 80)
@ -1462,8 +1466,8 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
private class LoggingCallableStatement extends
DelegatingCallableStatement {
private final String _sql;
private List _params = null;
private List _paramBatch = null;
private List<String> _params = null;
private List<List<String>> _paramBatch = null;
public LoggingCallableStatement(CallableStatement stmt, String sql)
throws SQLException {
@ -1594,7 +1598,7 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
// set the current params to the saved values
if (index < _paramBatch.size())
_params = (List) _paramBatch.get(index);
_params = (List<String>) _paramBatch.get(index);
}
}
err = wrap(se, LoggingCallableStatement.this);
@ -1707,6 +1711,7 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
super.setAsciiStream(i1, is, i2);
}
@Deprecated
public void setUnicodeStream(int i1, InputStream is, int i2)
throws SQLException {
setLogParameter(i1, "InputStream", is);
@ -1750,10 +1755,13 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
if (shouldTrackParameters()) {
// make sure our list is initialized
if (_paramBatch == null)
_paramBatch = new ArrayList();
_paramBatch = new ArrayList<List<String>>();
// copy parameters since they will be re-used
if (_params != null)
_paramBatch.add(new ArrayList(_params));
if (_params != null) {
List<String> copyParams =
new ArrayList<String>(_params);
_paramBatch.add(copyParams);
}
else
_paramBatch.add(null);
}
@ -1827,7 +1835,8 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
StringBuffer paramBuf = null;
if (_params != null && !_params.isEmpty()) {
paramBuf = new StringBuffer();
for (Iterator itr = _params.iterator(); itr.hasNext();) {
for (Iterator<String> itr = _params.iterator(); itr
.hasNext();) {
paramBuf.append(itr.next());
if (itr.hasNext())
paramBuf.append(", ");
@ -1896,7 +1905,7 @@ public class LoggingConnectionDecorator implements ConnectionDecorator {
private void setLogParameter(int index, String val) {
if (_params == null)
_params = new ArrayList();
_params = new ArrayList<String>();
while (_params.size() < index)
_params.add(null);
if (val.length() > 80)

View File

@ -28,6 +28,7 @@ import java.sql.Statement;
* @author Marc Prud'hommeaux
* @nojavadoc
*/
@SuppressWarnings("serial")
public class ReportingSQLException extends SQLException {
private final transient Statement _stmnt;

View File

@ -184,7 +184,7 @@ public class SQLFormatter {
int start = 0;
int end = -1;
StringBuffer clause;
List clauses = new ArrayList();
List<StringBuffer> clauses = new ArrayList<StringBuffer>();
clauses.add(new StringBuffer());
for (int i = 0; i < separators.length; i++) {
end = lowerCaseSql.indexOf(" " + separators[i].toLowerCase(),
@ -192,7 +192,7 @@ public class SQLFormatter {
if (end == -1)
break;
clause = (StringBuffer) clauses.get(clauses.size() - 1);
clause = clauses.get(clauses.size() - 1);
clause.append(sql.substring(start, end));
clause = new StringBuffer();
@ -203,12 +203,12 @@ public class SQLFormatter {
start = end + 1 + separators[i].length();
}
clause = (StringBuffer) clauses.get(clauses.size() - 1);
clause = clauses.get(clauses.size() - 1);
clause.append(sql.substring(start));
StringBuffer pp = new StringBuffer(sql.length());
for (Iterator iter = clauses.iterator(); iter.hasNext();) {
pp.append(wrapLine(((StringBuffer) iter.next()).toString()));
for (Iterator<StringBuffer> iter = clauses.iterator(); iter.hasNext();){
pp.append(wrapLine(iter.next().toString()));
if (iter.hasNext())
pp.append(newline);
}

View File

@ -31,11 +31,11 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class LogFactoryAdapter implements LogFactory {
// cache category to log adapters
private Map _logs = new ConcurrentHashMap();
private Map<String, Log> _logs = new ConcurrentHashMap<String, Log>();
public Log getLog(String channel) {
// no locking; OK if same adapter created multiple times
Log log = (Log) _logs.get(channel);
Log log = _logs.get(channel);
if (log == null) {
log = newLogAdapter(channel);
_logs.put(channel, log);

View File

@ -73,7 +73,8 @@ public class LogFactoryImpl
/**
* The {@link Log}s that this factory manages, keyed by log channel name.
*/
private Map _logs = new ConcurrentHashMap(); // <String,Log>
private Map<String, LogImpl> _logs =
new ConcurrentHashMap<String, LogImpl>();
/**
* The default logging level.
@ -83,7 +84,8 @@ public class LogFactoryImpl
/**
* Storage for logging level configuration specified at configuration time.
*/
private Map _configuredLevels = new HashMap(); // <String,Integer>
private Map<String, Short> _configuredLevels =
new HashMap<String, Short>();
/**
* The stream to write to. Defaults to System.err.
@ -106,11 +108,11 @@ public class LogFactoryImpl
public Log getLog(String channel) {
// no locking; ok if same log created multiple times
LogImpl l = (LogImpl) _logs.get(channel);
LogImpl l = _logs.get(channel);
if (l == null) {
l = newLogImpl();
l.setChannel(channel);
Short lvl = (Short) _configuredLevels.get(shorten(channel));
l.setChannel(channel); // TODO add to interface?
Short lvl = _configuredLevels.get(shorten(channel));
l.setLevel(lvl == null ? _defaultLogLevel : lvl.shortValue());
_logs.put(channel, l);
}
@ -271,11 +273,12 @@ public class LogFactoryImpl
public void setInto(Options opts) {
if (!opts.isEmpty()) {
Map.Entry e;
for (Iterator iter = opts.entrySet().iterator(); iter.hasNext();) {
e = (Map.Entry) iter.next();
_configuredLevels.put(shorten((String) e.getKey()),
new Short(getLevel((String) e.getValue())));
Map.Entry<Object, Object> e;
for (Iterator<Map.Entry<Object, Object>> iter =
opts.entrySet().iterator(); iter.hasNext();) {
e = iter.next();
_configuredLevels.put(shorten((String) e.getKey()), new Short(
getLevel((String) e.getValue())));
}
opts.clear();
}

View File

@ -20,7 +20,6 @@ package org.apache.openjpa.lib.log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@ -33,7 +32,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public class MultiLogFactory implements LogFactory {
private List _delegates;
private List<LogFactory> _delegates;
/**
* Create an instance with the given delegates.
@ -53,7 +52,8 @@ public class MultiLogFactory implements LogFactory {
* Create an instance with the given delegates.
*/
public MultiLogFactory(LogFactory[] delegates) {
_delegates = new CopyOnWriteArrayList(Arrays.asList(delegates));
_delegates =
new CopyOnWriteArrayList<LogFactory>(Arrays.asList(delegates));
}
public void addLogFactory(LogFactory factory) {
@ -75,16 +75,15 @@ public class MultiLogFactory implements LogFactory {
* Returns a Log impl that combines all logs.
*/
public synchronized Log getLog(String channel) {
List logs = new ArrayList(_delegates.size());
for (Iterator i = _delegates.iterator(); i.hasNext();) {
LogFactory f = (LogFactory) i.next();
List<Log> logs = new ArrayList<Log>(_delegates.size());
for(LogFactory f : _delegates) {
if (f != null) {
Log l = f.getLog(channel);
if (l != null)
logs.add(l);
}
}
return new MultiLog((Log[]) logs.toArray(new Log[logs.size()]));
return new MultiLog(logs.toArray(new Log[logs.size()]));
}
/**

View File

@ -278,11 +278,12 @@ public class CFMetaDataParser extends XMLMetaDataParser {
* taking into account the package currently being parsed for relative
* class names.
*/
protected Class classForName(String name, boolean resolve)
protected Class<?> classForName(String name, boolean resolve)
throws SAXException {
if (name == null)
return null;
Class cls = classForName(name, _package, resolve, currentClassLoader());
Class<?> cls =
classForName(name, _package, resolve, currentClassLoader());
if (cls == null)
throw getException(_loc.get("invalid-class", name).getMessage());
return cls;
@ -292,7 +293,7 @@ public class CFMetaDataParser extends XMLMetaDataParser {
* Load the given class name against the given package and the set
* of accepted standard packages. Return null if the class cannot be loaded.
*/
public static Class classForName(String name, String pkg,
public static Class<?> classForName(String name, String pkg,
boolean resolve, ClassLoader loader) {
if (StringUtils.isEmpty(name))
return null;

View File

@ -54,20 +54,22 @@ public abstract class CFMetaDataSerializer extends XMLMetaDataSerializer {
/**
* Helper method to group objects by package.
*
* @return mapping of package name to a collection of objects in
* that package
* @return mapping of package name to a collection of objects in that
* package
*/
protected Map groupByPackage(Collection objs) throws SAXException {
Map packages = new LinkedHashMap();
protected Map<String, Collection<Object>> groupByPackage(
Collection<Object> objs) throws SAXException {
Map<String, Collection<Object>> packages =
new LinkedHashMap<String, Collection<Object>>();
String packageName;
Collection packageObjs;
Collection<Object> packageObjs;
Object obj;
for (Iterator itr = objs.iterator(); itr.hasNext();) {
for (Iterator<Object> itr = objs.iterator(); itr.hasNext();) {
obj = itr.next();
packageName = getPackage(obj);
packageObjs = (Collection) packages.get(packageName);
packageObjs = packages.get(packageName);
if (packageObjs == null) {
packageObjs = new LinkedList();
packageObjs = new LinkedList<Object>();
packages.put(packageName, packageObjs);
}
packageObjs.add(obj);

View File

@ -44,14 +44,14 @@ public class ClassAnnotationMetaDataFilter implements MetaDataFilter {
/**
* Constructor; supply annotation to match against.
*/
public ClassAnnotationMetaDataFilter(Class anno) {
public ClassAnnotationMetaDataFilter(Class<?> anno) {
this(new Class[]{ anno });
}
/**
* Constructor; supply annotations to match against.
*/
public ClassAnnotationMetaDataFilter(Class[] annos) {
public ClassAnnotationMetaDataFilter(Class<?>[] annos) {
_annos = new String[annos.length];
for (int i = 0; i < annos.length; i++)
_annos[i] = "L" + annos[i].getName().replace('.', '/') + ";";

View File

@ -157,9 +157,9 @@ public class ClassArgParser {
* @param arg a class name, .java file, .class file, or metadata
* file naming the type(s) to act on
*/
public Class[] parseTypes(String arg) {
public Class<?>[] parseTypes(String arg) {
String[] names = parseTypeNames(arg);
Class[] objs = new Class[names.length];
Class<?>[] objs = new Class[names.length];
for (int i = 0; i < names.length; i++)
objs[i] = Strings.toClass(names[i], _loader);
return objs;
@ -169,9 +169,9 @@ public class ClassArgParser {
* Return the {@link Class} representation of the class(es) named in the
* given metadatas.
*/
public Class[] parseTypes(MetaDataIterator itr) {
public Class<?>[] parseTypes(MetaDataIterator itr) {
String[] names = parseTypeNames(itr);
Class[] objs = new Class[names.length];
Class<?>[] objs = new Class[names.length];
for (int i = 0; i < names.length; i++)
objs[i] = Strings.toClass(names[i], _loader);
return objs;
@ -181,20 +181,23 @@ public class ClassArgParser {
* Return a mapping of each metadata resource to an array of its
* contained classes.
*/
public Map mapTypes(MetaDataIterator itr) {
Map map = mapTypeNames(itr);
Map.Entry entry;
public Map<Object, Class<?>[]> mapTypes(MetaDataIterator itr) {
Map<Object, String[]> map = mapTypeNames(itr);
Map<Object, Class<?>[]> rval = new HashMap<Object, Class<?>[]>();
Map.Entry<Object, String[]> entry;
String[] names;
Class[] objs;
for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
entry = (Map.Entry) i.next();
names = (String[]) entry.getValue();
Class<?>[] objs;
for (Iterator<Map.Entry<Object, String[]>> i =
map.entrySet().iterator(); i.hasNext();) {
entry = i.next();
names = entry.getValue();
objs = new Class[names.length];
for (int j = 0; j < names.length; j++)
for (int j = 0; j < names.length; j++) {
objs[j] = Strings.toClass(names[j], _loader);
entry.setValue(objs);
}
return map;
rval.put(entry.getKey(), objs);
}
return rval;
}
/**
@ -216,8 +219,8 @@ public class ClassArgParser {
return new String[]{ getFromJavaFile(file) };
if ((AccessController.doPrivileged(
J2DoPrivHelper.existsAction(file))).booleanValue()) {
Collection col = getFromMetaDataFile(file);
return (String[]) col.toArray(new String[col.size()]);
Collection<String> col = getFromMetaDataFile(file);
return col.toArray(new String[col.size()]);
}
} catch (Exception e) {
throw new NestableRuntimeException(
@ -235,7 +238,7 @@ public class ClassArgParser {
if (itr == null)
return new String[0];
List names = new ArrayList();
List<String> names = new ArrayList<String>();
Object source = null;
try {
while (itr.hasNext()) {
@ -246,15 +249,15 @@ public class ClassArgParser {
throw new NestableRuntimeException(
_loc.get("class-arg", source).getMessage(), e);
}
return (String[]) names.toArray(new String[names.size()]);
return names.toArray(new String[names.size()]);
}
/**
* Parse the names in the given metadata iterator stream, closing the
* stream on completion.
*/
private void appendTypeNames(Object source, InputStream in, List names)
throws IOException {
private void appendTypeNames(Object source, InputStream in,
List<String> names) throws IOException {
try {
if (source.toString().endsWith(".class"))
names.add(getFromClass(in));
@ -271,20 +274,20 @@ public class ClassArgParser {
* Return a mapping of each metadata resource to an array of its contained
* class names.
*/
public Map mapTypeNames(MetaDataIterator itr) {
public Map<Object, String[]> mapTypeNames(MetaDataIterator itr) {
if (itr == null)
return Collections.EMPTY_MAP;
return Collections.emptyMap();
Map map = new HashMap();
Map<Object, String []> map = new HashMap<Object, String[]>();
Object source = null;
List names = new ArrayList();
List<String> names = new ArrayList<String>();
try {
while (itr.hasNext()) {
source = itr.next();
appendTypeNames(source, itr.getInputStream(), names);
if (!names.isEmpty())
map.put(source, (String[]) names.toArray
(new String[names.size()]));
if (!names.isEmpty()) {
map.put(source, names.toArray(new String[names.size()]));
}
names.clear();
}
} catch (Exception e) {
@ -372,7 +375,8 @@ public class ClassArgParser {
/**
* Returns the classes named in the given common format metadata file.
*/
private Collection getFromMetaDataFile(File file) throws IOException {
private Collection<String> getFromMetaDataFile(File file)
throws IOException {
FileReader in = null;
try {
in = new FileReader(file);
@ -389,8 +393,8 @@ public class ClassArgParser {
/**
* Returns the classes named in the given common format metadata stream.
*/
private Collection getFromMetaData(Reader xml) throws IOException {
Collection names = new ArrayList();
private Collection<String> getFromMetaData(Reader xml) throws IOException {
Collection<String> names = new ArrayList<String>();
BufferedReader in = new BufferedReader(xml);
boolean comment = false;

View File

@ -46,16 +46,16 @@ import serp.util.Strings;
public class ClassMetaDataIterator implements MetaDataIterator {
private final ClassLoader _loader;
private final List _locs;
private final List<String> _locs;
private int _loc = -1;
private final List _urls = new ArrayList(3);
private final List<URL> _urls = new ArrayList<URL>(3);
private int _url = -1;
/**
* Constructor; supply the class whose metadata to find, the suffix
* of metadata files, and whether to parse top-down or bottom-up.
*/
public ClassMetaDataIterator(Class cls, String suffix, boolean topDown) {
public ClassMetaDataIterator(Class<?> cls, String suffix, boolean topDown) {
this(cls, suffix, null, topDown);
}
@ -63,22 +63,22 @@ public class ClassMetaDataIterator implements MetaDataIterator {
* Constructor; supply the class whose metadata to find, the suffix
* of metadata files, and whether to parse top-down or bottom-up.
*/
public ClassMetaDataIterator(Class cls, String suffix, ClassLoader loader,
public ClassMetaDataIterator(Class<?> cls, String suffix, ClassLoader loader,
boolean topDown) {
// skip classes that can't have metadata
if (cls != null && (cls.isPrimitive()
|| cls.getName().startsWith("java.")
|| cls.getName().startsWith("javax."))) {
_loader = null;
_locs = Collections.EMPTY_LIST;
_locs = Collections.emptyList();
return;
}
if (loader == null) {
MultiClassLoader multi = AccessController
.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
multi.addClassLoader(multi.SYSTEM_LOADER);
multi.addClassLoader(multi.THREAD_LOADER);
multi.addClassLoader(MultiClassLoader.SYSTEM_LOADER);
multi.addClassLoader(MultiClassLoader.THREAD_LOADER);
multi.addClassLoader(getClass().getClassLoader());
if (cls != null)
{
@ -94,7 +94,7 @@ public class ClassMetaDataIterator implements MetaDataIterator {
// collect the set of all possible metadata locations; start with
// system locations
_locs = new ArrayList();
_locs = new ArrayList<String>();
_locs.add("META-INF/package" + suffix);
_locs.add("WEB-INF/package" + suffix);
_locs.add("package" + suffix);
@ -148,7 +148,7 @@ public class ClassMetaDataIterator implements MetaDataIterator {
}
public boolean hasNext() throws IOException {
Enumeration e;
Enumeration<URL> e;
while (_url + 1 >= _urls.size()) {
if (++_loc >= _locs.size())
return false;
@ -158,7 +158,7 @@ public class ClassMetaDataIterator implements MetaDataIterator {
try {
e = AccessController.doPrivileged(
J2DoPrivHelper.getResourcesAction(
_loader, (String) _locs.get(_loc)));
_loader, _locs.get(_loc)));
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getException();
}
@ -168,7 +168,7 @@ public class ClassMetaDataIterator implements MetaDataIterator {
return true;
}
public Object next() throws IOException {
public URL next() throws IOException {
if (!hasNext())
throw new NoSuchElementException();
return _urls.get(++_url);
@ -179,7 +179,7 @@ public class ClassMetaDataIterator implements MetaDataIterator {
throw new IllegalStateException();
try {
return AccessController.doPrivileged(
J2DoPrivHelper.openStreamAction((URL) _urls.get(_url)));
J2DoPrivHelper.openStreamAction(_urls.get(_url)));
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getException();
}
@ -188,8 +188,7 @@ public class ClassMetaDataIterator implements MetaDataIterator {
public File getFile() throws IOException {
if (_url == -1 || _url >= _urls.size())
throw new IllegalStateException();
File file = new File(URLDecoder.decode(((URL) _urls.get(_url)).
getFile()));
File file = new File(URLDecoder.decode((_urls.get(_url)).getFile()));
return ((AccessController.doPrivileged(
J2DoPrivHelper.existsAction(file))).booleanValue()) ? file:null;
}

View File

@ -65,8 +65,8 @@ public class ClasspathMetaDataIterator extends MetaDataIteratorChain {
if (!(AccessController.doPrivileged(
J2DoPrivHelper.existsAction(file))).booleanValue())
continue;
if ((AccessController.doPrivileged(J2DoPrivHelper
.isDirectoryAction(file))).booleanValue())
if (AccessController.doPrivileged(J2DoPrivHelper
.isDirectoryAction(file)).booleanValue())
addIterator(new FileMetaDataIterator(file, filter));
else if (tokens[i].endsWith(".jar")) {
try {

View File

@ -25,6 +25,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.util.ArrayList;
@ -49,7 +50,7 @@ public class FileMetaDataIterator implements MetaDataIterator {
private static final Localizer _loc = Localizer.forPackage
(FileMetaDataIterator.class);
private final Iterator _itr;
private final Iterator<File> _itr;
private File _file = null;
/**
@ -68,7 +69,7 @@ public class FileMetaDataIterator implements MetaDataIterator {
if (dir == null)
_itr = null;
else {
Collection metas = new ArrayList();
Collection<File> metas = new ArrayList<File>();
FileResource rsrc = (filter == null) ? null : new FileResource();
scan(dir, filter, rsrc, metas, 0);
_itr = metas.iterator();
@ -80,7 +81,7 @@ public class FileMetaDataIterator implements MetaDataIterator {
* to the given collection.
*/
private int scan(File file, MetaDataFilter filter, FileResource rsrc,
Collection metas, int scanned) throws IOException {
Collection<File> metas, int scanned) throws IOException {
if (scanned > SCAN_LIMIT)
throw new IllegalStateException(_loc.get("too-many-files",
String.valueOf(SCAN_LIMIT)).getMessage());
@ -107,11 +108,11 @@ public class FileMetaDataIterator implements MetaDataIterator {
return _itr != null && _itr.hasNext();
}
public Object next() throws IOException {
public URL next() throws IOException {
if (_itr == null)
throw new NoSuchElementException();
_file = (File) _itr.next();
_file = _itr.next();
try {
File f = AccessController.doPrivileged(J2DoPrivHelper
.getAbsoluteFileAction(_file));

View File

@ -22,7 +22,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
@ -34,7 +33,7 @@ import java.util.NoSuchElementException;
*/
public class MetaDataIteratorChain implements MetaDataIterator {
private List _itrs = null;
private List<MetaDataIterator> _itrs = null;
private int _cur = -1;
private MetaDataIterator _itr = null;
@ -48,7 +47,7 @@ public class MetaDataIteratorChain implements MetaDataIterator {
* Combine two iterators.
*/
public MetaDataIteratorChain(MetaDataIterator itr1, MetaDataIterator itr2) {
_itrs = new ArrayList(2);
_itrs = new ArrayList<MetaDataIterator>(2);
_itrs.add(itr1);
_itrs.add(itr2);
}
@ -60,7 +59,7 @@ public class MetaDataIteratorChain implements MetaDataIterator {
if (_cur != -1)
throw new IllegalStateException();
if (_itrs == null)
_itrs = new ArrayList(4);
_itrs = new ArrayList<MetaDataIterator>(4);
_itrs.add(itr);
}
@ -101,8 +100,10 @@ public class MetaDataIteratorChain implements MetaDataIterator {
}
public void close() {
if (_itrs != null)
for (Iterator itr = _itrs.iterator(); itr.hasNext();)
((MetaDataIterator) itr.next()).close();
if (_itrs != null) {
for(MetaDataIterator mdi: _itrs) {
mdi.close();
}
}
}
}

View File

@ -64,7 +64,7 @@ public interface MetaDataParser {
* top-down or bottom-up. If the class is null, only top-level locations
* will be parsed.
*/
public void parse(Class cls, boolean topDown) throws IOException;
public void parse(Class<?> cls, boolean topDown) throws IOException;
/**
* Parse the metadata in the given reader.

View File

@ -50,9 +50,9 @@ public interface MetaDataSerializer {
* parsed. The objects must implement the {@link SourceTracker} interface.
*
* @param output if null, then serialize directly to the file system;
* othwerwise, populate the specified {@link Map} with
* otherwise, populate the specified {@link Map} with
* keys that are the {@link File} instances, and
* values that are the {@link String} contents of the metadata
* values that are the {@link String} contents of the MetaData
* @param flags bit flags specifying the output flags; e.g. {@link #PRETTY}
*/
public void serialize(Map output, int flags) throws IOException;

View File

@ -41,7 +41,7 @@ import org.apache.openjpa.lib.util.MultiClassLoader;
*/
public class ResourceMetaDataIterator implements MetaDataIterator {
private List _urls = null;
private List<URL> _urls = null;
private int _url = -1;
/**
@ -59,18 +59,18 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
if (loader == null) {
MultiClassLoader multi = AccessController
.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
multi.addClassLoader(multi.SYSTEM_LOADER);
multi.addClassLoader(multi.THREAD_LOADER);
multi.addClassLoader(MultiClassLoader.SYSTEM_LOADER);
multi.addClassLoader(MultiClassLoader.THREAD_LOADER);
multi.addClassLoader(getClass().getClassLoader());
loader = multi;
}
try {
Enumeration e = AccessController.doPrivileged(
Enumeration<URL> e = AccessController.doPrivileged(
J2DoPrivHelper.getResourcesAction(loader, rsrc));
while (e.hasMoreElements()) {
if (_urls == null)
_urls = new ArrayList(3);
_urls = new ArrayList<URL>(3);
_urls.add(e.nextElement());
}
} catch (PrivilegedActionException pae) {
@ -82,7 +82,7 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
return _urls != null && _url + 1 < _urls.size();
}
public Object next() {
public URL next() {
if (!hasNext())
throw new NoSuchElementException();
return _urls.get(++_url);
@ -93,7 +93,7 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
throw new IllegalStateException();
try {
return AccessController.doPrivileged(
J2DoPrivHelper.openStreamAction((URL) _urls.get(_url)));
J2DoPrivHelper.openStreamAction(_urls.get(_url)));
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getException();
}
@ -102,8 +102,7 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
public File getFile() throws IOException {
if (_url == -1 || _url >= _urls.size())
throw new IllegalStateException();
File file = new File(URLDecoder.decode(((URL) _urls.get(_url)).
getFile()));
File file = new File(URLDecoder.decode((_urls.get(_url)).getFile()));
return ((AccessController.doPrivileged(
J2DoPrivHelper.existsAction(file))).booleanValue()) ? file :null;
}

View File

@ -50,7 +50,7 @@ public class URLMetaDataIterator implements MetaDataIterator {
return _url != null && !_iterated;
}
public Object next() throws IOException {
public URL next() throws IOException {
if (!hasNext())
throw new IllegalStateException();

View File

@ -82,7 +82,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
// map of classloaders to sets of parsed locations, so that we don't parse
// the same resource multiple times for the same class
private Map _parsed = null;
private Map<ClassLoader, Set<String>> _parsed = null;
private Log _log = null;
private boolean _validating = true;
@ -100,7 +100,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
private String _sourceName = null;
private File _sourceFile = null;
private StringBuffer _text = null;
private List _comments = null;
private List<String> _comments = null;
private Location _location = new Location();
private LexicalHandler _lh = null;
private int _depth = -1;
@ -254,7 +254,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
public List getResults() {
if (_results == null)
return Collections.EMPTY_LIST;
return Collections.emptyList();
return _results;
}
@ -392,12 +392,12 @@ public abstract class XMLMetaDataParser extends DefaultHandler
if (!_caching)
return false;
if (_parsed == null)
_parsed = new HashMap();
_parsed = new HashMap<ClassLoader, Set<String>>();
ClassLoader loader = currentClassLoader();
Set set = (Set) _parsed.get(loader);
Set<String> set = _parsed.get(loader);
if (set == null) {
set = new HashSet();
set = new HashSet<String>();
_parsed.put(loader, set);
}
boolean added = set.add(src);
@ -456,7 +456,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
public void comment(char[] ch, int start, int length) throws SAXException {
if (_parseComments && _depth <= _ignore) {
if (_comments == null)
_comments = new ArrayList(3);
_comments = new ArrayList<String>(3);
_comments.add(String.valueOf(ch, start, length));
}
if (_lh != null)
@ -597,7 +597,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
protected String[] currentComments() {
if (_comments == null || _comments.isEmpty())
return Commentable.EMPTY_COMMENTS;
return (String[]) _comments.toArray(new String[_comments.size()]);
return _comments.toArray(new String[_comments.size()]);
}
/**

View File

@ -29,7 +29,9 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.xml.transform.Result;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
@ -37,17 +39,17 @@ import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Files;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.xml.Commentable;
import org.apache.openjpa.lib.xml.XMLWriter;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
/**
* Abstract base type for serlializers that transfer groups of objects
@ -90,18 +92,16 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
serialize((Map) null, flags);
}
public void serialize(Map output, int flags) throws IOException {
Map files = getFileMap();
public void serialize(Map output, int flags)
throws IOException {
Map<File, Collection<Object>> files = getFileMap();
if (files == null)
return;
// for each file, serialize objects
Map.Entry entry;
for (Iterator itr = files.entrySet().iterator(); itr.hasNext();) {
entry = (Map.Entry) itr.next();
File file = (File) entry.getKey();
Collection fileObjs = (Collection) entry.getValue();
Collection<Object> fileObjs;
for(File file : files.keySet()) {
fileObjs = files.get(file);
if (_log != null && _log.isInfoEnabled())
_log.info(_loc.get("ser-file", file));
@ -151,18 +151,17 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
* written to, and values of a {@link Collection} of
* {@link SourceTracker} instances.
*/
protected Map getFileMap() {
Collection objs = getObjects();
protected Map<File, Collection<Object>> getFileMap() {
Collection<Object> objs = getObjects();
if (objs == null || objs.isEmpty())
return null;
// create a map of files to lists of objects
Map files = new HashMap();
Map<File, Collection<Object>> files =
new HashMap<File, Collection<Object>>();
File file;
Collection fileObjs;
Object obj;
for (Iterator itr = objs.iterator(); itr.hasNext();) {
obj = itr.next();
Collection<Object> fileObjs;
for(Object obj : objs) {
file = getSourceFile(obj);
if (file == null) {
if (_log != null && _log.isTraceEnabled())
@ -170,9 +169,9 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
continue;
}
fileObjs = (Collection) files.get(file);
fileObjs = (Collection<Object>) files.get(file);
if (fileObjs == null) {
fileObjs = new LinkedList();
fileObjs = new LinkedList<Object>();
files.put(file, fileObjs);
}
fileObjs.add(obj);
@ -244,8 +243,8 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
/**
* Serialize the given collection of objects to the given handler.
*/
private void serialize(Collection objs, ContentHandler handler, int flags)
throws SAXException {
private void serialize(Collection<Object> objs, ContentHandler handler,
int flags) throws SAXException {
if (_log != null && _log.isTraceEnabled())
_log.trace(_loc.get("ser-objs", objs));
@ -352,10 +351,10 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
/**
* Serialize the given set of objects.
*/
protected abstract void serialize(Collection objs) throws SAXException;
protected abstract void serialize(Collection<Object> objs) throws SAXException;
/**
* Return the current set of objects for serialization.
*/
protected abstract Collection getObjects();
protected abstract Collection<Object> getObjects();
}

View File

@ -44,7 +44,7 @@ public class ZipFileMetaDataIterator
private final ZipFile _file;
private final MetaDataFilter _filter;
private final Enumeration _entries;
private final Enumeration<? extends ZipEntry> _entries;
private ZipEntry _entry = null;
private ZipEntry _last = null;
@ -84,14 +84,14 @@ public class ZipFileMetaDataIterator
// search for next metadata file
while (_entry == null && _entries.hasMoreElements()) {
_entry = (ZipEntry) _entries.nextElement();
_entry = _entries.nextElement();
if (_filter != null && !_filter.matches(this))
_entry = null;
}
return _entry != null;
}
public Object next() throws IOException {
public String next() throws IOException {
if (!hasNext())
throw new NoSuchElementException();
String ret = _entry.getName();

View File

@ -75,7 +75,7 @@ public class ZipStreamMetaDataIterator
return _entry != null;
}
public Object next() throws IOException {
public String next() throws IOException {
if (!hasNext())
throw new NoSuchElementException();
String ret = _entry.getName();

View File

@ -28,17 +28,17 @@ import org.apache.openjpa.lib.util.Localizer;
* @author Abe White
* @nojavadoc
*/
abstract class AbstractListIterator implements ListIterator {
abstract class AbstractListIterator<E> implements ListIterator<E> {
private static final Localizer _loc = Localizer.forPackage
(AbstractListIterator.class);
public void add(Object o) {
public void add(E o) {
throw new UnsupportedOperationException(_loc.get("read-only")
.getMessage());
}
public void set(Object o) {
public void set(E o) {
throw new UnsupportedOperationException(_loc.get("read-only")
.getMessage());
}

View File

@ -30,7 +30,8 @@ import org.apache.openjpa.lib.util.Localizer;
* @author Abe White
* @nojavadoc
*/
public abstract class AbstractResultList implements ResultList {
@SuppressWarnings("serial")
public abstract class AbstractResultList<E> implements ResultList<E> {
private static final Localizer _loc = Localizer.forPackage
(AbstractResultList.class);
@ -48,15 +49,15 @@ public abstract class AbstractResultList implements ResultList {
throw readOnly();
}
public boolean addAll(Collection c) {
public boolean addAll(Collection<? extends E> c) {
throw readOnly();
}
public boolean addAll(int index, Collection c) {
public boolean addAll(int index, Collection<? extends E> c) {
throw readOnly();
}
public Object remove(int index) {
public E remove(int index) {
throw readOnly();
}
@ -64,15 +65,15 @@ public abstract class AbstractResultList implements ResultList {
throw readOnly();
}
public boolean removeAll(Collection c) {
public boolean removeAll(Collection<?> c) {
throw readOnly();
}
public boolean retainAll(Collection c) {
public boolean retainAll(Collection<?> c) {
throw readOnly();
}
public Object set(int index, Object element) {
public E set(int index, Object element) {
throw readOnly();
}
@ -80,7 +81,7 @@ public abstract class AbstractResultList implements ResultList {
throw readOnly();
}
public List subList(int from, int to) {
public List<E> subList(int from, int to) {
throw new UnsupportedOperationException();
}

View File

@ -37,7 +37,7 @@ import org.apache.openjpa.lib.util.Closeable;
*
* @author Marc Prud'hommeaux
*/
public interface ResultList extends List, Serializable, Closeable {
public interface ResultList<E> extends List<E>, Serializable, Closeable {
/**
* Returns true if the provider backing this list is open.

View File

@ -51,6 +51,7 @@ import serp.util.Strings;
* @author Abe White
* @nojavadoc
*/
@SuppressWarnings("serial")
public class Options extends TypedProperties {
/**