/* * It may in theory happen that an app calls BeanManager.createAnnotatedType() for a previously unknown class on node1 and then * stores this annotated type in session. On node2, this annotated type is not know. We'll try to load it. */ private SlimAnnotatedType<?> tryToLoadUnknownBackedAnnotatedType() { if (identifier.getSuffix() != null || identifier.isModified()) { return null; // this is not a backed annotated type } // first, obtain the BeanManager for a given BDA final BeanManagerImpl manager = Container.instance(identifier).getBeanManager(identifier.getBdaId()); if (manager == null) { return null; } // second, try to load the class final ResourceLoader resourceLoader = manager.getServices().get(ResourceLoader.class); Class<?> clazz = null; try { clazz = resourceLoader.classForName(identifier.getClassName()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } // finally, try to load the annotated type try { return manager .getServices() .get(ClassTransformer.class) .getBackedAnnotatedType(clazz, identifier.getBdaId()); } catch (ResourceLoadingException e) { MetadataLogger.LOG.catchingDebug(e); return null; } }
public Metadata<Class<? extends T>> apply(Metadata<String> from) { String location = from.getLocation(); try { return new MetadataImpl<Class<? extends T>>( Reflections.<Class<? extends T>>cast(resourceLoader.classForName(from.getValue())), location); } catch (ResourceLoadingException e) { throw new ResourceLoadingException( e.getMessage() + "; location: " + location, e.getCause()); } catch (Exception e) { throw new ResourceLoadingException(e.getMessage() + "; location: " + location, e); } }
/** * Bootstraps a new Weld SE container with the current {@link #containerId}. * * <p>The container must be shut down properly when an application is stopped. Applications are * encouraged to use the try-with-resources statement or invoke {@link WeldContainer#shutdown()} * explicitly. * * <p>However, a shutdown hook is also registered during initialization so that all running * containers are shut down automatically when a program exits or VM is terminated. This means * that it's not necessary to implement the shutdown logic in a class where a main method is used * to start the container. * * @return the Weld container * @see #enableDiscovery() * @see WeldContainer#shutdown() */ public WeldContainer initialize() { // If also building a synthetic bean archive the check for beans.xml is not necessary if (!isSyntheticBeanArchiveRequired() && resourceLoader.getResource(WeldDeployment.BEANS_XML) == null) { throw CommonLogger.LOG.missingBeansXml(); } final WeldBootstrap bootstrap = new WeldBootstrap(); final Deployment deployment = createDeployment(resourceLoader, bootstrap); final ExternalConfigurationBuilder configurationBuilder = new ExternalConfigurationBuilder() // weld-se uses CommonForkJoinPoolExecutorServices by default .add(EXECUTOR_THREAD_POOL_TYPE.get(), COMMON.toString()) // weld-se uses relaxed construction by default .add(ConfigurationKey.RELAXED_CONSTRUCTION.get(), true); for (Entry<String, Object> property : properties.entrySet()) { configurationBuilder.add(property.getKey(), property.getValue()); } deployment.getServices().add(ExternalConfiguration.class, configurationBuilder.build()); // Set up the container bootstrap.startContainer(containerId, Environments.SE, deployment); // Start the container bootstrap.startInitialization(); // Bean builders - set bean deployment finder if (!beanBuilders.isEmpty()) { BeanDeploymentFinder beanDeploymentFinder = bootstrap.getBeanDeploymentFinder(); for (BeanBuilderImpl<?> beanBuilder : beanBuilders) { beanBuilder.setBeanDeploymentFinder(beanDeploymentFinder); } } bootstrap.deployBeans(); bootstrap.validateBeans(); bootstrap.endInitialization(); final WeldManager manager = bootstrap.getManager(deployment.loadBeanDeploymentArchive(WeldContainer.class)); final WeldContainer weldContainer = WeldContainer.initialize(containerId, manager, bootstrap); initializedContainers.put(containerId, weldContainer); return weldContainer; }