1 19 package org.netbeans.modules.j2ee.sun.dd.impl.common; 20 21 import java.util.Arrays ; 22 import java.util.HashMap ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 import java.util.Vector ; 29 import org.netbeans.modules.schema2beans.BaseBean; 30 import org.netbeans.modules.schema2beans.BeanProp; 31 import org.netbeans.modules.schema2beans.Common; 32 import org.netbeans.modules.schema2beans.Version; 33 34 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 35 import org.netbeans.modules.j2ee.sun.dd.api.DDException; 36 37 41 public abstract class SunBaseBean extends BaseBean implements CommonDDBean { 42 43 45 public SunBaseBean(Vector comps, Version version) { 46 super(comps, version); 47 } 48 49 51 public void dump(StringBuffer str, String indent){ 52 } 53 54 public CommonDDBean getPropertyParent(String name){ 55 if(this.graphManager() != null) 56 return (CommonDDBean) this.graphManager().getPropertyParent(name); 57 else 58 return null; 59 } 60 61 public void write(java.io.Writer w) throws java.io.IOException , org.netbeans.modules.j2ee.sun.dd.api.DDException { 62 try { 63 super.write(w); 64 } catch(org.netbeans.modules.schema2beans.Schema2BeansException ex) { 65 DDException ddEx = new DDException(ex.getMessage()); 69 ddEx.setStackTrace(ex.getStackTrace()); 70 throw ddEx; 71 } 72 } 73 74 public void merge(CommonDDBean root, int mode) { 75 ((BaseBean) this).merge((BaseBean) root, mode); 77 } 78 79 82 public CommonDDBean cloneVersion(String version) { 83 95 SunBaseBean bean = null; 96 97 try { 98 Class newBeanClass = getNewBeanClass(version); 100 101 if(this.getClass() == newBeanClass) { 103 return (SunBaseBean) this.clone(); 104 } 105 106 bean = (SunBaseBean) newBeanClass.newInstance(); 107 } catch(Exception e) { 108 throw new IllegalArgumentException (e.getMessage(), e); 110 } 111 112 if (this.graphManager != null && this.graphManager.getBeanRoot() == this) { 114 throw new IllegalArgumentException ("Use setVersion() to change version of root bean " + this.getClass().getName()); 115 } 116 117 String [] attrs = this.getAttributeNames(); 120 if (attrs != null) { 121 for(int j=0; j<attrs.length; j++) { 122 String a = attrs[j]; 123 if (!this.beanProp().getAttrProp(a).isFixed()) { 124 String v = this.getAttributeValue(a); 125 if (bean.getAttributeValue(a) != v) { 126 bean.setAttributeValue(a, v); 127 } 128 } 129 } 130 } 131 132 136 Iterator it = beanPropsIterator(); 137 138 while (it.hasNext()) { 140 BeanProp prop = (BeanProp)it.next(); 141 142 if (prop == null) { 143 continue; 144 } 145 146 String name = prop.getBeanName(); 147 148 if (Common.isArray(prop.type)) { 149 int size = prop.size(); 150 if (Common.isBean(prop.type)) { 151 for(int i=0; i<size; i++) { 152 BaseBean b = (BaseBean)prop.getValue(i); 153 if (b != null) { 154 b = (SunBaseBean) ((SunBaseBean)b).cloneVersion(version); 155 } 156 try { 157 bean.addValue(name, b); 158 } catch(IllegalArgumentException ex) { 159 System.out.println(ex.getMessage()); 161 if(ex.getCause() != null) { 162 System.out.println(ex.getCause().getMessage()); 163 } 164 } 165 } 166 } else { 167 for(int i=0; i<size; i++) { 168 try { 169 bean.addValue(name, prop.getValue(i)); 170 } catch(IllegalArgumentException ex) { 171 System.out.println(ex.getMessage()); 173 if(ex.getCause() != null) { 174 System.out.println(ex.getCause().getMessage()); 175 } 176 } 177 } 178 179 attrs = prop.getAttributeNames(); 181 for(int j=0; j<attrs.length; j++) { 182 String a = attrs[j]; 183 if (!prop.getAttrProp(a).isFixed()) { 184 for(int i=0; i<size; i++) { 185 String v = prop.getAttributeValue(i, a); 186 if (bean.getAttributeValue(name, i, a) != v) { 187 bean.setAttributeValue(name, i, a, v); 188 } 189 } 190 } 191 } 192 } 193 } else { 194 if (Common.isBean(prop.type)) { 195 BaseBean b = (BaseBean)prop.getValue(0); 196 if (b != null) { 197 b = (SunBaseBean) ((SunBaseBean)b).cloneVersion(version); 198 } 199 try { 200 bean.setValue(name, b); 201 } catch(IllegalArgumentException ex) { 202 System.out.println(ex.getMessage()); 204 if(ex.getCause() != null) { 205 System.out.println(ex.getCause().getMessage()); 206 } 207 } 208 } else { 209 try { 210 bean.setValue(name, prop.getValue(0)); 211 } catch(IllegalArgumentException ex) { 212 System.out.println(ex.getMessage()); 214 if(ex.getCause() != null) { 215 System.out.println(ex.getCause().getMessage()); 216 } 217 } 218 219 attrs = prop.getAttributeNames(); 221 for(int j=0; j<attrs.length; j++) { 222 String a = attrs[j]; 223 if (!prop.getAttrProp(a).isFixed()) { 224 String v = prop.getAttributeValue(0, a); 225 if (bean.getAttributeValue(name, 0, a) != v) { 226 bean.setAttributeValue(name, a, v); 227 } 228 } 229 } 230 } 231 } 232 } 233 234 return bean; 235 } 236 237 private Class getNewBeanClass(String version) throws ClassNotFoundException { 238 String oldName = this.getClass().getName(); 239 String className = oldName.substring(oldName.lastIndexOf('.')+1); 240 String key = version + className; 241 String modelPostfix = (String ) commonBeanModelMap.get(key); 242 243 StringBuffer buf = new StringBuffer (128); 244 if(modelPostfix != null) { 245 buf.append("org.netbeans.modules.j2ee.sun.dd.impl.common.model_"); 247 buf.append(modelPostfix); 248 } else { 249 int modelIndex = oldName.indexOf("model_"); 251 buf.append(oldName.substring(0, modelIndex+6)); 252 buf.append(version.charAt(0)); 253 buf.append('_'); 254 buf.append(version.charAt(2)); 255 buf.append('_'); 256 buf.append(version.charAt(3)); 257 } 258 259 buf.append('.'); 260 buf.append(className); 261 String newClass = buf.toString(); 262 return Class.forName(newClass); 263 } 264 265 270 private static Map commonBeanModelMap = new HashMap (471); 271 272 static { 273 commonBeanModelMap.put("1.30EjbRef", "2_1_0"); 275 commonBeanModelMap.put("1.30ResourceRef", "2_1_0"); 276 commonBeanModelMap.put("1.30ResourceEnvRef", "2_1_0"); 277 278 commonBeanModelMap.put("1.40EjbRef", "2_1_0"); 280 commonBeanModelMap.put("1.40ResourceRef", "2_1_0"); 281 commonBeanModelMap.put("1.40ResourceEnvRef", "2_1_0"); 282 commonBeanModelMap.put("1.40ServiceRef", "2_1_1"); 283 commonBeanModelMap.put("1.40LoginConfig", "2_1_1"); 284 commonBeanModelMap.put("1.40MessageDestination", "2_1_1"); 285 286 commonBeanModelMap.put("1.40PortInfo", "2_1_1"); 287 commonBeanModelMap.put("1.40CallProperty", "2_1_1"); 288 commonBeanModelMap.put("1.40StubProperty", "2_1_1"); 289 commonBeanModelMap.put("1.40ServiceQname", "2_1_1"); 290 commonBeanModelMap.put("1.40WsdlPort", "2_1_1"); 291 commonBeanModelMap.put("1.40MessageSecurity", "2_1_1"); 292 commonBeanModelMap.put("1.40MessageSecurityBinding", "2_1_1"); 293 294 commonBeanModelMap.put("1.41EjbRef", "2_1_0"); 296 commonBeanModelMap.put("1.41ResourceRef", "2_1_0"); 297 commonBeanModelMap.put("1.41ResourceEnvRef", "2_1_0"); 298 commonBeanModelMap.put("1.41ServiceRef", "2_1_1"); 299 commonBeanModelMap.put("1.41LoginConfig", "2_1_1"); 300 commonBeanModelMap.put("1.41MessageDestination", "2_1_1"); 301 302 commonBeanModelMap.put("1.41PortInfo", "2_1_1"); 303 commonBeanModelMap.put("1.41CallProperty", "2_1_1"); 304 commonBeanModelMap.put("1.41StubProperty", "2_1_1"); 305 commonBeanModelMap.put("1.41ServiceQname", "2_1_1"); 306 commonBeanModelMap.put("1.41WsdlPort", "2_1_1"); 307 commonBeanModelMap.put("1.41MessageSecurity", "2_1_1"); 308 commonBeanModelMap.put("1.41MessageSecurityBinding", "2_1_1"); 309 310 commonBeanModelMap.put("5.00EjbRef", "2_1_0"); 312 commonBeanModelMap.put("5.00ResourceRef", "2_1_0"); 313 commonBeanModelMap.put("5.00ResourceEnvRef", "2_1_0"); 314 commonBeanModelMap.put("5.00ServiceRef", "2_1_1"); 315 commonBeanModelMap.put("5.00LoginConfig", "2_1_1"); 316 commonBeanModelMap.put("5.00MessageDestination", "2_1_1"); 317 commonBeanModelMap.put("5.00MessageDestinationRef", "3_0_0"); 318 319 commonBeanModelMap.put("5.00PortInfo", "2_1_1"); 320 commonBeanModelMap.put("5.00CallProperty", "2_1_1"); 321 commonBeanModelMap.put("5.00StubProperty", "2_1_1"); 322 commonBeanModelMap.put("5.00ServiceQname", "2_1_1"); 323 commonBeanModelMap.put("5.00WsdlPort", "2_1_1"); 324 commonBeanModelMap.put("5.00MessageSecurity", "2_1_1"); 325 commonBeanModelMap.put("5.00MessageSecurityBinding", "2_1_1"); 326 327 commonBeanModelMap.put("1.30SecurityRoleMapping", "2_1_0"); 329 330 commonBeanModelMap.put("1.40SecurityRoleMapping", "2_1_0"); 332 333 commonBeanModelMap.put("5.00SecurityRoleMapping", "3_0_0"); 335 336 commonBeanModelMap.put("2.00SecurityRoleMapping", "2_1_0"); 338 commonBeanModelMap.put("2.00WebserviceDescription", "2_1_1"); 339 commonBeanModelMap.put("2.00MessageDestination", "2_1_1"); 340 commonBeanModelMap.put("2.00ResourceRef", "2_1_0"); 341 commonBeanModelMap.put("2.00EjbRef", "2_1_0"); 342 commonBeanModelMap.put("2.00ResourceEnvRef", "2_1_0"); 343 commonBeanModelMap.put("2.00ServiceRef", "2_1_1"); 344 commonBeanModelMap.put("2.00LoginConfig", "2_1_1"); 345 commonBeanModelMap.put("2.00WebserviceEndpoint", "2_1_1"); 346 commonBeanModelMap.put("2.00DefaultResourcePrincipal", "2_1_0"); 347 348 commonBeanModelMap.put("3.00PortInfo", "2_1_1"); 349 commonBeanModelMap.put("3.00CallProperty", "2_1_1"); 350 commonBeanModelMap.put("3.00StubProperty", "2_1_1"); 351 commonBeanModelMap.put("3.00ServiceQname", "2_1_1"); 352 commonBeanModelMap.put("3.00WsdlPort", "2_1_1"); 353 commonBeanModelMap.put("3.00MessageSecurity", "2_1_1"); 354 commonBeanModelMap.put("3.00MessageSecurityBinding", "2_1_1"); 355 356 commonBeanModelMap.put("2.10SecurityRoleMapping", "2_1_0"); 358 commonBeanModelMap.put("2.10WebserviceDescription", "2_1_1"); 359 commonBeanModelMap.put("2.10MessageDestination", "2_1_1"); 360 commonBeanModelMap.put("2.10ResourceRef", "2_1_0"); 361 commonBeanModelMap.put("2.10EjbRef", "2_1_0"); 362 commonBeanModelMap.put("2.10ResourceEnvRef", "2_1_0"); 363 commonBeanModelMap.put("2.10ServiceRef", "2_1_1"); 364 commonBeanModelMap.put("2.10LoginConfig", "2_1_1"); 365 commonBeanModelMap.put("2.10WebserviceEndpoint", "2_1_1"); 366 commonBeanModelMap.put("2.10DefaultResourcePrincipal", "2_1_0"); 367 368 commonBeanModelMap.put("2.10PortInfo", "2_1_1"); 369 commonBeanModelMap.put("2.10CallProperty", "2_1_1"); 370 commonBeanModelMap.put("2.10StubProperty", "2_1_1"); 371 commonBeanModelMap.put("2.10ServiceQname", "2_1_1"); 372 commonBeanModelMap.put("2.10WsdlPort", "2_1_1"); 373 commonBeanModelMap.put("2.10MessageSecurity", "2_1_1"); 374 commonBeanModelMap.put("2.10MessageSecurityBinding", "2_1_1"); 375 376 commonBeanModelMap.put("2.11SecurityRoleMapping", "2_1_0"); 378 commonBeanModelMap.put("2.11WebserviceDescription", "2_1_1"); 379 commonBeanModelMap.put("2.11MessageDestination", "2_1_1"); 380 commonBeanModelMap.put("2.11ResourceRef", "2_1_0"); 381 commonBeanModelMap.put("2.11EjbRef", "2_1_0"); 382 commonBeanModelMap.put("2.11ResourceEnvRef", "2_1_0"); 383 commonBeanModelMap.put("2.11ServiceRef", "2_1_1"); 384 commonBeanModelMap.put("2.11LoginConfig", "2_1_1"); 385 commonBeanModelMap.put("2.11WebserviceEndpoint", "2_1_1"); 386 commonBeanModelMap.put("2.11DefaultResourcePrincipal", "2_1_0"); 387 commonBeanModelMap.put("2.11MethodParams", "2_1_1"); 388 389 commonBeanModelMap.put("2.11PortInfo", "2_1_1"); 390 commonBeanModelMap.put("2.11CallProperty", "2_1_1"); 391 commonBeanModelMap.put("2.11StubProperty", "2_1_1"); 392 commonBeanModelMap.put("2.11ServiceQname", "2_1_1"); 393 commonBeanModelMap.put("2.11WsdlPort", "2_1_1"); 394 commonBeanModelMap.put("2.11MessageSecurity", "2_1_1"); 395 commonBeanModelMap.put("2.11MessageSecurityBinding", "2_1_1"); 396 397 commonBeanModelMap.put("3.00SecurityRoleMapping", "3_0_0"); 399 commonBeanModelMap.put("3.00WebserviceDescription", "2_1_1"); 400 commonBeanModelMap.put("3.00MessageDestination", "2_1_1"); 401 commonBeanModelMap.put("3.00ResourceRef", "2_1_0"); 402 commonBeanModelMap.put("3.00EjbRef", "2_1_0"); 403 commonBeanModelMap.put("3.00ResourceEnvRef", "2_1_0"); 404 commonBeanModelMap.put("3.00ServiceRef", "2_1_1"); 405 commonBeanModelMap.put("3.00LoginConfig", "3_0_0"); 406 commonBeanModelMap.put("3.00MessageDestinationRef", "3_0_0"); 407 commonBeanModelMap.put("3.00WebserviceEndpoint", "3_0_0"); 408 commonBeanModelMap.put("3.00DefaultResourcePrincipal", "2_1_0"); 409 commonBeanModelMap.put("3.00MethodParams", "2_1_1"); 410 411 commonBeanModelMap.put("3.00PortInfo", "2_1_1"); 412 commonBeanModelMap.put("3.00CallProperty", "2_1_1"); 413 commonBeanModelMap.put("3.00StubProperty", "2_1_1"); 414 commonBeanModelMap.put("3.00ServiceQname", "2_1_1"); 415 commonBeanModelMap.put("3.00WsdlPort", "2_1_1"); 416 commonBeanModelMap.put("3.00MessageSecurity", "2_1_1"); 417 commonBeanModelMap.put("3.00MessageSecurityBinding", "2_1_1"); 418 419 commonBeanModelMap.put("2.30SecurityRoleMapping", "2_1_0"); 421 commonBeanModelMap.put("2.30ResourceEnvRef", "2_1_0"); 422 commonBeanModelMap.put("2.30ResourceRef", "2_1_0"); 423 commonBeanModelMap.put("2.30EjbRef", "2_1_0"); 424 commonBeanModelMap.put("2.30ServiceRef", "2_1_1"); 425 commonBeanModelMap.put("2.30LoginConfig", "2_1_1"); 426 commonBeanModelMap.put("2.30MessageDestination", "2_1_1"); 427 commonBeanModelMap.put("2.30WebserviceDescription", "2_1_1"); 428 commonBeanModelMap.put("2.30WebserviceEndpoint", "2_1_1"); 429 430 commonBeanModelMap.put("2.30PortInfo", "2_1_1"); 431 commonBeanModelMap.put("2.30CallProperty", "2_1_1"); 432 commonBeanModelMap.put("2.30StubProperty", "2_1_1"); 433 commonBeanModelMap.put("2.30ServiceQname", "2_1_1"); 434 commonBeanModelMap.put("2.30WsdlPort", "2_1_1"); 435 commonBeanModelMap.put("2.30MessageSecurity", "2_1_1"); 436 commonBeanModelMap.put("2.30MessageSecurityBinding", "2_1_1"); 437 438 commonBeanModelMap.put("2.40SecurityRoleMapping", "2_1_0"); 440 commonBeanModelMap.put("2.40EjbRef", "2_1_0"); 441 commonBeanModelMap.put("2.40ResourceRef", "2_1_0"); 442 commonBeanModelMap.put("2.40ResourceEnvRef", "2_1_0"); 443 commonBeanModelMap.put("2.40ServiceRef", "2_1_1"); 444 commonBeanModelMap.put("2.40LoginConfig", "2_1_1"); 445 commonBeanModelMap.put("2.40MessageDestination", "2_1_1"); 446 commonBeanModelMap.put("2.40WebserviceDescription", "2_1_1"); 447 commonBeanModelMap.put("2.40WebserviceEndpoint", "2_1_1"); 448 449 commonBeanModelMap.put("2.40PortInfo", "2_1_1"); 450 commonBeanModelMap.put("2.40CallProperty", "2_1_1"); 451 commonBeanModelMap.put("2.40StubProperty", "2_1_1"); 452 commonBeanModelMap.put("2.40ServiceQname", "2_1_1"); 453 commonBeanModelMap.put("2.40WsdlPort", "2_1_1"); 454 commonBeanModelMap.put("2.40MessageSecurity", "2_1_1"); 455 commonBeanModelMap.put("2.40MessageSecurityBinding", "2_1_1"); 456 457 commonBeanModelMap.put("2.41SecurityRoleMapping", "2_1_0"); 459 commonBeanModelMap.put("2.41EjbRef", "2_1_0"); 460 commonBeanModelMap.put("2.41ResourceRef", "2_1_0"); 461 commonBeanModelMap.put("2.41ResourceEnvRef", "2_1_0"); 462 commonBeanModelMap.put("2.41ServiceRef", "2_1_1"); 463 commonBeanModelMap.put("2.41LoginConfig", "2_1_1"); 464 commonBeanModelMap.put("2.41MessageDestination", "2_1_1"); 465 commonBeanModelMap.put("2.41WebserviceDescription", "2_1_1"); 466 commonBeanModelMap.put("2.41WebserviceEndpoint", "2_1_1"); 467 468 commonBeanModelMap.put("2.41PortInfo", "2_1_1"); 469 commonBeanModelMap.put("2.41CallProperty", "2_1_1"); 470 commonBeanModelMap.put("2.41StubProperty", "2_1_1"); 471 commonBeanModelMap.put("2.41ServiceQname", "2_1_1"); 472 commonBeanModelMap.put("2.41WsdlPort", "2_1_1"); 473 commonBeanModelMap.put("2.41MessageSecurity", "2_1_1"); 474 commonBeanModelMap.put("2.41MessageSecurityBinding", "2_1_1"); 475 476 commonBeanModelMap.put("2.50SecurityRoleMapping", "3_0_0"); 478 commonBeanModelMap.put("2.50EjbRef", "2_1_0"); 479 commonBeanModelMap.put("2.50ResourceRef", "2_1_0"); 480 commonBeanModelMap.put("2.50ResourceEnvRef", "2_1_0"); 481 commonBeanModelMap.put("2.50ServiceRef", "2_1_1"); 482 commonBeanModelMap.put("2.50LoginConfig", "2_1_1"); 483 commonBeanModelMap.put("2.50MessageDestination", "2_1_1"); 484 commonBeanModelMap.put("2.50MessageDestinationRef", "3_0_0"); 485 commonBeanModelMap.put("2.50WebserviceDescription", "2_1_1"); 486 487 commonBeanModelMap.put("2.50PortInfo", "2_1_1"); 488 commonBeanModelMap.put("2.50CallProperty", "2_1_1"); 489 commonBeanModelMap.put("2.50StubProperty", "2_1_1"); 490 commonBeanModelMap.put("2.50ServiceQname", "2_1_1"); 491 commonBeanModelMap.put("2.50WsdlPort", "2_1_1"); 492 commonBeanModelMap.put("2.50MessageSecurity", "2_1_1"); 493 commonBeanModelMap.put("2.50MessageSecurityBinding", "2_1_1"); 494 } 495 } 496 | Popular Tags |