HHH-8706 - Delay registering of the entity listener class as long as possible

This commit is contained in:
Steve Ebersole 2016-01-26 16:41:53 -06:00
parent 90f4fd9d55
commit 3b4c167482
3 changed files with 19 additions and 7 deletions

View File

@ -41,6 +41,12 @@ public class ListenerFactoryBeanManagerDelayedImpl implements ListenerFactory {
*/
@SuppressWarnings("unused")
public static ListenerFactoryBeanManagerDelayedImpl fromBeanManagerReference(Object reference) {
if ( !BeanManager.class.isInstance( reference ) ) {
throw new IllegalArgumentException(
"Expecting BeanManager reference that implements CDI BeanManager contract : " +
reference
);
}
return new ListenerFactoryBeanManagerDelayedImpl( (BeanManager) reference );
}

View File

@ -42,17 +42,17 @@ public class ListenerFactoryBeanManagerExtendedImpl implements ListenerFactory,
*/
@SuppressWarnings("unused")
public static ListenerFactoryBeanManagerExtendedImpl fromBeanManagerReference(Object reference) {
return new ListenerFactoryBeanManagerExtendedImpl( (BeanManager) reference );
}
public ListenerFactoryBeanManagerExtendedImpl(BeanManager beanManager) {
if ( !ExtendedBeanManager.class.isInstance( beanManager ) ) {
if ( !ExtendedBeanManager.class.isInstance( reference ) ) {
throw new IllegalArgumentException(
"Expecting BeanManager reference that implements optional ExtendedBeanManager contract : " +
beanManager
reference
);
}
( (ExtendedBeanManager) beanManager ).registerLifecycleListener( this );
return new ListenerFactoryBeanManagerExtendedImpl( (ExtendedBeanManager) reference );
}
public ListenerFactoryBeanManagerExtendedImpl(ExtendedBeanManager beanManager) {
beanManager.registerLifecycleListener( this );
log.debugf( "ExtendedBeanManager access requested to CDI BeanManager : " + beanManager );
}

View File

@ -46,6 +46,12 @@ public class ListenerFactoryBeanManagerStandardImpl implements ListenerFactory {
*/
@SuppressWarnings("unused")
public static ListenerFactoryBeanManagerStandardImpl fromBeanManagerReference(Object reference) {
if ( !BeanManager.class.isInstance( reference ) ) {
throw new IllegalArgumentException(
"Expecting BeanManager reference that implements CDI BeanManager contract : " +
reference
);
}
return new ListenerFactoryBeanManagerStandardImpl( (BeanManager) reference );
}