KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > completion > ELImplicitObjects


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.core.syntax.completion;
21
22 import java.lang.reflect.Modifier JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25 import java.util.List JavaDoc;
26 import org.netbeans.api.java.classpath.ClassPath;
27 //import org.netbeans.jmi.javamodel.JavaClass;
28
//import org.netbeans.jmi.javamodel.Method;
29
import org.netbeans.modules.editor.NbEditorUtilities;
30 import org.netbeans.modules.web.core.syntax.JspSyntaxSupport;
31 import org.openide.loaders.DataObject;
32
33 /**
34  *
35  * @author petr
36  */

37
38 /** Represents Implicit objects for EL
39  **/

40 public class ELImplicitObjects {
41     
42     public static final int OBJECT_TYPE = 0;
43     public static final int MAP_TYPE = 1;
44
45     public static class ELImplicitObject {
46         private String JavaDoc name;
47         private int type;
48         private String JavaDoc clazz;
49                 
50         /** Creates a new instance of ELImplicitObject */
51         public ELImplicitObject(String JavaDoc name) {
52             this.name = name;
53             this.setType(MAP_TYPE);
54         }
55
56         public String JavaDoc getName() {
57             return name;
58         }
59
60         public int getType() {
61             return type;
62         }
63
64         public void setType(int type) {
65             this.type = type;
66         }
67         
68         public String JavaDoc getClazz(){
69             return clazz;
70         }
71         
72         public void setClazz(String JavaDoc clazz){
73             this.clazz = clazz;
74         }
75     }
76     
77     public static class PageContextObject extends ELImplicitObject{
78         public PageContextObject(String JavaDoc name){
79             super(name);
80             setType(ELImplicitObjects.OBJECT_TYPE);
81             setClazz("javax.servlet.jsp.PageContext"); //NOI18N
82
}
83     }
84     
85     private static Collection JavaDoc <ELImplicitObject> implicitELObjects = null;
86     
87     private static void initImplicitObjects() {
88         if (implicitELObjects == null){
89             implicitELObjects = new ArrayList JavaDoc();
90             implicitELObjects.add(new PageContextObject("pageContext")); //NOI18N
91
implicitELObjects.add(new ELImplicitObject("pageScope")); //NOI18N
92
implicitELObjects.add(new ELImplicitObject("requestScope")); //NOI18N
93
implicitELObjects.add(new ELImplicitObject("sessionScope")); //NOI18N
94
implicitELObjects.add(new ELImplicitObject("applicationScope")); //NOI18N
95
implicitELObjects.add(new ELImplicitObject("param")); //NOI18N
96
implicitELObjects.add(new ELImplicitObject("paramValues")); //NOI18N
97
implicitELObjects.add(new ELImplicitObject("header")); //NOI18N
98
implicitELObjects.add(new ELImplicitObject("headerValues")); //NOI18N
99
implicitELObjects.add(new ELImplicitObject("initParam")); //NOI18N
100
implicitELObjects.add(new ELImplicitObject("cookie")); //NOI18N
101
}
102     }
103     
104     /** Returns implicit objects that starts with the prefix.
105      */

106     public static Collection JavaDoc <ELImplicitObject> getELImplicitObjects(String JavaDoc prefix){
107         initImplicitObjects();
108         Collection JavaDoc <ELImplicitObject> filtered = implicitELObjects;
109         if (prefix != null && !prefix.equals("")){
110             filtered = new ArrayList JavaDoc();
111             for (ELImplicitObject elem : implicitELObjects) {
112                 if (elem.getName().startsWith(prefix))
113                     filtered.add(elem);
114             }
115         }
116         return filtered;
117     }
118     
119     public static ELImplicitObject getELImplicitObject (String JavaDoc expr){
120         initImplicitObjects();
121         ELImplicitObject obj = null;
122         if (expr != null && !expr.equals("")){
123             int indexP = expr.indexOf('[');
124             int indexD = expr.indexOf('.');
125             String JavaDoc name = null;
126             if (indexD > -1 && (indexP == -1 || indexD < indexP))
127                 name = expr.substring(0, indexD);
128             else{
129                 if (indexP > -1)
130                     name = expr.substring(0, indexP);
131                 else
132                     name = expr;
133             }
134             name = name.trim();
135             for (ELImplicitObject elem : implicitELObjects) {
136                 if (elem.getName().equals(name)){
137                     obj = elem;
138                     break;
139                 }
140             }
141         }
142         return obj;
143     }
144
145     
146 }
147
Popular Tags