package no.steria.osgi.jsr330activator.implementation;

import java.lang.reflect.Method;

/**
 * Implementation of {@link Injection} that injects using a method.
 *
 * @author Steinar Bang
 *
 */
class InjectionMethod extends InjectionBase {

    private Object provider;
    private Method method;
    private Object currentService;

    public InjectionMethod(Object provider, Method method) {
    	this.provider = provider;
    	this.method = method;
    	this.method.setAccessible(true);
    }

    public Class<?> getInjectedServiceType() {
        return method.getParameterTypes()[0];
    }

    public boolean isInjected() {
        return currentService != null;
    }

    public void doInject(Object service) {
    	try {
            method.invoke(provider, service);
            currentService = service;
        } catch (Exception e) {
        }
    }

    public void doRetract(Object service) {
        try {
            method.invoke(provider, (String)null);
            currentService = null;
        } catch (Exception e) {
        }
    }

}

@@ -83,16 +83,58 @@
 ethod;%0A%0A
+import org.osgi.framework.BundleContext;%0A%0A
 /**%0A * I
@@ -526,32 +526,177 @@
 e(true);%0A    %7D%0A%0A
+    @Override%0A    public void unGet(BundleContext bundleContext) %7B%0A    %09signalDisconnectToProvider();%0A        super.unGet(bundleContext);%0A    %7D%0A%0A
     public Class
@@ -1214,32 +1214,32 @@
 (Exception e) %7B%0A
-
         %7D%0A    %7D%0A
@@ -1239,10 +1239,90 @@
 %0A    %7D%0A%0A
+    private void signalDisconnectToProvider() %7B%0A        doRetract(null);%0A    %7D%0A%0A
 %7D%0A

Fix #2 by retracting injected services on bundle shutdown.