KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > spi > entitymanagergenerator > ContainerManagedJTAInjectableInEJB


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.persistence.spi.entitymanagergenerator;
21
22 import org.netbeans.modules.j2ee.persistence.spi.entitymanagergenerator.EntityManagerGenerationStrategySupport;
23 import com.sun.source.tree.AnnotationTree;
24 import com.sun.source.tree.ClassTree;
25 import com.sun.source.tree.ExpressionTree;
26 import com.sun.source.tree.MethodTree;
27 import com.sun.source.tree.ModifiersTree;
28 import com.sun.source.tree.TypeParameterTree;
29 import java.util.Collections JavaDoc;
30 import javax.lang.model.element.Modifier;
31 import javax.lang.model.type.TypeKind;
32 import org.netbeans.api.java.source.TreeMaker;
33 import org.netbeans.api.java.source.WorkingCopy;
34 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit;
35
36 /**
37  * Generates the code needed for invoking an <code>EntityManager</code> in EJB 3
38  * environment with a container-managed persistence unit.
39  *
40  * @author Erno Mononen
41  */

42 public final class ContainerManagedJTAInjectableInEJB extends EntityManagerGenerationStrategySupport {
43     
44     public ClassTree generate() {
45         
46         ClassTree modifiedClazz = getClassTree();
47         
48         ModifiersTree methodModifiers = getTreeMaker().Modifiers(
49                 Collections.<Modifier>singleton(Modifier.PUBLIC),
50                 Collections.<AnnotationTree>emptyList()
51                 );
52         
53         MethodTree newMethod = getTreeMaker().Method(
54                 methodModifiers,
55                 computeMethodName(),
56                 getTreeMaker().PrimitiveType(TypeKind.VOID),
57                 Collections.<TypeParameterTree>emptyList(),
58                 getParameterList(),
59                 Collections.<ExpressionTree>emptyList(),
60                 "{ " +
61                 generateCallLines() +
62                 "}",
63                 null
64                 );
65         
66         if (getField(ENTITY_MANAGER_FQN) == null){
67             modifiedClazz = createEntityManager(Initialization.INJECT);
68         }
69         
70         return getTreeMaker().addClassMember(modifiedClazz, newMethod);
71     }
72     
73 }
74
Popular Tags