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

se.jbee.inject.service.ExtensionModule Maven / Gradle / Ivy

There is a newer version: 0.6
Show newest version
/*
 *  Copyright (c) 2012, Jan Bernitt 
 *			
 *  Licensed under the Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
 */
package se.jbee.inject.service;

import static se.jbee.inject.Name.named;
import static se.jbee.inject.Type.raw;
import se.jbee.inject.Dependency;
import se.jbee.inject.Name;
import se.jbee.inject.bind.Binder;
import se.jbee.inject.bind.BinderModule;

public abstract class ExtensionModule
		extends BinderModule {

	public static  & Extension, T> void extend( Binder binder,
			Class extension, Class type ) {
		binder.multibind( extensionName( extension, type ), Class.class ).to( type );
		binder.bind( type ).toConstructor(); //TODO implicit
	}

	public static  & Extension, T> void extend( Binder binder,
			E extension, Class type ) {
		binder.multibind( extensionName( extension, type ), Class.class ).to( type );
		binder.bind( type ).toConstructor(); //TODO implicit
	}

	public static  & Extension, T> Name extensionName(
			Class extension, Class type ) {
		return named( extension.getCanonicalName() + ":" + type.getCanonicalName() );
	}

	public static  & Extension, T> Name extensionName( E extension,
			Class type ) {
		return named( extension.getClass().getCanonicalName() + ":" + extension.name() + ":"
				+ type.getCanonicalName() );
	}

	@SuppressWarnings ( { "rawtypes" } )
	public static  & Extension, T> Dependency extensionDependency(
			Class extension ) {
		return Dependency.dependency( raw( Class[].class ).parametizedAsLowerBounds() ).named(
				Name.prefixed( extension.getCanonicalName() + ":" ) );
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy