javamanager/javainstaller/installer/javasrc/com/nokia/mj/impl/installer/jsrpluginnotifier/JsrPluginNotifierBase.java
changeset 72 1f0034e370aa
parent 21 2a9601315dfc
child 87 1627c337e51e
equal deleted inserted replaced
67:63b81d807542 72:1f0034e370aa
    80      * @see InstallerExtension#install
    80      * @see InstallerExtension#install
    81      */
    81      */
    82     public void notifyInstallation(InstallerExtensionInfo aInfo)
    82     public void notifyInstallation(InstallerExtensionInfo aInfo)
    83     {
    83     {
    84         Log.log("JsrPluginNotifierBase.NotifyInstallation called");
    84         Log.log("JsrPluginNotifierBase.NotifyInstallation called");
    85 
    85         boolean continueInstallation = true;
    86         // Are there any plugins to be notified
    86         InstallerExtension plugin = null;
    87         if (iJsrPlugins.size() > 0)
    87         for (int i = 0; i < iJsrPlugins.size(); i++)
    88         {
    88         {
    89             boolean continueInstallation = true;
    89             try
    90             Iterator iter = iJsrPlugins.iterator();
    90             {
    91             InstallerExtension plugin;
    91                 plugin = (InstallerExtension)iJsrPlugins.elementAt(i);
    92             while (iter.hasNext())
    92                 Log.log("Jsr plugin install " + plugin.getClass().getName());
    93             {
       
    94                 plugin = (InstallerExtension)iter.next();
       
    95                 continueInstallation = plugin.install(aInfo);
    93                 continueInstallation = plugin.install(aInfo);
    96 
    94             }
    97                 // Check whether JSR plugin cancels installation
    95             catch (Throwable t)
    98                 if (!continueInstallation)
    96             {
    99                 {
    97                 Log.logError("Installer Jsr plugin " +
   100                     InstallerException.internalError(
    98                              plugin.getClass().getName() +
   101                         "Jsr plugin " + plugin.getClass().getName() +
    99                              " install exception " + t, t);
   102                         " cancelled installation.");
   100                 continueInstallation = false;
   103                 }
   101             }
       
   102             // Check if JSR plugin cancelled installation.
       
   103             if (!continueInstallation)
       
   104             {
       
   105                 // Rollback those plugins which already got notified.
       
   106                 notifyRollbackInstall(aInfo, i);
       
   107                 InstallerException.internalError(
       
   108                     "Jsr plugin " + plugin.getClass().getName() +
       
   109                     " cancelled installation.");
   104             }
   110             }
   105         }
   111         }
   106     }
   112     }
   107 
   113 
   108     /**
   114     /**
   114      * @see InstallerExtension#uninstall
   120      * @see InstallerExtension#uninstall
   115      */
   121      */
   116     public void notifyUninstallation(InstallerExtensionInfo aInfo)
   122     public void notifyUninstallation(InstallerExtensionInfo aInfo)
   117     {
   123     {
   118         Log.log("JsrPluginNotifierBase.notifyUninstallation called");
   124         Log.log("JsrPluginNotifierBase.notifyUninstallation called");
   119 
   125         boolean continueUninstallation = true;
   120         // Are there any plugins to be notified
   126         InstallerExtension plugin = null;
   121         if (iJsrPlugins.size() > 0)
   127         for (int i = 0; i < iJsrPlugins.size(); i++)
   122         {
   128         {
   123             boolean continueUninstallation = true;
   129             try
   124             Iterator iter = iJsrPlugins.iterator();
   130             {
   125             InstallerExtension plugin;
   131                 plugin = (InstallerExtension)iJsrPlugins.elementAt(i);
   126             while (iter.hasNext())
   132                 Log.log("Jsr plugin uninstall " + plugin.getClass().getName());
   127             {
       
   128                 plugin = (InstallerExtension)iter.next();
       
   129                 continueUninstallation = plugin.uninstall(aInfo);
   133                 continueUninstallation = plugin.uninstall(aInfo);
   130 
   134             }
   131                 // Check whether JSR plugin cancels uninstallation
   135             catch (Throwable t)
   132                 if (!continueUninstallation)
   136             {
   133                 {
   137                 Log.logError("Installer Jsr plugin " +
   134                     InstallerException.internalError(
   138                              plugin.getClass().getName() +
   135                         "Jsr plugin " + plugin.getClass().getName() +
   139                              " uninstall exception " + t, t);
   136                         " cancelled uninstallation.");
   140                 continueUninstallation = false;
   137                 }
   141             }
       
   142             // Check if JSR plugin cancelled uninstallation.
       
   143             if (!continueUninstallation)
       
   144             {
       
   145                 // Rollback those plugins which already got notified.
       
   146                 notifyRollbackUninstall(aInfo, i);
       
   147                 InstallerException.internalError(
       
   148                     "Jsr plugin " + plugin.getClass().getName() +
       
   149                     " cancelled uninstallation.");
   138             }
   150             }
   139         }
   151         }
   140     }
   152     }
   141 
   153 
   142     /**
   154     /**
   148      * @see InstallerExtension#rollbackInstall
   160      * @see InstallerExtension#rollbackInstall
   149      */
   161      */
   150     public void notifyRollbackInstall(InstallerExtensionInfo aInfo)
   162     public void notifyRollbackInstall(InstallerExtensionInfo aInfo)
   151     {
   163     {
   152         Log.log("JsrPluginNotifierBase.notifyRollbackInstall called");
   164         Log.log("JsrPluginNotifierBase.notifyRollbackInstall called");
   153 
   165         notifyRollbackInstall(aInfo, iJsrPlugins.size());
   154         // Are there any plugins to be notified
       
   155         if (iJsrPlugins.size() > 0)
       
   156         {
       
   157             Iterator iter = iJsrPlugins.iterator();
       
   158             InstallerExtension plugin;
       
   159             while (iter.hasNext())
       
   160             {
       
   161                 plugin = (InstallerExtension)iter.next();
       
   162                 plugin.rollbackInstall(aInfo);
       
   163             }
       
   164         }
       
   165     }
   166     }
   166 
   167 
   167     /**
   168     /**
   168      * Notifies Jsr plugins in iJsrPlugins vector that the uninstallation of
   169      * Notifies Jsr plugins in iJsrPlugins vector that the uninstallation of
   169      * a MIDlet suite has been cancelled by calling the rollbackUninstall()
   170      * a MIDlet suite has been cancelled by calling the rollbackUninstall()
   173      * @see InstallerExtension#rollbackUninstall
   174      * @see InstallerExtension#rollbackUninstall
   174      */
   175      */
   175     public void notifyRollbackUninstall(InstallerExtensionInfo aInfo)
   176     public void notifyRollbackUninstall(InstallerExtensionInfo aInfo)
   176     {
   177     {
   177         Log.log("JsrPluginNotifierBase.notifyRollbackUninstall called");
   178         Log.log("JsrPluginNotifierBase.notifyRollbackUninstall called");
   178 
   179         notifyRollbackUninstall(aInfo, iJsrPlugins.size());
   179         // Are there any plugins to be notified
       
   180         if (iJsrPlugins.size() > 0)
       
   181         {
       
   182             Iterator iter = iJsrPlugins.iterator();
       
   183             InstallerExtension plugin;
       
   184             while (iter.hasNext())
       
   185             {
       
   186                 plugin = (InstallerExtension)iter.next();
       
   187                 plugin.rollbackUninstall(aInfo);
       
   188             }
       
   189         }
       
   190     }
   180     }
   191 
   181 
   192     /**
   182     /**
   193      * Returns true if this JsrPluginNotifier has any Jsr plugins.
   183      * Returns true if this JsrPluginNotifier has any Jsr plugins.
   194      *
   184      *
   238                 // store them to member variable
   228                 // store them to member variable
   239                 iJsrPlugins.add(extPlugin);
   229                 iJsrPlugins.add(extPlugin);
   240             }
   230             }
   241             catch (ClassNotFoundException e2)
   231             catch (ClassNotFoundException e2)
   242             {
   232             {
   243                 Log.logError("Jsr plugin class" + className + " is not found.");
   233                 Log.logError("Installer Jsr plugin class" + className + " not found.");
   244             }
   234             }
   245             catch (InstantiationException e3)
   235             catch (InstantiationException e3)
   246             {
   236             {
   247                 Log.logError("Cannot instantiate Jsr plugin " + className);
   237                 Log.logError("Installer cannot instantiate Jsr plugin " + className);
   248             }
   238             }
   249             catch (IllegalAccessException e4)
   239             catch (IllegalAccessException e4)
   250             {
   240             {
   251                 Log.logError("Cannot access Jsr plugin " + className);
   241                 Log.logError("Installer cannot access Jsr plugin " + className);
   252             }
   242             }
   253             catch (ClassCastException e5)
   243             catch (ClassCastException e5)
   254             {
   244             {
   255                 Log.logError("Jsr plugin " + className +
   245                 Log.logError("Installer Jsr plugin " + className +
   256                              " does not implement interface InstallerExtension.");
   246                              " does not implement interface InstallerExtension.");
   257             }
   247             }
   258         }
   248         }
   259     }
   249     }
   260 
   250 
   298                 }
   288                 }
   299             }
   289             }
   300         }
   290         }
   301         catch (IOException e)
   291         catch (IOException e)
   302         {
   292         {
   303             Log.logError("JsrPluginNotifier cannot read plugin " +
   293             Log.logError("Installer JsrPluginNotifier cannot read plugin " +
   304                          "config file " + aFileName, e);
   294                          "config file " + aFileName, e);
   305             return;
   295             return;
   306         }
   296         }
   307         finally
   297         finally
   308         {
   298         {
   314                     reader = null;
   304                     reader = null;
   315                 }
   305                 }
   316                 catch (IOException ioe)
   306                 catch (IOException ioe)
   317                 {
   307                 {
   318                     Log.logError(
   308                     Log.logError(
   319                         "JsrPluginNotifier: exception while closing reader",
   309                         "Installer JsrPluginNotifier: exception while closing reader",
   320                         ioe);
   310                         ioe);
   321                 }
   311                 }
   322             }
   312             }
   323         }
   313         }
   324     }
   314     }
   325 
   315 
       
   316     /**
       
   317      * Notifies Jsr plugins in iJsrPlugins vector that the installation of
       
   318      * a MIDlet suite has been cancelled by calling the rollbackInstall()
       
   319      * method of the plugins.
       
   320      *
       
   321      * @param aInfo notification information object
       
   322      * @param aCount number of plugins to notify
       
   323      * @see InstallerExtension#rollbackInstall
       
   324      */
       
   325     private void notifyRollbackInstall(InstallerExtensionInfo aInfo, int aCount)
       
   326     {
       
   327         InstallerExtension plugin = null;
       
   328         for (int i = aCount - 1; i >= 0; i--)
       
   329         {
       
   330             try
       
   331             {
       
   332                 plugin = (InstallerExtension)iJsrPlugins.elementAt(i);
       
   333                 Log.log("Jsr plugin rollbackInstall " +
       
   334                         plugin.getClass().getName());
       
   335                 plugin.rollbackInstall(aInfo);
       
   336             }
       
   337             catch (Throwable t)
       
   338             {
       
   339                 Log.logError("Installer Jsr plugin " +
       
   340                              plugin.getClass().getName() +
       
   341                              " rollbackInstall exception " + t, t);
       
   342             }
       
   343         }
       
   344     }
       
   345 
       
   346     /**
       
   347      * Notifies Jsr plugins in iJsrPlugins vector that the uninstallation of
       
   348      * a MIDlet suite has been cancelled by calling the rollbackUninstall()
       
   349      * method of the plugins.
       
   350      *
       
   351      * @param aInfo notification information object
       
   352      * @param aCount number of plugins to notify
       
   353      * @see InstallerExtension#rollbackUninstall
       
   354      */
       
   355     private void notifyRollbackUninstall(InstallerExtensionInfo aInfo, int aCount)
       
   356     {
       
   357         InstallerExtension plugin = null;
       
   358         for (int i = aCount - 1; i >= 0; i--)
       
   359         {
       
   360             try
       
   361             {
       
   362                 plugin = (InstallerExtension)iJsrPlugins.elementAt(i);
       
   363                 Log.log("Jsr plugin rollbackUninstall " +
       
   364                         plugin.getClass().getName());
       
   365                 plugin.rollbackUninstall(aInfo);
       
   366             }
       
   367             catch (Throwable t)
       
   368             {
       
   369                 Log.logError("Installer Jsr plugin " +
       
   370                              plugin.getClass().getName() +
       
   371                              " rollbackUninstall exception " + t, t);
       
   372             }
       
   373         }
       
   374     }
   326 }
   375 }