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, 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) if (mode == MODE_NONE)
return true; return true;
if (isMappingOnlyFactory() && (mode & MODE_MAPPING) == 0) if (isMappingOnlyFactory() && (mode & MODE_MAPPING) == 0)
@ -338,14 +338,14 @@ public abstract class AbstractCFMetaDataFactory
for (int i = 0; i < cls.length; i++) for (int i = 0; i < cls.length; i++)
ser.removeMetaData(pr.getMetaData(cls[i], envLoader, ser.removeMetaData(pr.getMetaData(cls[i], envLoader,
false)); false));
serialize(ser, null, ser.PRETTY); serialize(ser, null, Serializer.PRETTY);
} }
if (qqs != null && !qqs.isEmpty()) { if (qqs != null && !qqs.isEmpty()) {
ser = newSerializer(); ser = newSerializer();
ser.setMode(MODE_QUERY); ser.setMode(MODE_QUERY);
for (int i = 0; i < qqs.size(); i++) for (int i = 0; i < qqs.size(); i++)
ser.addQueryMetaData((QueryMetaData) qqs.get(i)); ser.addQueryMetaData((QueryMetaData) qqs.get(i));
serialize(ser, null, ser.PRETTY); serialize(ser, null, Serializer.PRETTY);
} }
return true; return true;
} }
@ -473,7 +473,8 @@ public abstract class AbstractCFMetaDataFactory
/** /**
* Tell the given serialier to write its metadatas. * 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 { try {
if (output == null) if (output == null)
ser.serialize(flags); ser.serialize(flags);

View File

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

View File

@ -87,7 +87,7 @@ public interface MetaDataFactory
* @return false if this factory is unable to store metadata * @return false if this factory is unable to store metadata
*/ */
public boolean store(ClassMetaData[] metas, QueryMetaData[] queries, 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). * 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.sql.SQLException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -36,7 +35,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/ */
public class DecoratingDataSource extends DelegatingDataSource { public class DecoratingDataSource extends DelegatingDataSource {
private List _decorators = new CopyOnWriteArrayList(); private List<ConnectionDecorator> _decorators =
new CopyOnWriteArrayList<ConnectionDecorator>();
/** /**
* Constructor. Supply wrapped data source. * 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 * Return a read-only list of connection decorators in the order they were
* added. * added.
*/ */
public Collection getDecorators() { public Collection<ConnectionDecorator> getDecorators() {
return Collections.unmodifiableCollection(_decorators); return Collections.unmodifiableCollection(_decorators);
} }
@ -64,7 +64,7 @@ public class DecoratingDataSource extends DelegatingDataSource {
/** /**
* Add multiple connection decorators efficiently. * Add multiple connection decorators efficiently.
*/ */
public void addDecorators(Collection decorators) { public void addDecorators(Collection<ConnectionDecorator> decorators) {
if (decorators != null) if (decorators != null)
_decorators.addAll(decorators); _decorators.addAll(decorators);
} }
@ -95,9 +95,9 @@ public class DecoratingDataSource extends DelegatingDataSource {
} }
private Connection decorate(Connection conn) throws SQLException { private Connection decorate(Connection conn) throws SQLException {
if (!_decorators.isEmpty()) for(ConnectionDecorator decorator : _decorators) {
for (Iterator itr = _decorators.iterator(); itr.hasNext();) conn = decorator.decorate(conn);
conn = ((ConnectionDecorator) itr.next()).decorate(conn); }
return conn; return conn;
} }
} }

View File

@ -336,6 +336,9 @@ public class DelegatingCallableStatement
_stmnt.setAsciiStream(i1, is, i2); _stmnt.setAsciiStream(i1, is, i2);
} }
/**
* @deprecated
*/
public void setUnicodeStream(int i1, InputStream is, int i2) public void setUnicodeStream(int i1, InputStream is, int i2)
throws SQLException { throws SQLException {
_stmnt.setUnicodeStream(i1, is, i2); _stmnt.setUnicodeStream(i1, is, i2);
@ -509,6 +512,10 @@ public class DelegatingCallableStatement
return _stmnt.getDouble(i); 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 { public BigDecimal getBigDecimal(int a, int b) throws SQLException {
return _stmnt.getBigDecimal(a, b); return _stmnt.getBigDecimal(a, b);
} }
@ -537,7 +544,7 @@ public class DelegatingCallableStatement
return _stmnt.getBigDecimal(i); 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); return _stmnt.getObject(i, m);
} }
@ -760,7 +767,7 @@ public class DelegatingCallableStatement
throw new UnsupportedOperationException(); 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(); throw new UnsupportedOperationException();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,11 +31,11 @@ import java.util.concurrent.ConcurrentHashMap;
public abstract class LogFactoryAdapter implements LogFactory { public abstract class LogFactoryAdapter implements LogFactory {
// cache category to log adapters // cache category to log adapters
private Map _logs = new ConcurrentHashMap(); private Map<String, Log> _logs = new ConcurrentHashMap<String, Log>();
public Log getLog(String channel) { public Log getLog(String channel) {
// no locking; OK if same adapter created multiple times // no locking; OK if same adapter created multiple times
Log log = (Log) _logs.get(channel); Log log = _logs.get(channel);
if (log == null) { if (log == null) {
log = newLogAdapter(channel); log = newLogAdapter(channel);
_logs.put(channel, log); _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. * 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. * The default logging level.
@ -83,7 +84,8 @@ public class LogFactoryImpl
/** /**
* Storage for logging level configuration specified at configuration time. * 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. * The stream to write to. Defaults to System.err.
@ -106,11 +108,11 @@ public class LogFactoryImpl
public Log getLog(String channel) { public Log getLog(String channel) {
// no locking; ok if same log created multiple times // no locking; ok if same log created multiple times
LogImpl l = (LogImpl) _logs.get(channel); LogImpl l = _logs.get(channel);
if (l == null) { if (l == null) {
l = newLogImpl(); l = newLogImpl();
l.setChannel(channel); l.setChannel(channel); // TODO add to interface?
Short lvl = (Short) _configuredLevels.get(shorten(channel)); Short lvl = _configuredLevels.get(shorten(channel));
l.setLevel(lvl == null ? _defaultLogLevel : lvl.shortValue()); l.setLevel(lvl == null ? _defaultLogLevel : lvl.shortValue());
_logs.put(channel, l); _logs.put(channel, l);
} }
@ -271,11 +273,12 @@ public class LogFactoryImpl
public void setInto(Options opts) { public void setInto(Options opts) {
if (!opts.isEmpty()) { if (!opts.isEmpty()) {
Map.Entry e; Map.Entry<Object, Object> e;
for (Iterator iter = opts.entrySet().iterator(); iter.hasNext();) { for (Iterator<Map.Entry<Object, Object>> iter =
e = (Map.Entry) iter.next(); opts.entrySet().iterator(); iter.hasNext();) {
_configuredLevels.put(shorten((String) e.getKey()), e = iter.next();
new Short(getLevel((String) e.getValue()))); _configuredLevels.put(shorten((String) e.getKey()), new Short(
getLevel((String) e.getValue())));
} }
opts.clear(); opts.clear();
} }

View File

@ -20,7 +20,6 @@ package org.apache.openjpa.lib.log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -33,7 +32,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/ */
public class MultiLogFactory implements LogFactory { public class MultiLogFactory implements LogFactory {
private List _delegates; private List<LogFactory> _delegates;
/** /**
* Create an instance with the given delegates. * Create an instance with the given delegates.
@ -53,7 +52,8 @@ public class MultiLogFactory implements LogFactory {
* Create an instance with the given delegates. * Create an instance with the given delegates.
*/ */
public MultiLogFactory(LogFactory[] delegates) { public MultiLogFactory(LogFactory[] delegates) {
_delegates = new CopyOnWriteArrayList(Arrays.asList(delegates)); _delegates =
new CopyOnWriteArrayList<LogFactory>(Arrays.asList(delegates));
} }
public void addLogFactory(LogFactory factory) { public void addLogFactory(LogFactory factory) {
@ -75,16 +75,15 @@ public class MultiLogFactory implements LogFactory {
* Returns a Log impl that combines all logs. * Returns a Log impl that combines all logs.
*/ */
public synchronized Log getLog(String channel) { public synchronized Log getLog(String channel) {
List logs = new ArrayList(_delegates.size()); List<Log> logs = new ArrayList<Log>(_delegates.size());
for (Iterator i = _delegates.iterator(); i.hasNext();) { for(LogFactory f : _delegates) {
LogFactory f = (LogFactory) i.next();
if (f != null) { if (f != null) {
Log l = f.getLog(channel); Log l = f.getLog(channel);
if (l != null) if (l != null)
logs.add(l); 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 * taking into account the package currently being parsed for relative
* class names. * class names.
*/ */
protected Class classForName(String name, boolean resolve) protected Class<?> classForName(String name, boolean resolve)
throws SAXException { throws SAXException {
if (name == null) if (name == null)
return null; return null;
Class cls = classForName(name, _package, resolve, currentClassLoader()); Class<?> cls =
classForName(name, _package, resolve, currentClassLoader());
if (cls == null) if (cls == null)
throw getException(_loc.get("invalid-class", name).getMessage()); throw getException(_loc.get("invalid-class", name).getMessage());
return cls; return cls;
@ -292,7 +293,7 @@ public class CFMetaDataParser extends XMLMetaDataParser {
* Load the given class name against the given package and the set * Load the given class name against the given package and the set
* of accepted standard packages. Return null if the class cannot be loaded. * 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) { boolean resolve, ClassLoader loader) {
if (StringUtils.isEmpty(name)) if (StringUtils.isEmpty(name))
return null; return null;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -34,7 +33,7 @@ import java.util.NoSuchElementException;
*/ */
public class MetaDataIteratorChain implements MetaDataIterator { public class MetaDataIteratorChain implements MetaDataIterator {
private List _itrs = null; private List<MetaDataIterator> _itrs = null;
private int _cur = -1; private int _cur = -1;
private MetaDataIterator _itr = null; private MetaDataIterator _itr = null;
@ -48,7 +47,7 @@ public class MetaDataIteratorChain implements MetaDataIterator {
* Combine two iterators. * Combine two iterators.
*/ */
public MetaDataIteratorChain(MetaDataIterator itr1, MetaDataIterator itr2) { public MetaDataIteratorChain(MetaDataIterator itr1, MetaDataIterator itr2) {
_itrs = new ArrayList(2); _itrs = new ArrayList<MetaDataIterator>(2);
_itrs.add(itr1); _itrs.add(itr1);
_itrs.add(itr2); _itrs.add(itr2);
} }
@ -60,7 +59,7 @@ public class MetaDataIteratorChain implements MetaDataIterator {
if (_cur != -1) if (_cur != -1)
throw new IllegalStateException(); throw new IllegalStateException();
if (_itrs == null) if (_itrs == null)
_itrs = new ArrayList(4); _itrs = new ArrayList<MetaDataIterator>(4);
_itrs.add(itr); _itrs.add(itr);
} }
@ -101,8 +100,10 @@ public class MetaDataIteratorChain implements MetaDataIterator {
} }
public void close() { public void close() {
if (_itrs != null) if (_itrs != null) {
for (Iterator itr = _itrs.iterator(); itr.hasNext();) for(MetaDataIterator mdi: _itrs) {
((MetaDataIterator) itr.next()).close(); 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 * top-down or bottom-up. If the class is null, only top-level locations
* will be parsed. * 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. * 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. * parsed. The objects must implement the {@link SourceTracker} interface.
* *
* @param output if null, then serialize directly to the file system; * @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 * 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} * @param flags bit flags specifying the output flags; e.g. {@link #PRETTY}
*/ */
public void serialize(Map output, int flags) throws IOException; 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 { public class ResourceMetaDataIterator implements MetaDataIterator {
private List _urls = null; private List<URL> _urls = null;
private int _url = -1; private int _url = -1;
/** /**
@ -59,18 +59,18 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
if (loader == null) { if (loader == null) {
MultiClassLoader multi = AccessController MultiClassLoader multi = AccessController
.doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction()); .doPrivileged(J2DoPrivHelper.newMultiClassLoaderAction());
multi.addClassLoader(multi.SYSTEM_LOADER); multi.addClassLoader(MultiClassLoader.SYSTEM_LOADER);
multi.addClassLoader(multi.THREAD_LOADER); multi.addClassLoader(MultiClassLoader.THREAD_LOADER);
multi.addClassLoader(getClass().getClassLoader()); multi.addClassLoader(getClass().getClassLoader());
loader = multi; loader = multi;
} }
try { try {
Enumeration e = AccessController.doPrivileged( Enumeration<URL> e = AccessController.doPrivileged(
J2DoPrivHelper.getResourcesAction(loader, rsrc)); J2DoPrivHelper.getResourcesAction(loader, rsrc));
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
if (_urls == null) if (_urls == null)
_urls = new ArrayList(3); _urls = new ArrayList<URL>(3);
_urls.add(e.nextElement()); _urls.add(e.nextElement());
} }
} catch (PrivilegedActionException pae) { } catch (PrivilegedActionException pae) {
@ -82,7 +82,7 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
return _urls != null && _url + 1 < _urls.size(); return _urls != null && _url + 1 < _urls.size();
} }
public Object next() { public URL next() {
if (!hasNext()) if (!hasNext())
throw new NoSuchElementException(); throw new NoSuchElementException();
return _urls.get(++_url); return _urls.get(++_url);
@ -93,7 +93,7 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
throw new IllegalStateException(); throw new IllegalStateException();
try { try {
return AccessController.doPrivileged( return AccessController.doPrivileged(
J2DoPrivHelper.openStreamAction((URL) _urls.get(_url))); J2DoPrivHelper.openStreamAction(_urls.get(_url)));
} catch (PrivilegedActionException pae) { } catch (PrivilegedActionException pae) {
throw (IOException) pae.getException(); throw (IOException) pae.getException();
} }
@ -102,8 +102,7 @@ public class ResourceMetaDataIterator implements MetaDataIterator {
public File getFile() throws IOException { public File getFile() throws IOException {
if (_url == -1 || _url >= _urls.size()) if (_url == -1 || _url >= _urls.size())
throw new IllegalStateException(); throw new IllegalStateException();
File file = new File(URLDecoder.decode(((URL) _urls.get(_url)). File file = new File(URLDecoder.decode((_urls.get(_url)).getFile()));
getFile()));
return ((AccessController.doPrivileged( return ((AccessController.doPrivileged(
J2DoPrivHelper.existsAction(file))).booleanValue()) ? file :null; J2DoPrivHelper.existsAction(file))).booleanValue()) ? file :null;
} }

View File

@ -50,7 +50,7 @@ public class URLMetaDataIterator implements MetaDataIterator {
return _url != null && !_iterated; return _url != null && !_iterated;
} }
public Object next() throws IOException { public URL next() throws IOException {
if (!hasNext()) if (!hasNext())
throw new IllegalStateException(); 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 // map of classloaders to sets of parsed locations, so that we don't parse
// the same resource multiple times for the same class // 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 Log _log = null;
private boolean _validating = true; private boolean _validating = true;
@ -100,7 +100,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
private String _sourceName = null; private String _sourceName = null;
private File _sourceFile = null; private File _sourceFile = null;
private StringBuffer _text = null; private StringBuffer _text = null;
private List _comments = null; private List<String> _comments = null;
private Location _location = new Location(); private Location _location = new Location();
private LexicalHandler _lh = null; private LexicalHandler _lh = null;
private int _depth = -1; private int _depth = -1;
@ -254,7 +254,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
public List getResults() { public List getResults() {
if (_results == null) if (_results == null)
return Collections.EMPTY_LIST; return Collections.emptyList();
return _results; return _results;
} }
@ -392,12 +392,12 @@ public abstract class XMLMetaDataParser extends DefaultHandler
if (!_caching) if (!_caching)
return false; return false;
if (_parsed == null) if (_parsed == null)
_parsed = new HashMap(); _parsed = new HashMap<ClassLoader, Set<String>>();
ClassLoader loader = currentClassLoader(); ClassLoader loader = currentClassLoader();
Set set = (Set) _parsed.get(loader); Set<String> set = _parsed.get(loader);
if (set == null) { if (set == null) {
set = new HashSet(); set = new HashSet<String>();
_parsed.put(loader, set); _parsed.put(loader, set);
} }
boolean added = set.add(src); 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 { public void comment(char[] ch, int start, int length) throws SAXException {
if (_parseComments && _depth <= _ignore) { if (_parseComments && _depth <= _ignore) {
if (_comments == null) if (_comments == null)
_comments = new ArrayList(3); _comments = new ArrayList<String>(3);
_comments.add(String.valueOf(ch, start, length)); _comments.add(String.valueOf(ch, start, length));
} }
if (_lh != null) if (_lh != null)
@ -597,7 +597,7 @@ public abstract class XMLMetaDataParser extends DefaultHandler
protected String[] currentComments() { protected String[] currentComments() {
if (_comments == null || _comments.isEmpty()) if (_comments == null || _comments.isEmpty())
return Commentable.EMPTY_COMMENTS; 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.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.xml.transform.Result; import javax.xml.transform.Result;
import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory; 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.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult; 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.log.Log;
import org.apache.openjpa.lib.util.Files; import org.apache.openjpa.lib.util.Files;
import org.apache.openjpa.lib.util.J2DoPrivHelper; import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.xml.Commentable; import org.apache.openjpa.lib.xml.Commentable;
import org.apache.openjpa.lib.xml.XMLWriter; 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 * Abstract base type for serlializers that transfer groups of objects
@ -90,18 +92,16 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
serialize((Map) null, flags); serialize((Map) null, flags);
} }
public void serialize(Map output, int flags) throws IOException { public void serialize(Map output, int flags)
Map files = getFileMap(); throws IOException {
Map<File, Collection<Object>> files = getFileMap();
if (files == null) if (files == null)
return; return;
// for each file, serialize objects // for each file, serialize objects
Map.Entry entry; Collection<Object> fileObjs;
for (Iterator itr = files.entrySet().iterator(); itr.hasNext();) { for(File file : files.keySet()) {
entry = (Map.Entry) itr.next(); fileObjs = files.get(file);
File file = (File) entry.getKey();
Collection fileObjs = (Collection) entry.getValue();
if (_log != null && _log.isInfoEnabled()) if (_log != null && _log.isInfoEnabled())
_log.info(_loc.get("ser-file", file)); _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 * written to, and values of a {@link Collection} of
* {@link SourceTracker} instances. * {@link SourceTracker} instances.
*/ */
protected Map getFileMap() { protected Map<File, Collection<Object>> getFileMap() {
Collection objs = getObjects(); Collection<Object> objs = getObjects();
if (objs == null || objs.isEmpty()) if (objs == null || objs.isEmpty())
return null; return null;
// create a map of files to lists of objects // 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; File file;
Collection fileObjs; Collection<Object> fileObjs;
Object obj; for(Object obj : objs) {
for (Iterator itr = objs.iterator(); itr.hasNext();) {
obj = itr.next();
file = getSourceFile(obj); file = getSourceFile(obj);
if (file == null) { if (file == null) {
if (_log != null && _log.isTraceEnabled()) if (_log != null && _log.isTraceEnabled())
@ -170,9 +169,9 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
continue; continue;
} }
fileObjs = (Collection) files.get(file); fileObjs = (Collection<Object>) files.get(file);
if (fileObjs == null) { if (fileObjs == null) {
fileObjs = new LinkedList(); fileObjs = new LinkedList<Object>();
files.put(file, fileObjs); files.put(file, fileObjs);
} }
fileObjs.add(obj); fileObjs.add(obj);
@ -244,8 +243,8 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
/** /**
* Serialize the given collection of objects to the given handler. * Serialize the given collection of objects to the given handler.
*/ */
private void serialize(Collection objs, ContentHandler handler, int flags) private void serialize(Collection<Object> objs, ContentHandler handler,
throws SAXException { int flags) throws SAXException {
if (_log != null && _log.isTraceEnabled()) if (_log != null && _log.isTraceEnabled())
_log.trace(_loc.get("ser-objs", objs)); _log.trace(_loc.get("ser-objs", objs));
@ -352,10 +351,10 @@ public abstract class XMLMetaDataSerializer implements MetaDataSerializer {
/** /**
* Serialize the given set of objects. * 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. * 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 ZipFile _file;
private final MetaDataFilter _filter; private final MetaDataFilter _filter;
private final Enumeration _entries; private final Enumeration<? extends ZipEntry> _entries;
private ZipEntry _entry = null; private ZipEntry _entry = null;
private ZipEntry _last = null; private ZipEntry _last = null;
@ -84,14 +84,14 @@ public class ZipFileMetaDataIterator
// search for next metadata file // search for next metadata file
while (_entry == null && _entries.hasMoreElements()) { while (_entry == null && _entries.hasMoreElements()) {
_entry = (ZipEntry) _entries.nextElement(); _entry = _entries.nextElement();
if (_filter != null && !_filter.matches(this)) if (_filter != null && !_filter.matches(this))
_entry = null; _entry = null;
} }
return _entry != null; return _entry != null;
} }
public Object next() throws IOException { public String next() throws IOException {
if (!hasNext()) if (!hasNext())
throw new NoSuchElementException(); throw new NoSuchElementException();
String ret = _entry.getName(); String ret = _entry.getName();

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ import org.apache.openjpa.lib.util.Closeable;
* *
* @author Marc Prud'hommeaux * @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. * Returns true if the provider backing this list is open.

View File

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