java.lang.Object
org.glassfish.hk2.extras.provides.ProvidesListener
- All Implemented Interfaces:
org.glassfish.hk2.api.DynamicConfigurationListener
@Singleton
public class ProvidesListener
extends Object
implements org.glassfish.hk2.api.DynamicConfigurationListener
Enables the
Provides annotation.
Only one ProvidesListener instance may be registered with each
ServiceLocator.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected org.glassfish.hk2.api.FilterMatches services whose implementation classes are scanned forProvidesannotations.protected voidonInvalidProvidesAnnotation(org.glassfish.hk2.api.ActiveDescriptor<?> providerDescriptor, Provides providesAnnotation, AnnotatedElement annotatedElement, String message) Called when an invalidProvidesannotation is found.
-
Constructor Details
-
ProvidesListener
@Inject public ProvidesListener(org.glassfish.hk2.api.ServiceLocator locator)
-
-
Method Details
-
getFilter
protected org.glassfish.hk2.api.Filter getFilter()Matches services whose implementation classes are scanned forProvidesannotations.The default filter matches all services. Override this method to permit a smaller subset of services. For example:
@Singleton public class FilteredProvidesListener extends ProvidesListener { @Inject public FilteredProvidesListener(ServiceLocator locator) { super(locator); } @Override protected Filter getFilter() { return d -> d.getImplementation().startsWith("com.example."); } } -
onInvalidProvidesAnnotation
protected void onInvalidProvidesAnnotation(org.glassfish.hk2.api.ActiveDescriptor<?> providerDescriptor, Provides providesAnnotation, AnnotatedElement annotatedElement, String message) Called when an invalidProvidesannotation is found.The default implementation of this method does nothing. Override this method to consume the reported information. For example:
@Singleton public class LoggingProvidesListener extends ProvidesListener { private final Logger logger = LoggerFactory.getLogger(getClass()); @Inject public LoggingProvidesListener(ServiceLocator locator) { super(locator); } @Override protected void onInvalidProvidesAnnotation( ActiveDescriptor<?> providerDescriptor, Provides providesAnnotation, AnnotatedElement annotatedElement, String message) { logger.error(message); } }If this method does not throw an exception, then after calling this method, this listener will ignore this
Providesannotation — registering no newActiveDescriptoron its behalf — and this listener will continue to scan this provider and other providers for otherProvidesannotations.If this method does throw an exception, then the behavior of this listener from this point forward is undefined.
- Parameters:
providerDescriptor- the descriptor of the service that contains thisProvidesannotationprovidesAnnotation- theProvidesannotation on the method or fieldannotatedElement- the method or field that is annotated withProvidesmessage- a message explaining why thisProvidesannotation is invalid
-
configurationChanged
public void configurationChanged()- Specified by:
configurationChangedin interfaceorg.glassfish.hk2.api.DynamicConfigurationListener
-