diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:08:37 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:08:37 +0000 |
commit | 4ef0430519e276c2bdecea75f7a0f42f49f0cf30 (patch) | |
tree | 19dd40a9336c52160da6671d2fb3d428725733d4 /branches/sca-java-1.5/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java | |
parent | 725006d4c47e63986ac042ade23a4d193298b1fe (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835132 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.5/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java')
-rw-r--r-- | branches/sca-java-1.5/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java | 168 |
1 files changed, 0 insertions, 168 deletions
diff --git a/branches/sca-java-1.5/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java b/branches/sca-java-1.5/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java deleted file mode 100644 index 19041daf50..0000000000 --- a/branches/sca-java-1.5/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.osgi.runtime; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.util.Hashtable; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; - -/** - * Implementation of an OSGi Runtime using Knopflerfish. - * - * @version $Rev$ $Date$ - */ -public class KnopflerfishRuntime extends OSGiRuntime { - - private static BundleContext bundleContext; - - private static KnopflerfishRuntime instance; - - - private static Class<?> frameworkClass; - - private static Object framework; - - public static OSGiRuntime getInstance() throws Exception { - if (instance == null) { - frameworkClass = KnopflerfishRuntime.class.getClassLoader().loadClass("org.knopflerfish.framework.Framework"); - KnopflerfishRuntime runtime = new KnopflerfishRuntime(); - instance = runtime; - } - return instance; - } - - - - // FIXME: Knopflerfish does not expose the methods used for configuration as public methods - // It may be worth using the private methods in org.knopflerfish.framework.Main for - // configuring using reflection if security policies allow it. - // For now, a simple configuration routine reads sca.xargs from the directory in - // the classpath which contains framework.jar. The entries in init.xargs starting with - // -install are assumed to be single-line entries with full bundle location. - // - @Override - protected BundleContext startRuntime(boolean tuscanyRunningInOSGiContainer) throws Exception { - - if (bundleContext != null) - return bundleContext; - - - - System.setProperty("org.knopflerfish.framework.bundlestorage", "memory"); - - Constructor frameworkConstructor = frameworkClass.getConstructor(Object.class); - framework = frameworkConstructor.newInstance(new KnopflerfishRuntime()); - Method launchMethod = frameworkClass.getMethod("launch", long.class); - launchMethod.invoke(framework, 0); - Method getContextMethod = frameworkClass.getMethod("getSystemBundleContext"); - bundleContext = (BundleContext)getContextMethod.invoke(framework); - - System.setProperty("com.gatespace.bundle.cm.store", "knopflerfish.store"); - File xargsFile = null; - String classpath = System.getProperty("java.class.path"); - String[] classpathEntries = classpath.split(System.getProperty("path.separator")); - for (int i = 0; i < classpathEntries.length; i++) { - if (classpathEntries[i].endsWith("framework.jar")) { - String path = classpathEntries[i].substring(0, classpathEntries[i].length() - "framework.jar".length()); - path = path + "sca.xargs"; - xargsFile = new File(path); - if (!xargsFile.exists()) - xargsFile = null; - break; - } - } - if (xargsFile != null) { - BufferedReader reader = new BufferedReader(new FileReader(xargsFile)); - String line; - Hashtable<String, Bundle> bundles = new Hashtable<String, Bundle>(); - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.startsWith("-install")) { - try { - - String bundleLocation = line.substring("-install".length()).trim(); - Bundle bundle = bundleContext.installBundle(bundleLocation); - bundles.put(bundleLocation, bundle); - - } catch (BundleException e) { - e.printStackTrace(); - } - - } - if (line.startsWith("-start")) { - - try { - String bundleLocation = line.substring("-start".length()).trim(); - Bundle bundle = bundles.get(bundleLocation); - bundle.start(); - } catch (BundleException e) { - e.printStackTrace(); - } - } - } - } - - - return bundleContext; - - } - - @Override - public BundleContext getBundleContext() { - return bundleContext; - } - - @Override - protected void setBundleContext(BundleContext bundleContext) { - super.setBundleContext(bundleContext); - KnopflerfishRuntime.bundleContext = bundleContext; - } - - @Override - public void shutdown() throws Exception { - - if (bundleContext == null) - return; - bundleContext = null; - instance = null; - if (framework != null) { - Method shutdownMethod = frameworkClass.getMethod("shutdown"); - try { - shutdownMethod.invoke(framework); - } catch (Exception e) { - // Ignore errors - } - framework = null; - } - super.shutdown(); - - } - - @Override - public boolean supportsBundleFragments() { - return true; - } -} |