1 23 24 144 145 package com.sun.enterprise.deployment.phasing; 146 147 import com.sun.enterprise.util.i18n.StringManager; 148 149 import com.sun.enterprise.config.ConfigException; 150 import com.sun.enterprise.config.ConfigContext; 151 import com.sun.enterprise.config.ConfigBean; 152 153 import com.sun.enterprise.config.serverbeans.ApplicationRef; 154 import com.sun.enterprise.config.serverbeans.WebModule; 155 import com.sun.enterprise.config.serverbeans.J2eeApplication; 156 157 import com.sun.enterprise.config.serverbeans.ServerHelper; 158 import com.sun.enterprise.config.serverbeans.ClusterHelper; 159 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 160 import com.sun.enterprise.config.serverbeans.PropertyResolver; 161 162 import com.sun.enterprise.admin.config.BaseConfigMBean; 163 import com.sun.enterprise.admin.target.Target; 164 import com.sun.enterprise.admin.target.TargetType; 165 import com.sun.enterprise.admin.target.TargetBuilder; 166 167 import com.sun.enterprise.deployment.backend.IASDeploymentException; 168 169 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 170 175 public class ApplicationConfigHelper 176 { 177 private static final String CONTEXT_ROOTS_PROPERTY_NAME = "context-roots"; 178 private static final StringManager _strMgr = 179 StringManager.getManager(ApplicationConfigHelper.class); 180 181 private ConfigContext _configContext = null; 182 183 184 public ApplicationConfigHelper(ConfigContext configContext) 185 { 186 _configContext = configContext; 187 } 188 189 private ConfigContext getConfigContext() 190 { 191 return _configContext; 192 } 193 194 201 public static String [] getAppContextRoots(ConfigBean appBean) throws ConfigException, IASDeploymentException 202 { 203 if (appBean instanceof WebModule) 204 { 205 return new String []{((WebModule)appBean).getContextRoot()}; 206 } 207 if (appBean instanceof J2eeApplication) 208 { 209 Object roots = appBean.getTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME); 210 if(roots==null) 211 { 212 String appName = ((J2eeApplication)appBean).getName(); 213 214 roots = DeploymentServiceUtils.getContextRootsForEmbeddedWebApp(appName); 216 appBean.setTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME, roots); 217 } 218 else 219 { 220 if(!(roots instanceof String [])) 221 { 222 throw new ConfigException(_strMgr.getString("configRootsPropertyIsNotStringArray", 223 ((J2eeApplication)appBean).getName())); 224 } 225 } 226 227 return (String [])roots; 228 } 229 return null; 230 } 231 232 240 public static String [] getAppContextRoots(ConfigContext ctx, String appName) throws ConfigException, IASDeploymentException 241 { 242 ConfigBean appBean = ApplicationHelper.findApplication(ctx, appName); 243 if(appBean==null) 244 { 245 throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appName)); 246 } 247 return getAppContextRoots(appBean); 248 } 249 250 260 public static void resetAppContextRoots( ConfigBean appBean, 261 boolean bForceToSetActualValue) throws ConfigException, IASDeploymentException 262 { 263 if (appBean instanceof J2eeApplication) 264 { 265 appBean.setTransientProperty(CONTEXT_ROOTS_PROPERTY_NAME, null); 266 if(bForceToSetActualValue) 267 getAppContextRoots(appBean); } 269 } 270 271 272 283 public static void resetAppContextRoots(ConfigContext ctx, String appName, 284 boolean bForceToSetActualValue) throws ConfigException, IASDeploymentException 285 { 286 ConfigBean appBean = ApplicationHelper.findApplication(ctx, appName); 287 if(appBean==null) 288 { 289 throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appName)); 290 } 291 resetAppContextRoots(appBean, bForceToSetActualValue); 292 } 293 294 295 307 public static String checkContextRootUniqueness(ConfigContext ctx, String appId, String targetName, String virtualServerList) 308 throws ConfigException, IASDeploymentException 309 { 310 ConfigBean appBean = ApplicationHelper.findApplication(ctx, appId); 311 if(appBean==null) 312 { 313 throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", appId)); 314 } 315 316 String [] ctxRoots = getAppContextRoots(appBean); 318 if(ctxRoots==null || ctxRoots.length<=0) 319 return null; 320 321 final Target target = TargetBuilder.INSTANCE.createTarget( 323 new TargetType[]{TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS}, targetName, ctx); 324 325 ApplicationRef[] refs = null; 327 if (target.getType() == TargetType.CLUSTER || 328 target.getType() == TargetType.STANDALONE_CLUSTER) 329 { 330 refs = ClusterHelper.getApplicationReferences(ctx, targetName); 331 } 332 else 333 { 334 refs = ServerHelper.getApplicationReferences(ctx, targetName); 335 } 336 337 if(refs==null) 338 return null; 339 340 for(int i=0; i<refs.length; i++) 341 { 342 if(isVSListsIntersected(refs[i].getVirtualServers(), virtualServerList)) 343 { 344 ConfigBean appBeanToCompare = ApplicationHelper.findApplication(ctx, refs[i].getRef()); 345 if(appBeanToCompare==null) 346 { 347 throw new ConfigException(_strMgr.getString("applicationElementIsNotFoundForName", refs[i].getRef())); 348 } 349 if(((Object )appBeanToCompare)!=((Object )appBean)) 350 { 351 String commonElement = (String )getFirstCommonElement(getAppContextRoots(appBeanToCompare), ctxRoots); 352 if(commonElement!=null) 353 return commonElement; 354 } 355 356 } 357 } 358 return null; 359 } 360 361 362 365 368 private static boolean isVSListsIntersected(String vsList1, String vsList2) 369 { 370 if(vsList1==null || vsList2 == null || 371 vsList1.length()==0 || vsList2.length()==0 ) 372 return true; 373 String [] arr1 = vsList1.split(","); 374 String [] arr2 = vsList2.split(","); 375 if(arr1.length==0 || arr2.length==0) 376 return true; 377 return (getFirstCommonElement(arr1, arr2)!=null); 378 379 } 380 381 384 private static Object getFirstCommonElement(Object [] arr1, Object [] arr2) 385 { 386 if(arr1!=null && arr2!=null && arr1.length!=0 && arr2.length!=0) 387 { 388 for(int i=0; i<arr1.length; i++) 389 { 390 for(int j=0; j<arr2.length; j++) 391 { 392 if( ((String )arr1[i]).startsWith("/") ) { 393 arr1[i] = ((String )arr1[i]).substring(1); 394 } 395 if( ((String )arr2[j]).startsWith("/") ) { 396 arr2[j] = ((String )arr2[j]).substring(1); 397 } 398 if(arr1[i].equals(arr2[j])) { 399 return arr1[i]; 400 } 401 } 402 } 403 } 404 return null; 405 } 406 407 } 408 | Popular Tags |