KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > JSFInjectionTargetQueryImplementation


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.web.jsf;
21
22 import java.util.List 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.web.api.webmodule.WebModule;
27 import org.netbeans.modules.web.jsf.api.ConfigurationUtils;
28 import org.netbeans.modules.web.jsf.api.facesmodel.ManagedBean;
29 import org.openide.filesystems.FileObject;
30 import org.openide.util.Parameters;
31
32 /**
33  *
34  * @author Petr Pisl
35  */

36
37 public class JSFInjectionTargetQueryImplementation implements InjectionTargetQueryImplementation {
38     
39     public JSFInjectionTargetQueryImplementation() {
40     }
41     
42     /**
43      * For method return true if:
44      * 1) The web module follows 2.5 servlet specification or higher
45      * 2) The jc is defined as manage bean in a jsp configuration file.
46      */

47     public boolean isInjectionTarget(CompilationController controller, TypeElement typeElement) {
48         Parameters.notNull("controller", controller);
49         Parameters.notNull("typeElement", typeElement);
50         
51         // Find the web module, where the class is
52
WebModule webModule = WebModule.getWebModule(controller.getFileObject());
53         // Is the web modile 2.5 servlet spec or higher?
54
if (webModule != null && !webModule.getJ2eePlatformVersion().equals(WebModule.J2EE_13_LEVEL)
55                 && !webModule.getJ2eePlatformVersion().equals(WebModule.J2EE_14_LEVEL)){
56             // Get deployment desctriptor from the web module
57
FileObject ddFileObject = webModule.getDeploymentDescriptor();
58             if (ddFileObject != null){
59                 // Get all jsf configurations files
60
FileObject[] jsfConfigs = ConfigurationUtils.getFacesConfigFiles(webModule);
61                 for (FileObject jsfConfigFO : ConfigurationUtils.getFacesConfigFiles(webModule)) {
62                     // Get manage beans from the configuration file
63
List JavaDoc<ManagedBean> beans = ConfigurationUtils.getConfigModel(jsfConfigFO, true).getRootComponent().getManagedBeans();
64                     for (ManagedBean managedBean : beans) {
65                         if (typeElement.getQualifiedName().contentEquals(managedBean.getManagedBeanClass())) {
66                             return true;
67                         }
68                     }
69                 }
70             }
71         }
72         return false;
73     }
74     
75     public boolean isStaticReferenceRequired(CompilationController controller, TypeElement typeElement) {
76         return false;
77     }
78     
79 }
80
Popular Tags