All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.weld.environment.se.WeldContainer Maven / Gradle / Ivy

/**
 * JBoss, Home of Professional Open Source
 * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
 * contributors by the @authors tag. See the copyright.txt in the
 * distribution for a full listing of individual contributors.
 *
 * Licensed 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.jboss.weld.environment.se;

import org.jboss.weld.environment.se.beans.InstanceManager;

import javax.enterprise.event.Event;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;

/**
 * Provides convenient access to beans and events, particularly helpful when
 * bootstrapping an application in Java SE.
 * 

* An instance of this class can be obtained using the Weld class by calling: * * WeldContainer weld = new Weld().initialize(); * * * @author Peter Royle * @see Weld */ public class WeldContainer { private final InstanceManager instanceManager; private final BeanManager beanManager; @Inject protected WeldContainer(InstanceManager instanceManager, BeanManager beanManager) { this.instanceManager = instanceManager; this.beanManager = beanManager; } /** * Provides access to all beans within the application. For example: * * Foo foo = weld.instance().select(Foo.class).get(); * */ public Instance instance() { return instanceManager.getInstances(); } /** * Provides access to all events within the application. For example: * * weld.event().select(Bar.class).fire(new Bar()); * */ public Event event() { return instanceManager.getEvents(); } /** * Provides direct access to the BeanManager. */ public BeanManager getBeanManager() { return beanManager; } }