1 19 20 package org.netbeans.modules.j2ee.sun.dd.api; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.lang.reflect.Constructor ; 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import java.text.MessageFormat ; 27 import java.util.HashMap ; 28 import javax.xml.parsers.DocumentBuilder ; 29 import javax.xml.parsers.DocumentBuilderFactory ; 30 import javax.xml.parsers.ParserConfigurationException ; 31 import org.netbeans.modules.j2ee.sun.dd.impl.common.SunBaseBean; 32 import org.netbeans.modules.schema2beans.Common; 33 import org.xml.sax.*; 34 import java.util.Map ; 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.DocumentType ; 37 import java.util.ResourceBundle ; 38 39 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar; 40 import org.netbeans.modules.j2ee.sun.dd.impl.ejb.SunEjbJarProxy; 41 42 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp; 43 import org.netbeans.modules.j2ee.sun.dd.impl.web.SunWebAppProxy; 44 45 import org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication; 46 import org.netbeans.modules.j2ee.sun.dd.impl.app.SunApplicationProxy; 47 48 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources; 49 import org.netbeans.modules.j2ee.sun.dd.impl.serverresources.ResourcesProxy; 50 51 import org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient; 52 import org.netbeans.modules.j2ee.sun.dd.impl.client.SunApplicationClientProxy; 53 54 import org.netbeans.modules.j2ee.sun.dd.impl.DTDRegistry; 55 56 61 62 public final class DDProvider { 63 private static final String EJB_30_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN"; private static final String EJB_21_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 EJB 2.1//EN"; private static final String EJB_21_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 EJB 2.1//EN"; private static final String EJB_20_70_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN"; private static final String EJB_21_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 EJB 2.1//EN"; 70 private static final String WEB_25_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN"; private static final String WEB_21_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN"; private static final String WEB_21_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 Servlet 2.4//EN"; private static final String WEB_20_70_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Servlet 2.3//EN" ; private static final String WEB_21_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Servlet 2.4//EN"; 76 private static final String APP_50_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Java EE Application 5.0//EN"; private static final String APP_14_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 J2EE Application 1.4//EN"; private static final String APP_14_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 J2EE Application 1.4//EN"; private static final String APP_13_70_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 J2EE Application 1.3//EN"; private static final String APP_14_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 J2EE Application 1.4//EN"; 82 private static final String APPCLIENT_50_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Application Client 5.0//EN"; private static final String APPCLIENT_14_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Application Client 1.4//EN"; private static final String APPCLIENT_14_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 Application Client 1.4//EN"; private static final String APPCLIENT_14_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Application Client 1.4//EN"; private static final String APPCLIENT_13_70_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client 1.3//EN"; 88 96 97 98 99 100 101 102 private static final DDProvider ddProvider = new DDProvider(); 103 private Map ddMap; 104 105 106 private DDProvider() { 107 ddMap = new java.util.HashMap (5); 109 } 110 111 115 public static DDProvider getDefault() { 116 return ddProvider; 117 } 118 119 125 public SunEjbJar getEjbDDRoot(InputSource is) throws IOException , SAXException { 126 DDParse parse = parseDD(is); 127 SunEjbJar ejbRoot = createEjbJar(parse); 128 SunEjbJarProxy proxy = new SunEjbJarProxy(ejbRoot, ejbRoot.getVersion().toString()); 129 setEjbProxyErrorStatus(proxy, parse); 130 return proxy; 131 } 132 133 139 public SunWebApp getWebDDRoot(InputSource is) throws IOException , SAXException, DDException { 140 DDParse parse = parseDD(is); 141 return processWebAppParseTree(parse); 142 } 143 144 150 public SunWebApp getWebDDRoot(InputStream is) throws IOException , SAXException, DDException { 151 DDParse parse = parseDD(is); 152 return processWebAppParseTree(parse); 153 } 154 155 161 public SunWebApp getWebDDRoot(org.w3c.dom.Document doc) throws DDException { 162 DDParse parse = new DDParse(doc, null); 163 return processWebAppParseTree(parse); 164 } 165 166 private SunWebApp processWebAppParseTree(DDParse parse) throws DDException { 167 SunWebApp webRoot = createWebApp(parse); 168 SunWebAppProxy proxy = new SunWebAppProxy(webRoot, webRoot.getVersion().toString()); 169 setWebProxyErrorStatus(proxy, parse); 170 return proxy; 171 } 172 173 179 public SunApplication getAppDDRoot(InputSource is) throws IOException , SAXException { 180 DDParse parse = parseDD(is); 181 SunApplication appRoot = createApplication(parse); 182 SunApplicationProxy proxy = new SunApplicationProxy(appRoot, appRoot.getVersion().toString()); 183 setAppProxyErrorStatus(proxy, parse); 184 return proxy; 185 } 186 187 193 public SunApplicationClient getAppClientDDRoot(InputSource is) throws IOException , SAXException { 194 DDParse parse = parseDD(is); 195 SunApplicationClient appClientRoot = createApplicationClient(parse); 196 SunApplicationClientProxy proxy = new SunApplicationClientProxy(appClientRoot, appClientRoot.getVersion().toString()); 197 setAppClientProxyErrorStatus(proxy, parse); 198 return proxy; 199 } 200 201 205 public org.netbeans.modules.schema2beans.BaseBean getBaseBean(org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean bean) { 206 if (bean instanceof org.netbeans.modules.schema2beans.BaseBean) 207 return (org.netbeans.modules.schema2beans.BaseBean)bean; 208 else if (bean instanceof SunEjbJarProxy) 209 return (org.netbeans.modules.schema2beans.BaseBean) ((SunEjbJarProxy)bean).getOriginal(); 210 else if (bean instanceof SunWebAppProxy) 211 return (org.netbeans.modules.schema2beans.BaseBean) ((SunWebAppProxy)bean).getOriginal(); 212 else if (bean instanceof SunApplicationProxy) 213 return (org.netbeans.modules.schema2beans.BaseBean) ((SunApplicationProxy)bean).getOriginal(); 214 else if (bean instanceof SunApplicationClientProxy) 215 return (org.netbeans.modules.schema2beans.BaseBean) ((SunApplicationClientProxy)bean).getOriginal(); 216 return null; 217 } 218 219 private static void setEjbProxyErrorStatus(SunEjbJarProxy ejbJarProxy, DDParse parse) { 220 SAXParseException error = parse.getWarning(); 221 ejbJarProxy.setError(error); 222 227 } 228 229 private static void setAppProxyErrorStatus(SunApplicationProxy appProxy, DDParse parse) { 230 SAXParseException error = parse.getWarning(); 231 appProxy.setError(error); 232 237 } 238 239 private static void setWebProxyErrorStatus(SunWebAppProxy webProxy, DDParse parse) { 240 SAXParseException error = parse.getWarning(); 241 webProxy.setError(error); 242 247 } 248 249 private static class VersionInfo { 250 private Class implClass; 251 private Class proxyClass; 252 private String publicId; 253 private String systemId; 254 255 public VersionInfo(Class implClass, Class proxyClass, String publicId, String systemId) { 256 this.implClass = implClass; 257 this.proxyClass = proxyClass; 258 this.publicId = publicId; 259 this.systemId = systemId; 260 } 261 262 public Class getImplClass() { 263 return implClass; 264 } 265 266 public Class getProxyClass() { 267 return proxyClass; 268 } 269 270 public String getPublicId() { 271 return publicId; 272 } 273 274 public String getSystemId() { 275 return systemId; 276 } 277 } 278 279 private static HashMap apiToVersionMap = new HashMap (11); 280 private static HashMap sunWebAppVersionMap = new HashMap (11); 281 private static HashMap sunEjbJarVersionMap = new HashMap (11); 282 private static HashMap sunApplicationVersionMap = new HashMap (11); 283 private static HashMap sunAppClientVersionMap = new HashMap (11); 284 285 static { 286 sunWebAppVersionMap.put(SunWebApp.VERSION_2_3_0, new VersionInfo( 287 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_3_0.SunWebApp.class, SunWebAppProxy.class, 288 DTDRegistry.SUN_WEBAPP_230_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_230_DTD_SYSTEM_ID 289 )); 290 sunWebAppVersionMap.put(SunWebApp.VERSION_2_4_0, new VersionInfo( 291 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_0.SunWebApp.class, SunWebAppProxy.class, 292 DTDRegistry.SUN_WEBAPP_240_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_240_DTD_SYSTEM_ID 293 )); 294 sunWebAppVersionMap.put(SunWebApp.VERSION_2_4_1, new VersionInfo( 295 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_1.SunWebApp.class, SunWebAppProxy.class, 296 DTDRegistry.SUN_WEBAPP_241_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_241_DTD_SYSTEM_ID 297 )); 298 sunWebAppVersionMap.put(SunWebApp.VERSION_2_5_0, new VersionInfo( 299 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_5_0.SunWebApp.class, SunWebAppProxy.class, 300 DTDRegistry.SUN_WEBAPP_250_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_250_DTD_SYSTEM_ID 301 )); 302 303 sunEjbJarVersionMap.put(SunEjbJar.VERSION_2_0_0, new VersionInfo( 304 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar.class, SunEjbJarProxy.class, 305 DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_200_DTD_SYSTEM_ID 306 )); 307 sunEjbJarVersionMap.put(SunEjbJar.VERSION_2_1_0, new VersionInfo( 308 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar.class, SunEjbJarProxy.class, 309 DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210_DTD_SYSTEM_ID 310 )); 311 sunEjbJarVersionMap.put(SunEjbJar.VERSION_2_1_1, new VersionInfo( 312 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar.class, SunEjbJarProxy.class, 313 DTDRegistry.SUN_EJBJAR_211_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_211_DTD_SYSTEM_ID 314 )); 315 sunEjbJarVersionMap.put(SunEjbJar.VERSION_3_0_0, new VersionInfo( 316 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar.class, SunEjbJarProxy.class, 317 DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID 318 )); 319 320 sunApplicationVersionMap.put(SunApplication.VERSION_1_3_0, new VersionInfo( 321 org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication.class, SunApplicationProxy.class, 322 DTDRegistry.SUN_APPLICATION_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_130_DTD_SYSTEM_ID 323 )); 324 sunApplicationVersionMap.put(SunApplication.VERSION_1_4_0, new VersionInfo( 325 org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication.class, SunApplicationProxy.class, 326 DTDRegistry.SUN_APPLICATION_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_140_DTD_SYSTEM_ID 327 )); 328 sunApplicationVersionMap.put(SunApplication.VERSION_5_0_0, new VersionInfo( 329 org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication.class, SunApplicationProxy.class, 330 DTDRegistry.SUN_APPLICATION_50_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_50_DTD_SYSTEM_ID 331 )); 332 333 sunAppClientVersionMap.put(SunApplicationClient.VERSION_1_3_0, new VersionInfo( 334 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient.class, SunApplicationClientProxy.class, 335 DTDRegistry.SUN_APPCLIENT_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_130_DTD_SYSTEM_ID 336 )); 337 sunAppClientVersionMap.put(SunApplicationClient.VERSION_1_4_0, new VersionInfo( 338 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient.class, SunApplicationClientProxy.class, 339 DTDRegistry.SUN_APPCLIENT_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_140_DTD_SYSTEM_ID 340 )); 341 sunAppClientVersionMap.put(SunApplicationClient.VERSION_1_4_1, new VersionInfo( 342 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient.class, SunApplicationClientProxy.class, 343 DTDRegistry.SUN_APPCLIENT_141_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_141_DTD_SYSTEM_ID 344 )); 345 sunAppClientVersionMap.put(SunApplicationClient.VERSION_5_0_0, new VersionInfo( 346 org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient.class, SunApplicationClientProxy.class, 347 DTDRegistry.SUN_APPCLIENT_50_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_50_DTD_SYSTEM_ID 348 )); 349 350 apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp.class, sunWebAppVersionMap); 351 apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar.class, sunEjbJarVersionMap); 352 apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication.class, sunApplicationVersionMap); 353 apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient.class, sunAppClientVersionMap); 354 } 355 356 public RootInterface newGraph(Class rootType, String version) { 357 RootInterface result = null; 358 SunBaseBean graphRoot = null; 359 Class graphRootClass = null; 360 361 Map versionMap = (Map ) apiToVersionMap.get(rootType); 362 if(versionMap != null) { 363 VersionInfo vInfo = (VersionInfo) versionMap.get(version); 364 if(vInfo != null) { 365 try { 366 graphRoot = (SunBaseBean) vInfo.getImplClass().newInstance(); 369 graphRoot.graphManager().setDoctype(vInfo.getPublicId(), vInfo.getSystemId()); 370 371 Class proxyClass = vInfo.getProxyClass(); 372 Constructor proxyConstructor = proxyClass.getConstructor(new Class [] { rootType, String .class }); 373 result = (RootInterface) proxyConstructor.newInstance(new Object [] { graphRoot, version }); 374 } catch(IllegalArgumentException ex) { 375 throw new RuntimeException (ex.getMessage(), ex); } catch(InvocationTargetException ex) { 380 throw new RuntimeException (ex.getMessage(), ex); } catch(InstantiationException ex) { 382 throw new RuntimeException (ex.getMessage(), ex); } catch(IllegalAccessException ex) { 384 throw new RuntimeException (ex.getMessage(), ex); } catch(NoSuchMethodException ex) { 386 throw new RuntimeException (ex.getMessage(), ex); } 388 } else { 389 throw new IllegalStateException ("No version information for " + version + " of type " + rootType.getName()); 390 } 391 } else { 392 throw new IllegalStateException ("No version map for " + rootType.getName()); 393 } 394 395 return result; 396 } 397 398 private static void setAppClientProxyErrorStatus(SunApplicationClientProxy appClientProxy, DDParse parse) { 399 SAXParseException error = parse.getWarning(); 400 appClientProxy.setError(error); 401 406 } 407 408 410 public RootInterface newGraph(Class rootType) { 411 if(org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp.class.equals(rootType)) { 412 return newGraph(rootType, SunWebApp.VERSION_2_4_1); 413 } else if(org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar.class.equals(rootType)) { 414 return newGraph(rootType, SunEjbJar.VERSION_2_1_1); 415 } else if(org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication.class.equals(rootType)) { 416 return newGraph(rootType, SunApplication.VERSION_1_4_0); 417 } else if(org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient.class.equals(rootType)) { 418 return newGraph(rootType, SunApplicationClient.VERSION_1_4_1); 419 } 420 421 return null; 422 } 423 424 private static SunEjbJar createEjbJar(DDParse parse) { 425 SunEjbJar jar = null; 426 String version = parse.getVersion(); 427 if (SunEjbJar.VERSION_3_0_0.equals(version)) { 428 return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES); 429 } else if (SunEjbJar.VERSION_2_1_1.equals(version)) { 430 return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES); 431 } else if (SunEjbJar.VERSION_2_1_0.equals(version)) { return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES); 433 } else if (SunEjbJar.VERSION_2_0_0.equals(version)) { return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES); 435 } else{ 437 return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES); 439 } 440 441 } 443 444 private static SunWebApp createWebApp(DDParse parse) throws DDException { 445 SunWebApp webRoot = null; 446 String version = parse.getVersion(); 447 if (SunWebApp.VERSION_2_5_0.equals(version)) { 448 return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_5_0.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES); 449 } else if (SunWebApp.VERSION_2_4_1.equals(version)) { 450 return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_1.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES); 451 } else if (SunWebApp.VERSION_2_4_0.equals(version)){ return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_0.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES); 453 } else if (SunWebApp.VERSION_2_3_0.equals(version)){ 454 return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_3_0.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES); 455 }else 456 throw new DDException( 457 MessageFormat.format(ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/dd/api/Bundle").getString("MSG_UnknownWebXml"),new Object [] {version} )); 458 459 } 460 461 private static SunApplication createApplication(DDParse parse) { 462 SunApplication jar = null; 463 String version = parse.getVersion(); 464 if (SunApplication.VERSION_5_0_0.equals(version)) { 465 return new org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication(parse.getDocument(), Common.NO_DEFAULT_VALUES); 466 } else if (SunApplication.VERSION_1_4_0.equals(version)) { 467 return new org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication(parse.getDocument(), Common.NO_DEFAULT_VALUES); 468 } else if(SunApplication.VERSION_1_3_0.equals(version)){ 469 return new org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication(parse.getDocument(), Common.NO_DEFAULT_VALUES); 470 } 471 472 return jar; 473 } 474 475 private static SunApplicationClient createApplicationClient(DDParse parse) { 476 SunApplicationClient jar = null; 477 String version = parse.getVersion(); 478 if (SunApplicationClient.VERSION_5_0_0.equals(version)) { 479 return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES); 480 } else if (SunApplicationClient.VERSION_1_4_1.equals(version)) { 481 return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES); 482 } else if (SunApplicationClient.VERSION_1_4_0.equals(version)) { 483 return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES); 484 } else if (SunApplicationClient.VERSION_1_3_0.equals(version)) { 485 return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES); 486 } 487 488 return jar; 489 } 490 491 496 public Resources getResourcesGraph() { 497 Resources resourcesRoot = org.netbeans.modules.j2ee.sun.dd.impl.serverresources.model.Resources.createGraph(); 498 ResourcesProxy proxy = new ResourcesProxy(resourcesRoot); 499 return proxy; 500 } 501 502 507 public Resources getResourcesGraph(InputStream in) { 508 Resources resourcesRoot = org.netbeans.modules.j2ee.sun.dd.impl.serverresources.model.Resources.createGraph(in); 509 ResourcesProxy proxy = new ResourcesProxy(resourcesRoot); 510 return proxy; 511 } 512 513 514 private static class DDResolver implements EntityResolver { 515 static DDResolver resolver; 516 static synchronized DDResolver getInstance() { 517 if (resolver==null) { 518 resolver=new DDResolver(); 519 } 520 return resolver; 521 } 522 public InputSource resolveEntity(String publicId, String systemId) { 523 String resource = null; 524 if (EJB_30_90_DOCTYPE.equals(publicId)) { 525 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_3_0-0.dtd"); }else if (EJB_21_81_DOCTYPE.equals(publicId)) { 528 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_1-1.dtd"); } else if (EJB_21_80_DOCTYPE.equals(publicId)) { 530 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_1-0.dtd"); } else if (EJB_21_80_DOCTYPE_SUNONE.equals(publicId)) { 532 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_1-0.dtd"); } else if (EJB_20_70_DOCTYPE_SUNONE.equals(publicId)) { resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_0-0.dtd"); } else if (WEB_25_90_DOCTYPE.equals(publicId)) { 536 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_5-0.dtd"); }else if (WEB_21_81_DOCTYPE.equals(publicId)) { 538 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_4-1.dtd"); } else if (WEB_21_80_DOCTYPE.equals(publicId)) { 540 resource ="/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_4-0.dtd"; } else if (WEB_21_80_DOCTYPE_SUNONE.equals(publicId)) { 542 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_4-0.dtd"); } else if (WEB_20_70_DOCTYPE_SUNONE.equals(publicId)) { resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_3-0.dtd"); } else if (APP_50_90_DOCTYPE.equals(publicId)) { 546 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application_5_0-0.dtd"); }else if (APP_14_80_DOCTYPE.equals(publicId) || APP_14_81_DOCTYPE.equals(publicId) || APP_14_80_DOCTYPE_SUNONE.equals(publicId) ) { 548 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application_1_4-0.dtd"); } else if(APP_13_70_DOCTYPE_SUNONE.equals(publicId)){ 550 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application_1_3-0.dtd"); } else if(APPCLIENT_50_90_DOCTYPE.equals(publicId)) { 552 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_5_0-0.dtd"); } else if (APPCLIENT_14_81_DOCTYPE.equals(publicId)) { 554 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_4-1.dtd"); } else if (APPCLIENT_14_80_DOCTYPE.equals(publicId)) { 556 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_4-0.dtd"); } else if (APPCLIENT_14_80_DOCTYPE_SUNONE.equals(publicId)) { 558 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_4-0.dtd"); } else if (APPCLIENT_13_70_DOCTYPE.equals(publicId)) { 560 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_3-0.dtd"); } 562 java.net.URL url = this.getClass().getResource(resource); 563 return new InputSource(url.toString()); 564 } 565 } 566 567 private static class ErrorHandler implements org.xml.sax.ErrorHandler { 568 private int errorType=-1; 569 SAXParseException error; 570 571 public void warning(org.xml.sax.SAXParseException sAXParseException) throws org.xml.sax.SAXException { 572 if (errorType<0) { 573 errorType=0; 574 error=sAXParseException; 575 } 576 } 578 public void error(org.xml.sax.SAXParseException sAXParseException) throws org.xml.sax.SAXException { 579 if (errorType<1) { 580 errorType=1; 581 error=sAXParseException; 582 } 583 } 585 public void fatalError(org.xml.sax.SAXParseException sAXParseException) throws org.xml.sax.SAXException { 586 errorType=2; 587 throw sAXParseException; 588 } 589 590 public int getErrorType() { 591 return errorType; 592 } 593 public SAXParseException getError() { 594 return error; 595 } 596 } 597 598 private DDParse parseDD (InputStream is) 599 throws SAXException, java.io.IOException { 600 return parseDD(new InputSource(is)); 601 } 602 603 private DDParse parseDD(InputSource is) throws SAXException, java.io.IOException { 604 605 DDProvider.ErrorHandler errorHandler = new DDProvider.ErrorHandler(); 606 DocumentBuilder parser = createParser(errorHandler); 607 parser.setEntityResolver(DDResolver.getInstance()); 608 Document document = parser.parse(is); 609 SAXParseException error = errorHandler.getError(); 610 return new DDParse(document, error); 611 } 612 613 private static DocumentBuilder createParser(ErrorHandler errorHandler) throws SAXException { 614 DocumentBuilder parser=null; 615 try { 616 DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance(); 617 parser = fact.newDocumentBuilder(); 618 } catch (ParserConfigurationException ex) { 619 throw new SAXException(ex.getMessage()); 620 } 621 parser.setErrorHandler(errorHandler); 622 return parser; 623 } 624 625 626 629 private static class DDParse { 630 private Document document; 631 private SAXParseException saxException; 632 private String version; 633 public DDParse(Document d, SAXParseException saxEx) { 634 document = d; 635 saxException = saxEx; 636 extractVersion(); 637 } 638 639 642 public Document getDocument() { 643 return document; 644 } 645 646 649 private void extractVersion () { 650 DocumentType dt = document.getDoctype(); 652 version = SunEjbJar.VERSION_3_0_0; 654 if (dt != null) { 655 if (EJB_21_81_DOCTYPE.equals(dt.getPublicId())) { 656 version = SunEjbJar.VERSION_2_1_1; 657 }else if (EJB_21_80_DOCTYPE.equals(dt.getPublicId())) { 658 version = SunEjbJar.VERSION_2_1_0; 659 }else if (EJB_30_90_DOCTYPE.equals(dt.getPublicId())) { 660 version = SunEjbJar.VERSION_3_0_0; 661 }else if(EJB_21_80_DOCTYPE_SUNONE.equals(dt.getPublicId())) { 662 version = SunEjbJar.VERSION_2_1_0; 663 }else if(EJB_20_70_DOCTYPE_SUNONE.equals(dt.getPublicId())) { 664 version = SunEjbJar.VERSION_2_0_0; 665 }else if(WEB_25_90_DOCTYPE.equals(dt.getPublicId())){ 666 version = SunWebApp.VERSION_2_5_0; 667 }else if(WEB_21_81_DOCTYPE.equals(dt.getPublicId())){ 668 version = SunWebApp.VERSION_2_4_1; 669 }else if(WEB_21_80_DOCTYPE.equals(dt.getPublicId())){ 670 version = SunWebApp.VERSION_2_4_0; 671 }else if(WEB_21_80_DOCTYPE_SUNONE.equals(dt.getPublicId())){ 672 version = SunWebApp.VERSION_2_4_0; 673 }else if(WEB_20_70_DOCTYPE_SUNONE.equals(dt.getPublicId())){ 674 version = SunWebApp.VERSION_2_3_0; 675 }else if(APP_50_90_DOCTYPE.equals(dt.getPublicId())){ 676 version = SunApplication.VERSION_5_0_0; 677 }else if(APP_14_80_DOCTYPE.equals(dt.getPublicId()) || APP_14_81_DOCTYPE.equals(dt.getPublicId()) || APP_14_80_DOCTYPE_SUNONE.equals(dt.getPublicId())){ 678 version = SunApplication.VERSION_1_4_0; 679 }else if(APP_13_70_DOCTYPE_SUNONE.equals(dt.getPublicId())) { 680 version = SunApplication.VERSION_1_3_0; 681 }else if (APPCLIENT_50_90_DOCTYPE.equals(dt.getPublicId())){ 682 version = SunApplicationClient.VERSION_5_0_0; 683 }else if (APPCLIENT_14_81_DOCTYPE.equals(dt.getPublicId())){ 684 version = SunApplicationClient.VERSION_1_4_1; 685 }else if(APPCLIENT_14_80_DOCTYPE.equals(dt.getPublicId()) || APPCLIENT_14_80_DOCTYPE_SUNONE.equals(dt.getPublicId())){ 686 version = SunApplicationClient.VERSION_1_4_0; 687 }else if(APPCLIENT_13_70_DOCTYPE.equals(dt.getPublicId())){ 688 version = SunApplicationClient.VERSION_1_3_0; 689 } 690 } 691 } 692 693 public String getVersion() { 694 return version; 695 } 696 697 700 public SAXParseException getWarning() { 701 return saxException; 702 } 703 } 704 705 } 706 | Popular Tags |