1 5 6 package com.raptus.owxv3; 7 8 import java.text.ParseException ; 9 import java.util.*; 10 11 import javax.sql.DataSource ; 12 13 35 public class VModule extends Object 36 { 37 public static final int TYPE_VIRTUAL = 3; 38 public static final int TYPE_STANDARD = 2; 39 public static final int TYPE_BUILTIN = 1; 40 41 44 protected String identification; 45 46 49 protected int type; 50 51 54 protected String [] locales; 55 56 59 61 64 protected String dmgrclass = null; 65 66 69 protected String dmgrcfgfile = null; 70 71 74 protected DataSource datasource = null; 75 76 79 protected Configuration cfg = null; 80 81 84 protected String [] sections; 85 86 89 protected Hashtable vmoduleSections = null; 90 91 94 protected String base= null; 95 96 99 protected String [] roles = null; 100 101 104 public String [] getRoles() 105 { 106 return roles; 107 } 108 109 112 public boolean isVirtual() 113 { 114 if(base != null) 115 { 116 return true; 117 } 118 else 119 { 120 return false; 121 } 122 } 123 124 127 public void setBaseModule(String baseModule) 128 { 129 this.base = baseModule; 130 } 131 132 135 public String getBaseModule() 136 { 137 return base; 138 } 139 140 143 public boolean initialize(String vmid, DataSource ds) 144 { 145 XMLConfigManager cm = XMLConfigManager.getInstance(); 146 cfg = cm.getConfiguration(); 147 148 String pfx = Constants.VMODULE_PREFIX + vmid; 149 String t = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vmid,"type"); 151 LoggingManager.log("VModule id is "+vmid+", type is "+t, this); 152 if(t.equals("virtual")) 153 { 154 base=cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vmid,"base"); 155 LoggingManager.log("Base vmodule is "+base, this); 156 } 157 159 roles=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vmid+"/roles", "value"); 160 LoggingManager.log("vmodule roles:"+roles, this); 161 if(roles != null) 162 { 163 for(int i=0;i<roles.length;i++) 164 { 165 LoggingManager.log("Role for vmodule "+vmid+":"+roles[i], this); 166 } 167 } 168 175 176 locales=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vmid+"/properties/property?name=locales", "value"); 177 LoggingManager.log("vmodule locales:"+locales, this); 178 179 if((locales==null || locales.length<1) && isVirtual()) 180 { 181 LoggingManager.log("Locale not found..loading from base!", this); 182 locales=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+base+"/properties/property?name=locales", "value"); 183 LoggingManager.log("vmodule locales(from base module):"+locales, this); 184 } 185 186 198 dmgrclass = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+vmid+"/properties/property?name=manager", "value"); 200 LoggingManager.log("vmodule manager "+dmgrclass, this); 201 if((dmgrclass==null || dmgrclass.trim().length()<1)&&isVirtual()) 202 { 203 dmgrclass = cm.getPropertyByTree("virtualhost/vmodules/vmodule?name="+base+"/properties/property?name=manager", "value"); 204 LoggingManager.log("vmodule manager (from base class)"+dmgrclass, this); 205 } 206 207 sections=cm.getStringArrayByTree("virtualhost/vmodules/vmodule?name="+vmid+"/section", "items"); 210 211 if(t != null && locales != null && sections != null) 212 { 213 if(t.compareToIgnoreCase("STANDARD") == 0) 214 type = TYPE_STANDARD; 215 else if(t.compareToIgnoreCase("BUILTIN") == 0) 216 type = TYPE_BUILTIN; 217 else if(t.compareToIgnoreCase("VIRTUAL") == 0) 218 type = TYPE_VIRTUAL; 219 220 datasource = ds; 221 identification = vmid; 222 vmoduleSections = new Hashtable(); 223 224 for(int i = 0; i < sections.length; i ++) 226 { 227 VModuleSection section = new VModuleSection(); 228 if(section.initialize(sections[i], this)) 229 vmoduleSections.put(sections[i], section); 230 } 231 232 LoggingManager.log("Returning true in vmodule.init()", this); 233 return true; 234 } 235 236 LoggingManager.log("Virtual module " + vmid + " cannot be initialized!", this); 237 return false; 238 } 239 240 243 public DataManager getDatamanager() 244 { 245 DataManager dm = null; 246 247 if(dmgrclass != null && dmgrclass.length() > 0) 248 { 249 try 250 { 251 Class classObj = Class.forName(dmgrclass); 252 if(classObj == null) 253 { 254 LoggingManager.log("Can't load datamanager " + dmgrclass + "!", this); 255 return null; 256 } 257 258 dm = (DataManager) classObj.newInstance(); 259 if(dm == null) 260 { 261 LoggingManager.log("Can't instantiate datamanager " + dmgrclass + "!", this); 262 return null; 263 } 264 265 return dm; 266 } 267 catch(Exception e) 268 { 269 LoggingManager.log("Exception while instantiating datamanager " + dmgrclass, this); 270 LoggingManager.log(e.toString(), this); 271 } 272 273 LoggingManager.log("Created an instance of " + dmgrclass + " for virtual module " + 274 identification, this); 275 } 276 277 return dm; 278 } 279 280 283 public boolean isLocaleAvailable(Locale locale) 284 { 285 String lcmp = locale.toString(); 286 for(int i = 0; i < locales.length; i ++) 287 { 288 if(lcmp.compareToIgnoreCase(locales[i]) == 0) 289 return true; 290 } 291 292 return false; 293 } 294 295 298 public String getStringProperty(String property) 299 { 300 return cfg.getStringByKey(Constants.VMODULE_PREFIX + identification + 301 Constants.VMODULE_PROPERTY_PREFIX + property); 302 } 303 304 307 public boolean getBooleanProperty(String property) 308 throws ParseException 309 { 310 return cfg.getBooleanByKey(Constants.VMODULE_PREFIX + identification + 311 Constants.VMODULE_PROPERTY_PREFIX + property); 312 } 313 314 317 public int getIntegerProperty(String property) 318 throws ParseException 319 { 320 return cfg.getIntByKey(Constants.VMODULE_PREFIX + identification + 321 Constants.VMODULE_PROPERTY_PREFIX + property); 322 } 323 324 325 328 public String [] getStringArrayProperty(String property) 329 { 330 return cfg.getStringArrayByKey(Constants.VMODULE_PREFIX + identification + 331 Constants.VMODULE_PROPERTY_PREFIX + property); 332 } 333 334 335 338 public String getIdentification() { return identification; } 339 340 343 public int getType() { return type; } 344 345 348 public String [] getLocales() { return locales; } 349 public int getLocalesCount() { return locales.length; } 350 351 354 356 359 public String [] getSections() { return sections; } 360 public int getSectionsCount() { return sections.length; } 361 362 365 public DataSource getDatasource() { return datasource; } 366 367 370 public String getDatamanagerCfgFile() { return dmgrcfgfile; } 371 372 375 public Configuration getConfiguration() { return cfg; } 376 377 380 public VModuleSection getSection(String section) { return (VModuleSection) vmoduleSections.get(section); } 381 382 } 383 384 385 | Popular Tags |