torsten@10: /* torsten@10: * JBoss, Home of Professional Open Source torsten@10: * Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual torsten@10: * contributors by the @authors tag. See the copyright.txt in the torsten@10: * distribution for a full listing of individual contributors. torsten@10: * torsten@10: * Licensed under the Apache License, Version 2.0 (the "License"); torsten@10: * you may not use this file except in compliance with the License. torsten@10: * You may obtain a copy of the License at torsten@10: * http://www.apache.org/licenses/LICENSE-2.0 torsten@10: * Unless required by applicable law or agreed to in writing, software torsten@10: * distributed under the License is distributed on an "AS IS" BASIS, torsten@10: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. torsten@10: * See the License for the specific language governing permissions and torsten@10: * limitations under the License. torsten@10: */ torsten@11: package de.intevation.utils; torsten@10: torsten@10: import java.util.logging.Logger; torsten@10: torsten@10: import javax.enterprise.context.RequestScoped; torsten@10: import javax.enterprise.inject.Produces; torsten@10: import javax.enterprise.inject.spi.InjectionPoint; torsten@10: import javax.faces.context.FacesContext; torsten@10: import javax.persistence.EntityManager; torsten@10: import javax.persistence.PersistenceContext; torsten@10: torsten@10: /** torsten@10: * This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans torsten@10: * torsten@10: *

torsten@10: * Example injection on a managed bean field: torsten@10: *

torsten@10: * torsten@10: *
torsten@10:  * @Inject
torsten@10:  * private EntityManager em;
torsten@10:  * 
torsten@10: */ torsten@10: public class Resources { torsten@10: // use @SuppressWarnings to tell IDE to ignore warnings about field not being referenced directly torsten@10: @SuppressWarnings("unused") torsten@10: @Produces torsten@10: @PersistenceContext torsten@10: private EntityManager em; torsten@10: torsten@10: @Produces torsten@10: public Logger produceLog(InjectionPoint injectionPoint) { torsten@10: return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); torsten@10: } torsten@10: torsten@10: @Produces torsten@10: @RequestScoped torsten@10: public FacesContext produceFacesContext() { torsten@10: return FacesContext.getCurrentInstance(); torsten@10: } torsten@10: torsten@10: }