From: <to...@us...> - 2007-02-12 23:29:23
|
Revision: 49 http://techne-dev.svn.sourceforge.net/techne-dev/?rev=49&view=rev Author: tonit Date: 2007-02-12 15:29:24 -0800 (Mon, 12 Feb 2007) Log Message: ----------- Modified Paths: -------------- sandbox/tonit/techne.launch/src/techne/launch/FrameworkLauncher.java sandbox/tonit/techne.launch/src/techne/launch/TechneLauncher.java sandbox/tonit/techne.launch/src/techne/launch/felix/FelixFrameworkLauncher.java Added Paths: ----------- sandbox/tonit/techne.launch/src/techne/launch/felix/FelixWrapper.java Modified: sandbox/tonit/techne.launch/src/techne/launch/FrameworkLauncher.java =================================================================== --- sandbox/tonit/techne.launch/src/techne/launch/FrameworkLauncher.java 2007-02-12 23:26:14 UTC (rev 48) +++ sandbox/tonit/techne.launch/src/techne/launch/FrameworkLauncher.java 2007-02-12 23:29:24 UTC (rev 49) @@ -3,4 +3,5 @@ public interface FrameworkLauncher { void init(String[] argv); void launch(); + void shutdown(); } Modified: sandbox/tonit/techne.launch/src/techne/launch/TechneLauncher.java =================================================================== --- sandbox/tonit/techne.launch/src/techne/launch/TechneLauncher.java 2007-02-12 23:26:14 UTC (rev 48) +++ sandbox/tonit/techne.launch/src/techne/launch/TechneLauncher.java 2007-02-12 23:29:24 UTC (rev 49) @@ -18,6 +18,8 @@ */ package techne.launch; +import java.io.File; + /** * @author Toni Menzel, based currently on apache frelix main module * <p> @@ -26,6 +28,7 @@ * </p> */ public class TechneLauncher { + public final static String TECHNE_TMP_DIR ="./tmp"; private String[] argv; public TechneLauncher(String[] argv) { @@ -38,15 +41,18 @@ } private void start() { - System.out.println("\nWelcome to Techne Runtime"); - System.out.println("============================\n"); - // just go for felix now + System.out.println("\n--> Welcome to Techne Runtime <--"); try { + // exit hook for temporary folder + File f = new File(TECHNE_TMP_DIR); + // for some reason this does not work at the mac currently..:-( + f.deleteOnExit(); + System.out.println("loading (default) felix as framework.."); FrameworkLauncher launch = (FrameworkLauncher) Class.forName( "techne.launch.felix.FelixFrameworkLauncher").newInstance(); launch.init(argv); - launch.launch(); + launch.launch(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); Modified: sandbox/tonit/techne.launch/src/techne/launch/felix/FelixFrameworkLauncher.java =================================================================== --- sandbox/tonit/techne.launch/src/techne/launch/felix/FelixFrameworkLauncher.java 2007-02-12 23:26:14 UTC (rev 48) +++ sandbox/tonit/techne.launch/src/techne/launch/felix/FelixFrameworkLauncher.java 2007-02-12 23:29:24 UTC (rev 49) @@ -26,483 +26,539 @@ import org.apache.felix.framework.util.StringMap; import techne.launch.FrameworkLauncher; +import techne.launch.TechneLauncher; -public class FelixFrameworkLauncher implements FrameworkLauncher { - /** - * The system property name used to specify an URL to the system property - * file. - */ - public static final String SYSTEM_PROPERTIES_PROP = "felix.system.properties"; - /** - * The default name used for the system properties file. - */ - public static final String SYSTEM_PROPERTIES_FILE_VALUE = "system.properties"; - /** - * The system property name used to specify an URL to the configuration - * property file to be used for the created the framework instance. - */ - public static final String CONFIG_PROPERTIES_PROP = "felix.config.properties"; - /** - * The default name used for the configuration properties file. - */ - public static final String CONFIG_PROPERTIES_FILE_VALUE = "config.properties"; +public class FelixFrameworkLauncher implements FrameworkLauncher{ + /** + * The system property name used to specify an URL to the system + * property file. + **/ + public static final String SYSTEM_PROPERTIES_PROP = "felix.system.properties"; + /** + * The default name used for the system properties file. + **/ + public static final String SYSTEM_PROPERTIES_FILE_VALUE = "system.properties"; + /** + * The system property name used to specify an URL to the configuration + * property file to be used for the created the framework instance. + **/ + public static final String CONFIG_PROPERTIES_PROP = "felix.config.properties"; + /** + * The default name used for the configuration properties file. + **/ + public static final String CONFIG_PROPERTIES_FILE_VALUE = "config.properties"; - public static final String KEYSTORE_FILE_PROP = "felix.keystore"; + public static final String KEYSTORE_FILE_PROP = "felix.keystore"; - public static final String KEYSTORE_FILE_VALUE = System - .getProperty("java.home") - + File.separatorChar - + "lib" - + File.separatorChar - + "security" - + File.separatorChar - + "cacerts" - + File.pathSeparatorChar - + System.getProperty("user.home") - + File.separatorChar - + ".keystore"; + public static final String KEYSTORE_FILE_VALUE = System.getProperty("java.home") + + File.separatorChar + "lib" + File.separatorChar + "security" + + File.separatorChar + "cacerts" + File.pathSeparatorChar + System.getProperty("user.home") + + File.separatorChar + ".keystore"; - public static final String KEYSTORE_TYPE_PROP = "felix.keystore.type"; + public static final String KEYSTORE_TYPE_PROP = "felix.keystore.type"; - public static final String KEYSTORE_TYPE_VALUE = "JKS" - + File.pathSeparatorChar + "JKS"; + public static final String KEYSTORE_TYPE_VALUE = "JKS" + File.pathSeparatorChar + "JKS"; - public static final String KEYSTORE_PASS_PROP = "felix.keystore.pass"; + public static final String KEYSTORE_PASS_PROP = "felix.keystore.pass"; - public static final String KEYSTORE_PASS_VALUE = "changeit" - + File.pathSeparatorChar + "changeit"; + public static final String KEYSTORE_PASS_VALUE = "changeit" + File.pathSeparatorChar + "changeit"; - private static Felix m_felix = null; + private static Felix m_felix = null; private String[] argv; - public FelixFrameworkLauncher() throws Exception { + public FelixFrameworkLauncher() throws Exception + { + + } + public void launch() { + FelixFrameworkLauncher.loadSystemProperties(); + try + { + Properties configProps = FelixFrameworkLauncher.loadConfigProperties(); + configProps.setProperty(BundleCache.CACHE_PROFILE_DIR_PROP,TechneLauncher.TECHNE_TMP_DIR); + m_felix = new FelixWrapper(); + m_felix.start( + new MutablePropertyResolverImpl(new StringMap(configProps, false)), + null, (System.getSecurityManager() == null) ? null : new TrustManager(configProps)); + System.out.println("felix done"); + } + catch (Exception ex) + { + System.err.println("Could not create framework: " + ex); + ex.printStackTrace(); + System.exit(-1); + } + } + + + + public void init(String[] argv) + { + this.argv = argv; + } + + + /** + * <p> + * Loads the properties in the system property file associated with the + * framework installation into <tt>System.setProperty()</tt>. These properties + * are not directly used by the framework in anyway. By default, the system + * property file is located in the <tt>conf/</tt> directory of the Felix + * installation directory and is called "<tt>system.properties</tt>". The + * installation directory of Felix is assumed to be the parent directory of + * the <tt>felix.jar</tt> file as found on the system class path property. + * The precise file from which to load system properties can be set by + * initializing the "<tt>felix.system.properties</tt>" system property to an + * arbitrary URL. + * </p> + **/ + public static void loadSystemProperties() + { + // The system properties file is either specified by a system + // property or it is in the same directory as the Felix JAR file. + // Try to load it from one of these places. - } + // See if the property URL was specified as a property. + URL propURL = null; + String custom = System.getProperty(SYSTEM_PROPERTIES_PROP); + if (custom != null) + { + try + { + propURL = new URL(custom); + } + catch (MalformedURLException ex) + { + System.err.print("Main: " + ex); + return; + } + } + else + { + // Determine where the configuration directory is by figuring + // out where felix.jar is located on the system class path. + File confDir = null; + String classpath = System.getProperty("java.class.path"); + int index = classpath.toLowerCase().indexOf("techne.jar"); + int start = classpath.lastIndexOf(File.pathSeparator, index) + 1; + if (index > start) + { + String jarLocation = classpath.substring(start, index); + if (jarLocation.length() == 0) + { + jarLocation = "."; + } + confDir = new File(new File(jarLocation).getParent(), "conf"); + } + else + { + // Can't figure it out so use the current directory as default. + confDir = new File(System.getProperty("user.dir")); + } - public void launch() { - FelixFrameworkLauncher.loadSystemProperties(); - try { - Properties configProps = FelixFrameworkLauncher - .loadConfigProperties(); - System.out - .println("keep in mind felix caches at (user.dir)/.felix/" - + configProps - .getProperty(BundleCache.CACHE_PROFILE_PROP)); - m_felix = new Felix(); - m_felix.start(new MutablePropertyResolverImpl(new StringMap( - configProps, false)), null, - (System.getSecurityManager() == null) ? null - : new TrustManager(configProps)); - System.out.println("felix done"); - } catch (Exception ex) { - System.err.println("Could not create framework: " + ex); - ex.printStackTrace(); - System.exit(-1); - } + try + { + propURL = new File(confDir, SYSTEM_PROPERTIES_FILE_VALUE).toURL(); + } + catch (MalformedURLException ex) + { + System.err.print("Main: " + ex); + return; + } + } - } + // Read the properties file. + Properties props = new Properties(); + InputStream is = null; + try + { + is = propURL.openConnection().getInputStream(); + props.load(is); + is.close(); + } + catch (FileNotFoundException ex) + { + // Ignore file not found. + } + catch (Exception ex) + { + System.err.println( + "Main: Error loading system properties from " + propURL); + System.err.println("Main: " + ex); + try + { + if (is != null) is.close(); + } + catch (IOException ex2) + { + // Nothing we can do. + } + return; + } - public void init(String[] argv) { - this.argv = argv; - } + // Perform variable substitution on specified properties. + for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) + { + String name = (String) e.nextElement(); + System.setProperty(name, + substVars(props.getProperty(name), name, null, null)); + } + } - /** - * <p> - * Loads the properties in the system property file associated with the - * framework installation into <tt>System.setProperty()</tt>. These - * properties are not directly used by the framework in anyway. By default, - * the system property file is located in the <tt>conf/</tt> directory of - * the Felix installation directory and is called "<tt>system.properties</tt>". - * The installation directory of Felix is assumed to be the parent directory - * of the <tt>felix.jar</tt> file as found on the system class path - * property. The precise file from which to load system properties can be - * set by initializing the "<tt>felix.system.properties</tt>" system - * property to an arbitrary URL. - * </p> - */ - public static void loadSystemProperties() { - // The system properties file is either specified by a system - // property or it is in the same directory as the Felix JAR file. - // Try to load it from one of these places. + /** + * <p> + * Loads the configuration properties in the configuration property file + * associated with the framework installation; these properties + * are accessible to the framework and to bundles and are intended + * for configuration purposes. By default, the configuration property + * file is located in the <tt>conf/</tt> directory of the Felix + * installation directory and is called "<tt>config.properties</tt>". + * The installation directory of Felix is assumed to be the parent + * directory of the <tt>felix.jar</tt> file as found on the system class + * path property. The precise file from which to load configuration + * properties can be set by initializing the "<tt>felix.config.properties</tt>" + * system property to an arbitrary URL. + * </p> + * @return A <tt>Properties</tt> instance or <tt>null</tt> if there was an error. + **/ + public static Properties loadConfigProperties() + { + // The config properties file is either specified by a system + // property or it is in the same directory as the Felix JAR file. + // Try to load it from one of these places. - // See if the property URL was specified as a property. - URL propURL = null; - String custom = System.getProperty(SYSTEM_PROPERTIES_PROP); - if (custom != null) { - try { - propURL = new URL(custom); - } catch (MalformedURLException ex) { - System.err.print("Main: " + ex); - return; - } - } else { - // Determine where the configuration directory is by figuring - // out where felix.jar is located on the system class path. - File confDir = null; - String classpath = System.getProperty("java.class.path"); - int index = classpath.toLowerCase().indexOf("techne.jar"); - int start = classpath.lastIndexOf(File.pathSeparator, index) + 1; - if (index > start) { - String jarLocation = classpath.substring(start, index); - if (jarLocation.length() == 0) { - jarLocation = "."; - } - confDir = new File(new File(jarLocation).getParent(), "conf"); - } else { - // Can't figure it out so use the current directory as default. - confDir = new File(System.getProperty("user.dir")); - } + // See if the property URL was specified as a property. + URL propURL = null; + String custom = System.getProperty(CONFIG_PROPERTIES_PROP); + if (custom != null) + { + try + { + propURL = new URL(custom); + } + catch (MalformedURLException ex) + { + System.err.print("Main: " + ex); + return null; + } + } + else + { + // Determine where the configuration directory is by figuring + // out where felix.jar is located on the system class path. + File confDir = null; + String classpath = System.getProperty("java.class.path"); + int index = classpath.toLowerCase().indexOf("techne.jar"); + int start = classpath.lastIndexOf(File.pathSeparator, index) + 1; + if (index > start) + { + String jarLocation = classpath.substring(start, index); + if (jarLocation.length() == 0) + { + jarLocation = "."; + } + confDir = new File(new File(jarLocation).getParent(), "conf"); + } + else + { + // Can't figure it out so use the current directory as default. + confDir = new File(System.getProperty("user.dir")); + } - try { - propURL = new File(confDir, SYSTEM_PROPERTIES_FILE_VALUE) - .toURL(); - } catch (MalformedURLException ex) { - System.err.print("Main: " + ex); - return; - } - } + try + { + propURL = new File(confDir, CONFIG_PROPERTIES_FILE_VALUE).toURL(); + } + catch (MalformedURLException ex) + { + System.err.print("Main: " + ex); + return null; + } + } - // Read the properties file. - Properties props = new Properties(); - InputStream is = null; - try { - is = propURL.openConnection().getInputStream(); - props.load(is); - is.close(); - } catch (FileNotFoundException ex) { - // Ignore file not found. - } catch (Exception ex) { - System.err.println("Main: Error loading system properties from " - + propURL); - System.err.println("Main: " + ex); - try { - if (is != null) - is.close(); - } catch (IOException ex2) { - // Nothing we can do. - } - return; - } + // Read the properties file. + Properties props = new Properties(); + InputStream is = null; + try + { + is = propURL.openConnection().getInputStream(); + props.load(is); + is.close(); + } + catch (FileNotFoundException ex) + { + // Ignore file not found. + } + catch (Exception ex) + { + System.err.println( + "Error loading config properties from " + propURL); + System.err.println("Main: " + ex); + try + { + if (is != null) is.close(); + } + catch (IOException ex2) + { + // Nothing we can do. + } + return null; + } - // Perform variable substitution on specified properties. - for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { - String name = (String) e.nextElement(); - System.setProperty(name, substVars(props.getProperty(name), name, - null, null)); - } - } + // Perform variable substitution for system properties. + for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) + { + String name = (String) e.nextElement(); + props.setProperty(name, + substVars(props.getProperty(name), name, null, props)); + } - /** - * <p> - * Loads the configuration properties in the configuration property file - * associated with the framework installation; these properties are - * accessible to the framework and to bundles and are intended for - * configuration purposes. By default, the configuration property file is - * located in the <tt>conf/</tt> directory of the Felix installation - * directory and is called "<tt>config.properties</tt>". The - * installation directory of Felix is assumed to be the parent directory of - * the <tt>felix.jar</tt> file as found on the system class path property. - * The precise file from which to load configuration properties can be set - * by initializing the "<tt>felix.config.properties</tt>" system - * property to an arbitrary URL. - * </p> - * - * @return A <tt>Properties</tt> instance or <tt>null</tt> if there was - * an error. - */ - public static Properties loadConfigProperties() { - // The config properties file is either specified by a system - // property or it is in the same directory as the Felix JAR file. - // Try to load it from one of these places. + return props; + } - // See if the property URL was specified as a property. - URL propURL = null; - String custom = System.getProperty(CONFIG_PROPERTIES_PROP); - if (custom != null) { - try { - propURL = new URL(custom); - } catch (MalformedURLException ex) { - System.err.print("Main: " + ex); - return null; - } - } else { - // Determine where the configuration directory is by figuring - // out where felix.jar is located on the system class path. - File confDir = null; - String classpath = System.getProperty("java.class.path"); - int index = classpath.toLowerCase().indexOf("techne.jar"); - int start = classpath.lastIndexOf(File.pathSeparator, index) + 1; - if (index > start) { - String jarLocation = classpath.substring(start, index); - if (jarLocation.length() == 0) { - jarLocation = "."; - } - confDir = new File(new File(jarLocation).getParent(), "conf"); - } else { - // Can't figure it out so use the current directory as default. - confDir = new File(System.getProperty("user.dir")); - } + private static final String DELIM_START = "${"; + private static final String DELIM_STOP = "}"; - try { - propURL = new File(confDir, CONFIG_PROPERTIES_FILE_VALUE) - .toURL(); - } catch (MalformedURLException ex) { - System.err.print("Main: " + ex); - return null; - } - } + /** + * <p> + * This method performs property variable substitution on the + * specified value. If the specified value contains the syntax + * <tt>${<prop-name>}</tt>, where <tt><prop-name></tt> + * refers to either a configuration property or a system property, + * then the corresponding property value is substituted for the variable + * placeholder. Multiple variable placeholders may exist in the + * specified value as well as nested variable placeholders, which + * are substituted from inner most to outer most. Configuration + * properties override system properties. + * </p> + * @param val The string on which to perform property substitution. + * @param currentKey The key of the property being evaluated used to + * detect cycles. + * @param cycleMap Map of variable references used to detect nested cycles. + * @param configProps Set of configuration properties. + * @return The value of the specified string after system property substitution. + * @throws IllegalArgumentException If there was a syntax error in the + * property placeholder syntax or a recursive variable reference. + **/ + public static String substVars(String val, String currentKey, + Map cycleMap, Properties configProps) + throws IllegalArgumentException + { + // If there is currently no cycle map, then create + // one for detecting cycles for this invocation. + if (cycleMap == null) + { + cycleMap = new HashMap(); + } - // Read the properties file. - Properties props = new Properties(); - InputStream is = null; - try { - is = propURL.openConnection().getInputStream(); - props.load(is); - is.close(); - } catch (FileNotFoundException ex) { - // Ignore file not found. - } catch (Exception ex) { - System.err.println("Error loading config properties from " - + propURL); - System.err.println("Main: " + ex); - try { - if (is != null) - is.close(); - } catch (IOException ex2) { - // Nothing we can do. - } - return null; - } + // Put the current key in the cycle map. + cycleMap.put(currentKey, currentKey); - // Perform variable substitution for system properties. - for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { - String name = (String) e.nextElement(); - props.setProperty(name, substVars(props.getProperty(name), name, - null, props)); - } + // Assume we have a value that is something like: + // "leading ${foo.${bar}} middle ${baz} trailing" - return props; - } + // Find the first ending '}' variable delimiter, which + // will correspond to the first deepest nested variable + // placeholder. + int stopDelim = val.indexOf(DELIM_STOP); - private static final String DELIM_START = "${"; - private static final String DELIM_STOP = "}"; + // Find the matching starting "${" variable delimiter + // by looping until we find a start delimiter that is + // greater than the stop delimiter we have found. + int startDelim = val.indexOf(DELIM_START); + while (stopDelim >= 0) + { + int idx = val.indexOf(DELIM_START, startDelim + DELIM_START.length()); + if ((idx < 0) || (idx > stopDelim)) + { + break; + } + else if (idx < stopDelim) + { + startDelim = idx; + } + } - /** - * <p> - * This method performs property variable substitution on the specified - * value. If the specified value contains the syntax - * <tt>${<prop-name>}</tt>, where <tt><prop-name></tt> - * refers to either a configuration property or a system property, then the - * corresponding property value is substituted for the variable placeholder. - * Multiple variable placeholders may exist in the specified value as well - * as nested variable placeholders, which are substituted from inner most to - * outer most. Configuration properties override system properties. - * </p> - * - * @param val - * The string on which to perform property substitution. - * @param currentKey - * The key of the property being evaluated used to detect cycles. - * @param cycleMap - * Map of variable references used to detect nested cycles. - * @param configProps - * Set of configuration properties. - * @return The value of the specified string after system property - * substitution. - * @throws IllegalArgumentException - * If there was a syntax error in the property placeholder - * syntax or a recursive variable reference. - */ - public static String substVars(String val, String currentKey, Map cycleMap, - Properties configProps) throws IllegalArgumentException { - // If there is currently no cycle map, then create - // one for detecting cycles for this invocation. - if (cycleMap == null) { - cycleMap = new HashMap(); - } + // If we do not have a start or stop delimiter, then just + // return the existing value. + if ((startDelim < 0) && (stopDelim < 0)) + { + return val; + } + // At this point, we found a stop delimiter without a start, + // so throw an exception. + else if (((startDelim < 0) || (startDelim > stopDelim)) + && (stopDelim >= 0)) + { + throw new IllegalArgumentException( + "stop delimiter with no start delimiter: " + + val); + } - // Put the current key in the cycle map. - cycleMap.put(currentKey, currentKey); + // At this point, we have found a variable placeholder so + // we must perform a variable substitution on it. + // Using the start and stop delimiter indices, extract + // the first, deepest nested variable placeholder. + String variable = + val.substring(startDelim + DELIM_START.length(), stopDelim); - // Assume we have a value that is something like: - // "leading ${foo.${bar}} middle ${baz} trailing" + // Verify that this is not a recursive variable reference. + if (cycleMap.get(variable) != null) + { + throw new IllegalArgumentException( + "recursive variable reference: " + variable); + } - // Find the first ending '}' variable delimiter, which - // will correspond to the first deepest nested variable - // placeholder. - int stopDelim = val.indexOf(DELIM_STOP); + // Get the value of the deepest nested variable placeholder. + // Try to configuration properties first. + String substValue = (configProps != null) + ? configProps.getProperty(variable, null) + : null; + if (substValue == null) + { + // Ignore unknown property values. + substValue = System.getProperty(variable, ""); + } - // Find the matching starting "${" variable delimiter - // by looping until we find a start delimiter that is - // greater than the stop delimiter we have found. - int startDelim = val.indexOf(DELIM_START); - while (stopDelim >= 0) { - int idx = val.indexOf(DELIM_START, startDelim - + DELIM_START.length()); - if ((idx < 0) || (idx > stopDelim)) { - break; - } else if (idx < stopDelim) { - startDelim = idx; - } - } + // Remove the found variable from the cycle map, since + // it may appear more than once in the value and we don't + // want such situations to appear as a recursive reference. + cycleMap.remove(variable); - // If we do not have a start or stop delimiter, then just - // return the existing value. - if ((startDelim < 0) && (stopDelim < 0)) { - return val; - } - // At this point, we found a stop delimiter without a start, - // so throw an exception. - else if (((startDelim < 0) || (startDelim > stopDelim)) - && (stopDelim >= 0)) { - throw new IllegalArgumentException( - "stop delimiter with no start delimiter: " + val); - } + // Append the leading characters, the substituted value of + // the variable, and the trailing characters to get the new + // value. + val = val.substring(0, startDelim) + + substValue + + val.substring(stopDelim + DELIM_STOP.length(), val.length()); - // At this point, we have found a variable placeholder so - // we must perform a variable substitution on it. - // Using the start and stop delimiter indices, extract - // the first, deepest nested variable placeholder. - String variable = val.substring(startDelim + DELIM_START.length(), - stopDelim); + // Now perform substitution again, since there could still + // be substitutions to make. + val = substVars(val, currentKey, cycleMap, configProps); - // Verify that this is not a recursive variable reference. - if (cycleMap.get(variable) != null) { - throw new IllegalArgumentException("recursive variable reference: " - + variable); - } + // Return the value. + return val; + } - // Get the value of the deepest nested variable placeholder. - // Try to configuration properties first. - String substValue = (configProps != null) ? configProps.getProperty( - variable, null) : null; - if (substValue == null) { - // Ignore unknown property values. - substValue = System.getProperty(variable, ""); - } + private static class TrustManager extends AbstractCollection + { + private String[] m_keystores = null; + private String[] m_passwds = null; + private String[] m_types = null; + private ArrayList m_stores = null; - // Remove the found variable from the cycle map, since - // it may appear more than once in the value and we don't - // want such situations to appear as a recursive reference. - cycleMap.remove(variable); + TrustManager(Properties config) + { + StringTokenizer tok = new StringTokenizer(System.getProperty(KEYSTORE_FILE_PROP, + config.getProperty(KEYSTORE_FILE_PROP, KEYSTORE_FILE_VALUE)), File.pathSeparator); - // Append the leading characters, the substituted value of - // the variable, and the trailing characters to get the new - // value. - val = val.substring(0, startDelim) + substValue - + val.substring(stopDelim + DELIM_STOP.length(), val.length()); + m_keystores = new String[tok.countTokens()]; - // Now perform substitution again, since there could still - // be substitutions to make. - val = substVars(val, currentKey, cycleMap, configProps); + for (int i = 0;tok.hasMoreTokens();i++) + { + m_keystores[i] = tok.nextToken(); + } - // Return the value. - return val; - } + tok = new StringTokenizer(System.getProperty(KEYSTORE_PASS_PROP, + config.getProperty(KEYSTORE_PASS_PROP, KEYSTORE_PASS_VALUE)), File.pathSeparator); - private static class TrustManager extends AbstractCollection { - private String[] m_keystores = null; - private String[] m_passwds = null; - private String[] m_types = null; - private ArrayList m_stores = null; + m_passwds = new String[tok.countTokens()]; - TrustManager(Properties config) { - StringTokenizer tok = new StringTokenizer(System.getProperty( - KEYSTORE_FILE_PROP, config.getProperty(KEYSTORE_FILE_PROP, - KEYSTORE_FILE_VALUE)), File.pathSeparator); + for (int i = 0;tok.hasMoreTokens();i++) + { + m_passwds[i] = tok.nextToken(); + } - m_keystores = new String[tok.countTokens()]; + tok = new StringTokenizer(System.getProperty(KEYSTORE_TYPE_PROP, + config.getProperty(KEYSTORE_TYPE_PROP, KEYSTORE_TYPE_VALUE)), File.pathSeparator); - for (int i = 0; tok.hasMoreTokens(); i++) { - m_keystores[i] = tok.nextToken(); - } + m_types = new String[tok.countTokens()]; - tok = new StringTokenizer(System - .getProperty(KEYSTORE_PASS_PROP, config.getProperty( - KEYSTORE_PASS_PROP, KEYSTORE_PASS_VALUE)), - File.pathSeparator); + for (int i = 0;tok.hasMoreTokens();i++) + { + m_types[i] = tok.nextToken(); + } + } - m_passwds = new String[tok.countTokens()]; + @Override + public synchronized Iterator iterator() + { + if (m_stores == null) + { + loadStores(); + } - for (int i = 0; tok.hasMoreTokens(); i++) { - m_passwds[i] = tok.nextToken(); - } + return m_stores.iterator(); + } - tok = new StringTokenizer(System - .getProperty(KEYSTORE_TYPE_PROP, config.getProperty( - KEYSTORE_TYPE_PROP, KEYSTORE_TYPE_VALUE)), - File.pathSeparator); + @Override + public synchronized int size() + { + if (m_stores == null) + { + loadStores(); + } - m_types = new String[tok.countTokens()]; + return m_stores.size(); + } - for (int i = 0; tok.hasMoreTokens(); i++) { - m_types[i] = tok.nextToken(); - } - } + private void loadStores() + { + m_stores = new ArrayList(); - @Override - public synchronized Iterator iterator() { - if (m_stores == null) { - loadStores(); - } + if ((m_keystores.length == m_passwds.length) && (m_passwds.length == m_types.length) + && (System.getSecurityManager() != null)) + { + AccessController.doPrivileged(new PrivilegedAction() + { + public Object run() + { + List certs = new ArrayList(); - return m_stores.iterator(); - } + for (int i = 0;i < m_keystores.length;i++) + { - @Override - public synchronized int size() { - if (m_stores == null) { - loadStores(); - } + try + { + KeyStore ks = KeyStore.getInstance(m_types[i]); + ks.load(new FileInputStream(m_keystores[i]), m_passwds[i].toCharArray()); + for (Enumeration e = ks.aliases(); e.hasMoreElements();) + { + String alias = (String) e.nextElement(); + if (ks.isCertificateEntry(alias)) + { + certs.add(ks.getCertificate(alias)); + } + } + } + catch (Exception ex) + { + certs.clear(); + ex.printStackTrace(System.err); - return m_stores.size(); - } + System.err.println("WARNING: Error accessing keystore: " + m_keystores[i]); + } - private void loadStores() { - m_stores = new ArrayList(); + if (!certs.isEmpty()) + { + m_stores.addAll(certs); + certs.clear(); + } + } - if ((m_keystores.length == m_passwds.length) - && (m_passwds.length == m_types.length) - && (System.getSecurityManager() != null)) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - List certs = new ArrayList(); + return null; + } + }); + } + if (m_stores.isEmpty()) + { + System.err.println("WARNING: No trusted CA certificates!"); + } + } + } - for (int i = 0; i < m_keystores.length; i++) { - - try { - KeyStore ks = KeyStore.getInstance(m_types[i]); - ks.load(new FileInputStream(m_keystores[i]), - m_passwds[i].toCharArray()); - for (Enumeration e = ks.aliases(); e - .hasMoreElements();) { - String alias = (String) e.nextElement(); - if (ks.isCertificateEntry(alias)) { - certs.add(ks.getCertificate(alias)); - } - } - } catch (Exception ex) { - certs.clear(); - ex.printStackTrace(System.err); - - System.err - .println("WARNING: Error accessing keystore: " - + m_keystores[i]); - } - - if (!certs.isEmpty()) { - m_stores.addAll(certs); - certs.clear(); - } - } - - return null; - } - }); - } - if (m_stores.isEmpty()) { - System.err.println("WARNING: No trusted CA certificates!"); - } - } + public void shutdown() { + // got shutdown ! + System.out.println("Got SHUTDOWN HOOK!"); } } Added: sandbox/tonit/techne.launch/src/techne/launch/felix/FelixWrapper.java =================================================================== --- sandbox/tonit/techne.launch/src/techne/launch/felix/FelixWrapper.java (rev 0) +++ sandbox/tonit/techne.launch/src/techne/launch/felix/FelixWrapper.java 2007-02-12 23:29:24 UTC (rev 49) @@ -0,0 +1,17 @@ +package techne.launch.felix; + +import org.apache.felix.framework.Felix; + +public class FelixWrapper extends Felix { + FelixFrameworkLauncher launcher; + + public void FelixWrapper(FelixFrameworkLauncher launcher) { + this.launcher = launcher; + } + + public void shutdown() { + super.shutdown(); + launcher.shutdown(); + // + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |