From: <ri...@us...> - 2007-02-12 00:30:11
|
Revision: 42 http://techne-dev.svn.sourceforge.net/techne-dev/?rev=42&view=rev Author: rickles Date: 2007-02-11 16:30:11 -0800 (Sun, 11 Feb 2007) Log Message: ----------- Intercept all felix shell commands. Modified Paths: -------------- sandbox/rickles/org.digivitality.techne.shell/.classpath sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java Modified: sandbox/rickles/org.digivitality.techne.shell/.classpath =================================================================== --- sandbox/rickles/org.digivitality.techne.shell/.classpath 2007-02-12 00:27:16 UTC (rev 41) +++ sandbox/rickles/org.digivitality.techne.shell/.classpath 2007-02-12 00:30:11 UTC (rev 42) @@ -4,6 +4,8 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="lib" path="/org.digivitality.techne.core/lib/commons-logging-1.0.4.jar"/> - <classpathentry kind="lib" path="C:/Workspace/eclipse-3.2/techne/sandbox/tonit/techne-env/bin/techne.jar"/> + <classpathentry kind="lib" path="/org.digivitality.techne.core/lib/felix.jar"/> + <classpathentry kind="lib" path="/org.digivitality.techne.core/bundle/org.apache.felix.shell-0.8.0-SNAPSHOT.jar"/> + <classpathentry kind="lib" path="/org.digivitality.techne.core/classes"/> <classpathentry kind="output" path="classes"/> </classpath> Modified: sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java =================================================================== --- sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java 2007-02-12 00:27:16 UTC (rev 41) +++ sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java 2007-02-12 00:30:11 UTC (rev 42) @@ -5,11 +5,20 @@ import java.io.*; import java.text.*; +import java.lang.reflect.Field; +import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +//import org.ungoverned.osgi.service.shell.ShellService; +import org.apache.felix.shell.ShellService; +import org.apache.felix.shell.impl.*; +import org.apache.felix.framework.*; -import techne.launch.*; +import org.digivitality.techne.launch.felix.*; /** * This is intended to demonstrate the concept of a container shell. @@ -26,6 +35,11 @@ private boolean stopping = false; Thread techneThread; Thread frameworkThread; + FelixLauncher launcher; + FelixFrameworkThread felix; + //static ShellService shellService; + static Method executeCommand; + BundleContext context; public void init() { System.out.println("\n===============================================================================\n"); @@ -47,6 +61,7 @@ public void execute() { final Runnable shell = new Runnable() { + public void run() { String line = null; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); @@ -90,20 +105,34 @@ * Will use Command pattern later on. */ public void runCommand(String line, PrintStream out, PrintStream err) { - + if (line.equals("set framework to Felix")) { if (FRAMEWORK_SET) { out.print("Framework has already been set to Felix\n"); } else { - frameworkThread = new Thread(new FelixFrameworkThread()); + try { + File file = new File("mytempfile"); + System.out.println("Where am i: " + file.getCanonicalPath()); + } catch (Exception e) { + e.printStackTrace(); + } + felix = new FelixFrameworkThread(); + frameworkThread = new Thread(felix); frameworkThread.setPriority(1); frameworkThread.start(); } } else if (line.equals("exit") || line.equals("quit") ) { stopping = true; - System.exit(0); - } else { - out.print("Unsupported command. Please try another command.\n"); + try { + Runtime.getRuntime().halt(0); + } catch (Exception e) { + e.printStackTrace(); + } finally { + System.exit(0); + } + } else { // assume that it is a framework command + //out.print("Unsupported command. Please try another command.\n"); + execute(line, System.out, System.out); } } }; @@ -112,14 +141,96 @@ techneThread.start(); } - private class FelixFrameworkThread implements Runnable { + protected void execute(String line, PrintStream in, PrintStream out) { + //Bundle[] bundles = felix.getBundles(); + ShellService shell = null; + //System.out.println("Bundles found: " + bundles.length); + + /* + for (int i = 0; i < bundles.length; i++) { + System.out.println("Got this bundle: " + bundles[i].getLocation()); + if (bundles[i].getSymbolicName().startsWith("org.digivitality.techne.bundle")) { + try { + Class clazz = bundles[i].getClass(); + System.out.println("clazz: " + clazz.getName()); + Method m = clazz.getSuperclass().getDeclaredMethod("getShellService", new Class[0]); + m.setAccessible(true); + shell = (ShellService)m.invoke(bundles[i], new Object[0]); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + */ + try { + Method m = Felix.class.getDeclaredMethod("getBundle", new Class[] { long.class }); + m.setAccessible(true); + Bundle systemBundle = (Bundle) m.invoke(launcher.getFelix(), new Object[] { new Long(0) }); + System.out.println("systemBundle superclass: " + systemBundle.getClass().getSuperclass().getName()); + Method getContext = systemBundle.getClass().getSuperclass().getDeclaredMethod("getContext", null); + getContext.setAccessible(true); + context = (BundleContext) getContext.invoke(systemBundle, null); + System.out.println("BundleContext: " + context); + + Class clazz = Class.forName("org.apache.felix.shell.ShellService"); + Object[] args = {line, in, out}; + + ServiceReference ref = context.getServiceReference(ShellService.class.getName()); + if (ref!=null) { + Object o = context.getService(ref); + System.out.println("o: " + o.getClass().getName() + " cl: " + o.getClass().getClassLoader()); + Class[] parameterTypes={String.class,PrintStream.class,PrintStream.class}; + executeCommand = o.getClass().getDeclaredMethod("executeCommand", parameterTypes); + executeCommand.setAccessible(true); + executeCommand.invoke(o, args); + //Thread.currentThread().setContextClassLoader(clazz.getClassLoader()); + //shell = ShellService.class.cast(o); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static BundleContext getBundleContext(Bundle bundle) { + try { + Class clazz = bundle.getClass(); + /* + System.out.println("clazz is " + clazz.getName()); Field field = clazz.getDeclaredField("bundleContext"); + field.setAccessible(true); + return (BundleContext) field.get(bundle); + */ + Method m = clazz.getDeclaredMethod("getContext", new Class[0]); + m.setAccessible(true); + return (BundleContext) m.invoke(bundle, new Object[0]); + } catch (Exception e) { + logger.error("getBundleContext failed", e); + e.printStackTrace(); + return null; + } + } + + class FelixFrameworkThread implements Runnable { + + Bundle[] bundles; + public void run() { try { - TechneLauncher.main(null); + launcher = new FelixLauncher(); + launcher.launch(); System.out.print("techne> "); } catch (Exception e) { e.printStackTrace(); } } + + /* + public Bundle[] getBundles() { + return launcher.getBundles(); + } + + public Object getService(Bundle b, ServiceReference ref) { + return launcher.getService(b, ref); + } + */ } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <to...@us...> - 2007-03-01 13:10:20
|
Revision: 93 http://techne-dev.svn.sourceforge.net/techne-dev/?rev=93&view=rev Author: tonit Date: 2007-03-01 05:10:17 -0800 (Thu, 01 Mar 2007) Log Message: ----------- moved Main class to shell project to fix cyclic dep. Modified Paths: -------------- sandbox/rickles/org.digivitality.techne.shell/.classpath Added Paths: ----------- sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java Modified: sandbox/rickles/org.digivitality.techne.shell/.classpath =================================================================== --- sandbox/rickles/org.digivitality.techne.shell/.classpath 2007-03-01 13:08:20 UTC (rev 92) +++ sandbox/rickles/org.digivitality.techne.shell/.classpath 2007-03-01 13:10:17 UTC (rev 93) @@ -1,11 +1,11 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> - <classpathentry kind="lib" path="/org.digivitality.techne.core/lib/commons-logging-1.0.4.jar"/> - <classpathentry kind="lib" path="/org.digivitality.techne.core/lib/felix.jar"/> - <classpathentry kind="lib" path="/org.digivitality.techne.core/bundle/org.apache.felix.shell-0.8.0-SNAPSHOT.jar"/> - <classpathentry kind="lib" path="/org.digivitality.techne.core/classes"/> - <classpathentry kind="output" path="classes"/> -</classpath> +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="lib" path="/org.digivitality.techne.core/lib/commons-logging-1.0.4.jar"/> + <classpathentry kind="lib" path="/org.digivitality.techne.core/lib/felix.jar"/> + <classpathentry kind="lib" path="/org.digivitality.techne.core/bundle/org.apache.felix.shell-0.8.0-SNAPSHOT.jar"/> + <classpathentry combineaccessrules="false" kind="src" path="/org.digivitality.techne.core"/> + <classpathentry kind="output" path="classes"/> +</classpath> Copied: sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java (from rev 91, sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/Main.java) =================================================================== --- sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java (rev 0) +++ sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java 2007-03-01 13:10:17 UTC (rev 93) @@ -0,0 +1,36 @@ +/** + * + */ +package org.digivitality.techne.shell; + +import org.apache.log4j.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.impl.Log4JLogger; + +import org.digivitality.techne.shell.*; +import org.digivitality.techne.launch.felix.*; + +/** + * Generic starter. + * + * @author Rick Litton + * + */ +public class Main { + + static Log logger = LogFactory.getLog(Main.class); + + /** + * @param args + */ + public static void main(String[] args) { + (LogFactory.getLog(Main.class)).info("user.dir = " + System.getProperty("user.dir")); + Shell container = new Shell(); + container.init(); + /* test to run launcher directly */ + //FelixLauncher l = new FelixLauncher(); + //l.launch(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <to...@us...> - 2007-03-03 20:02:20
|
Revision: 103 http://techne-dev.svn.sourceforge.net/techne-dev/?rev=103&view=rev Author: tonit Date: 2007-03-03 12:02:20 -0800 (Sat, 03 Mar 2007) Log Message: ----------- implemented dynamic provisioning Modified Paths: -------------- sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java Property Changed: ---------------- sandbox/rickles/org.digivitality.techne.shell/ Property changes on: sandbox/rickles/org.digivitality.techne.shell ___________________________________________________________________ Name: svn:ignore + classes Modified: sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java =================================================================== --- sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java 2007-03-03 16:58:08 UTC (rev 102) +++ sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java 2007-03-03 20:02:20 UTC (rev 103) @@ -3,32 +3,37 @@ */ package org.digivitality.techne.shell; -import java.io.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.util.Iterator; import java.util.List; -import java.util.Map; -import java.lang.reflect.Method; +import java.util.Stack; +import java.util.Vector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.felix.framework.Felix; +import org.apache.felix.shell.ShellService; +import org.digivitality.techne.core.ContainerFactory; +import org.digivitality.techne.core.util.ContainerState; +import org.digivitality.techne.core.util.bundle; +import org.digivitality.techne.core.util.containertype; +import org.digivitality.techne.launch.felix.FelixLauncher; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkEvent; import org.osgi.framework.FrameworkListener; import org.osgi.framework.ServiceReference; -import org.apache.felix.shell.ShellService; -import org.apache.felix.framework.*; -import org.digivitality.techne.core.ContainerFactory; -import org.digivitality.techne.core.util.bundle; -import org.digivitality.techne.core.util.containertype; -import org.digivitality.techne.launch.felix.*; - /** - * This is intended to demonstrate the concept of a container shell. - * To set the framework, type 'set framework to Felix' on the command prompt. + * This is intended to demonstrate the concept of a container shell. To set the + * framework, type 'set framework to Felix' on the command prompt. * * @author Rick Liton - * + * */ public class Shell implements FrameworkListener { @@ -36,89 +41,96 @@ private String profile = "Peter"; private static String DEFAULT_CONTAINER_TYPE = "basic"; protected static final Log logger = LogFactory.getLog(Shell.class); - private boolean stopping = false; - private ContainerFactory containerFactory; - private Thread techneThread; - private Thread frameworkThread; - protected FelixLauncher launcher; - protected FelixFrameworkThread felix; - private static Method executeCommand; - private BundleContext context; - protected Shell container; - private List containerInstances; - private List bundleList; - private String containerType; - - public Shell() { + private boolean stopping = false; + private ContainerFactory containerFactory; + private Thread techneThread; + private Thread frameworkThread; + protected FelixLauncher launcher; + protected FelixFrameworkThread felix; + private static Method executeCommand; + private BundleContext context; + protected Shell container; + private ContainerState containerState; - } - + public Shell() { + + } + public void init() { - container = this; - System.out.println("\n===============================================================================\n"); - System.out.println(" TTTTTTTTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNN NNNNN EEEEEEEEE"); - System.out.println(" TTTTTTTTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNNN NNNNN EEEEEEEEE"); - System.out.println(" TTTTT EEEEE CCCCC HHHHH HHHHH NNNNNNNNNNNN EEEEE"); - System.out.println(" TTTTT EEEEEEEE CCCCC HHHHHHHHHHHH NNNNN NNNNNN EEEEEEEE"); - System.out.println(" TTTTT EEEEEEEE CCCCC HHHHHHHHHHHH NNNNN NNNNN EEEEEEEE"); - System.out.println(" TTTTT EEEEE CCCCC HHHHH HHHHH NNNNN NNNNN EEEEE"); - System.out.println(" TTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNN NNNNN EEEEEEEEE"); - System.out.println(" TTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNN NNNNN EEEEEEEEE\n"); - System.out.println(" WELCOME TO THE TECHNE SHELL!"); - System.out.println("===============================================================================\n\n"); - System.out.println("Your default profile is " + profile + "."); - System.out.println("Please select a framework by executing the `set framework to' command"); - System.out.println("or specify it in your techne.properties file.\n\n"); - execute(); + container = this; + System.out + .println("\n===============================================================================\n"); + System.out + .println(" TTTTTTTTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNN NNNNN EEEEEEEEE"); + System.out + .println(" TTTTTTTTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNNN NNNNN EEEEEEEEE"); + System.out + .println(" TTTTT EEEEE CCCCC HHHHH HHHHH NNNNNNNNNNNN EEEEE"); + System.out + .println(" TTTTT EEEEEEEE CCCCC HHHHHHHHHHHH NNNNN NNNNNN EEEEEEEE"); + System.out + .println(" TTTTT EEEEEEEE CCCCC HHHHHHHHHHHH NNNNN NNNNN EEEEEEEE"); + System.out + .println(" TTTTT EEEEE CCCCC HHHHH HHHHH NNNNN NNNNN EEEEE"); + System.out + .println(" TTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNN NNNNN EEEEEEEEE"); + System.out + .println(" TTTTT EEEEEEEEE CCCCCCCCCC HHHHH HHHHH NNNNN NNNNN EEEEEEEEE\n"); + System.out + .println(" WELCOME TO THE TECHNE SHELL!"); + System.out + .println("===============================================================================\n\n"); + System.out.println("Your default profile is " + profile + "."); + System.out + .println("Please select a framework by executing the `set framework to' command"); + System.out.println("or specify it in your techne.properties file.\n\n"); + execute(); } - + public void execute() { final Runnable shell = new Runnable() { - - public void run() { - String line = null; - BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); - while (!stopping) - { - System.out.print("techne> "); + public void run() { + String line = null; + BufferedReader in = new BufferedReader(new InputStreamReader( + System.in)); - try { - line = in.readLine(); - } catch (IOException ex) { - System.err.println("Could not read input, please try again."); - continue; - } + while (!stopping) { + System.out.print("techne> "); - synchronized (Shell.this) - { - if (line == null) - { - continue; - } + try { + line = in.readLine(); + } catch (IOException ex) { + System.err + .println("Could not read input, please try again."); + continue; + } - line = line.trim(); + synchronized (Shell.this) { + if (line == null) { + continue; + } - if (line.length() == 0) - { - continue; - } + line = line.trim(); - try { - runCommand(line, System.out, System.err); - } catch (Exception ex) { - System.err.println("ERROR: " + ex); - ex.printStackTrace(); - } - } - } + if (line.length() == 0) { + continue; + } + + try { + runCommand(line, System.out, System.err); + } catch (Exception ex) { + System.err.println("ERROR: " + ex); + ex.printStackTrace(); + } + } + } } - + /* * Will use Command pattern later on. */ public void runCommand(String line, PrintStream out, PrintStream err) { - if (line.equals("set framework to Felix")) { if (FRAMEWORK_SET) { out.print("Framework has already been set to Felix\n"); @@ -127,52 +139,27 @@ frameworkThread = new Thread(felix); frameworkThread.setPriority(1); frameworkThread.start(); - - try { - - } catch (Exception e) { - e.printStackTrace(); - } } - } else if (line.equals("set container type to web")) { - List list = containerFactory.getContainerTypes(); - for (int i = 0; i < list.size(); i++) { - containertype ct = (containertype)list.get(i); - Map props = ct.getProperties(); - String type = (String)props.get("value"); - if (type.equals("web")) { - bundleList = ct.getBundles(); - for (int j = 0; j < bundleList.size(); j++) { - bundle b = (bundle)bundleList.get(j); - Map p = b.getProperties(); - execute("start " + p.get("url"), System.out, System.out); - } - } + } else if (line.startsWith("set container type to")) { + switchContainerTypeCommand(line, out, err); + } else if (line.equals("show container type")) { + System.out.println("container type is " + + containerState.getType()); + } else if (line.equals("inspect container")) { + System.out.println(containerState.toString()); + } else if (line.equals("exit") || line.equals("quit")) { + stopping = true; + try { + Runtime.getRuntime().halt(0); + } catch (Exception e) { + e.printStackTrace(); + } finally { + System.exit(0); } - containerType = "web"; - } else if (line.equals("set container type to basic") || line.equals("set container type to default")) { - if (containerType.equals("web")) { - int id = 4; - for (int j = 0; j < bundleList.size(); j++) { - execute("uninstall " + id, System.out, System.out); - id++; - } - } - containerType = "basic"; - } else if (line.equals("show container type")) { - System.out.println("Container type is " + containerType); - } else if (line.equals("exit") || line.equals("quit") ) { - stopping = true; - try { - Runtime.getRuntime().halt(0); - } catch (Exception e) { - e.printStackTrace(); - } finally { - System.exit(0); - } } else { // assume that it is a framework command - //out.print("Unsupported command. Please try another command.\n"); - execute(line, System.out, System.out); + // out.print("Unsupported command. Please try another + // command.\n"); + execute(line, System.out, System.out); } } }; @@ -180,92 +167,179 @@ techneThread.setPriority(5); techneThread.start(); } - + + private void switchContainerTypeCommand(String line, PrintStream out, + PrintStream err) { + String wantType = line.substring(line.lastIndexOf(' ')).trim() + .toLowerCase(); + List newBundles = new Vector(); + Stack removeBundles = new Stack(); + + // create "plan" (which to remove and which bundles to install + if (wantType.equals(containerState.getType())) { + out.println("container is already in type " + wantType); + return; + } else if (wantType.equalsIgnoreCase("basic") + || wantType.equalsIgnoreCase("default")) { + // just select "all" to be removed + removeBundles = containerState.getInstalledBundles(); + } else { + List list = containerFactory.getContainerTypes(); + removeBundles = containerState.getInstalledBundles(); + for (int i = 0; i < list.size(); i++) { + containertype ct = (containertype) list.get(i); + String type = (String) ct.getProperties().get("value"); + if (type.equals(wantType)) { + // found wanted type + for (Iterator itBundle = ct.getBundles().iterator(); itBundle + .hasNext();) { + bundle b = (bundle) itBundle.next(); + // check if already installed and running.. + // hook it + String newBundleURL = (String) b.getProperties().get( + "url"); + if (removeBundles.contains(newBundleURL)) { + removeBundles.remove(newBundleURL); + } else { + newBundles.add(newBundleURL); + } + } + } + } + } + // execute "plan" + // step 1: uninstall old + while (removeBundles.size() > 0) { + String bundleURL = (String) removeBundles.pop(); + containerState.remove(getBundleId(bundleURL), bundleURL); + execute("uninstall " + getBundleId(bundleURL), out, err); + } + // step 2: install new + for (Iterator itNew = newBundles.iterator(); itNew.hasNext();) { + String bundleURL = (String) itNew.next(); + execute("start " + bundleURL, out, err); + containerState.addInstalled(getBundleId(bundleURL), bundleURL); + } + // reset container type + containerState.setType(wantType); + } + + private long getBundleId(String newBundleURL) { + long id = -1; + try { + Bundle[] bundles = (context.getBundles()); + for (int i = 0; i < bundles.length; i++) { + Bundle bundle = bundles[i]; + if (bundle.getLocation().equals(newBundleURL)) { + return bundle.getBundleId(); + } + } + } catch (Exception e) { + // this may fail because of the dynamic nature + } + return id; + } + protected void execute(String line, PrintStream in, PrintStream out) { - ShellService shell = null; try { - Object[] args = {line, in, out}; - ServiceReference ref = context.getServiceReference(ShellService.class.getName()); - if (ref!=null) { - Object o = context.getService(ref); - System.out.println("o: " + o.getClass().getName() + " cl: " + o.getClass().getClassLoader()); - Class[] parameterTypes={String.class,PrintStream.class,PrintStream.class}; - executeCommand = o.getClass().getDeclaredMethod("executeCommand", parameterTypes); - executeCommand.setAccessible(true); - executeCommand.invoke(o, args); - } + Object[] args = { line, in, out }; + ServiceReference ref = context + .getServiceReference(ShellService.class.getName()); + if (ref != null) { + Object o = context.getService(ref); + System.out.println("o: " + o.getClass().getName() + " cl: " + + o.getClass().getClassLoader()); + Class[] parameterTypes = { String.class, PrintStream.class, + PrintStream.class }; + executeCommand = o.getClass().getDeclaredMethod( + "executeCommand", parameterTypes); + executeCommand.setAccessible(true); + executeCommand.invoke(o, args); + } } catch (NullPointerException npe) { - logger.warn("Could not invoke execute method: ", npe); - System.out.println("Cannot execute framework command. Please select a framework."); + logger.warn("Could not invoke execute method: ", npe); + System.out + .println("Cannot execute framework command. Please select a framework."); } catch (Exception e) { e.printStackTrace(); } } - + public static BundleContext getBundleContext(Bundle bundle) { try { - Class clazz = bundle.getClass(); - Method m = clazz.getDeclaredMethod("getContext", new Class[0]); - m.setAccessible(true); - return (BundleContext) m.invoke(bundle, new Object[0]); - } catch (Exception e) { - logger.error("getBundleContext failed", e); - e.printStackTrace(); - return null; - } + Class clazz = bundle.getClass(); + Method m = clazz.getDeclaredMethod("getContext", new Class[0]); + m.setAccessible(true); + return (BundleContext) m.invoke(bundle, new Object[0]); + } catch (Exception e) { + logger.error("getBundleContext failed", e); + e.printStackTrace(); + return null; + } } - + class FelixFrameworkThread implements Runnable { - + Bundle[] bundles; - + public void run() { try { - launcher = new FelixLauncher(); - launcher.launch(); - setContainer(); - System.out.print("techne> "); + launcher = new FelixLauncher(); + launcher.launch(); + initializeContainer(); + System.out.print("techne> "); } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } } /* - public Bundle[] getBundles() { - return launcher.getBundles(); - } - - public Object getService(Bundle b, ServiceReference ref) { - return launcher.getService(b, ref); - } - */ + * public Bundle[] getBundles() { return launcher.getBundles(); } + * + * public Object getService(Bundle b, ServiceReference ref) { return + * launcher.getService(b, ref); } + */ } - - protected void setContainer() { + + protected void initializeContainer() { try { - Method m = Felix.class.getDeclaredMethod("getBundle", new Class[] { long.class }); - m.setAccessible(true); - Bundle systemBundle = (Bundle) m.invoke(launcher.getFelix(), new Object[] { new Long(0) }); - System.out.println("systemBundle superclass: " + systemBundle.getClass().getSuperclass().getName()); - Method getContext = systemBundle.getClass().getSuperclass().getDeclaredMethod("getContext", null); - getContext.setAccessible(true); - context = (BundleContext) getContext.invoke(systemBundle, null); - System.out.println("BundleContext: " + context); - containerFactory = ContainerFactory.getInstance(); - containerFactory.init(); - containerInstances = containerFactory.getContainerInstances(); - System.out.println("Available container instances: " + containerInstances.size()); - System.out.println("Container type: " + DEFAULT_CONTAINER_TYPE); + Method m = Felix.class.getDeclaredMethod("getBundle", + new Class[] { long.class }); + m.setAccessible(true); + Bundle systemBundle = (Bundle) m.invoke(launcher.getFelix(), + new Object[] { new Long(0) }); + System.out.println("systemBundle superclass: " + + systemBundle.getClass().getSuperclass().getName()); + Method getContext = systemBundle.getClass().getSuperclass() + .getDeclaredMethod("getContext", null); + getContext.setAccessible(true); + context = (BundleContext) getContext.invoke(systemBundle, null); + System.out.println("BundleContext: " + context); + + loadContainer(); + } catch (Exception e) { e.printStackTrace(); } } + private void loadContainer() { + containerFactory = ContainerFactory.getInstance(); + + System.out.println("Available container instances: " + + containerFactory.getContainerInstances().size()); + // load default bundles + containerState = new ContainerState(DEFAULT_CONTAINER_TYPE); + // load + + System.out.println("Container type: " + containerState.getType()); + } + protected Shell getContainer() { - System.out.println("Container: " + container); + System.out.println("Container: " + container); return container; } - + /* * need to create a Techne event dispatcher later */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |