001 package org.crsh.shell.impl; 002 003 import groovy.lang.Script; 004 import org.crsh.command.GroovyScriptCommand; 005 import org.crsh.command.NoSuchCommandException; 006 import org.crsh.command.ShellCommand; 007 import org.crsh.plugin.PluginContext; 008 import org.crsh.plugin.ResourceKind; 009 010 import java.security.Principal; 011 012 /** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */ 013 public class CRaSH { 014 015 016 /** . */ 017 final ClassManager<ShellCommand> commands; 018 019 /** . */ 020 final ClassManager<Script> lifecycles; 021 022 /** . */ 023 final PluginContext context; 024 025 public CRaSH(PluginContext context) { 026 this.context = context; 027 this.commands = new ClassManager<ShellCommand>(context, ResourceKind.COMMAND, ShellCommand.class, GroovyScriptCommand.class); 028 this.lifecycles = new ClassManager<Script>(context, ResourceKind.LIFECYCLE, Script.class, Script.class); 029 } 030 031 public CRaSHSession createSession(Principal user) { 032 return new CRaSHSession(this, user); 033 } 034 035 /** 036 * Returns the plugin context. 037 * 038 * @return the plugin context 039 */ 040 public PluginContext getContext() { 041 return context; 042 } 043 044 /** 045 * Attempt to obtain a command instance. Null is returned when such command does not exist. 046 * 047 * @param name the command name 048 * @return a command instance 049 * @throws org.crsh.command.NoSuchCommandException if an error occured preventing the command creation 050 * @throws NullPointerException if the name argument is null 051 */ 052 public ShellCommand getCommand(String name) throws NoSuchCommandException, NullPointerException { 053 return commands.getInstance(name); 054 } 055 }