Package org.eclipse.sisu.space
package org.eclipse.sisu.space
Customizable scanning of bean implementations.
The default visitor strategy is to use
The SpaceModule should be given a ClassSpace representing the classes and resources to scan:
Guice.createInjector( new SpaceModule( new URLClassSpace( classloader ) ) );Reduce scanning time by using an
index or provide your own ClassFinder approach:
Guice.createInjector( new SpaceModule( new URLClassSpace( classloader ), BeanScanning.INDEX ) );
The default visitor strategy is to use
QualifiedTypeVisitor with QualifiedTypeBinder to find types annotated with @Named or other @Qualifiers and bind them as follows:
Components
Any qualified components are bound using a special "wildcard" key that theBeanLocator uses to check type compatibility at lookup time:
(This avoids the need to walk the type hierarchy and register bindings for each and every super-type, turning the injector graph to spaghetti.)
@Named("example") public class MyTypeImpl implements MyType {
// ...
}
If you use an empty @Named or a different @Qualifier annotation then Sisu will pick a canonical name based on the implementation type.
Sometimes you need explicit typed bindings for external integration; you can list the types in a @Typed annotation or leave it empty to use the declared interfaces:
@Named @Typed public class MyTypeImpl implements MyType {
// ...
}
Default implementations can be indicated by using "default" as a binding name:
@Named("default") public class MyTypeImpl implements MyType {
// ...
}
or by starting the implementation name with "Default":
@Named public class DefaultMyType implements MyType {
// ...
}
Default components are bound without a qualifier and have a higher ranking than non-default components.
Providers
Any qualified providers are bound using the same binding heuristics as components:
@Named public class MyProvider implements Provider<MyType> {
public MyType get() {
// ...
}
}
Use @Singleton to scope the provided binding(s) as a singleton:
@Named @Singleton public class MyProvider implements Provider<MyType> {
public MyType get() {
// ...
}
}
Note: this is different to the normal Guice behaviour where singleton only applies to the provider itself.
Modules
Any qualified modules are are installed using the current binder:
@Named public class MyModule extends AbstractModule {
@Override protected void configure() {
// ...
}
}
Mediators
Any qualifiedMediators are registered with the BeanLocator:
@Named public class MyMediator implements Mediator<Named, MyType, MyWatcher> {
public void add( BeanEntry<Named, MyType> entry, MyWatcher watcher ) throws Exception {
// ...
}
public void remove( BeanEntry<Named, MyType> entry, MyWatcher watcher ) throws Exception {
// ...
}
}-
ClassDescriptionAbstract combination of
DeferredClassandDeferredProvider.Skeleton class that generates a qualified class index.Something that can visit annotation declarations.Common techniques for discovering bean implementations.ClassSpacebacked by a strongly-referencedBundle.Chains a series ofEnumerations together to look like a singleEnumeration.Finds (and optionally filters)Classresources fromClassSpaces.Represents an abstract collection of related classes and resources.Something that can visit class definitions.ClassSpacethat can create multiple (deferred) copies of the same implementation type.ClassLoaderthat can define multiple copies of the same implementation type.ClassFinderthat findsClassresources under a given package name.Iteratorthat iterates over named entries beneath a file-system directory.Enumerates various optimized globbing strategies.ClassFinderthat findsClassresources listed in the named index.LoadedClass<T>PseudoDeferredClassbacked by an already loadedClass.InjectionListenerthat listens for mediated watchers and registers them with theBeanLocator.Record containing all the necessary details about a mediated watcher.NamedClass<T>DeferredClassrepresenting a named class from aClassSpace.Listens for types annotated withQualifierannotations.SpaceVisitorthat reports types annotated withQualifierannotations.CachingClassVisitorthat maintains a map of knownQualifierannotations.Enumerationof resources found by scanning JARs and directories.CustomURLConnectionthat can access JARs nested inside an arbitrary resource.CustomURLStreamHandlerthat can stream JARs nested inside an arbitrary resource.Command-line utility that generates a qualified class index for a space-separated list of JARs.Java 6 AnnotationProcessorthat generates a qualified class index for the current build.GuiceModulethat automatically binds types annotated withQualifierannotations.Visitor strategy.Something that can visitClassSpaces.Utility methods for dealing with streams.Utility methods for dealing with tokens.Iteratorthat lazily splits a string into tokens.BindingKeyfor implementations that act as "wild-cards", meaning they match against any assignable type.Qualifierthat captures a qualified implementation type.Pseudo-Annotationthat can wrap any implementation type as aQualifier.Iteratorthat iterates over named entries inside JAR or ZIP resources.