Top Description Inners Fields Constructors Methods
javax.enterprise.inject.spi

public Class Unmanaged<T>

extends Object
Class Inheritance
Type Parameters
<T>
type of unmanaged instances
Imports
javax.enterprise.context.spi.CreationalContext

Helper class for injecting and calling lifecycle callbacks unmanaged instances for use by framework and library integrators.

Unmanaged<Foo> unmanagedFoo = new Unmanaged<Foo>(Foo.class);
UnmanagedInstance<Foo> fooInstance = unmanagedFoo.newInstance();
Foo foo = fooInstance.produce().inject().postConstruct().get();
... // Use the foo instance
fooInstance.preDestroy().dispose();

An instance of this class can be safely held for the lifetime of the application.

UnmanagedInstances created by this class are not suitable for sharing between threads.

Author
Pete Muir
Since
1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Unmanaged.UnmanagedInstance<T>

Represents a non-contextual instance.

Field Summary

Modifier and TypeField and Description
private final BeanManager
private final InjectionTarget<T>

Constructor Summary

AccessConstructor and Description
public
Unmanaged(BeanManager manager, Class<T>
class of the unmanaged instances
clazz
)

Create an injector for the given class

public
Unmanaged(Class<T>
class of the unmanaged instances
clazz
)

Create an injector for the given class, using the current bean manager

Method Summary

Modifier and TypeMethod and Description
public Unmanaged.UnmanagedInstance<T>

Returns:

a new UnmanagedInstance
newInstance
()

Instantiate a new UnmanagedInstance

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanManagerback to summary
private final BeanManager beanManager
injectionTargetback to summary
private final InjectionTarget<T> injectionTarget

Constructor Detail

Unmanagedback to summary
public Unmanaged(BeanManager manager, Class<T> clazz)

Create an injector for the given class

Parameters
manager:BeanManager

the BeanManager

clazz:Class<T>

class of the unmanaged instances

Unmanagedback to summary
public Unmanaged(Class<T> clazz)

Create an injector for the given class, using the current bean manager

Parameters
clazz:Class<T>

class of the unmanaged instances

Method Detail

newInstanceback to summary
public Unmanaged.UnmanagedInstance<T> newInstance()

Instantiate a new UnmanagedInstance

Returns:Unmanaged.UnmanagedInstance<T>

a new UnmanagedInstance

javax.enterprise.inject.spi back to summary

public Class Unmanaged.UnmanagedInstance<T>

extends Object
Class Inheritance

Represents a non-contextual instance.
See Also
Unmanaged

Field Summary

Modifier and TypeField and Description
private final CreationalContext<T>
private boolean
private final InjectionTarget<T>
private T

Constructor Summary

AccessConstructor and Description
private
UnmanagedInstance(BeanManager beanManager, InjectionTarget<T> injectionTarget)

Method Summary

Modifier and TypeMethod and Description
public Unmanaged.UnmanagedInstance<T>

Returns:

self
dispose
()

Dispose of the instance, doing any necessary cleanup

public T

Returns:

the instance
get
()

Get the instance

public Unmanaged.UnmanagedInstance<T>

Returns:

self
inject
()

Inject the instance

public Unmanaged.UnmanagedInstance<T>

Returns:

self
postConstruct
()

Call the @PostConstruct callback

public Unmanaged.UnmanagedInstance<T>

Returns:

self
preDestroy
()

Call the @PreDestroy callback

public Unmanaged.UnmanagedInstance<T>

Returns:

self
produce
()

Create the instance

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ctxback to summary
private final CreationalContext<T> ctx
disposedback to summary
private boolean disposed
injectionTargetback to summary
private final InjectionTarget<T> injectionTarget
instanceback to summary
private T instance

Constructor Detail

UnmanagedInstanceback to summary
private UnmanagedInstance(BeanManager beanManager, InjectionTarget<T> injectionTarget)

Method Detail

disposeback to summary
public Unmanaged.UnmanagedInstance<T> dispose()

Dispose of the instance, doing any necessary cleanup

Returns:Unmanaged.UnmanagedInstance<T>

self

Exceptions
IllegalStateException:
  • if dispose() is called before produce() is called
  • if dispose() is called on an instance that has already been disposed
getback to summary
public T get()

Get the instance

Returns:T

the instance

injectback to summary
public Unmanaged.UnmanagedInstance<T> inject()

Inject the instance

Returns:Unmanaged.UnmanagedInstance<T>

self

Exceptions
IllegalStateException:
  • if inject() is called before produce() is called
  • if inject() is called on an instance that has already been disposed
postConstructback to summary
public Unmanaged.UnmanagedInstance<T> postConstruct()

Call the @PostConstruct callback

Returns:Unmanaged.UnmanagedInstance<T>

self

Exceptions
IllegalStateException:
  • if postConstruct() is called before produce() is called
  • if postConstruct() is called on an instance that has already been disposed
preDestroyback to summary
public Unmanaged.UnmanagedInstance<T> preDestroy()

Call the @PreDestroy callback

Returns:Unmanaged.UnmanagedInstance<T>

self

Exceptions
IllegalStateException:
  • if preDestroy() is called before produce() is called
  • if preDestroy() is called on an instance that has already been disposed
produceback to summary
public Unmanaged.UnmanagedInstance<T> produce()

Create the instance

Returns:Unmanaged.UnmanagedInstance<T>

self

Exceptions
IllegalStateException:
  • if produce() is called on an already produced instance
  • if produce() is called on an instance that has already been disposed