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

com.google.inject.internal.InternalFactoryToInitializableAdapter Maven / Gradle / Ivy

package com.google.inject.internal;

import com.google.inject.spi.Dependency;
import com.google.inject.spi.ProviderInstanceBinding;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Adapts {@link ProviderInstanceBinding} providers, ensuring circular proxies
 * fail (or proxy) properly.
 */
final class InternalFactoryToInitializableAdapter extends ProviderInternalFactory {

    private final ProvisionListenerStackCallback provisionCallback;
    private final Initializable> initializable;

    InternalFactoryToInitializableAdapter(
            Initializable> initializable,
            Object source, ProvisionListenerStackCallback provisionCallback) {
        super(source);
        this.provisionCallback = checkNotNull(provisionCallback, "provisionCallback");
        this.initializable = checkNotNull(initializable, "provider");
    }

    @Override
    public T get(InternalContext context, Dependency dependency, boolean linked)
            throws InternalProvisionException {
        return circularGet(initializable.get(), context, dependency, provisionCallback);
    }

    @Override
    protected T provision(javax.inject.Provider provider,
                          Dependency dependency,
                          ConstructionContext constructionContext) throws InternalProvisionException {
        try {
            return super.provision(provider, dependency, constructionContext);
        } catch (RuntimeException userException) {
            throw InternalProvisionException.errorInProvider(userException).addSource(source);
        }
    }

    @Override
    public String toString() {
        return initializable.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy