KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > netbeans > SJSASVersion


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.websvc.registry.netbeans;
21
22 import java.io.File JavaDoc;
23
24 import org.openide.ErrorManager;
25 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
26 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
27
28
29 /** This class represents the Sun Java System Application Version installed
30  * (from which this module uses JWSDP jars for Web Service runtime support.)
31  *
32  * @author Peter Williams
33  */

34 public final class SJSASVersion {
35     
36     private static String JavaDoc REGISTRY_JARS_8_0_AND_8_1_BETA [] = {
37         "/lib/j2ee.jar",
38         "/lib/jaxrpc-api.jar",
39         "/lib/jaxrpc-spi.jar",
40         "/lib/jaxrpc-impl.jar",
41         "/lib/endorsed/xercesImpl.jar",
42         "/lib/endorsed/dom.jar",
43         "/lib/endorsed/xalan.jar",
44         "/lib/activation.jar",
45         "/lib/mail.jar",
46         "/lib/xsdlib.jar",
47         "/lib/relaxngDatatype.jar",
48         "/lib/commons-logging.jar",
49         "/lib/namespace.jar",
50         "/lib/jaxr-impl.jar",
51         "/lib/saaj-api.jar",
52         "/lib/saaj-impl.jar",
53         "/lib/jax-qname.jar"
54     };
55     
56     private static String JavaDoc REGISTRY_JARS_8_1 [] = {
57         "/lib/j2ee.jar",
58         "/lib/jaxrpc-api.jar",
59         "/lib/jaxrpc-spi.jar",
60         "/lib/jaxrpc-impl.jar",
61         "/lib/xercesImpl.jar",
62         "/lib/dom.jar",
63         "/lib/xalan.jar",
64         "/lib/activation.jar",
65         "/lib/mail.jar",
66         "/lib/xsdlib.jar",
67         "/lib/relaxngDatatype.jar",
68         "/lib/commons-logging.jar",
69         "/lib/namespace.jar",
70         "/lib/jaxr-impl.jar",
71         "/lib/saaj-api.jar",
72         "/lib/saaj-impl.jar",
73         "/lib/jax-qname.jar"
74     };
75     
76     private static String JavaDoc SAX_PARSER_IMPL_8_0 = "org.apache.xerces.jaxp.SAXParserFactoryImpl"; // NOI18N
77
private static String JavaDoc SAX_PARSER_IMPL_8_1 = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"; // NOI18N
78

79     // Appserver version strings. We do not differ between minor versions (e.g. 8.0.0.1 is the same as 8.0)
80
public static final SJSASVersion APPSERVER_VERSION_8_0 = new SJSASVersion(
81         "8.0", REGISTRY_JARS_8_0_AND_8_1_BETA, SAX_PARSER_IMPL_8_0); // NOI18N
82

83     // AKA SJSAS 8.1 2004Q4
84
public static final SJSASVersion APPSERVER_VERSION_8_1_BETA = new SJSASVersion(
85         "8.1 beta", REGISTRY_JARS_8_0_AND_8_1_BETA, SAX_PARSER_IMPL_8_1); // NOI18N
86

87     // AKA SJSAS 8.1 2005Q1
88
public static final SJSASVersion APPSERVER_VERSION_8_1 = new SJSASVersion(
89         "8.1", REGISTRY_JARS_8_1, SAX_PARSER_IMPL_8_1); // NOI18N
90

91     // unknown defaults to 8.1 release behavior (but also prompts a warning message)
92
public static final SJSASVersion APPSERVER_VERSION_UNKNOWN = new SJSASVersion(
93         "unknown", REGISTRY_JARS_8_1, SAX_PARSER_IMPL_8_1); // NOI18N
94

95     private String JavaDoc sjsasVersion;
96     private String JavaDoc [] registryRuntimeLibraries;
97     private String JavaDoc saxParserImplClass;
98     
99     private SJSASVersion(String JavaDoc version, String JavaDoc [] registryRuntimeLibs, String JavaDoc saxParserImplClass) {
100         if(version == null) {
101             throw new NullPointerException JavaDoc("Null Application Server Version is not allowed.");
102         }
103         
104         this.sjsasVersion = version;
105         this.registryRuntimeLibraries = registryRuntimeLibs;
106         this.saxParserImplClass = saxParserImplClass;
107     }
108     
109     public String JavaDoc toString() {
110         return sjsasVersion;
111     }
112     
113     public boolean equals(Object JavaDoc obj) {
114         SJSASVersion target = (SJSASVersion) obj;
115         return sjsasVersion.equals(target.sjsasVersion);
116     }
117     
118     public int hashCode() {
119         return sjsasVersion.hashCode();
120     }
121     
122     public String JavaDoc [] getRegistryRuntimeLibraries() {
123         return registryRuntimeLibraries;
124     }
125     
126     public String JavaDoc getSaxParserImplClass() {
127         return saxParserImplClass;
128     }
129     
130     /** Attempt to discern the application server version we're running against.
131      *
132      * 8.0 uses sun-domain_1_0.dtd
133      * 8.1 uses sun-domain_1_1.dtd (also includes the 1_0 version for backwards compatibility)
134      *
135      */

136     public static SJSASVersion getSJSAppServerVersion() {
137         SJSASVersion version = APPSERVER_VERSION_UNKNOWN; // NOI18N
138
String JavaDoc serverInstanceIDs[] = Deployment.getDefault().getServerInstanceIDs ();
139                 J2eePlatform platform = null;
140                 for (int i = 0; i < serverInstanceIDs.length; i++) {
141                     J2eePlatform p = Deployment.getDefault().getJ2eePlatform (serverInstanceIDs [i]);
142                     if (p != null && p.isToolSupported ("wscompile")) {
143                         platform = p;
144                         break;
145                     }
146                 }
147         File JavaDoc asInstallRoot = platform == null ? null : platform.getPlatformRoots () [0];
148         if(asInstallRoot != null && asInstallRoot.exists()) {
149             File JavaDoc sunDomain11Dtd = new File JavaDoc(asInstallRoot, "lib/dtds/sun-domain_1_1.dtd"); // NOI18N
150
if(sunDomain11Dtd.exists()) {
151                 File JavaDoc endorsedXerces = new File JavaDoc(asInstallRoot, "lib/endorsed/xercesImpl.jar");
152                 if(endorsedXerces.exists()) {
153                     // SJSAS 8.1 Beta had xercesImpl, xalan, and dom in the endorsed lib directory
154
version = APPSERVER_VERSION_8_1_BETA;
155                 } else {
156                     // SJSAS 8.1 moved xercesImpl, xalan, and dom to the main lib directory
157
version = APPSERVER_VERSION_8_1;
158                 }
159             } else {
160                 // SJSAS 8.0 does not support sun-domain 1.1, only 1.0.
161
version = APPSERVER_VERSION_8_0;
162             }
163         }
164
165         if(APPSERVER_VERSION_UNKNOWN.equals(version)) {
166             ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL,
167                 "Cannot determine version of installed Sun Java System Application Server.");
168         }
169         
170         return version;
171     }
172 }
173
Popular Tags