KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > naming > internal > VersionHelper


1 /*
2  * @(#)VersionHelper.java 1.9 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.naming.internal;
9
10 import java.io.InputStream JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.net.MalformedURLException JavaDoc;
13 import java.net.URL JavaDoc;
14 import java.util.Enumeration JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16 import java.util.Vector JavaDoc;
17
18 import javax.naming.NamingEnumeration JavaDoc;
19
20 /**
21  * VersionHelper was used by JNDI to accommodate differences between
22  * JDK 1.1.x and the Java 2 platform. Since this is no longer necessary
23  * due to JNDI's presence in the Java 2 Platform v1.3 and higher, this
24  * class currently serves as a set of utilities for performing
25  * system-level things, such as class-loading and reading system properties.
26  *
27  * @author Rosanna Lee
28  * @author Scott Seligman
29  * @version 1.9 03/12/19
30  */

31
32 public abstract class VersionHelper {
33     private static VersionHelper helper = null;
34
35     final static String JavaDoc[] PROPS = new String JavaDoc[] {
36     javax.naming.Context.INITIAL_CONTEXT_FACTORY,
37     javax.naming.Context.OBJECT_FACTORIES,
38     javax.naming.Context.URL_PKG_PREFIXES,
39     javax.naming.Context.STATE_FACTORIES,
40     javax.naming.Context.PROVIDER_URL,
41     javax.naming.Context.DNS_URL,
42     // The following shouldn't create a runtime dependence on ldap package.
43
javax.naming.ldap.LdapContext.CONTROL_FACTORIES
44     };
45
46     public final static int INITIAL_CONTEXT_FACTORY = 0;
47     public final static int OBJECT_FACTORIES = 1;
48     public final static int URL_PKG_PREFIXES = 2;
49     public final static int STATE_FACTORIES = 3;
50     public final static int PROVIDER_URL = 4;
51     public final static int DNS_URL = 5;
52     public final static int CONTROL_FACTORIES = 6;
53
54     VersionHelper() {} // Disallow anyone from creating one of these.
55

56     static {
57     helper = new VersionHelper12();
58     }
59
60     public static VersionHelper getVersionHelper() {
61     return helper;
62     }
63
64     public abstract Class JavaDoc loadClass(String JavaDoc className)
65     throws ClassNotFoundException JavaDoc;
66
67     abstract Class JavaDoc loadClass(String JavaDoc className, ClassLoader JavaDoc cl)
68     throws ClassNotFoundException JavaDoc;
69
70     public abstract Class JavaDoc loadClass(String JavaDoc className, String JavaDoc codebase)
71     throws ClassNotFoundException JavaDoc, MalformedURLException JavaDoc;
72
73     /*
74      * Returns a JNDI property from the system properties. Returns
75      * null if the property is not set, or if there is no permission
76      * to read it.
77      */

78     abstract String JavaDoc getJndiProperty(int i);
79
80     /*
81      * Reads each property in PROPS from the system properties, and
82      * returns their values -- in order -- in an array. For each
83      * unset property, the corresponding array element is set to null.
84      * Returns null if there is no permission to call System.getProperties().
85      */

86     abstract String JavaDoc[] getJndiProperties();
87
88     /*
89      * Returns the resource of a given name associated with a particular
90      * class (never null), or null if none can be found.
91      */

92     abstract InputStream JavaDoc getResourceAsStream(Class JavaDoc c, String JavaDoc name);
93
94     /*
95      * Returns an input stream for a file in <java.home>/lib,
96      * or null if it cannot be located or opened.
97      *
98      * @param filename The file name, sans directory.
99      */

100     abstract InputStream JavaDoc getJavaHomeLibStream(String JavaDoc filename);
101
102     /*
103      * Returns an enumeration (never null) of InputStreams of the
104      * resources of a given name associated with a particular class
105      * loader. Null represents the bootstrap class loader in some
106      * Java implementations.
107      */

108     abstract NamingEnumeration JavaDoc getResources(ClassLoader JavaDoc cl, String JavaDoc name)
109     throws IOException JavaDoc;
110
111     /*
112      * Returns the context class loader associated with the current thread.
113      * Null indicates the bootstrap class loader in some Java implementations.
114      *
115      * @throws SecurityException if the class loader is not accessible.
116      */

117     abstract ClassLoader JavaDoc getContextClassLoader();
118
119     static protected URL JavaDoc[] getUrlArray(String JavaDoc codebase)
120     throws MalformedURLException JavaDoc {
121     // Parse codebase into separate URLs
122
StringTokenizer JavaDoc parser = new StringTokenizer JavaDoc(codebase);
123     Vector JavaDoc vec = new Vector JavaDoc(10);
124     while (parser.hasMoreTokens()) {
125         vec.addElement(parser.nextToken());
126     }
127     String JavaDoc[] url = new String JavaDoc[vec.size()];
128     for (int i = 0; i < url.length; i++) {
129         url[i] = (String JavaDoc)vec.elementAt(i);
130     }
131     
132     URL JavaDoc[] urlArray = new URL JavaDoc[url.length];
133     for (int i = 0; i < urlArray.length; i++) {
134         urlArray[i] = new URL JavaDoc(url[i]);
135     }
136     return urlArray;
137     }
138 }
139
Popular Tags