本文整理了Java中javax.enterprise.inject.spi.Unmanaged.newInstance()
方法的一些代码示例,展示了Unmanaged.newInstance()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Unmanaged.newInstance()
方法的具体详情如下:
包路径:javax.enterprise.inject.spi.Unmanaged
类名称:Unmanaged
方法名:newInstance
[英]Instantiate a new UnmanagedInstance
[中]实例化一个新的非托管状态
代码示例来源:origin: jersey/jersey
@Override
public <T> T createAndInitialize(Class<T> createMe) {
if (container != null) {
Unmanaged.UnmanagedInstance<T> unmanaged = new Unmanaged<>(createMe).newInstance();
return unmanaged.produce()
.inject()
.postConstruct()
.get();
} else {
// TODO: method is invoked before #completeRegistration - creates AutoDiscoverable, ForcedAutoDiscoverable.
// Hack: creates an object with default constructor and without an injection.
try {
Constructor<T> constructor = createMe.getConstructor();
return constructor.newInstance();
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new RuntimeException("Cannot create an instance of a class: " + createMe, e);
}
}
}
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
private UnmanagedInstance<House> createUnmanagedInstance() {
Unmanaged<House> unmanagedHouse = new Unmanaged<House>(getCurrentManager(), House.class);
UnmanagedInstance<House> unmanagedHouseInstance = unmanagedHouse.newInstance();
return unmanagedHouseInstance;
}
代码示例来源:origin: hammock-project/hammock
@Override
public InstanceHandle<T> createInstance() {
try {
return new HammockInstanceHandle<>(new Unmanaged<>(beanManager, clazz).newInstance());
}
catch (Exception e) {
try {
return new BasicInstanceFactory<T>(clazz.newInstance());
} catch (Exception ex) {
throw new RuntimeException("Unable to instantiate "+clazz, ex);
}
}
}
}
代码示例来源:origin: ws.ament.hammock/web-undertow
@Override
public InstanceHandle<T> createInstance() {
try {
return new HammockInstanceHandle<>(new Unmanaged<>(beanManager, clazz).newInstance());
}
catch (Exception e) {
try {
return new BasicInstanceFactory<T>(clazz.newInstance());
} catch (Exception ex) {
throw new RuntimeException("Unable to instantiate "+clazz, ex);
}
}
}
}
代码示例来源:origin: ws.ament.hammock/web-tomcat
@Override
public Object newInstance(Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException {
try {
Unmanaged.UnmanagedInstance<?> instance = new Unmanaged<>(beanManager, clazz).newInstance();
instance.produce().inject().postConstruct();
Object o = instance.get();
instanceMap.put(o, instance);
return o;
} catch (Exception e) {
return clazz.newInstance();
}
}
代码示例来源:origin: hammock-project/hammock
@Override
public Object newInstance(Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException {
try {
Unmanaged.UnmanagedInstance<?> instance = new Unmanaged<>(beanManager, clazz).newInstance();
instance.produce().inject().postConstruct();
Object o = instance.get();
instanceMap.put(o, instance);
return o;
} catch (Exception e) {
return clazz.newInstance();
}
}
代码示例来源:origin: io.thorntail/microprofile-health
public void afterDeploymentValidation(@Observes final AfterDeploymentValidation abd, BeanManager beanManager) {
try {
if (delegate != null) {
Unmanaged<SmallRyeHealthReporter> unmanagedHealthCheck =
new Unmanaged<>(beanManager, SmallRyeHealthReporter.class);
reporterInstance = unmanagedHealthCheck.newInstance();
reporter = reporterInstance.produce().inject().postConstruct().get();
monitor.registerHealthReporter(reporter);
// THORN-2195: Use the correct TCCL when health checks are obtained
// In WildFly, the TCCL should always be set to the top-level deployment CL during extension notification
monitor.registerContextClassLoader(Thread.currentThread().getContextClassLoader());
log.info(">> Added health reporter bean " + reporter);
delegate = null;
}
} catch (Exception e) {
throw new RuntimeException("Failed to register health reporter bean", e);
}
}
代码示例来源:origin: hammock-project/hammock
public Unmanageable(Class<T> clazz) {
this.instance = new Unmanaged<T>(clazz).newInstance();
this.instance.produce().inject().postConstruct();
}
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
@Test(groups = INTEGRATION)
@SpecAssertion(section = BM_OBTAIN_UNMANAGED_INSTANCE, id = "b")
public void testObtainNonContextualInstance() {
Zoo.reset();
Proboscis.reset();
Elephant.reset();
Unmanaged<Zoo> unmanagedZoo = new Unmanaged<Zoo>(Zoo.class);
UnmanagedInstance<Zoo> unmanagedZooInstance = unmanagedZoo.newInstance();
Zoo zoo = unmanagedZooInstance.produce().inject().postConstruct().get();
zoo.build();
assertTrue(Zoo.postConstructCalled);
assertTrue(Proboscis.postConstructCalled);
assertTrue(Elephant.postConstructCalled);
unmanagedZooInstance.preDestroy().dispose();
assertTrue(Zoo.preDestroyCalled);
assertTrue(Proboscis.preDestroyCalled);
assertFalse(Elephant.preDestroyCalled);
}
代码示例来源:origin: weld/core
@Override
public InstanceHandle<T> createInstance() throws InstantiationException {
Object manager = context.getAttribute(WeldServletLifecycle.BEAN_MANAGER_ATTRIBUTE_NAME);
if (manager instanceof BeanManager) {
UnmanagedInstance<T> instance = new Unmanaged<T>(BeanManagerProxy.unwrap((BeanManager) manager), clazz).newInstance();
instance.produce().inject().postConstruct();
return new WeldInstanceHandle<T>(instance);
} else {
// fallback
return delegate.createInstance();
}
}
代码示例来源:origin: org.jboss.weld.servlet/weld-servlet-shaded
@Override
public InstanceHandle<T> createInstance() throws InstantiationException {
Object manager = context.getAttribute(WeldServletLifecycle.BEAN_MANAGER_ATTRIBUTE_NAME);
if (manager instanceof BeanManager) {
UnmanagedInstance<T> instance = new Unmanaged<T>(BeanManagerProxy.unwrap((BeanManager) manager), clazz).newInstance();
instance.produce().inject().postConstruct();
return new WeldInstanceHandle<T>(instance);
} else {
// fallback
return delegate.createInstance();
}
}
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
@Test
@SpecAssertions({ @SpecAssertion(section = BM_OBTAIN_UNMANAGED_INSTANCE, id = "a") })
public void testObtainNonContextualInstanceUsingCurrentBeanManager() {
Builder.reset();
Nail.reset();
Hammer.reset();
Unmanaged<Builder> unmanagedBuilder = new Unmanaged<Builder>(getCurrentManager(), Builder.class);
UnmanagedInstance<Builder> unmanagedBuilderInstance = unmanagedBuilder.newInstance();
Builder builder = unmanagedBuilderInstance.produce().inject().postConstruct().get();
builder.build();
assertTrue(Builder.postConstructCalled);
assertTrue(Nail.postConstructCalled);
assertTrue(Hammer.postConstructCalled);
unmanagedBuilderInstance.preDestroy().dispose();
assertTrue(Builder.preDestroyCalled);
assertTrue(Nail.preDestroyCalled);
assertFalse(Hammer.preDestroyCalled);
}
代码示例来源:origin: weld/core
@Override
public InstanceHandle<T> createInstance() throws InstantiationException {
Object manager = context.getAttribute(WeldServletLifecycle.BEAN_MANAGER_ATTRIBUTE_NAME);
if (manager instanceof BeanManager) {
UnmanagedInstance<T> instance = new Unmanaged<T>(BeanManagerProxy.unwrap((BeanManager) manager), clazz).newInstance();
instance.produce().inject().postConstruct();
return new WeldInstanceHandle<T>(instance);
} else {
// fallback
return delegate.createInstance();
}
}
代码示例来源:origin: weld/weld-junit
create(ctx -> {
Unmanaged<?> unmanaged = new Unmanaged<>(WeldContainer.current().getBeanManager(), beanClass);
UnmanagedInstance<?> unmanagedInstance = unmanaged.newInstance();
ctxToUnmanaged.put(ctx.toString(), unmanagedInstance);
return (T) unmanagedInstance.produce().inject().postConstruct().get();
代码示例来源:origin: org.jboss.cdi.tck/cdi-tck-impl
@Test
@SpecAssertions({ @SpecAssertion(section = BIZ_METHOD_EE, id = "ac") })
public void testNonContextualInstanceIsIntercepted() {
ToolInterceptor.intercepted = false;
Unmanaged<Axe> unmanagedAxe = new Unmanaged<Axe>(getCurrentManager(), Axe.class);
UnmanagedInstance<Axe> unmanagedAxeInstance = unmanagedAxe.newInstance();
unmanagedAxeInstance.produce().inject().postConstruct().get().cut();
unmanagedAxeInstance.preDestroy().dispose();
assertTrue(ToolInterceptor.intercepted);
}
代码示例来源:origin: org.jboss.weld/weld-junit-common
create(ctx -> {
Unmanaged<?> unmanaged = new Unmanaged<>(WeldContainer.current().getBeanManager(), beanClass);
UnmanagedInstance<?> unmanagedInstance = unmanaged.newInstance();
ctxToUnmanaged.put(ctx.toString(), unmanagedInstance);
return (T) unmanagedInstance.produce().inject().postConstruct().get();
代码示例来源:origin: io.smallrye/smallrye-fault-tolerance
@Override
public T handle(ExecutionContext context) {
Unmanaged<FallbackHandler<T>> unmanaged = new Unmanaged<>(beanManager, operation.getFallback().get(FallbackConfig.VALUE));
Unmanaged.UnmanagedInstance<FallbackHandler<T>> unmanagedInstance = unmanaged.newInstance();
FallbackHandler<T> handler = unmanagedInstance.produce().inject().postConstruct().get();
try {
return handler.handle(context);
} finally {
// The instance exists to service a single invocation only
unmanagedInstance.preDestroy().dispose();
}
}
};
内容来源于网络,如有侵权,请联系作者删除!