KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > dd > webapp > MetaData


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /** MetaData.java
25
26  *This class provides the static data required for editing WebApp Data Descriptors
27  *Author gaur , created on November 28 5:25 PM
28  */

29 package com.sun.enterprise.tools.common.dd.webapp;
30
31 import java.io.*;
32 import java.util.*;
33 import java.net.URL JavaDoc;
34 import java.util.jar.*;
35 import org.netbeans.modules.schema2beans.Schema2BeansException;
36
37 import com.sun.enterprise.tools.common.dd.webapp.data.*;
38 import com.sun.enterprise.tools.common.dd.ParamData;
39
40 public class MetaData {
41
42 static final java.util.ResourceBundle JavaDoc helpBundle = java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.HelpIDBundle"); // NOI18N
43
// Static constants for Cache
44
public static final int CMAPNUMBCOLS = 8;
45     public static final int CMAPCACHETARGET = 0;
46     public static final int CMAPCACHETARGETVALUE = 1;
47     public static final int CMAPHTTPMETHOD = 2;
48     public static final int CMAPKEYFIELD = 3;
49     public static final int CMAPFIELDCONSTRAINT = 4;
50     public static final int CMAPTIMEOUT = 5;
51     public static final int CMAPTIMEOUTNAME = 6;
52     public static final int CMAPTIMEOUTSCOPE = 7;
53
54     public static final String JavaDoc DESCRIPTION = "Description"; // NOI18N
55
public static final String JavaDoc NAME = "Name"; // NOI18N
56
public static final String JavaDoc VALUE = "Value"; // NOI18N
57
public static final String JavaDoc DEFAULT_LOCALE = "DefaultLocale"; // NOI18N
58
public static final String JavaDoc LOCALE = "Locale"; // NOI18N
59
public static final String JavaDoc CHARSET = "Charset"; // NOI18N
60
public static final String JavaDoc AGENT = "Agent"; // NOI18N
61
public static final String JavaDoc PERSISTENCE_TYPE = "PersistenceType"; // NOI18N
62

63     public static final String JavaDoc LESSER = "lesser"; // NOI18N
64
public static final String JavaDoc GREATER = "greater"; // NOI18N
65

66     public static final String JavaDoc CLASS_NAME = "ClassName"; // NOI18N
67

68     public static final String JavaDoc [] CACHE_SCOPE = {
69     "request.attribute", // NOI18N
70
"request.header", // NOI18N
71
"request.parameter", // NOI18N
72
"session.attribute", // NOI18N
73
"request.cookie", // NOI18N
74
"context.attribute" // NOI18N
75
};
76
77     public static final String JavaDoc [] CACHE_KEY_SCOPE = {
78     "request.parameter", // NOI18N
79
"request.header", // NOI18N
80
"request.cookie", // NOI18N
81
"context.attribute", // NOI18N
82
"session.id", //NOI18N
83
"session.attribute" // NOI18N
84
};
85
86     public static final String JavaDoc CACHE_MAX_ENTRIES = "4096"; // NOI18N
87
public static final String JavaDoc CACHE_TIMEOUT = "30"; // NOI18N
88

89     public static final String JavaDoc [] CACHE_KEY_BOOLEAN = {
90         "true", // NOI18N
91
"false" // NOI18N
92
};
93
94     public static final String JavaDoc [] CACHE_KEY_EXPR = {
95     "equals", // NOI18N
96
"greater", // NOI18N
97
"lesser", // NOI18N
98
"not-equals" // NOI18N
99
};
100
101     public static final String JavaDoc MATCH_ALL_VALUE = "*"; // NOI18N
102

103     public static final String JavaDoc [] CACHE_TARGET = {
104     "ServletName", // NOI18N
105
"URLPattern" // NOI18N
106
};
107     public static final String JavaDoc CACHE_TARGET_SERVLET = "ServletName"; // NOI18N
108
public static final String JavaDoc CACHE_TARGET_URL = "URLPattern"; // NOI18N
109

110     public static final String JavaDoc [] CACHE_REF = {
111     "CacheHelperRef", // NOI18N
112
"CachePolicyRef" // NOI18N
113
};
114     public static final String JavaDoc CACHE_HELPER_STR = "CacheHelperRef"; // NOI18N
115
public static final String JavaDoc CACHE_POLICY_OBJ = "CachePolicyRef"; // NOI18N
116

117     public static final String JavaDoc CACHE_REF_DEFAULT_VAL = "defaultCacheRefValue"; // NOI18N
118

119     public static final String JavaDoc [] HTTP_METHODS = {
120     "GET", // NOI18N
121
"POST" // NOI18N
122
};
123
124     public static final int EXTRAPARAMS = 1;
125     public static final int SESSIONPARAM = 2;
126     public static final int STOREPARAM = 3;
127     public static final int JSPPARAM = 4;
128     public static final int COOKIEPARAM = 5;
129     public static final int MANAGERPARAM = 6;
130     public static final int PERSISTPARAM = 7;
131     public static final int HELPERCLASSPARAM = 8;
132
133     // Cache Object Types
134
public static final int CACHE_HELPER = 9;
135     public static final int DEFAULT_HELPER = 10;
136     public static final int CACHE_PROPERTY_ARRAY = 11;
137     public static final int CACHE_MAP = 12;
138     public static final int CACHE_MAP_HTTP_METHOD = 13;
139     public static final int CACHE_MAP_KEY_FIELD = 14;
140     public static final int CACHE_MAP_CONSTRAINT_FIELD = 15;
141     public static final int CACHE_MAP_CONSTRAINT_FIELD_VALUE = 16;
142
143     // Cache Helper Table Columns
144
public static final int CACHE_HELPER_NUMB_COLS = 3;
145     public static final int CACHE_HELPER_COL_NAME = 0;
146     public static final int CACHE_HELPER_COL_CLASS_NAME = 1;
147     public static final int CACHE_HELPER_COL_PROPERTY = 2;
148
149     // Cache Mapping Table Columns
150
public static final int CACHE_MAP_NUMB_COLS = 4;
151     public static final int CACHE_MAP_COL_TGT = 0;
152     public static final int CACHE_MAP_COL_TGTVAL = 1;
153     public static final int CACHE_MAP_COL_REF = 2;
154     public static final int CACHE_MAP_COL_REFVAL = 3;
155
156     // Cache Constraint Field Table Columns
157
public static final int CACHE_CF_NUMB_COLS = 5;
158     public static final int CACHE_CF_COL_NAME = 0;
159     public static final int CACHE_CF_COL_SCOPE = 1;
160     public static final int CACHE_CF_COL_COM = 2;
161     public static final int CACHE_CF_COL_COMF = 3;
162     public static final int CACHE_CF_COL_VALUE = 4;
163
164     // Cache Object Names
165
public static final String JavaDoc WEB_PROPERTY_ARRAY_WRAPPER_STR = "WebPropertyArrayWrapper"; // NOI18N
166
public static final String JavaDoc CACHE_PROPERTY_ARRAY_STR = "CachePropertyArray"; // NOI18N
167
public static final String JavaDoc CACHE_HELPER_ARRAY = "CacheHelperArray"; // NOI18N
168
public static final String JavaDoc CACHE_MAP_ARRAY = "CacheMapArray"; // NOI18N
169
public static final String JavaDoc CACHE_MAPPING = "CacheMapping"; // NOI18N
170
public static final String JavaDoc CACHE_HTTP_METHOD_ARRAY = "CacheHTTPMethodArray"; // NOI18N
171
public static final String JavaDoc CACHE_KEY_FIELD_ARRAY = "CacheKeyFieldArray"; // NOI18N
172
public static final String JavaDoc CACHE_CONSTRAINT_FIELD_ARRAY = "CacheConstraintFieldArray"; // NOI18N
173
public static final String JavaDoc CACHE_CONSTRAINT_FIELD_VALUE_ARRAY = "CacheConstraintFieldValueArray"; // NOI18N
174

175     private static final String JavaDoc DELIMITER = "::";//NOI18N
176
private static final String JavaDoc DATAFILE = "com/sun/enterprise/tools/common/dd/webapp/data/sun-web-app-data.xml";//NOI18N
177
private static Hashtable paramContainer = null;
178     private static ParamData pData = null;
179     
180     public static String JavaDoc[] emptyList = {""};//NOI18N
181
public static String JavaDoc[] extraParamName = {""};//NOI18N
182
public static final String JavaDoc extraParamHelpID = helpBundle.getString("webmod_extraparams_add"); //NOI18N
183

184     public static String JavaDoc[] sessionParamName;
185     public static final String JavaDoc sessionParamHelpID = helpBundle.getString("webmod_sessionparam_add"); //NOI18N
186

187     public static String JavaDoc[] storeParamName;
188     public static final String JavaDoc storeParamHelpID = helpBundle.getString("webmod_storeparam_add"); //NOI18N
189

190     public static String JavaDoc[] jspParamName;
191     public static final String JavaDoc jspParamHelpID = helpBundle.getString("webmod_jspparam_add"); //NOI18N
192

193     public static String JavaDoc[] cookieParamName;
194     public static final String JavaDoc cookieParamHelpID = helpBundle.getString("webmod_cookieparam_add"); //NOI18N
195

196     public static String JavaDoc[] managerParamName;
197     public static final String JavaDoc managerParamHelpID = helpBundle.getString("webmod_managerparam_add"); //NOI18N
198

199     public static String JavaDoc[] persistParamName;
200     public static final String JavaDoc persistParamHelpID = helpBundle.getString("webmod_sessionparam_add"); //NOI18N
201

202     public static String JavaDoc[] helperClassParamName;
203     public static final String JavaDoc helperClassParamHelpID = helpBundle.getString("webmod_sessionparam_add"); //NOI18N
204

205     
206     
207     
208     
209     public static String JavaDoc[] getParamNames(int type){
210         if(paramContainer == null) initialize();
211         switch ( type ) {
212             case EXTRAPARAMS:
213                 return extraParamName;
214             case SESSIONPARAM:
215                 return sessionParamName;
216             case STOREPARAM:
217                 return storeParamName;
218             case JSPPARAM:
219                 return jspParamName;
220             case COOKIEPARAM:
221                 return cookieParamName;
222             case MANAGERPARAM:
223                 return managerParamName;
224             case PERSISTPARAM:
225                 return persistParamName;
226         case HELPERCLASSPARAM:
227         return helperClassParamName;
228         }
229         return new String JavaDoc[] {};
230     }
231     
232     public static String JavaDoc[] getParamValues(int type, String JavaDoc key){
233         if(paramContainer == null) initialize();
234         pData = (ParamData) paramContainer.get(type+DELIMITER+key);
235         if(pData != null){
236             return pData.getParamValues();
237         }else{
238             return emptyList;
239         }
240     }
241     
242     public static String JavaDoc getDefaultValue(int type, String JavaDoc key){
243         if(paramContainer == null) initialize();
244         pData = (ParamData) paramContainer.get(type+DELIMITER+key);
245         if(pData != null){
246             return pData.getDefaultValue();
247         }else{
248             return "";//NOI18N
249
}
250     }
251     
252     public static String JavaDoc getHelpID(int type, String JavaDoc key){
253         if(paramContainer == null) initialize();
254         pData = (ParamData) paramContainer.get(type+DELIMITER+key);
255         if(pData != null){
256             return pData.getHelpID();
257         }else{
258             return "";//NOI18N
259
}
260     }
261     
262    public static String JavaDoc getType(int type, String JavaDoc key){
263         if(paramContainer == null) initialize();
264         
265         pData = (ParamData) paramContainer.get(type+DELIMITER+key);
266         
267         if(pData != null){
268             return pData.getParamType();
269         }else{
270             return "";//NOI18N
271
}
272     }
273  
274    /* test the value to check if this is the right type
275     **/

276    
277    public static boolean isValidType(int type, String JavaDoc key, String JavaDoc value){
278        boolean valid = true;
279        if ((type == EXTRAPARAMS) || (type == HELPERCLASSPARAM)) return true;
280        pData = (ParamData) paramContainer.get(type+DELIMITER+key);
281        String JavaDoc reqType = pData.getParamType();
282       // System.out.println("###**** reqType = " + reqType); //NOI18N
283
if(reqType != null && reqType.equalsIgnoreCase("number")){//NOI18N
284
try{
285                //System.out.println("###**** Trying to parse"); //NOI18N
286
Integer.parseInt(value);
287            }catch(Exception JavaDoc e){
288                valid = false;
289            }
290        }
291        return valid;
292    }
293    
294     public static String JavaDoc getHelpID(int type){
295         switch ( type ) {
296             case EXTRAPARAMS:
297                 return extraParamHelpID;
298             case SESSIONPARAM:
299                 return sessionParamHelpID;
300             case STOREPARAM:
301                 return storeParamHelpID;
302             case JSPPARAM:
303                 return jspParamHelpID;
304             case COOKIEPARAM:
305                 return cookieParamHelpID;
306             case MANAGERPARAM:
307                 return managerParamHelpID;
308             case PERSISTPARAM:
309                 return persistParamHelpID;
310             case HELPERCLASSPARAM:
311                 return helperClassParamHelpID;
312         }
313         return ""; // NOI18N
314
}
315     
316     private static void initialize(){
317         paramContainer = new Hashtable();
318         InputStream in = MetaData.class.getClassLoader().getResourceAsStream(DATAFILE);
319         //System.out.println("############ getParamFromFile DATAFILE =" + DATAFILE); //NOI18N
320
//System.out.println("############ getParamFromFile in =" + in); //NOI18N
321
SunWebAppData data = null;
322     try {
323             data = SunWebAppData.createGraph(in);
324     } catch (Schema2BeansException e) {
325         System.out.println("Failed to create bean graph for SunWebAppData"); //NOI18N
326
}
327         //System.out.println("############ " + data.dumpBeanNode()); //NOI18N
328
ParamData pData = null;
329         
330         // initialize all param name arrays
331
sessionParamName = new String JavaDoc[data.sizeSessionParam()];
332         storeParamName = new String JavaDoc[data.sizeStoreParam()];
333         managerParamName = new String JavaDoc[data.sizeManagerParam()];
334         jspParamName = new String JavaDoc[data.sizeJspParam()];
335         extraParamName = new String JavaDoc[data.sizeExtraParam()];
336         cookieParamName = new String JavaDoc[data.sizeCookieParam()];
337         persistParamName = new String JavaDoc[data.sizePersistenceParam()];
338         helperClassParamName = new String JavaDoc[data.sizeHelperClassParam()];
339         
340         for(int i = 0; i < data.sizeSessionParam(); i ++){
341             pData = data.getSessionParam(i);
342             sessionParamName[i] = pData.getParamName();
343             //System.out.println("#### putting key = " + SESSIONPARAM + DELIMITER + pData.getParamName()); //NOI18N
344
paramContainer.put(SESSIONPARAM + DELIMITER + pData.getParamName() , pData);
345         }
346         
347         for(int i = 0; i < data.sizePersistenceParam(); i ++){
348             pData = data.getPersistenceParam(i);
349             persistParamName[i] = pData.getParamName();
350             paramContainer.put(PERSISTPARAM + DELIMITER + pData.getParamName(), pData);
351         }
352         
353         for(int i = 0; i < data.sizeStoreParam(); i ++){
354             pData = data.getStoreParam(i);
355             storeParamName[i] = pData.getParamName();
356             paramContainer.put(STOREPARAM + DELIMITER + pData.getParamName() , pData);
357         }
358         
359         for(int i = 0; i < data.sizeManagerParam(); i ++){
360             pData = data.getManagerParam(i);
361             managerParamName[i] = pData.getParamName();
362             paramContainer.put(MANAGERPARAM + DELIMITER + pData.getParamName() , pData);
363         }
364         
365         for(int i = 0; i < data.sizeJspParam(); i ++){
366             pData = data.getJspParam(i);
367             jspParamName[i] = pData.getParamName();
368             paramContainer.put(JSPPARAM + DELIMITER + pData.getParamName() , pData);
369         }
370         
371         for(int i = 0; i < data.sizeExtraParam(); i ++){
372             pData = data.getExtraParam(i);
373             extraParamName[i] = pData.getParamName();
374             paramContainer.put(EXTRAPARAMS + DELIMITER + pData.getParamName() , pData);
375         }
376         
377         for(int i = 0; i < data.sizeCookieParam(); i ++){
378             pData = data.getCookieParam(i);
379             cookieParamName[i] = pData.getParamName();
380             paramContainer.put(COOKIEPARAM + DELIMITER + pData.getParamName() , pData);
381         }
382         for(int i = 0; i < data.sizeHelperClassParam(); i ++){
383             pData = data.getHelperClassParam(i);
384             helperClassParamName[i] = pData.getParamName();
385             paramContainer.put(HELPERCLASSPARAM + DELIMITER + pData.getParamName() , pData);
386         }
387     }
388     
389     
390 }
391
Popular Tags