KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > internal > baseadaptor > DevClassPathHelper


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.osgi.internal.baseadaptor;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.URL JavaDoc;
17 import java.util.*;
18 import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
19 import org.eclipse.osgi.util.ManifestElement;
20
21 /**
22  * This class provides helper methods to support developement classpaths.
23  * @since 3.1
24  */

25 public final class DevClassPathHelper {
26     static private boolean inDevelopmentMode = false;
27     static private String JavaDoc[] devDefaultClasspath;
28     static private Dictionary devProperties = null;
29
30     static {
31         // Check the osgi.dev property to see if dev classpath entries have been defined.
32
String JavaDoc osgiDev = FrameworkProperties.getProperty("osgi.dev"); //$NON-NLS-1$
33
if (osgiDev != null) {
34             try {
35                 inDevelopmentMode = true;
36                 URL JavaDoc location = new URL JavaDoc(osgiDev);
37                 devProperties = load(location);
38                 if (devProperties != null)
39                     devDefaultClasspath = getArrayFromList((String JavaDoc) devProperties.get("*")); //$NON-NLS-1$
40
} catch (MalformedURLException JavaDoc e) {
41                 devDefaultClasspath = getArrayFromList(osgiDev);
42             }
43         }
44     }
45
46     private static String JavaDoc[] getDevClassPath(String JavaDoc id, Dictionary properties, String JavaDoc[] defaultClasspath) {
47         String JavaDoc[] result = null;
48         if (id != null && properties != null) {
49             String JavaDoc entry = (String JavaDoc) properties.get(id);
50             if (entry != null)
51                 result = getArrayFromList(entry);
52         }
53         if (result == null)
54             result = defaultClasspath;
55         return result;
56     }
57
58     /**
59      * Returns a list of classpath elements for the specified bundle symbolic name.
60      * @param id a bundle symbolic name to get the development classpath for
61      * @param properties a Dictionary of properties to use or <code>null</code> if
62      * the default develoment classpath properties should be used
63      * @return a list of development classpath elements
64      */

65     public static String JavaDoc[] getDevClassPath(String JavaDoc id, Dictionary properties) {
66         if (properties == null)
67             return getDevClassPath(id, devProperties, devDefaultClasspath);
68         return getDevClassPath(id, properties, getArrayFromList((String JavaDoc) properties.get("*"))); //$NON-NLS-1$
69
}
70
71     /**
72      * Returns a list of classpath elements for the specified bundle symbolic name.
73      * @param id a bundle symbolic name to get the development classpath for
74      * @return a list of development classpath elements
75      */

76     public static String JavaDoc[] getDevClassPath(String JavaDoc id) {
77         return getDevClassPath(id, null);
78     }
79
80     /**
81      * Returns the result of converting a list of comma-separated tokens into an array
82      *
83      * @return the array of string tokens
84      * @param prop the initial comma-separated string
85      */

86     public static String JavaDoc[] getArrayFromList(String JavaDoc prop) {
87         return ManifestElement.getArrayFromList(prop, ","); //$NON-NLS-1$
88
}
89
90     /**
91      * Indicates the development mode.
92      * @return true if in development mode; false otherwise
93      */

94     public static boolean inDevelopmentMode() {
95         return inDevelopmentMode;
96     }
97
98     /*
99      * Load the given properties file
100      */

101     private static Properties load(URL JavaDoc url) {
102         Properties props = new Properties();
103         try {
104             InputStream JavaDoc is = null;
105             try {
106                 is = url.openStream();
107                 props.load(is);
108             } finally {
109                 if (is != null)
110                     is.close();
111             }
112         } catch (IOException JavaDoc e) {
113             // TODO consider logging here
114
}
115         return props;
116     }
117 }
118
Popular Tags