Arik Hadas has uploaded a new change for review.

Change subject: core: refactoring in CommandsFactory
......................................................................

core: refactoring in CommandsFactory

Extract the code that instantiate the command to separate method

Change-Id: Ib1d15d69afad9cefad95d0d266a495e3d95cd6e4
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
1 file changed, 12 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/32572/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
index 3071b5a..4bbbf1e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
@@ -59,18 +59,10 @@
         return createCommand(action, parameters, null);
     }
 
-    @SuppressWarnings("unchecked")
     public static <P extends VdcActionParametersBase> CommandBase<P> 
createCommand(VdcActionType action, P parameters, CommandContext 
commandContext) {
         try {
-            CommandBase<P> result = null;
-            if (commandContext == null) {
-                result = 
(CommandBase<P>)findCommandConstructor(getCommandClass(action.name(), 
CommandSuffix), parameters.getClass()).newInstance(parameters);
-            } else {
-                result =
-                        (CommandBase<P>) 
findCommandConstructor(getCommandClass(action.name(), CommandSuffix),
-                                parameters.getClass(),
-                                
commandContext.getClass()).newInstance(parameters, commandContext);
-            }
+            CommandBase<P> result = instantiateCommand(action, parameters, 
commandContext);
+
             Injector.injectMembers(result);
             return result;
         }
@@ -84,6 +76,15 @@
         }
     }
 
+    @SuppressWarnings("unchecked")
+    private static <P extends VdcActionParametersBase> CommandBase<P> 
instantiateCommand(VdcActionType action, P parameters, CommandContext 
commandContext)
+            throws InstantiationException, IllegalAccessException, 
IllegalArgumentException, InvocationTargetException {
+        return commandContext == null ?
+                
(CommandBase<P>)findCommandConstructor(getCommandClass(action.name(), 
CommandSuffix), parameters.getClass()).newInstance(parameters)
+                : (CommandBase<P>) 
findCommandConstructor(getCommandClass(action.name(), CommandSuffix),
+                        parameters.getClass(),
+                        commandContext.getClass()).newInstance(parameters, 
commandContext);
+    }
 
     /**
      * Creates an instance of the given command class and passed the command 
id to it's constructor
@@ -163,6 +164,7 @@
         if (clazz != null) {
             return clazz;
         }
+
         for (String commandPackage : COMMAND_PACKAGES) {
             String className = String.format(CLASS_NAME_FORMAT, 
commandPackage, name, suffix);
             Class<CommandBase<? extends VdcActionParametersBase>> type = 
loadClass(className);


-- 
To view, visit http://gerrit.ovirt.org/32572
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib1d15d69afad9cefad95d0d266a495e3d95cd6e4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Arik Hadas <aha...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to