1 19 20 package org.netbeans.modules.j2ee.dd.impl.ejb; 21 22 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException; 23 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 24 import org.netbeans.modules.j2ee.dd.api.ejb.Interceptors; 25 import org.netbeans.modules.j2ee.dd.impl.common.DDProviderDataObject; 26 import org.netbeans.modules.schema2beans.Schema2BeansUtil; 27 import org.netbeans.modules.schema2beans.BaseBean; 28 import org.openide.loaders.DataObject; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileLock; 31 32 import java.math.BigDecimal ; 33 import java.io.OutputStream ; 34 35 39 public class EjbJarProxy implements EjbJar { 40 private EjbJar ejbJar; 41 private String version; 42 private java.util.List listeners; 43 public boolean writing=false; 44 private org.xml.sax.SAXParseException error; 45 private int ddStatus; 46 private Schema2BeansUtil.ReindentationListener reindentationListener = new Schema2BeansUtil.ReindentationListener(); 47 48 49 public EjbJarProxy(EjbJar ejbJar, String version) { 50 this.ejbJar=ejbJar; 51 this.version = version; 52 listeners = new java.util.ArrayList (); 53 addPropertyChangeListener(reindentationListener); 54 } 55 56 public void setOriginal(EjbJar ejbJar) { 57 if (this.ejbJar!=ejbJar) { 58 for (int i=0;i<listeners.size();i++) { 59 java.beans.PropertyChangeListener pcl = 60 (java.beans.PropertyChangeListener )listeners.get(i); 61 if (this.ejbJar!=null) this.ejbJar.removePropertyChangeListener(pcl); 62 if (ejbJar!=null) ejbJar.addPropertyChangeListener(pcl); 63 64 } 65 this.ejbJar=ejbJar; 66 if (ejbJar!=null) setProxyVersion(ejbJar.getVersion().toString()); 67 } 68 } 69 70 public EjbJar getOriginal() { 71 return ejbJar; 72 } 73 74 public void setProxyVersion(java.lang.String value) { 75 if ((version == null && value != null) || (version != null && !version.equals(value))) { 76 java.beans.PropertyChangeEvent evt = 77 new java.beans.PropertyChangeEvent (this, PROPERTY_VERSION, version, value); 78 version = value; 79 for (int i = 0; i < listeners.size(); i++) { 80 ((java.beans.PropertyChangeListener ) listeners.get(i)).propertyChange(evt); 81 } 82 } 83 } 84 85 89 public void setVersion(java.math.BigDecimal version) { 90 String newVersion = version.toString(); 91 if (this.version.equals(newVersion)) return; 92 if (!EjbJar.VERSION_2_1.equals(newVersion)) 93 throw new RuntimeException ("Only the upgrade from lower to upper version is supported"); if (ejbJar!=null) { 95 org.w3c.dom.Document document = null; 96 if (ejbJar instanceof org.netbeans.modules.j2ee.dd.impl.ejb.model_2_0.EjbJar) { 97 document = 98 ((org.netbeans.modules.j2ee.dd.impl.ejb.model_2_0.EjbJar)ejbJar).graphManager().getXmlDocument(); 99 } 100 if (document!=null) { 101 org.w3c.dom.Element docElement = document.getDocumentElement(); 102 if (docElement!=null) { 103 org.w3c.dom.DocumentType docType = document.getDoctype(); 104 if (docType!=null) { 105 document.removeChild(docType); } 107 docElement.setAttribute("version","2.1"); docElement.setAttribute("xmlns","http://java.sun.com/xml/ns/j2ee"); docElement.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); docElement.setAttribute("xsi:schemaLocation", "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"); } 113 } 114 } 115 } 116 117 public java.math.BigDecimal getVersion() { 118 return version == null ? BigDecimal.valueOf(0) : new BigDecimal (version); 119 } 120 public org.xml.sax.SAXParseException getError() { 121 return error; 122 } 123 public void setError(org.xml.sax.SAXParseException error) { 124 this.error=error; 125 } 126 public int getStatus() { 127 return ddStatus; 128 } 129 public void setStatus(int value) { 130 if (ddStatus!=value) { 131 java.beans.PropertyChangeEvent evt = 132 new java.beans.PropertyChangeEvent (this, PROPERTY_STATUS, new Integer (ddStatus), new Integer (value)); 133 ddStatus=value; 134 for (int i=0;i<listeners.size();i++) { 135 ((java.beans.PropertyChangeListener )listeners.get(i)).propertyChange(evt); 136 } 137 } 138 } 139 140 public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl) { 141 if (ejbJar!=null) ejbJar.addPropertyChangeListener(pcl); 142 listeners.add(pcl); 143 } 144 145 public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl) { 146 if (ejbJar!=null) ejbJar.removePropertyChangeListener(pcl); 147 listeners.remove(pcl); 148 } 149 150 public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean createBean(String beanName) throws ClassNotFoundException { 151 return ejbJar==null?null:ejbJar.createBean(beanName); 152 } 153 154 public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean addBean(String beanName, String [] propertyNames, Object [] propertyValues, String keyProperty) throws ClassNotFoundException , org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException { 155 return ejbJar==null?null:ejbJar.addBean(beanName, propertyNames, propertyValues, keyProperty); 156 } 157 158 public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean addBean(String beanName) throws ClassNotFoundException { 159 return ejbJar==null?null:ejbJar.addBean(beanName); 160 } 161 162 public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean findBeanByName(String beanName, String propertyName, String value) { 163 return ejbJar==null?null:ejbJar.findBeanByName(beanName, propertyName, value); 164 } 165 166 public java.util.Map getAllDescriptions() { 167 return ejbJar==null?new java.util.HashMap ():ejbJar.getAllDescriptions(); 168 } 169 170 public java.util.Map getAllDisplayNames() { 171 return ejbJar==null?new java.util.HashMap ():ejbJar.getAllDisplayNames(); 172 } 173 174 public java.util.Map getAllIcons() { 175 return ejbJar==null?new java.util.HashMap ():ejbJar.getAllIcons(); 176 } 177 178 public String getDefaultDescription() { 179 return ejbJar==null?null:ejbJar.getDefaultDescription(); 180 } 181 182 public String getDefaultDisplayName() { 183 return ejbJar==null?null:ejbJar.getDefaultDisplayName(); 184 } 185 186 public org.netbeans.modules.j2ee.dd.api.common.Icon getDefaultIcon() { 187 return ejbJar==null?null:ejbJar.getDefaultIcon(); 188 } 189 190 public String getDescription(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 191 return ejbJar==null?null:ejbJar.getDescription(locale); 192 } 193 194 public String getDisplayName(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 195 return ejbJar==null?null:ejbJar.getDisplayName(locale); 196 } 197 198 public java.lang.String getId() { 199 return ejbJar==null?null:ejbJar.getId(); 200 } 201 202 public String getLargeIcon() { 203 return ejbJar==null?null:ejbJar.getLargeIcon(); 204 } 205 206 public String getLargeIcon(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 207 return ejbJar==null?null:ejbJar.getLargeIcon(locale); 208 } 209 210 public String getSmallIcon() { 211 return ejbJar==null?null:ejbJar.getSmallIcon(); 212 } 213 214 public String getSmallIcon(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 215 return ejbJar==null?null:ejbJar.getSmallIcon(locale); 216 } 217 218 public Object getValue(String name) { 219 return ejbJar==null?null:ejbJar.getValue(name); 220 } 221 222 public void merge(org.netbeans.modules.j2ee.dd.api.common.RootInterface bean, int mode) { 223 if (bean instanceof EjbJarProxy) { 224 bean = ((EjbJarProxy) bean).getOriginal(); 225 } 226 if (ejbJar != bean && bean instanceof EjbJar) { 227 EjbJar newEjbJar = (EjbJar) bean; 228 if (ejbJar != null && ejbJar.getVersion().equals(newEjbJar.getVersion())) { 229 removePropertyChangeListener(reindentationListener); 230 ejbJar.merge(newEjbJar, mode); 231 addPropertyChangeListener(reindentationListener); 232 } else { 233 setOriginal((EjbJar) newEjbJar.clone()); 234 } 235 } 236 } 237 238 public void removeAllDescriptions() { 239 240 if (ejbJar!=null) ejbJar.removeAllDescriptions(); 241 } 242 243 public void removeAllDisplayNames() { 244 if (ejbJar!=null) ejbJar.removeAllDisplayNames(); 245 } 246 247 public void removeAllIcons() { 248 if (ejbJar!=null) ejbJar.removeAllIcons(); 249 } 250 251 public void removeDescription() { 252 if (ejbJar!=null) ejbJar.removeDescription(); 253 } 254 255 public void removeDescriptionForLocale(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 256 if (ejbJar!=null) ejbJar.removeDescriptionForLocale(locale); 257 } 258 259 public void removeDisplayName() { 260 if (ejbJar!=null) ejbJar.removeDisplayName(); 261 } 262 263 public void removeDisplayNameForLocale(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 264 if (ejbJar!=null) ejbJar.removeDisplayNameForLocale(locale); 265 } 266 267 public void removeIcon() { 268 if (ejbJar!=null) ejbJar.removeIcon(); 269 } 270 271 public void removeIcon(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 272 if (ejbJar!=null) ejbJar.removeIcon(locale); 273 } 274 275 public void removeLargeIcon() { 276 if (ejbJar!=null) ejbJar.removeLargeIcon(); 277 } 278 279 public void removeLargeIcon(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 280 if (ejbJar!=null) ejbJar.removeLargeIcon(locale); 281 } 282 283 public void removeSmallIcon() { 284 if (ejbJar!=null) ejbJar.removeSmallIcon(); 285 } 286 287 public void removeSmallIcon(String locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 288 if (ejbJar!=null) ejbJar.removeSmallIcon(locale); 289 } 290 291 public void setAllDescriptions(java.util.Map descriptions) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 292 if (ejbJar!=null) ejbJar.setAllDescriptions(descriptions); 293 } 294 295 public void setAllDisplayNames(java.util.Map displayNames) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 296 if (ejbJar!=null) ejbJar.setAllDisplayNames(displayNames); 297 } 298 299 public void setAllIcons(String [] locales, String [] smallIcons, String [] largeIcons) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 300 if (ejbJar!=null) ejbJar.setAllIcons(locales, smallIcons, largeIcons); 301 } 302 303 public void setDescription(String description) { 304 if (ejbJar!=null) ejbJar.setDescription(description); 305 } 306 307 public void setDescription(String locale, String description) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 308 if (ejbJar!=null) ejbJar.setDescription(locale, description); 309 } 310 311 public void setDisplayName(String displayName) { 312 if (ejbJar!=null) ejbJar.setDisplayName(displayName); 313 } 314 315 public void setDisplayName(String locale, String displayName) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 316 if (ejbJar!=null) ejbJar.setDisplayName(locale, displayName); 317 } 318 319 public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon) { 320 if (ejbJar!=null) ejbJar.setIcon(icon); 321 } 322 323 public void setId(java.lang.String value) { 324 if (ejbJar!=null) ejbJar.setId(value); 325 } 326 327 public void setLargeIcon(String icon) { 328 if (ejbJar!=null) ejbJar.setLargeIcon(icon); 329 } 330 331 public void setLargeIcon(String locale, String icon) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 332 if (ejbJar!=null) ejbJar.setLargeIcon(locale, icon); 333 } 334 335 public void setSmallIcon(String icon) { 336 if (ejbJar!=null) ejbJar.setSmallIcon(icon); 337 } 338 339 public void setSmallIcon(String locale, String icon) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException { 340 if (ejbJar!=null) ejbJar.setSmallIcon(locale, icon); 341 } 342 343 public void write(java.io.OutputStream os) throws java.io.IOException { 344 if (ejbJar!=null) { 345 writing=true; 346 Schema2BeansUtil.write((BaseBean) ejbJar, os); 347 } 348 } 349 350 public void write(FileObject fo) throws java.io.IOException { 351 if (ejbJar != null) { 352 DataObject dataObject = DataObject.find(fo); 353 if (dataObject instanceof DDProviderDataObject) { 354 ((DDProviderDataObject) dataObject).writeModel(ejbJar); 355 } else { 356 FileLock lock = fo.lock(); 357 try { 358 OutputStream os = fo.getOutputStream(lock); 359 try { 360 writing = true; 361 write(os); 362 } finally { 363 os.close(); 364 } 365 } finally { 366 lock.releaseLock(); 367 } 368 } 369 } 370 } 371 372 public Object clone() { 373 EjbJarProxy proxy; 374 if (ejbJar==null) 375 proxy = new EjbJarProxy(null,version); 376 else { 377 EjbJar clonedEjbJar=(EjbJar)ejbJar.clone(); 378 proxy = new EjbJarProxy(clonedEjbJar,version); 379 if (EjbJar.VERSION_1_1.equals(version)) { 380 ((org.netbeans.modules.schema2beans.BaseBean)clonedEjbJar).changeDocType 381 ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.0//EN","http://java.sun.com/dtd/ejb-jar_1.1.dtd"); 382 } else if (EjbJar.VERSION_2_0.equals(version)) { 383 ((org.netbeans.modules.schema2beans.BaseBean)clonedEjbJar).changeDocType 384 ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN","http://java.sun.com/dtd/ejb-jar_2_0.dtd"); 385 } else { 386 ((org.netbeans.modules.j2ee.dd.impl.ejb.model_2_1.EjbJar)clonedEjbJar)._setSchemaLocation 387 ("http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"); 388 clonedEjbJar.setVersion(new java.math.BigDecimal (EjbJar.VERSION_2_1)); 389 } 390 } 391 proxy.setError(error); 392 proxy.setStatus(ddStatus); 393 return proxy; 394 } 395 396 public boolean isWriting() { 397 return writing; 398 } 399 400 public void setWriting(boolean writing) { 401 this.writing=writing; 402 } 403 404 public org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans getEnterpriseBeans() { 405 return ejbJar==null?null:ejbJar.getEnterpriseBeans(); 406 } 407 408 public org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor getSingleAssemblyDescriptor() { 409 return ejbJar==null?null:ejbJar.getSingleAssemblyDescriptor(); 410 } 411 412 public String getSingleEjbClientJar() { 413 return ejbJar==null?null:ejbJar.getSingleEjbClientJar(); 414 } 415 416 public org.netbeans.modules.j2ee.dd.api.ejb.Relationships getSingleRelationships() { 417 return ejbJar==null?null:ejbJar.getSingleRelationships(); 418 } 419 420 public void setAssemblyDescriptor(org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor value) { 421 if (ejbJar!=null) ejbJar.setAssemblyDescriptor(value); 422 } 423 424 public void setEjbClientJar(String value) { 425 if (ejbJar!=null) ejbJar.setEjbClientJar(value); 426 } 427 428 public void setEnterpriseBeans(org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans value) { 429 if (ejbJar!=null) ejbJar.setEnterpriseBeans(value); 430 } 431 432 public void setRelationships(org.netbeans.modules.j2ee.dd.api.ejb.Relationships value) { 433 if (ejbJar!=null) ejbJar.setRelationships(value); 434 } 435 436 public org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor newAssemblyDescriptor() { 437 if(ejbJar == null) 438 return null; 439 else 440 return ejbJar.newAssemblyDescriptor(); 441 } 442 443 public org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans newEnterpriseBeans() { 444 if(ejbJar == null) 445 return null; 446 else 447 return ejbJar.newEnterpriseBeans(); 448 } 449 450 public org.netbeans.modules.j2ee.dd.api.ejb.Relationships newRelationships() { 451 if(ejbJar == null) 452 return null; 453 else 454 return ejbJar.newRelationships(); 455 } 456 457 public void setInterceptors(Interceptors valueInterface) throws VersionNotSupportedException { 458 if (ejbJar!=null) ejbJar.setInterceptors(valueInterface); 459 } 460 461 public Interceptors newInterceptors() throws VersionNotSupportedException { 462 if(ejbJar == null) 463 return null; 464 else 465 return ejbJar.newInterceptors(); 466 } 467 468 public Interceptors getInterceptors() throws VersionNotSupportedException { 469 if(ejbJar == null) 470 return null; 471 else 472 return ejbJar.getInterceptors(); 473 } 474 } 475 | Popular Tags |