
org.apache.openwebbeans.se.CDILauncher Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openwebbeans.se;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.se.SeContainer;
import javax.enterprise.inject.se.SeContainerInitializer;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
public final class CDILauncher
{
private CDILauncher()
{
// no-op
}
public static void main(final String[] args)
{
final SeContainerInitializer initializer = SeContainerInitializer.newInstance();
final Config config = configure(initializer, args);
try (final SeContainer container = initializer.initialize())
{
if (config.main != null)
{
executeMain(config, container);
}
// else the app can use other ways to execute code like @PreDestroy of a startup bean
}
}
private static void executeMain(final Config config, final SeContainer container)
{
final BeanManager manager = container.getBeanManager();
Set> beans = manager.getBeans(config.main);
if (beans == null || beans.isEmpty())
{
try
{
beans = manager.getBeans(Thread.currentThread().getContextClassLoader().loadClass(config.main));
}
catch (final ClassNotFoundException e)
{
throw new IllegalArgumentException("No bean '" + config.main + "' found");
}
}
final Bean> bean = manager.resolve(beans);
final CreationalContext
© 2015 - 2025 Weber Informatics LLC | Privacy Policy