KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > EjbInjectionTargetQueryImplementation


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.ejbcore;
21
22 import java.io.IOException JavaDoc;
23 import javax.lang.model.element.TypeElement;
24 import org.netbeans.api.java.source.CompilationController;
25 import org.netbeans.modules.j2ee.common.queries.spi.InjectionTargetQueryImplementation;
26 import org.netbeans.modules.j2ee.dd.api.ejb.DDProvider;
27 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
28 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans;
29 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
30 import org.netbeans.modules.j2ee.dd.api.ejb.Session;
31 import org.openide.ErrorManager;
32
33 /**
34  *
35  * @author Martin Adamek
36  */

37 public class EjbInjectionTargetQueryImplementation implements InjectionTargetQueryImplementation {
38     
39     public EjbInjectionTargetQueryImplementation() {
40     }
41     
42     public boolean isInjectionTarget(CompilationController controller, TypeElement typeElement) {
43         org.netbeans.modules.j2ee.api.ejbjar.EjbJar apiEjbJar = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(controller.getFileObject());
44         String JavaDoc fqn = typeElement.getQualifiedName().toString();
45         if (apiEjbJar != null &&
46                 !apiEjbJar.getJ2eePlatformVersion().equals("1.3") &&
47                 !apiEjbJar.getJ2eePlatformVersion().equals("1.4")) {
48             try {
49                 EjbJar ejbJar = DDProvider.getDefault().getMergedDDRoot(apiEjbJar.getMetadataUnit());
50                 if (ejbJar != null && ejbJar.getEnterpriseBeans() != null) {
51                     if (ejbJar.getEnterpriseBeans().findBeanByName(EnterpriseBeans.SESSION, Session.EJB_CLASS, fqn) != null) {
52                         return true;
53                     }
54                     if (ejbJar.getEnterpriseBeans().findBeanByName(EnterpriseBeans.MESSAGE_DRIVEN, MessageDriven.EJB_CLASS, fqn) != null) {
55                         return true;
56                     }
57                 }
58             } catch (IOException JavaDoc ex) {
59                 ErrorManager.getDefault().notify(ex);
60             }
61         }
62         return false;
63     }
64
65     public boolean isStaticReferenceRequired(CompilationController controller, TypeElement typeElement) {
66         return false;
67     }
68     
69 }
70
Popular Tags