1/*2 * Copyright 2001-2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * http://www.apache.org/licenses/LICENSE-2.08 * 9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15package org.apache.juddi.v3.client;
1617import java.io.IOException;
18import java.io.InputStream;
19import java.net.URL;
20import java.util.Enumeration;
21import java.util.jar.Attributes;
22import java.util.jar.JarFile;
23import java.util.jar.Manifest;
2425/**26 * The release class is a utility for obtaining the version number27 */28publicclassRelease {
2930privatestaticfinal String UDDI_VERSION = "3.0";
31privatestaticfinal String JAR_NAME = "juddi-client";
32privatestatic String registryVersion = null;
33publicstaticfinal String UNKNOWN = "unknown";
34privateRelease () {
35 }
3637/**38 * Returns the version of this jUDDI-Client jar as defined in the manifest.39 * Calls getRegistryVersion()40 * @return the version number of the release41 * @since 3.242 */43publicstatic String getjUDDIClientVersion() {
44return getRegistryVersion();
45 }
46/**47 * Returns the version of this jUDDI-Client jar as defined in the manifest.48 * This function is poorly named, but left in place for backward compatibility49 * @return the version number of the release50 */51publicstatic String getRegistryVersion() {
52if (registryVersion == null) {
53 registryVersion = getVersionFromManifest(JAR_NAME);
54 }
55return registryVersion;
5657 }
5859publicstatic String getUDDIVersion() {
60return UDDI_VERSION;
61 }
6263publicstatic String getVersionFromManifest(String jarName) {
64 Enumeration<URL> resEnum;
65try {
66 resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);
67while (resEnum.hasMoreElements()) {
68try {
69 URL url = (URL) resEnum.nextElement();
70if (url.toString().toLowerCase().contains(jarName)) {
71 InputStream is = url.openStream();
72if (is != null) {
73 Manifest manifest = new Manifest(is);
74 Attributes mainAttribs = manifest.getMainAttributes();
75 String version = mainAttribs.getValue("Bundle-Version");
76if (version != null) {
77return (version);
78 }
79 }
80 }
81 } catch (Exception e) {
82// Silently ignore wrong manifests on classpath?83 }
84 }
85 } catch (IOException e1) {
86// Silently ignore wrong manifests on classpath?87 }
88return UNKNOWN;
89 }
90 }