29
29
import com .cloud .agent .api .Command ;
30
30
31
31
public 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
+ }
32
41
33
42
private static final Logger s_logger = Logger .getLogger (RequestWrapper .class );
34
43
@@ -52,7 +61,7 @@ protected Hashtable<Class<? extends Command>, CommandWrapper> retrieveResource(f
52
61
53
62
keepResourceClass = keepResourceClass2 ;
54
63
} 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!" );
56
65
}
57
66
}
58
67
return resource ;
@@ -69,14 +78,14 @@ protected CommandWrapper<Command, Answer, ServerResource> retrieveCommands(final
69
78
final Class <? extends Command > commandClass2 = (Class <? extends Command >) keepCommandClass .getSuperclass ();
70
79
71
80
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 + "'." );
73
82
}
74
83
75
84
commandWrapper = resourceCommands .get (commandClass2 );
76
85
77
86
keepCommandClass = commandClass2 ;
78
87
} 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!" );
80
89
} catch (final NullPointerException e ) {
81
90
// Will now traverse all the resource hierarchy. Returning null
82
91
// is not a problem.
@@ -102,18 +111,16 @@ protected CommandWrapper<Command, Answer, ServerResource> retryWhenAllFails(fina
102
111
final Class <? extends ServerResource > resourceClass2 = (Class <? extends ServerResource >) keepResourceClass .getSuperclass ();
103
112
104
113
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 () + "'." );
106
115
}
107
116
108
117
final Hashtable <Class <? extends Command >, CommandWrapper > resourceCommands2 = retrieveResource (command ,
109
118
(Class <? extends ServerResource >) keepResourceClass .getSuperclass ());
110
119
keepResourceClass = resourceClass2 ;
111
120
112
121
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 );
117
124
}
118
125
}
119
126
return commandWrapper ;
0 commit comments