KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > util > Release


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 at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.util;
17
18 import java.io.File JavaDoc;
19 import java.net.JarURLConnection JavaDoc;
20 import java.net.URL JavaDoc;
21 import java.text.DateFormat JavaDoc;
22 import java.util.Date JavaDoc;
23
24 /**
25  * @author Steve Viens (sviens@apache.org)
26  */

27 public class Release
28 {
29   private static final String JavaDoc REGISTRY_VERSION = "0.9rc4";
30   private static final String JavaDoc UDDI_VERSION = "2.0";
31   
32   // Made private to avoid instantiation
33
private Release()
34   {
35   }
36   
37   public static String JavaDoc getRegistryVersion()
38   {
39     return REGISTRY_VERSION;
40   }
41   
42   public static String JavaDoc getUDDIVersion()
43   {
44     return UDDI_VERSION;
45   }
46
47   public static String JavaDoc getLastModified()
48   {
49     String JavaDoc filePath = getClassFileLocation(Release.class);
50     if (filePath == null)
51       return "Unknown";
52       
53     File JavaDoc file = new File JavaDoc(filePath);
54     long lastMod = file.lastModified();
55   
56     return DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG).format(new Date JavaDoc(lastMod));
57   }
58
59   /**
60    * Determine the jar file or class file containing a Java
61    * classes byte code.
62    *
63    * @param clazz
64    * @return the file path to the jar file or class
65    * file where the class byte code is located.
66    */

67   private static String JavaDoc getClassFileLocation(Class JavaDoc clazz)
68   {
69     // class was found, now get it's URL
70
URL JavaDoc url = null;
71     try {
72       url = clazz.getProtectionDomain().getCodeSource().getLocation();
73       if (url == null)
74         return "";
75     }
76     catch(Throwable JavaDoc t) {
77       return "";
78     }
79
80     try
81     {
82       String JavaDoc location = url.toString();
83       if (location.startsWith("jar:file:/"))
84       {
85         File JavaDoc file = new File JavaDoc(url.getFile());
86         return file.getPath().substring(6);
87       }
88       else if (location.startsWith("jar"))
89       {
90         url = ((JarURLConnection JavaDoc)url.openConnection()).getJarFileURL();
91         return url.toString();
92       }
93       else if (location.startsWith("file"))
94       {
95         File JavaDoc file = new File JavaDoc(url.getFile());
96         return file.getAbsolutePath();
97       }
98       else
99       {
100         return url.toString();
101       }
102     }
103     catch (Throwable JavaDoc t) {
104       return null;
105     }
106   }
107 }
108
Popular Tags