Java Reference
In-Depth Information
Adding producer classes
Producer classes have been introduced in the earlier chapter as a means of providing some
resources through CDI to our application. In this example, we will use it to produce many
resources, such as the JPA Entity Manager and the list of objects that are transferred to the
JSF views. For this reason, we provided the LoggerProducer , FacesContextPro-
ducer , and EntityManagerProducer classes that contain some general-purpose re-
sources and single instances of the SeatProducer and SeatTypeProducer classes,
which will be used to produce collections of entities.
Here's the content of the three basic producer classes:
public class LoggerProducer {
@Produces
public Logger produceLoger(InjectionPoint
injectionPoint) {
return
Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
}
public class FacesContextProducer {
@Produces
@RequestScoped
public FacesContext produceFacesContext() {
return FacesContext.getCurrentInstance();
}
}
public class EntityManagerProducer {
@Produces
@PersistenceContext
private EntityManager em;
}
Search WWH ::




Custom Search