Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010, 2012 IBM Corporation, SAP AG. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: Thomas Watson, IBM Corporation - initial API and implementation Lazar Kirchev, SAP AG - initial API and implementation /
 
 
 package org.eclipse.equinox.console.command.adapter;
 
 import java.util.List;
 
The activator class controls the plug-in life cycle
 
 public class Activator implements BundleActivator {
 	private static boolean isFirstProcessor = true;
 	private static TelnetCommand telnetConnection = null;
 	
 	// Tracker for Equinox CommandProviders
 	
 
 	public static class ProcessorCustomizer implements
 
 		private final BundleContext context;
 
 		public ProcessorCustomizer(BundleContext context) {
 			this. = context;
 		}
 
 			CommandProcessor processor = .getService(reference);
 			if (processor == null)
 				return null;
 			
 			if () {
 				 = false;
 				 = new TelnetCommand(processor);
 			} else {
 			}
 			
 			tracker.open();
 			return tracker;
 		}
 
 		public void modifiedService(
 			// nothing
 		}
 
		public void removedService(
			tracker.close();
			CommandProcessor processor = .getService(reference);
		}	
	}
	// Provides support for Equinox ConsoleSessions
	public static class SessionCustomizer implements
		private final BundleContext context;
		public SessionCustomizer(BundleContext contextCommandProcessor processor) {
			this. = context;
			this. = processor;
		}
			final ConsoleSession equinoxSession = .getService(reference);
			if (equinoxSession == null)
				return null;
			PrintStream output = new PrintStream(equinoxSession.getOutput());
			final CommandSession gogoSession = .createSession(equinoxSession.getInput(), outputoutput);
			new Thread(new Runnable(){
				public void run() {
                    try {
                    	gogoSession.put("SCOPE""equinox:*");
                    	gogoSession.put("prompt""osgi> ");
                        gogoSession.execute("gosh --login --noshutdown");
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                    }
                    finally {
                        gogoSession.close();
                        equinoxSession.close();
                    }
				}
			}, "Equinox Console Session").start();
			return null;
		}
				CommandSession service) {
			// nothing
		}
				CommandSession session) {
			session.close();
		}
	}
	// All commands, provided by an Equinox CommandProvider, are registered as provided by a CommandProviderAdapter.
	public class CommandCustomizer implements
		public CommandCustomizer(BundleContext context) {
			this. = context;
		}
			if (reference.getProperty("osgi.command.function") != null) {
				// must be a gogo function already; don' track
				return null;
			}
			CommandProvider command = .getService(reference);
			try {
				Method[] commandMethods = getCommandMethods(command);
				if (commandMethods.length > 0) {
					List<ServiceRegistration<?>> registrations = new ArrayList<ServiceRegistration<?>>();
					registrations.add(.registerService(Object.classnew CommandProviderAdapter((CommandProvidercommandcommandMethods), getAttributes(commandMethods)));
					return registrations;
else {
					return null;
				}
catch (Exception e) {
				return null;
			}
		}
		public void modifiedService(ServiceReference<CommandProviderreferenceList<ServiceRegistration<?>> service) {
			// Nothing to do.
		}
		public void removedService(ServiceReference<CommandProviderreferenceList<ServiceRegistration<?>> registrations) {
			for (ServiceRegistration<?> serviceRegistration : registrations) {
				serviceRegistration.unregister();
			}
		}
	}
	public void start(BundleContext contextthrows Exception {
		// grab permission admin
		HelpCommand helpCommand = new HelpCommand(context); 
		helpCommand.startService();
		ManCommand manCommand = new ManCommand(context);
		manCommand.startService();
		DisconnectCommand disconnectCommand = new DisconnectCommand(context);
		disconnectCommand.startService();
		startBundle("org.apache.felix.gogo.runtime"true);
		startBundle("org.apache.felix.gogo.shell"true);
		startBundle("org.apache.felix.gogo.command"false);
	}
	private void startBundle(String bsnboolean requiredthrows BundleException {
		if (pa != null) {
			@SuppressWarnings("deprecation")
			Bundle[] shells = pa.getBundles(bsnnull);
			if (shells != null && shells.length > 0) {
else if (required) {
				throw new BundleException("Missing required bundle: " + bsn);
			}
		}
	}
	}
	}
	}
	}
	}
	private static Object getServiceFromTracker(ServiceTracker<?, ?> trackerString serviceClass) {
		if (tracker == null)
			throw new IllegalStateException("Missing service: " + serviceClass);
		Object result = tracker.getService();
		if (result == null)
			throw new IllegalStateException("Missing service: " + serviceClass);
		return result;
	}
		ArrayList<Methodnames = new ArrayList<Method>();
		Class<?> c = command.getClass();
		Method[] methods = c.getDeclaredMethods();
		for (Method method : methods) {
			if (method.getName().startsWith("_")
					&& method.getModifiers() == . && !method.getName().equals("_help")) {
				Type[] types = method.getGenericParameterTypes();
				if (types.length == 1
						&& types[0].equals(CommandInterpreter.class)) {
					names.add(method);
				}
			}
		}
		return names.toArray(new Method[names.size()]);
	}
	Dictionary<StringObjectgetAttributes(Method[] commandMethods) {
		dict.put("osgi.command.scope""equinox");
		String[] methodNames = new String[commandMethods.length];
		for (int i = 0; i < commandMethods.lengthi++) {
			String methodName = "" + commandMethods[i].getName().substring(1);
			methodNames[i] = methodName;
		}
		dict.put("osgi.command.function"methodNames);
		return dict;
	}
	public void stop(BundleContext contextthrows Exception {
		if ( != null) {
		}
		try {
catch (Exception e) {
			// expected if the telnet server is not started
		}
	}
New to GrepCode? Check out our FAQ X