|
From: <ri...@us...> - 2007-03-07 08:54:37
|
Revision: 113
http://techne-dev.svn.sourceforge.net/techne-dev/?rev=113&view=rev
Author: rickles
Date: 2007-03-07 00:54:36 -0800 (Wed, 07 Mar 2007)
Log Message:
-----------
Checked in prototype
Added Paths:
-----------
prototype/org.digivitality.techne.shell/
prototype/org.digivitality.techne.shell/.classpath
prototype/org.digivitality.techne.shell/.project
prototype/org.digivitality.techne.shell/META-INF/
prototype/org.digivitality.techne.shell/META-INF/MANIFEST.MF
prototype/org.digivitality.techne.shell/build.properties
prototype/org.digivitality.techne.shell/build.xml
prototype/org.digivitality.techne.shell/classes/
prototype/org.digivitality.techne.shell/classes/org/
prototype/org.digivitality.techne.shell/classes/org/digivitality/
prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/
prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/
prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Activator.class
prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$1.class
prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$FelixFrameworkThread.class
prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$SubShell.class
prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell.class
prototype/org.digivitality.techne.shell/src/
prototype/org.digivitality.techne.shell/src/org/
prototype/org.digivitality.techne.shell/src/org/digivitality/
prototype/org.digivitality.techne.shell/src/org/digivitality/techne/
prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/
prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Activator.java
prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java
prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java
Added: prototype/org.digivitality.techne.shell/.classpath
===================================================================
--- prototype/org.digivitality.techne.shell/.classpath (rev 0)
+++ prototype/org.digivitality.techne.shell/.classpath 2007-03-07 08:54:36 UTC (rev 113)
@@ -0,0 +1,13 @@
+<?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.9.0-incubator-SNAPSHOT.jar"/>
+ <classpathentry kind="lib" path="/org.digivitality.techne.core/lib/org.apache.felix.main-0.9.0-incubator-SNAPSHOT.jar"/>
+ <classpathentry kind="lib" path="/org.digivitality.techne.component/classes"/>
+ <classpathentry kind="lib" path="/org.digivitality.techne.core/classes"/>
+ <classpathentry kind="output" path="classes"/>
+</classpath>
Added: prototype/org.digivitality.techne.shell/.project
===================================================================
--- prototype/org.digivitality.techne.shell/.project (rev 0)
+++ prototype/org.digivitality.techne.shell/.project 2007-03-07 08:54:36 UTC (rev 113)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.digivitality.techne.shell</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: prototype/org.digivitality.techne.shell/META-INF/MANIFEST.MF
===================================================================
--- prototype/org.digivitality.techne.shell/META-INF/MANIFEST.MF (rev 0)
+++ prototype/org.digivitality.techne.shell/META-INF/MANIFEST.MF 2007-03-07 08:54:36 UTC (rev 113)
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Shell Plug-in
+Bundle-SymbolicName: org.digivitality.techne.shell
+Bundle-Version: 1.0.0
+Bundle-Activator: org.digivitality.techne.shell.Activator
+Bundle-Vendor: Techne
+Bundle-Localization: plugin
+Import-Package: org.osgi.framework;version="1.3.0"
Added: prototype/org.digivitality.techne.shell/build.properties
===================================================================
--- prototype/org.digivitality.techne.shell/build.properties (rev 0)
+++ prototype/org.digivitality.techne.shell/build.properties 2007-03-07 08:54:36 UTC (rev 113)
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = classes/
+bin.includes = META-INF/,\
+ .
Added: prototype/org.digivitality.techne.shell/build.xml
===================================================================
--- prototype/org.digivitality.techne.shell/build.xml (rev 0)
+++ prototype/org.digivitality.techne.shell/build.xml 2007-03-07 08:54:36 UTC (rev 113)
@@ -0,0 +1,152 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="org.digivitality.techne.shell" default="build.jars" basedir=".">
+
+ <property name="basews" value="${ws}"/>
+ <property name="baseos" value="${os}"/>
+ <property name="basearch" value="${arch}"/>
+ <property name="basenl" value="${nl}"/>
+
+ <!-- Compiler settings. -->
+ <property name="javacFailOnError" value="false"/>
+ <property name="javacDebugInfo" value="on"/>
+ <property name="javacVerbose" value="false"/>
+ <property name="logExtension" value=".log"/>
+ <property name="compilerArg" value=""/>
+ <property name="javacSource" value="1.3"/>
+ <property name="javacTarget" value="1.2"/>
+ <path id="path_bootclasspath">
+ <fileset dir="${java.home}/lib">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+ <property name="bootclasspath" refid="path_bootclasspath"/>
+ <property name="bundleJavacSource" value="${javacSource}"/>
+ <property name="bundleJavacTarget" value="${javacTarget}"/>
+ <property name="bundleBootClasspath" value="${bootclasspath}"/>
+
+ <target name="init" depends="properties">
+ <condition property="pluginTemp" value="${buildTempFolder}/plugins">
+ <isset property="buildTempFolder"/>
+ </condition>
+ <property name="pluginTemp" value="${basedir}"/>
+ <condition property="build.result.folder" value="${pluginTemp}/org.digivitality.techne.shell">
+ <isset property="buildTempFolder"/>
+ </condition>
+ <property name="build.result.folder" value="${basedir}"/>
+ <property name="temp.folder" value="${basedir}/temp.folder"/>
+ <property name="plugin.destination" value="${basedir}"/>
+ </target>
+
+ <target name="properties" if="eclipse.running">
+ <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
+
+ </target>
+
+ <target name="build.update.jar" depends="init" description="Build the plug-in: org.digivitality.techne.shell for an update site.">
+ <delete dir="${temp.folder}"/>
+ <mkdir dir="${temp.folder}"/>
+ <antcall target="build.jars"/>
+ <antcall target="gather.bin.parts">
+ <param name="destination.temp.folder" value="${temp.folder}/"/>
+ </antcall>
+ <zip destfile="${plugin.destination}/org.digivitality.techne.shell_1.0.0.jar" basedir="${temp.folder}/org.digivitality.techne.shell_1.0.0" filesonly="false" whenempty="skip" update="false"/>
+ <delete dir="${temp.folder}"/>
+ </target>
+
+ <target name="@dot" depends="init" unless="@dot" description="Create jar: org.digivitality.techne.shell @dot.">
+ <delete dir="${temp.folder}/@dot.bin"/>
+ <mkdir dir="${temp.folder}/@dot.bin"/>
+ <path id="@dot.classpath">
+ <pathelement path="../../../../../../eclipse-wbt-3.2/eclipse/plugins/org.eclipse.osgi_3.2.0.v20060601.jar"/>
+ </path>
+ <!-- compile the source code -->
+ <javac destdir="${temp.folder}/@dot.bin" failonerror="${javacFailOnError}" verbose="${javacVerbose}" debug="${javacDebugInfo}" includeAntRuntime="no" bootclasspath="${bundleBootClasspath}" source="${bundleJavacSource}" target="${bundleJavacTarget}" >
+ <compilerarg line="${compilerArg}" compiler="${build.compiler}"/>
+ <classpath refid="@dot.classpath" />
+ <src path="src/" />
+ <compilerarg value="@${basedir}/javaCompiler...args" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"/>
+ <compilerarg line="-log '${temp.folder}/@dot.bin${logExtension}'" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"/>
+ </javac>
+ <!-- Copy necessary resources -->
+ <copy todir="${temp.folder}/@dot.bin" failonerror="true" overwrite="false">
+ <fileset dir="src/" excludes="**/*.java, **/package.htm*" />
+ </copy>
+ <mkdir dir="${build.result.folder}"/>
+ <copy todir="${build.result.folder}/@dot" failonerror="true" overwrite="false">
+ <fileset dir="${temp.folder}/@dot.bin" />
+ </copy>
+ <delete dir="${temp.folder}/@dot.bin"/>
+ </target>
+
+ <target name="src.zip" depends="init" unless="src.zip">
+ <mkdir dir="${build.result.folder}"/>
+ <zip destfile="${build.result.folder}/src.zip" filesonly="false" whenempty="skip" update="false">
+ <fileset dir="src/" includes="**/*.java" />
+ </zip>
+ </target>
+
+ <target name="build.jars" depends="init" description="Build all the jars for the plug-in: org.digivitality.techne.shell.">
+ <available property="@dot" file="${build.result.folder}/@dot"/>
+ <antcall target="@dot"/>
+ </target>
+
+ <target name="build.sources" depends="init">
+ <available property="src.zip" file="${build.result.folder}/src.zip"/>
+ <antcall target="src.zip"/>
+ </target>
+
+ <target name="gather.bin.parts" depends="init" if="destination.temp.folder">
+ <mkdir dir="${destination.temp.folder}/org.digivitality.techne.shell_1.0.0"/>
+ <copy todir="${destination.temp.folder}/org.digivitality.techne.shell_1.0.0" failonerror="true" overwrite="false">
+ <fileset dir="${build.result.folder}/@dot" includes="**" />
+ </copy>
+ <copy todir="${destination.temp.folder}/org.digivitality.techne.shell_1.0.0" failonerror="true" overwrite="false">
+ <fileset dir="${basedir}" includes="META-INF/" />
+ </copy>
+ </target>
+
+ <target name="build.zips" depends="init">
+ </target>
+
+ <target name="gather.sources" depends="init" if="destination.temp.folder">
+ <mkdir dir="${destination.temp.folder}/org.digivitality.techne.shell_1.0.0"/>
+ <copy file="${build.result.folder}/src.zip" todir="${destination.temp.folder}/org.digivitality.techne.shell_1.0.0" failonerror="false" overwrite="false"/>
+ </target>
+
+ <target name="gather.logs" depends="init" if="destination.temp.folder">
+ <mkdir dir="${destination.temp.folder}/org.digivitality.techne.shell_1.0.0"/>
+ <copy file="${temp.folder}/@dot.bin${logExtension}" todir="${destination.temp.folder}/org.digivitality.techne.shell_1.0.0" failonerror="false" overwrite="false"/>
+ </target>
+
+ <target name="clean" depends="init" description="Clean the plug-in: org.digivitality.techne.shell of all the zips, jars and logs created.">
+ <delete dir="${build.result.folder}/@dot"/>
+ <delete file="${build.result.folder}/src.zip"/>
+ <delete file="${plugin.destination}/org.digivitality.techne.shell_1.0.0.jar"/>
+ <delete file="${plugin.destination}/org.digivitality.techne.shell_1.0.0.zip"/>
+ <delete dir="${temp.folder}"/>
+ </target>
+
+ <target name="refresh" depends="init" if="eclipse.running" description="Refresh this folder.">
+ <eclipse.convertPath fileSystemPath="C:/Workspace/eclipse-3.2/techne/sandbox/rickles/org.digivitality.techne.shell" property="resourcePath"/>
+ <eclipse.refreshLocal resource="${resourcePath}" depth="infinite"/>
+ </target>
+
+ <target name="zip.plugin" depends="init" description="Create a zip containing all the elements for the plug-in: org.digivitality.techne.shell.">
+ <delete dir="${temp.folder}"/>
+ <mkdir dir="${temp.folder}"/>
+ <antcall target="build.jars"/>
+ <antcall target="build.sources"/>
+ <antcall target="gather.bin.parts">
+ <param name="destination.temp.folder" value="${temp.folder}/"/>
+ </antcall>
+ <antcall target="gather.sources">
+ <param name="destination.temp.folder" value="${temp.folder}/"/>
+ </antcall>
+ <delete>
+ <fileset dir="${temp.folder}" includes="**/*.bin${logExtension}" />
+ </delete>
+ <zip destfile="${plugin.destination}/org.digivitality.techne.shell_1.0.0.zip" basedir="${temp.folder}" filesonly="true" whenempty="skip" update="false"/>
+ <delete dir="${temp.folder}"/>
+ </target>
+
+</project>
Added: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Activator.class
===================================================================
(Binary files differ)
Property changes on: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Activator.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$1.class
===================================================================
(Binary files differ)
Property changes on: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$1.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$FelixFrameworkThread.class
===================================================================
(Binary files differ)
Property changes on: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$FelixFrameworkThread.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$SubShell.class
===================================================================
(Binary files differ)
Property changes on: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell$SubShell.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell.class
===================================================================
(Binary files differ)
Property changes on: prototype/org.digivitality.techne.shell/classes/org/digivitality/techne/shell/Shell.class
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Activator.java
===================================================================
--- prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Activator.java (rev 0)
+++ prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Activator.java 2007-03-07 08:54:36 UTC (rev 113)
@@ -0,0 +1,24 @@
+package org.digivitality.techne.shell;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class Activator implements BundleActivator {
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ System.out.println("Hello World!!");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ System.out.println("Goodbye World!!");
+ }
+
+}
Added: prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java
===================================================================
--- prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java (rev 0)
+++ prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Main.java 2007-03-07 08:54:36 UTC (rev 113)
@@ -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();
+ }
+
+}
Added: prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java
===================================================================
--- prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java (rev 0)
+++ prototype/org.digivitality.techne.shell/src/org/digivitality/techne/shell/Shell.java 2007-03-07 08:54:36 UTC (rev 113)
@@ -0,0 +1,623 @@
+/**
+ *
+ */
+package org.digivitality.techne.shell;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+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.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.component.ComponentManager;
+import org.digivitality.techne.component.Feature;
+import org.digivitality.techne.component.Fragment;
+import org.digivitality.techne.component.interfaces.Component;
+import org.digivitality.techne.core.ContainerFactory;
+import org.digivitality.techne.core.FunctionalArchiveImpl;
+import org.digivitality.techne.core.interfaces.ContainerInstance;
+import org.digivitality.techne.core.interfaces.FunctionalArchive;
+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.
+ *
+ * @author Rick Liton
+ *
+ */
+public class Shell implements FrameworkListener {
+
+ private static boolean FRAMEWORK_SET;
+ 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;
+ protected 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 = "basic";
+ private ComponentManager cm = new ComponentManager();
+ private int componentId = 4;
+ static int FIELD_LEN = 11;
+ private int farId = 0;
+ protected String prompt = "techne> ";
+
+ 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();
+ }
+
+ 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(prompt);
+
+ try {
+ line = in.readLine();
+ } catch (IOException ex) {
+ System.err.println("Could not read input, please try again.");
+ continue;
+ }
+
+ synchronized (Shell.this)
+ {
+ if (line == null)
+ {
+ continue;
+ }
+
+ line = line.trim();
+
+ 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");
+ } else {
+ felix = new FelixFrameworkThread();
+ 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);
+ }
+ }
+ }
+ 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("show bundles")) {
+ execute("ps", System.out, System.out);
+ } else if (line.equals("show components")) {
+ Object[] objs = cm.getComponents().toArray();
+ List fragments = new ArrayList();
+ List features = new ArrayList();
+ printHeaders();
+ for (int i = 0; i < objs.length; i++) {
+ ArrayList list = (ArrayList)objs[i];
+ Object[] components = list.toArray();
+ for (int j = 0; j < components.length; j++){
+ if (components[j] instanceof org.digivitality.techne.component.Fragment)
+ fragments.add(components[j]);
+ else if (components[j] instanceof org.digivitality.techne.component.Feature)
+ features.add(components[j]);
+ }
+ }
+ displayComponents(fragments, features, null);
+ } else if (line.startsWith("create fragment ")) {
+ int pos1 = line.indexOf('\'');
+ int pos2 = line.lastIndexOf('\'');
+ int pos3 = line.lastIndexOf("using ");
+ String name = line.substring(pos1 + 1, pos2);
+ String url = line.substring(pos3 + 6);
+ File file = new File(url);
+ //System.out.println("url: " + url);
+ try {
+ Fragment f = new Fragment(name, file.toURL(), "1.0", Integer.toString(componentId));
+ componentId++;
+ System.out.println("Fragment " + f.getName() + " with id " + f.getId() + " created");
+ cm.addFragment(f);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (line.startsWith("create feature ")) {
+ int pos1 = line.indexOf('\'');
+ int pos2 = line.lastIndexOf('\'');
+ int pos3 = line.lastIndexOf("using ");
+ String name = line.substring(pos1 + 1, pos2);
+ try {
+ Feature ft = new Feature(name, "1.0", Integer.toString(componentId));
+ componentId++;
+ System.out.println("Feature " + ft.getName() + " with id " + ft.getId() + " created");
+ cm.addFeature(ft);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (line.startsWith("add component")) {
+ String[] tokens = line.split(" ");
+ String id = tokens[2];
+ int pos1 = line.indexOf('\'');
+ int pos2 = line.lastIndexOf('\'');
+ String farName = line.substring(pos1 + 1, pos2);
+ FunctionalArchive far = null;
+ try {
+ far = (FunctionalArchive)cm.find(farName);
+ far.add(cm.getComponent(id));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println("Component " + id + " added to far '" + far.getName() + "' for assembly");
+ } else if (line.startsWith("add ")) {
+ String[] tokens = line.split(" ");
+ //System.out.println("Number of tokens: " + tokens.length);
+ String id = tokens[1];
+ StringBuffer sb = new StringBuffer();
+ for (int i = 3; i < tokens.length; i++) {
+ sb.append(tokens[i]);
+ // there's more
+ if (i < tokens.length)
+ sb.append(" ");
+ }
+ String feature = sb.toString();
+ System.out.println("feature = " + feature);
+ // right now, assume all components to be added are fragments
+ Fragment f = cm.addFragmentToFeature(id, feature);
+ System.out.println("Added fragment " + f.getName() + " to " + feature);
+ } else if (line.equals("show container")) {
+ printHeaders();
+ displayContainer();
+ } else if (line.startsWith("show far")) {
+ String[] tokens = line.split(" ");
+ String id = tokens[2];
+ int pos1 = line.indexOf('\'');
+ int pos2 = line.lastIndexOf('\'');
+ String farName = line.substring(pos1 + 1, pos2);
+ FunctionalArchive far = null;
+ try {
+ far = (FunctionalArchive)cm.find(farName);
+ System.out.println("Info: Enter sub-shell to view the FAR assembly");
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (line.startsWith("create far")) {
+ int pos1 = line.indexOf('\'');
+ int pos2 = line.lastIndexOf('\'');
+ String name = line.substring(pos1 + 1, pos2);
+ try {
+ FunctionalArchive far = new FunctionalArchiveImpl(name, Integer.toString(farId));
+ componentId++;
+ System.out.println("FAR assembly `" + far.getName() + "' with id " + far.getId() + " created");
+ cm.register(far.getName(), far);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (line.startsWith("load")) {
+ int pos1 = line.indexOf('\'');
+ int pos2 = line.lastIndexOf('\'');
+ String source = line.substring(pos1 + 1, pos2);
+ FunctionalArchive far = (FunctionalArchive)cm.find(source);
+ String target = line.substring(pos2);
+ target = target.trim();
+ if (target.contains("to instance")) {
+ String instanceId = target.substring(14);
+ //System.out.println("instanceId = " + instanceId);
+ containerFactory.load(far, instanceId.trim());
+ }
+ System.out.println("FAR assembly has been loaded.");
+ } else if (line.startsWith("switch to")) {
+ String instanceId = line.substring(10);
+ System.out.println("instanceName = " + instanceId);
+ ContainerInstance ci = containerFactory.getContainerInstance(instanceId);
+ //Thread t = ci.getInstanceThread();
+ try {
+ Thread t = new Thread(new SubShell(ci));
+ t.start();
+ try {
+ t.join();
+ } catch (InterruptedException ioe) {
+ ioe.printStackTrace();
+ }
+ } catch (Exception e) {
+ System.out.println("Error: No far assembly loaded. Load far and try again.");
+ }
+ } 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);
+ }
+ }
+ };
+ techneThread = new Thread(shell);
+ techneThread.setPriority(5);
+ techneThread.start();
+ }
+
+ private 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);
+ }
+ } catch (NullPointerException npe) {
+ 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 String getContainerType() {
+ return containerType;
+ }
+
+ 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 FelixFrameworkThread implements Runnable {
+
+ Bundle[] bundles;
+
+ public void run() {
+ try {
+ launcher = new FelixLauncher();
+ launcher.launch();
+ setContainer();
+ System.out.print(prompt);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ public Bundle[] getBundles() {
+ return launcher.getBundles();
+ }
+
+ public Object getService(Bundle b, ServiceReference ref) {
+ return launcher.getService(b, ref);
+ }
+ */
+ }
+
+ class SubShell implements Runnable {
+
+ private String name;
+ private ContainerInstance instance;
+ public boolean waiting;
+ private FunctionalArchive far;
+
+ SubShell(ContainerInstance instance) {
+ this.instance = instance;
+ far = instance.getFAR();
+ setName(far.getName());
+ prompt();
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void prompt() {
+ prompt = name + "> ";
+ }
+
+ public void run() {
+ String line = null;
+ BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+
+ while (true)
+ {
+ System.out.print(prompt);
+
+ try {
+ line = in.readLine();
+ } catch (IOException ex) {
+ System.err.println("Could not read input, please try again.");
+ continue;
+ }
+
+ synchronized (SubShell.this)
+ {
+ if (line == null)
+ {
+ continue;
+ }
+
+ line = line.trim();
+
+ if (line.length() == 0)
+ {
+ continue;
+ }
+
+ try {
+ subCommand(line, System.out, System.err);
+ if (waiting)
+ break;
+ } catch (Exception ex) {
+ System.err.println("ERROR: " + ex);
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private void subCommand(String line, PrintStream in, PrintStream out) {
+ if (line.equals("exit")) {
+ System.out.println("Exiting this instance... ");
+ prompt = "techne> ";
+ waiting = true;
+ try {
+ Thread t = Thread.currentThread();
+ t.interrupt();
+ //t = null;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (line.equals("show instance")) {
+ displayInstance();
+ }
+ }
+
+ private void displayInstance() {
+ List list = far.getComponents();
+ Iterator iter = list.iterator();
+ printHeaders();
+ while (iter.hasNext()) {
+ Component c = (Component)iter.next();
+ String n = c.getName();
+ String s = c.getState();
+ String v = c.getVersion();
+ String id = c.getId();
+ String t = c.getType();
+ String spad = getPadding(s);
+ String cpad = getPadding(t);
+ System.out.println("[ " + id + "] " + "[" + s + spad + "] [" + t + cpad + "] " + n + " (" + v + ")");
+ }
+ }
+ }
+
+ protected void setContainer() {
+ 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(this);
+ containerInstances = containerFactory.getContainerInstances();
+ System.out.println("Available container instances: " + containerInstances.size());
+ System.out.println("Container type: " + DEFAULT_CONTAINER_TYPE);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void displayComponents(List fragments, List features, List featureSets) {
+ // display fragments, features, feature sets in this order
+ if (fragments != null) {
+ Iterator iter = fragments.iterator();
+ while (iter.hasNext()) {
+ Fragment f = (Fragment)iter.next();
+ String n = f.getName();
+ String s = f.getState();
+ String v = f.getVersion();
+ String id = f.getId();
+ System.out.println("[ " + id + "] " + "[" + s + "] [Fragment ] " + n + " (" + v + ")");
+ }
+ }
+
+ if (features != null) {
+ Iterator iter2 = features.iterator();
+ String name = null;
+ while (iter2.hasNext()) {
+ Feature ft = (Feature)iter2.next();
+ String n = ft.getName();
+ String s = ft.getState();
+ String v = ft.getVersion();
+ String id = ft.getId();
+ List list = ft.getFragments();
+ String dependency = null;
+ if (list.size() > 0) {
+ Iterator iter = list.iterator();
+ int i = 0;
+ while (iter.hasNext()) {
+ Fragment f = (Fragment)iter.next();
+ if (i == 0)
+ dependency = f.getId();
+ else
+ dependency += "," + f.getId();
+ i++;
+ }
+ dependency = " -> " + dependency;
+ }
+ if (dependency == null)
+ dependency = "";
+ if (name == null || !name.equals(n))
+ System.out.println("[ " + id + "] " + "[" + s + "] [Feature ] " + n + " (" + v + ")" + dependency);
+ //name = n;
+ }
+ }
+ }
+
+ private void displayContainer() {
+ List list = containerFactory.getContainerInstances();
+ ContainerInstance[] instances = (ContainerInstance[])list.toArray(new ContainerInstance[list.size()]);
+ //System.out.println("instances: " + instances.length);
+ for (int i = 0; i < instances.length; i++) {
+ ContainerInstance ci = (ContainerInstance)instances[i];
+ String n = ci.getName();
+ String s = ci.getState();
+ String id = ci.getId();
+ String spad = getPadding(s);
+ String cpad = getPadding(containerType);
+ FunctionalArchive far = ci.getFAR();
+ String dependency = null;
+ if (far != null)
+ dependency = " -> " + far.getName();
+ if (dependency == null)
+ dependency = "";
+ System.out.println("[ " + id + "] " + "[" + s + spad + "] [" + firstToUpper(containerType) + cpad + "] " + n + dependency);
+ ci = null;
+ }
+ }
+
+ private void printHeaders() {
+ System.out.println("START LEVEL 1");
+ System.out.println(" ID State Type Name");
+ }
+
+ private String getPadding(String s) {
+ //System.out.println("s is " + s);
+ String space = " ";
+ if (s != null) {
+ int len = FIELD_LEN - s.length();
+ char[] padding = new char[len];
+ for (int i = 0; i < len; i++) {
+ padding[i] = ' ';
+ }
+ return new String(padding);
+ }
+ return space;
+ }
+
+ private String firstToUpper(String s){
+ char[] chars = s.toCharArray();
+ String first = "" + chars[0];
+ return (first.toUpperCase() + s.substring(1));
+ }
+
+ protected Shell getContainer() {
+ System.out.println("Container: " + container);
+ return container;
+ }
+
+ /*
+ * need to create a Techne event dispatcher later
+ */
+ public void frameworkEvent(FrameworkEvent event) {
+ // will implement later
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|