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

com.netflix.fabricator.guice.mapping.CompositeExistingBinding Maven / Gradle / Ivy

package com.netflix.fabricator.guice.mapping;

import com.google.inject.Binding;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.util.Types;
import com.netflix.fabricator.ConfigurationNode;
import com.netflix.fabricator.component.ComponentFactory;

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;

/**
 * Created by hyuan on 1/17/14.
 */
public class CompositeExistingBinding implements BindingReslove {
    @Override
    public boolean execute(String name, Object obj, ConfigurationNode node, Class argType, Injector injector, Method method) throws Exception {
        ParameterizedType subType = Types.newParameterizedType(ComponentFactory.class, argType);
        Key> subKey = (Key>) Key.get(subType);
        Binding> binding = injector.getExistingBinding(subKey);
        if (binding != null) {
            ComponentFactory factory = injector.getInstance(subKey);
            if (factory != null) {
                Object subObject = factory.create(node);
                method.invoke(obj, subObject);
                return true;
            }
        }
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy