All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.steria.osgi.jsr330activator.implementation.InjectionMethod Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
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() {
        try {
            method.invoke(provider, (String)null);
            currentService = null;
        } catch (Exception e) {
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy