EMMA Coverage Report (generated Mon Aug 23 17:21:34 CEST 2010)
[all classes][dmg.util]

COVERAGE SUMMARY FOR SOURCE FILE [CommandInterpreter.java]

nameclass, %method, %block, %line, %
CommandInterpreter.java100% (2/2)47%  (17/36)36%  (536/1507)44%  (132.3/302)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CommandInterpreter100% (1/1)40%  (6/15)34%  (411/1215)40%  (102.3/255)
CommandInterpreter (Object): void 0%   (0/1)0%   (0/9)0%   (0/4)
checkAclPermission (Authorizable, Object, String []): void 0%   (0/1)0%   (0/1)0%   (0/1)
command (CommandRequestable): Object 0%   (0/1)0%   (0/5)0%   (0/1)
command (String): String 0%   (0/1)0%   (0/147)0%   (0/27)
dumpCommands (): void 0%   (0/1)0%   (0/6)0%   (0/2)
dumpHelpHint (CommandInterpreter$_CommandEntry [], CommandInterpreter$_Comman... 0%   (0/1)0%   (0/37)0%   (0/6)
dumpHelpHint (String, CommandInterpreter$_CommandEntry, StringBuilder): void 0%   (0/1)0%   (0/131)0%   (0/23)
printCommandEntry (CommandInterpreter$_CommandEntry, int): void 0%   (0/1)0%   (0/226)0%   (0/35)
runHelp (Args): String 0%   (0/1)0%   (0/65)0%   (0/16)
execute (Object, int): Object 100% (1/1)50%  (170/337)53%  (40.3/76)
_addCommandListener (Object): void 100% (1/1)96%  (218/228)96%  (53.6/56)
<static initializer> 100% (1/1)100% (5/5)100% (2/2)
CommandInterpreter (): void 100% (1/1)100% (9/9)100% (4/4)
addCommandListener (Object): void 100% (1/1)100% (4/4)100% (2/2)
command (Args): Object 100% (1/1)100% (5/5)100% (1/1)
     
class CommandInterpreter$_CommandEntry100% (1/1)52%  (11/21)43%  (125/292)64%  (30/47)
checkArgs (int): boolean 0%   (0/1)0%   (0/16)0%   (0/1)
elements (): Enumeration 0%   (0/1)0%   (0/9)0%   (0/1)
getArgs (): String 0%   (0/1)0%   (0/35)0%   (0/1)
getFullHelp (): Field 0%   (0/1)0%   (0/3)0%   (0/1)
getHelpHint (): Field 0%   (0/1)0%   (0/3)0%   (0/1)
getMethodString (): String 0%   (0/1)0%   (0/19)0%   (0/1)
getName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
keys (): Enumeration 0%   (0/1)0%   (0/12)0%   (0/1)
setACLS (Object, Field): void 0%   (0/1)0%   (0/9)0%   (0/3)
toString (): String 0%   (0/1)0%   (0/58)0%   (0/6)
CommandInterpreter$_CommandEntry (String): void 100% (1/1)100% (37/37)100% (10/10)
get (String): CommandInterpreter$_CommandEntry 100% (1/1)100% (11/11)100% (1/1)
getACLS (): Field 100% (1/1)100% (3/3)100% (1/1)
getListener (int): Object 100% (1/1)100% (5/5)100% (1/1)
getMaxArgs (int): int 100% (1/1)100% (5/5)100% (1/1)
getMethod (int): Method 100% (1/1)100% (5/5)100% (1/1)
getMinArgs (int): int 100% (1/1)100% (5/5)100% (1/1)
put (String, CommandInterpreter$_CommandEntry): void 100% (1/1)100% (15/15)100% (3/3)
setFullHelp (Object, Field): void 100% (1/1)100% (9/9)100% (3/3)
setHelpHint (Object, Field): void 100% (1/1)100% (9/9)100% (3/3)
setMethod (int, Object, Method, int, int): void 100% (1/1)100% (21/21)100% (5/5)

1package dmg.util ;
2 
3import java.lang.reflect.Field;
4import java.lang.reflect.InvocationTargetException;
5import java.lang.reflect.Method;
6import java.util.Enumeration;
7import java.util.Hashtable;
8import java.util.StringTokenizer;
9/**
10  *
11  *   Scans a specified object and makes a special set
12  *   of methods available for dynamic invocation on
13  *   command strings.
14  *
15  *   <pre>
16  *      method syntax :
17  *      1)  public Object ac_&lt;key1&gt;_..._&lt;keyN&gt;(Args args)
18  *      2)  public Object ac_&lt;key1&gt;_..._&lt;keyN&gt;_$_n(Args args)
19  *      3)  public Object ac_&lt;key1&gt;_..._&lt;keyN&gt;_$_n_m(Args args)
20  *   </pre>
21  *   The first syntax requires a command string which exactly matches
22  *   the specified <code>key1</code> to <code>keyN</code>.
23  *   No extra arguments are excepted.
24  *   The second syntax allows exactly <code>n</code> extra arguments
25  *   following a matching sequence of keys. The third
26  *   syntax allows between <code>n</code> and <code>m</code>
27  *   extra arguments following a matching sequence of keys.
28  *   Each ac_ method may have a corresponding one line help hint
29  *   with the following signature.
30  *   <pre>
31  *       String hh_&lt;key1&gt;_..._&lt;keyN&gt; = "..." ;
32  *   </pre>
33  *   The assigned string should only present the
34  *   additional arguments and shouldn't repeat the command part
35  *   itself.
36  *   A full help can be made available with the signature
37  *   <pre>
38  *       String fh_&lt;key1&gt;_..._&lt;keyN&gt; = "..." ;
39  *   </pre>
40  *   The assigned String should contain a detailed multiline
41  *   description of the command. This text is returned
42  *   as a result of the <code>help ... </code> command.
43  *   Consequently <code>help</code> is a reserved keyword
44  *   and can't be used as first key.
45  *   <p>
46  *
47  */
48public class CommandInterpreter implements Interpretable {
49 
50   static private class _CommandEntry {
51      Hashtable<String, _CommandEntry> _hash     = null ;
52      String    _name     = "" ;
53      Method [] _method   = new Method[2] ;
54      int    [] _minArgs  = new int[2] ;
55      int    [] _maxArgs  = new int[2] ;
56      Object [] _listener = new Object[5] ;
57      Field     _fullHelp = null ;
58      Field     _helpHint = null ;
59      Field     _acls     = null ;
60 
61      _CommandEntry( String com ){ _name   = com ; }
62 
63      String getName(){ return _name ; }
64 
65      void setMethod( int methodType , Object commandListener ,
66                      Method m , int mn , int mx                    ){
67 
68         _method[methodType]   = m ;
69         _minArgs[methodType]  = mn ;
70         _maxArgs[methodType]  = mx ;
71         _listener[methodType] = commandListener ;
72      }
73      Method getMethod( int type ){ return _method[type] ; }
74      Object getListener( int type ){ return _listener[type] ; }
75      int getMinArgs( int type ){ return _minArgs[type] ; }
76      int getMaxArgs( int type ){ return _maxArgs[type] ; }
77 
78      void setFullHelp( Object commandListener , Field f ){
79         _fullHelp = f ;
80         _listener[CommandInterpreter.FULL_HELP] = commandListener ;
81      }
82      void setHelpHint( Object commandListener , Field f ){
83         _helpHint = f ;
84         _listener[CommandInterpreter.HELP_HINT] = commandListener ;
85      }
86      void setACLS( Object commandListener , Field f ){
87         _acls = f ;
88         _listener[CommandInterpreter.ACLS] = commandListener ;
89      }
90      Field getACLS(){ return _acls ; }
91      Field getFullHelp(){ return _fullHelp ; }
92      Field getHelpHint(){ return _helpHint ; }
93      boolean checkArgs( int a ){
94         return ( a >= _minArgs[0] ) && ( a <= _maxArgs[0] ) ;
95      }
96      String getArgs(){
97           return ""+_minArgs[0]+"<x<"+_maxArgs[0]+"|"+
98                  ""+_minArgs[1]+"<x<"+_maxArgs[1]  ; }
99      String getMethodString(){ return ""+_method[0]+"|"+_method[1] ; }
100      void put( String str , _CommandEntry e ){
101         if( _hash == null )_hash = new Hashtable<String, _CommandEntry>() ;
102         _hash.put(str,e) ;
103      }
104      Enumeration<_CommandEntry> elements(){ return _hash==null?null:_hash.elements() ; }
105      Enumeration<String> keys(){ return _hash==null?new Hashtable<String, _CommandEntry>().keys():_hash.keys() ; }
106      _CommandEntry get( String str ){
107           return _hash==null?null:(_CommandEntry)_hash.get(str); }
108      @Override
109    public String toString(){
110         if( _hash == null )return " --> no hash yet : "+getName() ;
111 
112         StringBuilder sb = new StringBuilder() ;
113         sb.append( "Entry : "+getName() ) ;
114 
115         for( String key: _hash.keySet() )
116            sb.append( " -> "+key+"\n" ) ;
117         return sb.toString() ;
118      }
119   }
120 
121   private static Class<?> __asciiArgsClass  = dmg.util.Args.class ;
122   private static Class<?> __binaryArgsClass = dmg.util.CommandRequestable.class ;
123   private static final int  ASCII  = 0 ;
124   private static final int  BINARY = 1 ;
125   private static final int  FULL_HELP = 2 ;
126   private static final int  HELP_HINT = 3 ;
127   private static final int  ACLS      = 4 ;
128   //
129   // start of object part
130   //
131   _CommandEntry _rootEntry = null  ;
132 
133   /**
134     * Default constructor to be used if the inspected class
135     * is has inherited the CommandInterpreter.
136     *
137     */
138   public CommandInterpreter(){
139       addCommandListener(this);
140   }
141   /**
142     * Creates an interpreter on top of the specified object.
143     * @params commandListener is the object which will be inspected.
144     * @return the CommandInterpreter connected to the
145     *         specified object.
146     */
147   public CommandInterpreter( Object commandListener ){
148       addCommandListener(commandListener);
149   }
150   /**
151     * Adds an interpreter too the current object.
152     * @params commandListener is the object which will be inspected.
153     */
154   public void addCommandListener( Object commandListener ){
155       _addCommandListener( commandListener ) ;
156   }
157   private static final int FT_HELP_HINT = 0 ;
158   private static final int FT_FULL_HELP = 1 ;
159   private static final int FT_ACL       = 2 ;
160 
161   private synchronized void _addCommandListener( Object commandListener ){
162 
163      Class<?>    c = commandListener.getClass() ;
164      if( _rootEntry == null )_rootEntry = new _CommandEntry("") ;
165 
166      Method m[] = c.getMethods() ;
167 
168      for( int i = 0 ; i < m.length ; i++ ){
169 
170         Class<?> [] params = m[i].getParameterTypes() ;
171         //
172         // check the signature  ( Args args or CommandRequestable )
173         //
174         int methodType = 0 ;
175         if( params.length == 1 ){
176            if( params[0].equals( __asciiArgsClass ) )
177               methodType = CommandInterpreter.ASCII ;
178            else if( params[0].equals( __binaryArgsClass ) )
179               methodType = CommandInterpreter.BINARY ;
180            else
181               continue ;
182 
183         }else continue ;
184         //
185         // scan  ac_.._.._..
186         //
187         StringTokenizer st = new StringTokenizer( m[i].getName() , "_" ) ;
188 
189         if( ! st.nextToken().equals("ac") )continue ;
190 
191         _CommandEntry currentEntry = _rootEntry ;
192         for( ; st.hasMoreTokens() ; ){
193             String comName = st.nextToken() ;
194             if( comName.equals("$" ) )break ;
195             _CommandEntry h = null ;
196             if( ( h = currentEntry.get( comName ) ) == null ){
197                currentEntry.put( comName , h = new _CommandEntry(comName) ) ;
198             }
199             currentEntry = h ;
200         }
201         //
202         // determine the number of arguments  [_$_min[_max]]
203         //
204         int minArgs = 0 ;
205         int maxArgs = 0 ;
206         if( st.hasMoreTokens() ){
207             minArgs = new Integer( st.nextToken() ).intValue() ;
208             if( st.hasMoreTokens() ){
209                maxArgs = new Integer( st.nextToken() ).intValue() ;
210             }else{
211                maxArgs = minArgs ;
212             }
213         }
214         currentEntry.setMethod( methodType , commandListener ,
215                                 m[i] , minArgs , maxArgs ) ;
216 
217      }
218      //
219      // the help fields   fh_( = full help ) or hh_( = help hint )
220      //
221      Field f[] = c.getFields() ;
222 
223      for( int i = 0 ; i < f.length ; i++ ){
224 
225         StringTokenizer st = new StringTokenizer( f[i].getName() , "_" ) ;
226         int     helpMode   = -1 ;
227         String  helpType   = st.nextToken() ;
228         if( helpType.equals("hh") ){
229           helpMode = FT_HELP_HINT ;
230         }else if( helpType.equals("fh") ){
231           helpMode = FT_FULL_HELP ;
232         }else if( helpType.equals("acl") ){
233           helpMode = FT_ACL ;
234         }else{
235           continue ;
236         }
237 
238         _CommandEntry currentEntry = _rootEntry ;
239         _CommandEntry h = null ;
240 
241         for( ; st.hasMoreTokens() ; ){
242             String  comName = st.nextToken() ;
243             if( ( h = currentEntry.get( comName ) ) == null )break ;
244             currentEntry = h ;
245         }
246         if( h == null )continue ;
247         switch( helpMode ){
248            case FT_FULL_HELP :
249               currentEntry.setFullHelp( commandListener , f[i] ) ;
250               break ;
251            case FT_HELP_HINT :
252               currentEntry.setHelpHint( commandListener , f[i] ) ;
253               break ;
254            case FT_ACL :
255               currentEntry.setACLS( commandListener , f[i] ) ;
256               break ;
257          }
258      }
259      return  ;
260   }
261   public void dumpCommands(){
262       printCommandEntry( _rootEntry , 0 ) ;
263   }
264   private void printCommandEntry( _CommandEntry h , int n ){
265     StringBuilder spb = new StringBuilder() ;
266     for( int i = 0 ; i < n ; i++ )spb.append("     ") ;
267     String space = spb.toString() ;
268     System.out.println(   space+"-> "+h.getName() ) ;
269     System.out.println(   space+"   Args : "+h.getArgs() ) ;
270     Method m = h.getMethod(CommandInterpreter.ASCII) ;
271     if( m != null)
272        System.out.println( space+"   Method : "+m.getName() ) ;
273     else
274        System.out.println( space+"   Method : none" ) ;
275     m = h.getMethod(CommandInterpreter.BINARY) ;
276     if( m != null)
277        System.out.println( space+"   BMethod : "+m.getName() ) ;
278     else
279        System.out.println( space+"   BSMethod : none" ) ;
280     Field f = h.getHelpHint() ;
281     String str = "None" ;
282     if( f != null )
283     try{
284         str = f.getName()+" : "+
285               (String)f.get(h.getListener(CommandInterpreter.HELP_HINT))  ;
286     } catch (IllegalAccessException se) {
287         str = f.getName()+" : "+se.toString();
288     }
289     System.out.println( space +"   Hint : "+str ) ;
290     str = "None" ;
291     if( ( f = h.getFullHelp() ) != null )
292     try{
293         str = f.getName()+" : "+
294         (String) f.get(h.getListener(CommandInterpreter.FULL_HELP))  ;
295     } catch (IllegalAccessException se) {
296         str = f.getName()+" : "+ se.toString();
297     }
298     System.out.println( space +"   Help : "+str ) ;
299 
300     Enumeration<_CommandEntry> e = h.elements() ;
301     if( e != null ){
302        for( ; e.hasMoreElements() ; ){
303           _CommandEntry nh    = e.nextElement() ;
304           printCommandEntry( nh , n+1 ) ;
305        }
306     }
307   }
308   private void dumpHelpHint( _CommandEntry [] path , _CommandEntry e , StringBuilder sb ){
309      StringBuilder sbx = new StringBuilder() ;
310      for( int i = 0 ; path[i+1] != null ; i++ )
311        sbx.append( path[i].getName()+" " ) ;
312      String top = sbx.toString() ;
313      dumpHelpHint( top , e , sb ) ;
314   }
315   private void dumpHelpHint( String top , _CommandEntry e , StringBuilder sb ){
316     top += e.getName()+" " ;
317     Field helpHint = e.getHelpHint() ;
318     int mt = CommandInterpreter.ASCII ;
319     Method m = e.getMethod(mt) ;
320     if( helpHint != null ){
321         try {
322             sb.append(top + helpHint.get(e.getListener(mt)) + "\n");
323         } catch (IllegalAccessException ee) {
324         }
325     }else if( m != null ){
326         sb.append( top ) ;
327         for( int i = 0 ; i < e.getMinArgs(mt) ; i++ )
328           sb.append( " <arg-"+i+">" ) ;
329         if( e.getMaxArgs(mt) != e.getMinArgs(mt) ){
330           sb.append( " [ " ) ;
331           for( int i = e.getMinArgs(mt) ; i < e.getMaxArgs(mt) ; i++ )
332             sb.append( " <arg-"+i+">" ) ;
333           sb.append( " ] " ) ;
334         }
335         sb.append( "\n" ) ;
336 
337     }
338     Enumeration<_CommandEntry> list = e.elements() ;
339     if( list != null )
340       for( ; list.hasMoreElements() ; )
341         dumpHelpHint(top,list.nextElement(),sb) ;
342   }
343   private String runHelp( Args args ){
344       _CommandEntry    e    = _rootEntry ;
345       _CommandEntry    ce   = null ;
346       _CommandEntry [] path = new _CommandEntry[64] ;
347       for(int i = 0 ; args.argc() > 0 ; i++ ){
348          if( ( path[i] = ce = e.get( args.argv(0) ) ) == null )break ;
349          args.shift();
350          e = ce ;
351       }
352       Field        f  = e.getFullHelp() ;
353       StringBuilder sb = new StringBuilder();
354       if( f == null ){
355          dumpHelpHint( path , e , sb ) ;
356       }else{
357           try {
358               sb.append(f.get(e.getListener(0)));
359           } catch (IllegalAccessException ee) {
360               dumpHelpHint( path , e , sb ) ;
361           }
362       }
363       return sb.toString() ;
364 
365   }
366 
367   /**
368     * Is a convenient method of <code>command(Args args)</code>.
369     * All Exceptions are catched and converted to a meaningful
370     * String except the CommandExitException which allows the
371     * corresponding object to signal a kind
372     * of final state. This method should be overwritten to
373     * customize the behavior on different Exceptions.
374     * This method <strong>never</strong> returns the null
375     * pointer even if the underlying <code>command</code>
376     * method does so.
377     */
378   public String command( String str ) throws CommandExitException {
379 
380      try{
381//         return (String)command( new Args( str ) ) ;
382         Object o = command( new Args( str ) ) ;
383         if( o == null )return "" ;
384         return (String)o ;
385      }catch( CommandSyntaxException cse ){
386         StringBuilder sb = new StringBuilder() ;
387         sb.append( "Syntax Error : "+cse.getMessage()+"\n" ) ;
388         String help  = cse.getHelpText() ;
389         if( help != null ){
390            sb.append( "Help : \n" ) ;
391            sb.append( help ) ;
392         }
393         return sb.toString() ;
394      }catch( CommandExitException cee ){
395         throw cee ;
396      }catch( CommandThrowableException cte ){
397         StringBuilder sb = new StringBuilder() ;
398         sb.append( cte.getMessage()+"\n" ) ;
399         Throwable t = cte.getTargetException() ;
400         sb.append( t.getClass().getName()+" : "+t.getMessage()+"\n" ) ;
401         return sb.toString() ;
402      }catch( CommandPanicException cpe ){
403         StringBuilder sb = new StringBuilder() ;
404         sb.append( "Panic : "+cpe.getMessage()+"\n" ) ;
405         Throwable t = cpe.getTargetException() ;
406         sb.append( t.getClass().getName()+" : "+t.getMessage()+"\n" ) ;
407         return sb.toString() ;
408      }catch( CommandException e ){
409         return "??? : "+e.toString() ;
410      }
411   }
412   /**
413     * Interpreters the specified arguments and calles the
414     * corresponding method of the connected Object.
415     *
416     * @params args is the initialized Args Object containing
417     *         the commands.
418     * @return the string returned by the corresponding
419     *         method of the reflected object.
420     *
421     * @exception CommandSyntaxException if the used command syntax
422     *            doesn't match any of the corresponding methods.
423     *            The .getHelpText() method provides a short
424     *            description of the correct syntax, if possible.
425     * @exception CommandExitException if the corresponding
426     *            object doesn't want to be used any more.
427     *            Usually shells send this Exception to 'exit'.
428     * @exception CommandThrowableException if the corresponding
429     *            method throws any kind of throwable.
430     *            The thrown throwable can be obtaines by calling
431     *            .getTargetException of the CommandThrowableException.
432     * @exception CommandPanicException if the invocation of the
433     *            corresponding method failed. .getTargetException
434     *            provides the actual Exception of the failure.
435     * @exception CommandAclException if an acl was defined and the
436     *            AclServices denied access.
437     *
438     */
439   public Object command( Args args )  throws CommandException{
440       return execute( args , CommandInterpreter.ASCII ) ;
441   }
442   public Object command( CommandRequestable request )  throws CommandException{
443       return execute( request , CommandInterpreter.BINARY ) ;
444   }
445   public Object execute( Object command , int methodType )
446          throws CommandException{
447 
448                     Args args    = null ;
449       CommandRequestable request = null ;
450                      int params  = 0 ;
451                   Object values  = null ;
452 
453       if( methodType == CommandInterpreter.ASCII ){
454          args    = (Args)command ;
455          request = null ;
456          params  = args.argc() ;
457          values  = args ;
458       }else{
459          request = (CommandRequestable)command ;
460          args    = new Args( request.getRequestCommand() ) ;
461          params  = request.getArgc() ;
462          values  = request ;
463       }
464 
465       if( args.argc() == 0 )return "" ;
466 
467       _CommandEntry    e    = _rootEntry ;
468       _CommandEntry    ce   = null ;
469       _CommandEntry [] path = new _CommandEntry[64] ;
470       Method           m    = null ;
471       //
472       // check for the help command.
473       //
474       if( ( args.argc() > 0 ) &&
475           ( args.argv(0).equals("help") ) ){
476 
477          args.shift();
478          return runHelp( args ) ;
479 
480       }
481       //
482       // check for the NOOP command.
483       //
484       if( ( args.argc() > 0 ) &&
485           ( args.argv(0).equals("xyzzy") ) ) {
486           return "Nothing happens.";
487       }
488       //
489       // walk along the command tree as long as arguments are
490       // available and as long as those arguments match the
491       // tree.
492       //
493       _CommandEntry lastAcl = null ;
494       for(int i = 0 ; args.argc() > 0 ; i++ ){
495          if( ( path[i] = ce = e.get( args.argv(0) ) ) == null )break ;
496          if( ce.getACLS() != null )lastAcl = ce ;
497          args.shift();
498          e = ce ;
499       }
500       //
501       // the specified command was not found in the hash list
502       // or the command was to short. Try to find a kind of
503       // help text and send it together with the CommandSyntaxException.
504       //
505       m  = e.getMethod(methodType) ;
506       ce = e ;
507       if(  m == null ){
508          StringBuilder sb = new StringBuilder() ;
509          if( methodType == CommandInterpreter.ASCII )
510              dumpHelpHint( path , e , sb ) ;
511          throw new CommandSyntaxException(
512                      "Command not found" +
513                      (args.argc()>0?(" : "+args.argv(0)):"") ,
514                      sb.toString() ) ;
515       }
516       //
517       // command string was correct, method was found,
518       // but the number of arguments don't match.
519       //
520       if( methodType == CommandInterpreter.ASCII )params  = args.argc() ;
521 
522       if( ( ce.getMinArgs(methodType) > params ) ||
523           ( ce.getMaxArgs(methodType) < params )    ){
524 
525          StringBuilder sb = new StringBuilder() ;
526          if( methodType == CommandInterpreter.ASCII )
527              dumpHelpHint( path , ce , sb ) ;
528          throw new CommandSyntaxException(
529                      "Invalid number of arguments" ,
530                      sb.toString() ) ;
531       }
532       //
533       // check acls
534       //
535       boolean _checkAcls = true ;
536       Field  aclField = lastAcl == null ? null : lastAcl.getACLS() ;
537       if( _checkAcls && ( values instanceof Authorizable ) && ( aclField != null ) ){
538          String [] acls  = null ;
539          try{
540             Object field = aclField.get( ce.getListener(CommandInterpreter.ASCII) ) ;
541             if( field instanceof String [] ){
542                acls = (String [])field ;
543             }else if( field instanceof String ){
544                acls    = new String[1] ;
545                acls[0] = (String)field ;
546             }
547          }catch(IllegalAccessException ee ){
548             // might be dangerous
549          }
550          if( acls != null )checkAclPermission( (Authorizable)values , command , acls ) ;
551       }
552       //
553       // everything seems to be fine right now.
554       // so we invoke the selected function.
555       //
556       StringBuilder sb = new StringBuilder() ;
557       try{
558 
559          Object [] o = new Object[1] ;
560          o[0] = values ;
561          return m.invoke( e.getListener(methodType) , o ) ;
562 
563       }catch( InvocationTargetException ite ){
564          //
565          // is thrown if the underlying method
566          // actively throws an exception.
567          //
568          Throwable    te = ite.getTargetException() ;
569          if( te instanceof CommandSyntaxException ){
570             CommandSyntaxException cse = (CommandSyntaxException)te ;
571             if(  ( methodType == CommandInterpreter.ASCII ) &&
572                  ( cse.getHelpText() == null  )                 ){
573                dumpHelpHint( path , ce , sb ) ;
574                cse.setHelpText( sb.toString() ) ;
575             }
576             throw cse ;
577          }else if( te instanceof CommandException ){
578             //
579             // can be CommandExit or a pure CommandException
580             // which is used as transport for a normal
581             // command problem.
582             //
583             throw (CommandException)te ;
584          }else{
585              // We treat uncaught RuntimeExceptions other than
586              // IllegalArgumentExceptions as bugs and log them as
587              // that.
588              if (te instanceof RuntimeException &&
589                  !(te instanceof IllegalArgumentException)) {
590                  throw (RuntimeException) te;
591              }
592              if (te instanceof Error) {
593                  throw (Error) te;
594              }
595 
596             throw new CommandThrowableException(
597                         te.toString()+" from "+m.getName() ,
598                         te ) ;
599          }
600       } catch (IllegalAccessException ee) {
601           throw new CommandPanicException("Exception while invoking " +
602                                           m.getName(), ee);
603       }
604   }
605   protected void checkAclPermission( Authorizable values , Object command , String [] acls ) throws CommandException {
606//       String principal = values.getAuthorizedPrincipal() ;
607//       System.out.println("!!! Checking permissions for "+principal );
608//       for( int i= 0 ; i < acls.length ; i++ ){
609//          System.out.println("!!!    acl["+i+"] : "+acls[i]);
610//       }
611   }
612 
613 
614}

[all classes][dmg.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov