Interface RollbackRegister


  • public interface RollbackRegister

    This interface provides a rollback registration service that can be requested by a custom code action. Through this service, the action can register a rollback handler, which will be executed by InstallAnywhere installer runtime if the install is cancelled.

    The RollbackRegister object is obtained through the InstallerProxy, CustomCodePanelProxy, and CustomCodeConsoleProxy objects by a request for the RollbackRegister class. This is an example of how rollback is implemented:


    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;

    import com.zerog.ia.api.pub.CustomCodeAction;
    import com.zerog.ia.api.pub.FatalInstallException;
    import com.zerog.ia.api.pub.InstallException;
    import com.zerog.ia.api.pub.InstallerProxy;
    import com.zerog.ia.api.pub.RollbackHandler;
    import com.zerog.ia.api.pub.RollbackRegister;
    import com.zerog.ia.api.pub.UninstallerProxy;

    public class AutomaticRollbackAction extends CustomCodeAction {

       private static final String FILE_NAME = "installed-file.txt";


       public void install(InstallerProxy proxy) throws InstallException {
          registerRollbackHandler(proxy);
          installFile(proxy);
       }

       private void installFile(InstallerProxy proxy) throws FatalInstallException {
          String installDir = proxy.substitute("$USER_INSTALL_DIR$");
          try {
             FileOutputStream stream = new FileOutputStream(new File(installDir,
                   FILE_NAME));
             try {
                stream.write("contents".getBytes("UTF-8"));
             } finally {
                stream.close();
             }
          } catch (IOException e) {
             throw new FatalInstallException(e.getMessage());
          }
       }

       private void registerRollbackHandler(InstallerProxy proxy) {
          RollbackRegister register = (RollbackRegister) proxy
                .getService(RollbackRegister.class);
          register.addHandler(new RollbackHandler() {
             public void rollBack(InstallerProxy proxy) {
                String installDir = proxy.substitute("$USER_INSTALL_DIR$");
                File installedFile = new File(installDir, FILE_NAME);

                if (installedFile.exists()) {
                   installedFile.delete();
                }
             }
          });
       }

       // TODO Add other required methods

    }
    • Method Detail

      • addHandler

        void addHandler​(RollbackHandler handler)
        Add a handler to that will be called when rollback is triggered.
        Parameters:
        handler - The object that will handle rollback procedures.