A command is a scripted method or compiled command class implementing a specified method signature. Commands are loaded from the classpath and may be imported using the importCommands() method. This method searches the imported commands packages for a script or command object corre
( String name, Class [] argTypes, Interpreter interpreter )
| 876 | i.e. on errors loading a script that was found |
| 877 | */ |
| 878 | public Object getCommand( |
| 879 | String name, Class [] argTypes, Interpreter interpreter ) |
| 880 | throws UtilEvalError |
| 881 | { |
| 882 | if (Interpreter.DEBUG) Interpreter.debug("getCommand: "+name); |
| 883 | BshClassManager bcm = interpreter.getClassManager(); |
| 884 | |
| 885 | if ( importedCommands != null ) |
| 886 | { |
| 887 | // loop backwards for precedence |
| 888 | for(int i=importedCommands.size()-1; i>=0; i--) |
| 889 | { |
| 890 | String path = importedCommands.get(i); |
| 891 | |
| 892 | String scriptPath; |
| 893 | if ( path.equals("/") ) |
| 894 | scriptPath = path + name +".bsh"; |
| 895 | else |
| 896 | scriptPath = path +"/"+ name +".bsh"; |
| 897 | |
| 898 | Interpreter.debug("searching for script: "+scriptPath ); |
| 899 | |
| 900 | InputStream in = bcm.getResourceAsStream( scriptPath ); |
| 901 | |
| 902 | if ( in != null ) |
| 903 | return loadScriptedCommand( |
| 904 | in, name, argTypes, scriptPath, interpreter ); |
| 905 | |
| 906 | // Chop leading "/" and change "/" to "." |
| 907 | String className; |
| 908 | if ( path.equals("/") ) |
| 909 | className = name; |
| 910 | else |
| 911 | className = path.substring(1).replace('/','.') +"."+name; |
| 912 | |
| 913 | Interpreter.debug("searching for class: "+className); |
| 914 | Class clas = bcm.classForName( className ); |
| 915 | if ( clas != null ) |
| 916 | return clas; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | if ( parent != null ) |
| 921 | return parent.getCommand( name, argTypes, interpreter ); |
| 922 | else |
| 923 | return null; |
| 924 | } |
| 925 | |
| 926 | protected BshMethod getImportedMethod( String name, Class [] sig ) |
| 927 | throws UtilEvalError |
no test coverage detected