From 2af38feadc2d3c83557d1b70399c024f5ef5059c Mon Sep 17 00:00:00 2001 From: zml2008 Date: Tue, 23 Aug 2011 21:31:17 -0700 Subject: [PATCH] Added a generic injector for commands --- .../util/commands/SimpleInjector.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java diff --git a/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java b/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java new file mode 100644 index 000000000..22bf16bf9 --- /dev/null +++ b/src/main/java/com/sk89q/minecraft/util/commands/SimpleInjector.java @@ -0,0 +1,23 @@ +package com.sk89q.minecraft.util.commands; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +public class SimpleInjector implements Injector { + private final T injectionObject; + 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; + } + +}