2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.test.inject;
18 import java.util.List;
20 import javax.persistence.EntityManager;
21 import javax.persistence.PersistenceContext;
23 import org.wamblee.inject.Injector;
24 import org.wamblee.reflection.Accessor;
25 import org.wamblee.reflection.AnnotationUtils;
28 * Injector that performs additional injection on top of the injections that are standard
29 * available (e.g. entity manager in Java SE environment).
31 * @author Erik Brakkee
33 public class JavaEETestInjector implements Injector {
35 private EntityManager entityManager;
36 private Injector delegate;
37 private List<Accessor> accessors;
40 * Constructs the injector.
41 * @param aClass Class to inject for.
42 * @param aEntityManager Entity manager.
43 * @param aDelegate Injecto to delegate to to perform the standard injections.
45 public JavaEETestInjector(Class aClass, EntityManager aEntityManager,
47 entityManager = aEntityManager;
49 accessors = AnnotationUtils.analyse(aClass, PersistenceContext.class);
53 public void inject(Object aComponent) {
54 delegate.inject(aComponent);
55 for (Accessor accessor: accessors) {
56 accessor.set(aComponent, entityManager);