2929import com .cloud .agent .api .Command ;
3030
3131public abstract class RequestWrapper {
32+ static public class CommandNotSupported extends NullPointerException {
33+ public CommandNotSupported (String msg ) {
34+ super (msg );
35+ }
36+ public CommandNotSupported (String msg , Throwable cause ) {
37+ super (msg );
38+ initCause (cause );
39+ }
40+ }
3241
3342 private static final Logger s_logger = Logger .getLogger (RequestWrapper .class );
3443
@@ -52,7 +61,7 @@ protected Hashtable<Class<? extends Command>, CommandWrapper> retrieveResource(f
5261
5362 keepResourceClass = keepResourceClass2 ;
5463 } catch (final ClassCastException e ) {
55- throw new NullPointerException ("No key found for '" + command .getClass () + "' in the Map!" );
64+ throw new CommandNotSupported ("No key found for '" + command .getClass () + "' in the Map!" );
5665 }
5766 }
5867 return resource ;
@@ -69,14 +78,14 @@ protected CommandWrapper<Command, Answer, ServerResource> retrieveCommands(final
6978 final Class <? extends Command > commandClass2 = (Class <? extends Command >) keepCommandClass .getSuperclass ();
7079
7180 if (commandClass2 == null ) {
72- throw new NullPointerException ("All the COMMAND hierarchy tree has been visited but no compliant key has been found for '" + commandClass + "'." );
81+ throw new CommandNotSupported ("All the COMMAND hierarchy tree has been visited but no compliant key has been found for '" + commandClass + "'." );
7382 }
7483
7584 commandWrapper = resourceCommands .get (commandClass2 );
7685
7786 keepCommandClass = commandClass2 ;
7887 } catch (final ClassCastException e ) {
79- throw new NullPointerException ("No key found for '" + keepCommandClass .getClass () + "' in the Map!" );
88+ throw new CommandNotSupported ("No key found for '" + keepCommandClass .getClass () + "' in the Map!" );
8089 } catch (final NullPointerException e ) {
8190 // Will now traverse all the resource hierarchy. Returning null
8291 // is not a problem.
@@ -102,18 +111,16 @@ protected CommandWrapper<Command, Answer, ServerResource> retryWhenAllFails(fina
102111 final Class <? extends ServerResource > resourceClass2 = (Class <? extends ServerResource >) keepResourceClass .getSuperclass ();
103112
104113 if (resourceClass2 == null ) {
105- throw new NullPointerException ("All the SERVER-RESOURCE hierarchy tree has been visited but no compliant key has been found for '" + command .getClass () + "'." );
114+ throw new CommandNotSupported ("All the SERVER-RESOURCE hierarchy tree has been visited but no compliant key has been found for '" + command .getClass () + "'." );
106115 }
107116
108117 final Hashtable <Class <? extends Command >, CommandWrapper > resourceCommands2 = retrieveResource (command ,
109118 (Class <? extends ServerResource >) keepResourceClass .getSuperclass ());
110119 keepResourceClass = resourceClass2 ;
111120
112121 commandWrapper = retrieveCommands (command .getClass (), resourceCommands2 );
113- } catch (final ClassCastException e ) {
114- throw new NullPointerException ("No key found for '" + command .getClass () + "' in the Map!" );
115- } catch (final NullPointerException e ) {
116- throw e ;
122+ } catch (final ClassCastException | NullPointerException e ) {
123+ throw new CommandNotSupported ("No key found for '" + command .getClass () + "' in the Map!" , e );
117124 }
118125 }
119126 return commandWrapper ;
0 commit comments