1 19 24 25 package org.netbeans.modules.j2ee.sun.dd.impl.ejb; 26 27 import org.netbeans.modules.j2ee.sun.dd.api.DDException; 28 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean; 29 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar; 30 import org.netbeans.modules.j2ee.sun.dd.impl.DDTreeWalker; 31 import org.netbeans.modules.j2ee.sun.dd.impl.DTDRegistry; 32 33 import org.w3c.dom.Document ; 34 35 36 40 public class SunEjbJarProxy implements SunEjbJar { 41 42 private SunEjbJar ejbJarRoot; 43 private String version; 44 private OutputProvider outputProvider; 45 private int ddStatus; 46 private org.xml.sax.SAXParseException error; 47 private java.util.List listeners; 48 49 50 public SunEjbJarProxy(SunEjbJar ejbJarRoot, String version) { 51 this.ejbJarRoot = ejbJarRoot; 52 this.version = version; 53 } 54 55 public int addSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping securityRoleMapping) { 56 return ejbJarRoot==null?-1:ejbJarRoot.addSecurityRoleMapping(securityRoleMapping); 57 } 58 59 public org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans getEnterpriseBeans() { 60 return ejbJarRoot==null?null:ejbJarRoot.getEnterpriseBeans(); 61 } 62 63 public org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping[] getSecurityRoleMapping() { 64 return ejbJarRoot==null?null:ejbJarRoot.getSecurityRoleMapping(); 65 } 66 67 public org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping getSecurityRoleMapping(int param) { 68 return ejbJarRoot==null?null:ejbJarRoot.getSecurityRoleMapping(param); 69 } 70 71 public org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans newEnterpriseBeans() { 72 if(ejbJarRoot == null) 73 return null; 74 else 75 return ejbJarRoot.newEnterpriseBeans(); 76 } 77 78 public int removeSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping securityRoleMapping) { 79 return ejbJarRoot==null?-1:ejbJarRoot.removeSecurityRoleMapping(securityRoleMapping); 80 } 81 82 public void setEnterpriseBeans(org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans enterpriseBeans) { 83 if (ejbJarRoot!=null) ejbJarRoot.setEnterpriseBeans(enterpriseBeans); 84 } 85 86 public void setSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping[] securityRoleMapping) { 87 if (ejbJarRoot!=null) ejbJarRoot.setSecurityRoleMapping(securityRoleMapping); 88 } 89 90 public void setSecurityRoleMapping(int param, org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping securityRoleMapping) { 91 if (ejbJarRoot!=null) ejbJarRoot.setSecurityRoleMapping(param, securityRoleMapping); 92 } 93 94 public int sizeSecurityRoleMapping() { 95 return ejbJarRoot==null?-1:ejbJarRoot.sizeSecurityRoleMapping(); 96 } 97 98 public void removePropertyChangeListener(java.beans.PropertyChangeListener pcl) { 99 if (ejbJarRoot != null) 100 ejbJarRoot.removePropertyChangeListener(pcl); 101 listeners.remove(pcl); 102 } 103 104 public void addPropertyChangeListener(java.beans.PropertyChangeListener pcl) { 105 if (ejbJarRoot != null) 106 ejbJarRoot.addPropertyChangeListener(pcl); 107 listeners.add(pcl); 108 } 109 110 public void setVersion(java.math.BigDecimal version) { 111 String newVersion = version.toString(); 112 String currentVersion = null; 113 if (this.version.equals(newVersion)) 114 return; 115 if (ejbJarRoot != null) { 116 Document document = null; 117 if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar) { 118 document = 119 ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument(); 120 currentVersion = SunEjbJar.VERSION_2_0_0; 121 }else if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar) { 122 document = 123 ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument(); 124 currentVersion = SunEjbJar.VERSION_2_1_0; 125 }else if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar) { 126 document = 127 ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument(); 128 currentVersion = SunEjbJar.VERSION_2_1_1; 129 }else if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar) { 130 document = 131 ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument(); 132 currentVersion = SunEjbJar.VERSION_3_0_0; 133 } 134 135 document = removeDocType(document); 137 138 if(newVersion.equals(SunEjbJar.VERSION_3_0_0)){ 139 generate3_00Graph(document); 141 } 142 if(newVersion.equals(SunEjbJar.VERSION_2_1_1)){ 143 if(currentVersion.equals(SunEjbJar.VERSION_2_1_0) || currentVersion.equals(SunEjbJar.VERSION_2_0_0)) 144 generate2_11Graph(document); 145 else 146 downgradeEjbJarGraph(document, newVersion, currentVersion); 147 } 148 if(newVersion.equals(SunEjbJar.VERSION_2_1_0)){ 149 if(currentVersion.equals(SunEjbJar.VERSION_2_0_0)) 150 generate2_10Graph(document); 151 else 152 downgradeEjbJarGraph(document, newVersion, currentVersion); 153 } 154 if(newVersion.equals(SunEjbJar.VERSION_2_0_0)){ 155 downgradeEjbJarGraph(document, newVersion, currentVersion); 157 } 158 } 159 } 160 161 private Document removeDocType(Document document){ 162 if (document != null) { 163 org.w3c.dom.Element docElement = document.getDocumentElement(); 164 if (docElement != null) { 165 org.w3c.dom.DocumentType docType = document.getDoctype(); 166 if (docType != null) { 167 document.removeChild(docType); } 169 } 170 } 171 return document; 172 } 173 174 private void downgradeEjbJarGraph(Document document, String downgradeVersion, String currentVersion){ 175 DDTreeWalker downgradeScanner = new DDTreeWalker(document, downgradeVersion, currentVersion); 176 downgradeScanner.downgradeSunEjbJarDocument(); 177 if(downgradeVersion.equals(SunEjbJar.VERSION_2_1_1)){ 178 generate2_11Graph(document); 179 }else if(downgradeVersion.equals(SunEjbJar.VERSION_2_1_0)){ 180 generate2_10Graph(document); 181 }else if(downgradeVersion.equals(SunEjbJar.VERSION_2_0_0)){ 182 generate2_00Graph(document); 183 } 184 } 185 186 private void generate3_00Graph(Document document){ 187 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar ejbGraph = 188 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar.createGraph(document); 189 ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID); 190 this.ejbJarRoot = ejbGraph; 191 } 192 193 private void generate2_11Graph(Document document){ 194 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar ejbGraph = 195 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar.createGraph(document); 196 ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_211_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_211_DTD_SYSTEM_ID); 197 this.ejbJarRoot = ejbGraph; 198 } 199 200 private void generate2_10Graph(Document document){ 201 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar ejbGraph = 202 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar.createGraph(document); 203 ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210_DTD_SYSTEM_ID); 204 this.ejbJarRoot = ejbGraph; 205 } 206 207 private void generate2_00Graph(Document document){ 208 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar ejbGraph = 209 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar.createGraph(document); 210 ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_200_DTD_SYSTEM_ID); 211 this.ejbJarRoot = ejbGraph; 212 } 213 214 public java.math.BigDecimal getVersion() { 215 return new java.math.BigDecimal (version); 216 } 217 218 public void setOriginal(SunEjbJar ejbJarRoot) { 219 if (this.ejbJarRoot != ejbJarRoot) { 220 for (int i=0;i<listeners.size();i++) { 221 java.beans.PropertyChangeListener pcl = 222 (java.beans.PropertyChangeListener )listeners.get(i); 223 if (this.ejbJarRoot != null) 224 this.ejbJarRoot.removePropertyChangeListener(pcl); 225 if (ejbJarRoot != null) 226 ejbJarRoot.addPropertyChangeListener(pcl); 227 228 } 229 this.ejbJarRoot = ejbJarRoot; 230 if (ejbJarRoot != null) 231 setProxyVersion(ejbJarRoot.getVersion().toString()); 232 } 233 } 234 235 public SunEjbJar getOriginal() { 236 return ejbJarRoot; 237 } 238 239 public org.xml.sax.SAXParseException getError() { 240 return error; 241 } 242 public void setError(org.xml.sax.SAXParseException error) { 243 this.error=error; 244 } 245 246 public void setProxyVersion(java.lang.String value) { 247 if ((version==null && value!=null) || !version.equals(value)) { 248 java.beans.PropertyChangeEvent evt = 249 new java.beans.PropertyChangeEvent (this, PROPERTY_VERSION, version, value); 250 version=value; 251 for (int i=0;i<listeners.size();i++) { 252 ((java.beans.PropertyChangeListener )listeners.get(i)).propertyChange(evt); 253 } 254 } 255 } 256 257 public Object getValue(String name) { 258 return ejbJarRoot==null?null:ejbJarRoot.getValue(name); 259 } 260 261 public void write(java.io.OutputStream os) throws java.io.IOException { 262 if (ejbJarRoot!=null) { 263 ejbJarRoot.write(os); 264 } 265 } 266 267 public String dumpBeanNode() { 268 if (ejbJarRoot!=null) 269 return ejbJarRoot.dumpBeanNode(); 270 else 271 return null; 272 } 273 274 public void setValue(String name, Object [] value) { 275 if (ejbJarRoot!=null) ejbJarRoot.setValue(name, value); 276 } 277 278 public Object [] getValues(String name) { 279 return ejbJarRoot==null?null:ejbJarRoot.getValues(name); 280 } 281 282 public void setValue(String name, int index, Object value) { 283 if (ejbJarRoot!=null) ejbJarRoot.setValue(name, index, value); 284 } 285 286 public void setValue(String name, Object value) { 287 if (ejbJarRoot!=null) ejbJarRoot.setValue(name, value); 288 } 289 290 public Object getValue(String name, int index) { 291 return ejbJarRoot==null?null:ejbJarRoot.getValue(name, index); 292 } 293 294 public String getAttributeValue(String name) { 295 return ejbJarRoot==null?null:ejbJarRoot.getAttributeValue(name); 296 } 297 298 public int size(String name) { 299 return ejbJarRoot==null?-1:ejbJarRoot.size(name); 300 } 301 302 public int addValue(String name, Object value) { 303 return ejbJarRoot==null?-1:ejbJarRoot.addValue(name, value); 304 } 305 306 public String [] findPropertyValue(String propName, Object value) { 307 return ejbJarRoot==null?null:ejbJarRoot.findPropertyValue(propName, value); 308 } 309 310 public int removeValue(String name, Object value) { 311 return ejbJarRoot==null?-1:ejbJarRoot.removeValue(name, value); 312 } 313 314 public void write(java.io.Writer w) throws java.io.IOException , DDException { 315 if (ejbJarRoot!=null) ejbJarRoot.write(w); 316 } 317 318 public void removeValue(String name, int index) { 319 if (ejbJarRoot!=null) ejbJarRoot.removeValue(name, index); 320 } 321 322 public Object clone() { 323 SunEjbJarProxy proxy = null; 324 if (ejbJarRoot==null) 325 proxy = new SunEjbJarProxy(null, version); 326 else { 327 SunEjbJar clonedSunEjb=(SunEjbJar)ejbJarRoot.clone(); 328 proxy = new SunEjbJarProxy(clonedSunEjb, version); 329 } 330 proxy.setError(error); 331 return proxy; 332 } 333 334 public String getAttributeValue(String propName, String name) { 335 return ejbJarRoot==null?null:ejbJarRoot.getAttributeValue(propName, name); 336 } 337 338 public String getAttributeValue(String propName, int index, String name) { 339 return ejbJarRoot==null?null:ejbJarRoot.getAttributeValue(propName, index, name); 340 } 341 342 public void setAttributeValue(String name, String value) { 343 if (ejbJarRoot!=null) ejbJarRoot.setAttributeValue(name, value); 344 } 345 346 public void setAttributeValue(String propName, String name, String value) { 347 if (ejbJarRoot!=null) ejbJarRoot.setAttributeValue(propName, name, value); 348 } 349 350 public void setAttributeValue(String propName, int index, String name, String value) { 351 if (ejbJarRoot!=null) ejbJarRoot.setAttributeValue(propName, index, name, value); 352 } 353 354 public CommonDDBean getPropertyParent(String name) { 355 return ejbJarRoot.getPropertyParent(name); 356 } 357 358 public void merge(CommonDDBean root, int mode) { 359 if (root != null) { 360 if (root instanceof SunEjbJarProxy) 361 ejbJarRoot.merge(((SunEjbJarProxy)root).getOriginal(), mode); 362 else ejbJarRoot.merge(root, mode); 363 } 364 } 365 366 public CommonDDBean cloneVersion(String version) { 367 return ejbJarRoot == null ? null : ejbJarRoot.cloneVersion(version); 368 } 369 370 373 public static interface OutputProvider { 374 public void write(SunEjbJar ejbJarRoot) throws java.io.IOException ; 375 } 376 } 377 | Popular Tags |