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

com.mastfrog.webapi.WebApiModule Maven / Gradle / Ivy

There is a newer version: 2.9.7
Show newest version
package com.mastfrog.webapi;

import com.mastfrog.webapi.builtin.Parameters;
import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
import com.mastfrog.acteur.util.BasicCredentials;
import com.mastfrog.giulius.scope.ReentrantScope;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Tim Boudreau
 */
public final class WebApiModule & WebCallEnum> extends AbstractModule {
    private final Class type;
    public WebApiModule(Class type) {
        this.type = type;
    }

    @Override
    protected void configure() {
        ReentrantScope scope = new ReentrantScope();
        bind(ReentrantScope.class).annotatedWith(Names.named("webapi")).toInstance(scope);
        scope.bindTypes(binder(), WebCall.class, WebCallEnum.class);
        scope.bindTypesAllowingNulls(binder(), Parameters.class, BasicCredentials.class);
        
        Set> types = new HashSet<>();
        for (T obj : type.getEnumConstants()) {
            WebCallEnum e = obj;
            WebCall call = e.get();
            types.addAll(Arrays.asList(call.requiredTypes()));
        }
        scope.bindTypesAllowingNulls(binder(), types.toArray(new Class[types.size()]));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy