2011-08-24 04:31:17 +00:00
|
|
|
package com.sk89q.minecraft.util.commands;
|
|
|
|
|
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
|
|
|
public class SimpleInjector<T> implements Injector {
|
|
|
|
private final T injectionObject;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-08-24 04:31:17 +00:00
|
|
|
public SimpleInjector(T injectionObject) {
|
|
|
|
this.injectionObject = injectionObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object getInstance(Class<?> cls) throws InvocationTargetException,
|
|
|
|
IllegalAccessException, InstantiationException {
|
|
|
|
try {
|
|
|
|
Constructor<?> construct = cls.getConstructor(injectionObject.getClass());
|
|
|
|
return construct.newInstance(injectionObject);
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|