forked from I2P_Developers/i2p.i2p
Class generics
This commit is contained in:
@ -832,7 +832,7 @@ public class PluginStarter implements Runnable {
|
|||||||
*/
|
*/
|
||||||
private static void addPath(URL u) throws Exception {
|
private static void addPath(URL u) throws Exception {
|
||||||
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
|
||||||
Class urlClass = URLClassLoader.class;
|
Class<URLClassLoader> urlClass = URLClassLoader.class;
|
||||||
Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
|
Method method = urlClass.getDeclaredMethod("addURL", new Class[]{URL.class});
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(urlClassLoader, new Object[]{u});
|
method.invoke(urlClassLoader, new Object[]{u});
|
||||||
|
@ -46,7 +46,7 @@ public class EncodingFactory {
|
|||||||
String[] classNames = list.split( ";" );
|
String[] classNames = list.split( ";" );
|
||||||
for( int i = 0; i < classNames.length; i++ ) {
|
for( int i = 0; i < classNames.length; i++ ) {
|
||||||
try {
|
try {
|
||||||
Class c = Class.forName( classNames[i] );
|
Class<?> c = Class.forName( classNames[i] );
|
||||||
Encoding e = (Encoding)c.newInstance();
|
Encoding e = (Encoding)c.newInstance();
|
||||||
encodings.put( e.getName(), e );
|
encodings.put( e.getName(), e );
|
||||||
Debug.debug( Debug.DEBUG, "Registered " + e.getClass().getName() );
|
Debug.debug( Debug.DEBUG, "Registered " + e.getClass().getName() );
|
||||||
|
@ -38,8 +38,8 @@ public class MetaNamingService extends DummyNamingService {
|
|||||||
_services = new CopyOnWriteArrayList<NamingService>();
|
_services = new CopyOnWriteArrayList<NamingService>();
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
try {
|
try {
|
||||||
Class cls = Class.forName(tok.nextToken());
|
Class<?> cls = Class.forName(tok.nextToken());
|
||||||
Constructor con = cls.getConstructor(new Class[] { I2PAppContext.class });
|
Constructor<?> con = cls.getConstructor(new Class[] { I2PAppContext.class });
|
||||||
addNamingService((NamingService)con.newInstance(new Object[] { context }), false);
|
addNamingService((NamingService)con.newInstance(new Object[] { context }), false);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
|
@ -462,8 +462,8 @@ public abstract class NamingService {
|
|||||||
NamingService instance = null;
|
NamingService instance = null;
|
||||||
String impl = context.getProperty(PROP_IMPL, DEFAULT_IMPL);
|
String impl = context.getProperty(PROP_IMPL, DEFAULT_IMPL);
|
||||||
try {
|
try {
|
||||||
Class cls = Class.forName(impl);
|
Class<?> cls = Class.forName(impl);
|
||||||
Constructor con = cls.getConstructor(new Class[] { I2PAppContext.class });
|
Constructor<?> con = cls.getConstructor(new Class[] { I2PAppContext.class });
|
||||||
instance = (NamingService)con.newInstance(new Object[] { context });
|
instance = (NamingService)con.newInstance(new Object[] { context });
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Log log = context.logManager().getLog(NamingService.class);
|
Log log = context.logManager().getLog(NamingService.class);
|
||||||
|
@ -41,8 +41,8 @@ class ECConstants {
|
|||||||
boolean loaded;
|
boolean loaded;
|
||||||
if (Security.getProvider("BC") == null) {
|
if (Security.getProvider("BC") == null) {
|
||||||
try {
|
try {
|
||||||
Class cls = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
|
Class<?> cls = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider");
|
||||||
Constructor con = cls.getConstructor(new Class[0]);
|
Constructor<?> con = cls.getConstructor(new Class[0]);
|
||||||
Provider bc = (Provider)con.newInstance(new Object[0]);
|
Provider bc = (Provider)con.newInstance(new Object[0]);
|
||||||
Security.addProvider(bc);
|
Security.addProvider(bc);
|
||||||
log("Added BC provider");
|
log("Added BC provider");
|
||||||
|
@ -295,7 +295,7 @@ public class FileUtil {
|
|||||||
//Pack200.newUnpacker().unpack(in, out);
|
//Pack200.newUnpacker().unpack(in, out);
|
||||||
if (!_failedOracle) {
|
if (!_failedOracle) {
|
||||||
try {
|
try {
|
||||||
Class p200 = Class.forName("java.util.jar.Pack200", true, ClassLoader.getSystemClassLoader());
|
Class<?> p200 = Class.forName("java.util.jar.Pack200", true, ClassLoader.getSystemClassLoader());
|
||||||
Method newUnpacker = p200.getMethod("newUnpacker", (Class[]) null);
|
Method newUnpacker = p200.getMethod("newUnpacker", (Class[]) null);
|
||||||
Object unpacker = newUnpacker.invoke(null,(Object[]) null);
|
Object unpacker = newUnpacker.invoke(null,(Object[]) null);
|
||||||
Method unpack = unpacker.getClass().getMethod("unpack", new Class[] {InputStream.class, JarOutputStream.class});
|
Method unpack = unpacker.getClass().getMethod("unpack", new Class[] {InputStream.class, JarOutputStream.class});
|
||||||
@ -316,8 +316,8 @@ public class FileUtil {
|
|||||||
//(new Archive(in, out)).unpack();
|
//(new Archive(in, out)).unpack();
|
||||||
if (!_failedApache) {
|
if (!_failedApache) {
|
||||||
try {
|
try {
|
||||||
Class p200 = Class.forName("org.apache.harmony.unpack200.Archive", true, ClassLoader.getSystemClassLoader());
|
Class<?> p200 = Class.forName("org.apache.harmony.unpack200.Archive", true, ClassLoader.getSystemClassLoader());
|
||||||
Constructor newUnpacker = p200.getConstructor(new Class[] {InputStream.class, JarOutputStream.class});
|
Constructor<?> newUnpacker = p200.getConstructor(new Class[] {InputStream.class, JarOutputStream.class});
|
||||||
Object unpacker = newUnpacker.newInstance(new Object[] {in, out});
|
Object unpacker = newUnpacker.newInstance(new Object[] {in, out});
|
||||||
Method unpack = unpacker.getClass().getMethod("unpack", (Class[]) null);
|
Method unpack = unpacker.getClass().getMethod("unpack", (Class[]) null);
|
||||||
// throws IOException or Pack200Exception
|
// throws IOException or Pack200Exception
|
||||||
|
@ -25,7 +25,7 @@ import net.i2p.I2PAppContext;
|
|||||||
* @author jrandom
|
* @author jrandom
|
||||||
*/
|
*/
|
||||||
public class Log {
|
public class Log {
|
||||||
private final Class _class;
|
private final Class<?> _class;
|
||||||
private final String _className;
|
private final String _className;
|
||||||
private final String _name;
|
private final String _name;
|
||||||
private int _minPriority;
|
private int _minPriority;
|
||||||
@ -75,7 +75,7 @@ public class Log {
|
|||||||
* Warning - not recommended.
|
* Warning - not recommended.
|
||||||
* Use I2PAppContext.getGlobalContext().logManager().getLog(cls)
|
* Use I2PAppContext.getGlobalContext().logManager().getLog(cls)
|
||||||
*/
|
*/
|
||||||
public Log(Class cls) {
|
public Log(Class<?> cls) {
|
||||||
this(I2PAppContext.getGlobalContext().logManager(), cls, null);
|
this(I2PAppContext.getGlobalContext().logManager(), cls, null);
|
||||||
_manager.addLog(this);
|
_manager.addLog(this);
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ public class Log {
|
|||||||
_manager.addLog(this);
|
_manager.addLog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogManager manager, Class cls) {
|
Log(LogManager manager, Class<?> cls) {
|
||||||
this(manager, cls, null);
|
this(manager, cls, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ public class Log {
|
|||||||
this(manager, null, name);
|
this(manager, null, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log(LogManager manager, Class cls, String name) {
|
Log(LogManager manager, Class<?> cls, String name) {
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
_class = cls;
|
_class = cls;
|
||||||
_className = cls != null ? cls.getName() : null;
|
_className = cls != null ? cls.getName() : null;
|
||||||
@ -229,7 +229,7 @@ public class Log {
|
|||||||
/** @return the LogScope (private class) */
|
/** @return the LogScope (private class) */
|
||||||
public Object getScope() { return _scope; }
|
public Object getScope() { return _scope; }
|
||||||
|
|
||||||
static String getScope(String name, Class cls) {
|
static String getScope(String name, Class<?> cls) {
|
||||||
if ( (name == null) && (cls == null) ) return "f00";
|
if ( (name == null) && (cls == null) ) return "f00";
|
||||||
if (cls == null) return name;
|
if (cls == null) return name;
|
||||||
if (name == null) return cls.getName();
|
if (name == null) return cls.getName();
|
||||||
@ -239,7 +239,7 @@ public class Log {
|
|||||||
private static final class LogScope {
|
private static final class LogScope {
|
||||||
private final String _scopeCache;
|
private final String _scopeCache;
|
||||||
|
|
||||||
public LogScope(String name, Class cls) {
|
public LogScope(String name, Class<?> cls) {
|
||||||
_scopeCache = getScope(name, cls);
|
_scopeCache = getScope(name, cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,9 +166,9 @@ public class LogManager {
|
|||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log getLog(Class cls) { return getLog(cls, null); }
|
public Log getLog(Class<?> cls) { return getLog(cls, null); }
|
||||||
public Log getLog(String name) { return getLog(null, name); }
|
public Log getLog(String name) { return getLog(null, name); }
|
||||||
public Log getLog(Class cls, String name) {
|
public Log getLog(Class<?> cls, String name) {
|
||||||
String scope = Log.getScope(name, cls);
|
String scope = Log.getScope(name, cls);
|
||||||
boolean isNew = false;
|
boolean isNew = false;
|
||||||
Log rv = _logs.get(scope);
|
Log rv = _logs.get(scope);
|
||||||
|
@ -15,14 +15,14 @@ package net.i2p.util;
|
|||||||
*/
|
*/
|
||||||
class LogRecord {
|
class LogRecord {
|
||||||
private final long _date;
|
private final long _date;
|
||||||
private final Class _source;
|
private final Class<?> _source;
|
||||||
private final String _name;
|
private final String _name;
|
||||||
private final String _threadName;
|
private final String _threadName;
|
||||||
private final int _priority;
|
private final int _priority;
|
||||||
private final String _message;
|
private final String _message;
|
||||||
private final Throwable _throwable;
|
private final Throwable _throwable;
|
||||||
|
|
||||||
public LogRecord(Class src, String name, String threadName, int priority, String msg, Throwable t) {
|
public LogRecord(Class<?> src, String name, String threadName, int priority, String msg, Throwable t) {
|
||||||
_date = Clock.getInstance().now();
|
_date = Clock.getInstance().now();
|
||||||
_source = src;
|
_source = src;
|
||||||
_name = name;
|
_name = name;
|
||||||
@ -36,7 +36,7 @@ class LogRecord {
|
|||||||
return _date;
|
return _date;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class getSource() {
|
public Class<?> getSource() {
|
||||||
return _source;
|
return _source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public abstract class SystemVersion {
|
|||||||
int sdk = 0;
|
int sdk = 0;
|
||||||
if (_isAndroid) {
|
if (_isAndroid) {
|
||||||
try {
|
try {
|
||||||
Class ver = Class.forName("android.os.Build.VERSION", true, ClassLoader.getSystemClassLoader());
|
Class<?> ver = Class.forName("android.os.Build.VERSION", true, ClassLoader.getSystemClassLoader());
|
||||||
Field field = ver.getField("SDK_INT");
|
Field field = ver.getField("SDK_INT");
|
||||||
sdk = field.getInt(null);
|
sdk = field.getInt(null);
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
|
@ -277,7 +277,7 @@ public class JobQueue {
|
|||||||
if (_maxWaitingJobs <= 0) return false; // dont ever drop jobs
|
if (_maxWaitingJobs <= 0) return false; // dont ever drop jobs
|
||||||
if (!_allowParallelOperation) return false; // dont drop during startup [duh]
|
if (!_allowParallelOperation) return false; // dont drop during startup [duh]
|
||||||
if (numReady > _maxWaitingJobs) {
|
if (numReady > _maxWaitingJobs) {
|
||||||
Class cls = job.getClass();
|
Class<? extends Job> cls = job.getClass();
|
||||||
// lets not try to drop too many tunnel messages...
|
// lets not try to drop too many tunnel messages...
|
||||||
//if (cls == HandleTunnelMessageJob.class)
|
//if (cls == HandleTunnelMessageJob.class)
|
||||||
// return true;
|
// return true;
|
||||||
|
@ -197,7 +197,7 @@ public class LoadClientAppsJob extends JobImpl {
|
|||||||
log.info("Loading up the client application " + clientName + ": " + className + " " + Arrays.toString(args));
|
log.info("Loading up the client application " + clientName + ": " + className + " " + Arrays.toString(args));
|
||||||
if (args == null)
|
if (args == null)
|
||||||
args = new String[0];
|
args = new String[0];
|
||||||
Class cls = Class.forName(className, true, cl);
|
Class<?> cls = Class.forName(className, true, cl);
|
||||||
Method method = cls.getMethod("main", new Class[] { String[].class });
|
Method method = cls.getMethod("main", new Class[] { String[].class });
|
||||||
method.invoke(cls, new Object[] { args });
|
method.invoke(cls, new Object[] { args });
|
||||||
}
|
}
|
||||||
@ -264,15 +264,15 @@ public class LoadClientAppsJob extends JobImpl {
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Class cls = Class.forName(_className, true, _cl);
|
Class<?> cls = Class.forName(_className, true, _cl);
|
||||||
if (isRouterApp(cls)) {
|
if (isRouterApp(cls)) {
|
||||||
Constructor con = cls.getConstructor(RouterContext.class, ClientAppManager.class, String[].class);
|
Constructor<?> con = cls.getConstructor(RouterContext.class, ClientAppManager.class, String[].class);
|
||||||
RouterAppManager mgr = _ctx.clientAppManager();
|
RouterAppManager mgr = _ctx.clientAppManager();
|
||||||
Object[] conArgs = new Object[] {_ctx, _ctx.clientAppManager(), _args};
|
Object[] conArgs = new Object[] {_ctx, _ctx.clientAppManager(), _args};
|
||||||
RouterApp app = (RouterApp) con.newInstance(conArgs);
|
RouterApp app = (RouterApp) con.newInstance(conArgs);
|
||||||
mgr.addAndStart(app, _args);
|
mgr.addAndStart(app, _args);
|
||||||
} else if (isClientApp(cls)) {
|
} else if (isClientApp(cls)) {
|
||||||
Constructor con = cls.getConstructor(I2PAppContext.class, ClientAppManager.class, String[].class);
|
Constructor<?> con = cls.getConstructor(I2PAppContext.class, ClientAppManager.class, String[].class);
|
||||||
RouterAppManager mgr = _ctx.clientAppManager();
|
RouterAppManager mgr = _ctx.clientAppManager();
|
||||||
Object[] conArgs = new Object[] {_ctx, _ctx.clientAppManager(), _args};
|
Object[] conArgs = new Object[] {_ctx, _ctx.clientAppManager(), _args};
|
||||||
ClientApp app = (ClientApp) con.newInstance(conArgs);
|
ClientApp app = (ClientApp) con.newInstance(conArgs);
|
||||||
@ -288,17 +288,17 @@ public class LoadClientAppsJob extends JobImpl {
|
|||||||
_log.info("Done running client application " + _appName);
|
_log.info("Done running client application " + _appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRouterApp(Class cls) {
|
private static boolean isRouterApp(Class<?> cls) {
|
||||||
return isInterface(cls, RouterApp.class);
|
return isInterface(cls, RouterApp.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isClientApp(Class cls) {
|
private static boolean isClientApp(Class<?> cls) {
|
||||||
return isInterface(cls, ClientApp.class);
|
return isInterface(cls, ClientApp.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInterface(Class cls, Class intfc) {
|
private static boolean isInterface(Class<?> cls, Class<?> intfc) {
|
||||||
try {
|
try {
|
||||||
Class[] intfcs = cls.getInterfaces();
|
Class<?>[] intfcs = cls.getInterfaces();
|
||||||
for (int i = 0; i < intfcs.length; i++) {
|
for (int i = 0; i < intfcs.length; i++) {
|
||||||
if (intfcs[i] == intfc)
|
if (intfcs[i] == intfc)
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user