From: <ri...@us...> - 2007-03-03 10:52:20
|
Revision: 100 http://techne-dev.svn.sourceforge.net/techne-dev/?rev=100&view=rev Author: rickles Date: 2007-03-03 02:52:20 -0800 (Sat, 03 Mar 2007) Log Message: ----------- Activated several new commands for demo. Modified Paths: -------------- sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java 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 10:51:03 UTC (rev 99) +++ sandbox/rickles/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java 2007-03-03 10:52:20 UTC (rev 100) @@ -4,9 +4,8 @@ package org.digivitality.techne.shell; import java.io.*; -import java.text.*; import java.util.List; -import java.lang.reflect.Field; +import java.util.Map; import java.lang.reflect.Method; import org.apache.commons.logging.Log; @@ -16,12 +15,12 @@ import org.osgi.framework.FrameworkEvent; import org.osgi.framework.FrameworkListener; 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 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.*; /** @@ -43,11 +42,12 @@ private Thread frameworkThread; protected FelixLauncher launcher; protected FelixFrameworkThread felix; - //static ShellService shellService; private static Method executeCommand; private BundleContext context; protected Shell container; private List containerInstances; + private List bundleList; + private String containerType; public Shell() { @@ -134,6 +134,33 @@ 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); + } + } + } + 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 { @@ -155,28 +182,8 @@ } 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 { - //Class clazz = Class.forName("org.apache.felix.shell.ShellService"); Object[] args = {line, in, out}; ServiceReference ref = context.getServiceReference(ShellService.class.getName()); if (ref!=null) { @@ -186,8 +193,6 @@ executeCommand = o.getClass().getDeclaredMethod("executeCommand", parameterTypes); executeCommand.setAccessible(true); executeCommand.invoke(o, args); - //Thread.currentThread().setContextClassLoader(clazz.getClassLoader()); - //shell = ShellService.class.cast(o); } } catch (NullPointerException npe) { logger.warn("Could not invoke execute method: ", npe); @@ -200,13 +205,8 @@ 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); + m.setAccessible(true); return (BundleContext) m.invoke(bundle, new Object[0]); } catch (Exception e) { logger.error("getBundleContext failed", e); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |