1 23 24 29 package com.sun.enterprise.tools.common.dd.webapp; 30 31 import java.io.*; 32 import java.util.*; 33 import java.net.URL ; 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 helpBundle = java.util.ResourceBundle.getBundle("com.sun.enterprise.tools.common.HelpIDBundle"); 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 DESCRIPTION = "Description"; public static final String NAME = "Name"; public static final String VALUE = "Value"; public static final String DEFAULT_LOCALE = "DefaultLocale"; public static final String LOCALE = "Locale"; public static final String CHARSET = "Charset"; public static final String AGENT = "Agent"; public static final String PERSISTENCE_TYPE = "PersistenceType"; 63 public static final String LESSER = "lesser"; public static final String GREATER = "greater"; 66 public static final String CLASS_NAME = "ClassName"; 68 public static final String [] CACHE_SCOPE = { 69 "request.attribute", "request.header", "request.parameter", "session.attribute", "request.cookie", "context.attribute" }; 76 77 public static final String [] CACHE_KEY_SCOPE = { 78 "request.parameter", "request.header", "request.cookie", "context.attribute", "session.id", "session.attribute" }; 85 86 public static final String CACHE_MAX_ENTRIES = "4096"; public static final String CACHE_TIMEOUT = "30"; 89 public static final String [] CACHE_KEY_BOOLEAN = { 90 "true", "false" }; 93 94 public static final String [] CACHE_KEY_EXPR = { 95 "equals", "greater", "lesser", "not-equals" }; 100 101 public static final String MATCH_ALL_VALUE = "*"; 103 public static final String [] CACHE_TARGET = { 104 "ServletName", "URLPattern" }; 107 public static final String CACHE_TARGET_SERVLET = "ServletName"; public static final String CACHE_TARGET_URL = "URLPattern"; 110 public static final String [] CACHE_REF = { 111 "CacheHelperRef", "CachePolicyRef" }; 114 public static final String CACHE_HELPER_STR = "CacheHelperRef"; public static final String CACHE_POLICY_OBJ = "CachePolicyRef"; 117 public static final String CACHE_REF_DEFAULT_VAL = "defaultCacheRefValue"; 119 public static final String [] HTTP_METHODS = { 120 "GET", "POST" }; 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 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 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 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 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 public static final String WEB_PROPERTY_ARRAY_WRAPPER_STR = "WebPropertyArrayWrapper"; public static final String CACHE_PROPERTY_ARRAY_STR = "CachePropertyArray"; public static final String CACHE_HELPER_ARRAY = "CacheHelperArray"; public static final String CACHE_MAP_ARRAY = "CacheMapArray"; public static final String CACHE_MAPPING = "CacheMapping"; public static final String CACHE_HTTP_METHOD_ARRAY = "CacheHTTPMethodArray"; public static final String CACHE_KEY_FIELD_ARRAY = "CacheKeyFieldArray"; public static final String CACHE_CONSTRAINT_FIELD_ARRAY = "CacheConstraintFieldArray"; public static final String CACHE_CONSTRAINT_FIELD_VALUE_ARRAY = "CacheConstraintFieldValueArray"; 175 private static final String DELIMITER = "::";private static final String DATAFILE = "com/sun/enterprise/tools/common/dd/webapp/data/sun-web-app-data.xml"; private static Hashtable paramContainer = null; 178 private static ParamData pData = null; 179 180 public static String [] emptyList = {""}; public static String [] extraParamName = {""}; public static final String extraParamHelpID = helpBundle.getString("webmod_extraparams_add"); 184 public static String [] sessionParamName; 185 public static final String sessionParamHelpID = helpBundle.getString("webmod_sessionparam_add"); 187 public static String [] storeParamName; 188 public static final String storeParamHelpID = helpBundle.getString("webmod_storeparam_add"); 190 public static String [] jspParamName; 191 public static final String jspParamHelpID = helpBundle.getString("webmod_jspparam_add"); 193 public static String [] cookieParamName; 194 public static final String cookieParamHelpID = helpBundle.getString("webmod_cookieparam_add"); 196 public static String [] managerParamName; 197 public static final String managerParamHelpID = helpBundle.getString("webmod_managerparam_add"); 199 public static String [] persistParamName; 200 public static final String persistParamHelpID = helpBundle.getString("webmod_sessionparam_add"); 202 public static String [] helperClassParamName; 203 public static final String helperClassParamHelpID = helpBundle.getString("webmod_sessionparam_add"); 205 206 207 208 209 public static String [] 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 [] {}; 230 } 231 232 public static String [] getParamValues(int type, String 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 getDefaultValue(int type, String 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 ""; } 250 } 251 252 public static String getHelpID(int type, String 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 ""; } 260 } 261 262 public static String getType(int type, String 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 ""; } 272 } 273 274 276 277 public static boolean isValidType(int type, String key, String value){ 278 boolean valid = true; 279 if ((type == EXTRAPARAMS) || (type == HELPERCLASSPARAM)) return true; 280 pData = (ParamData) paramContainer.get(type+DELIMITER+key); 281 String reqType = pData.getParamType(); 282 if(reqType != null && reqType.equalsIgnoreCase("number")){ try{ 285 Integer.parseInt(value); 287 }catch(Exception e){ 288 valid = false; 289 } 290 } 291 return valid; 292 } 293 294 public static String 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 ""; } 315 316 private static void initialize(){ 317 paramContainer = new Hashtable(); 318 InputStream in = MetaData.class.getClassLoader().getResourceAsStream(DATAFILE); 319 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"); } 327 ParamData pData = null; 329 330 sessionParamName = new String [data.sizeSessionParam()]; 332 storeParamName = new String [data.sizeStoreParam()]; 333 managerParamName = new String [data.sizeManagerParam()]; 334 jspParamName = new String [data.sizeJspParam()]; 335 extraParamName = new String [data.sizeExtraParam()]; 336 cookieParamName = new String [data.sizeCookieParam()]; 337 persistParamName = new String [data.sizePersistenceParam()]; 338 helperClassParamName = new String [data.sizeHelperClassParam()]; 339 340 for(int i = 0; i < data.sizeSessionParam(); i ++){ 341 pData = data.getSessionParam(i); 342 sessionParamName[i] = pData.getParamName(); 343 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 |