KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > event > RegistryUninstallerListener


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2004 Klaus Bartz
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.event;
23
24 import java.io.InputStream JavaDoc;
25 import java.io.ObjectInputStream JavaDoc;
26 import java.util.List JavaDoc;
27
28 import com.coi.tools.os.win.NativeLibException;
29 import com.izforge.izpack.util.AbstractUIProgressHandler;
30 import com.izforge.izpack.util.TargetFactory;
31 import com.izforge.izpack.util.os.RegistryHandler;
32 import com.izforge.izpack.util.os.WrappedNativeLibException;
33
34 /**
35  * Uninstaller custom action for handling registry entries. The needed configuration data are
36  * written at installation time from the corresponding installer custom action. An external
37  * definiton is not needed.
38  *
39  * @author Klaus Bartz
40  *
41  */

42 public class RegistryUninstallerListener extends NativeUninstallerListener
43 {
44
45     /**
46      * Default constructor
47      */

48     public RegistryUninstallerListener()
49     {
50         super();
51     }
52
53     /*
54      * (non-Javadoc)
55      *
56      * @see com.izforge.izpack.uninstaller.UninstallerListener#afterDeletion(java.util.List,
57      * com.izforge.izpack.util.AbstractUIProgressHandler)
58      */

59     public void beforeDeletion(List JavaDoc files, AbstractUIProgressHandler handler) throws Exception JavaDoc
60     {
61         // Load the defined actions.
62
InputStream JavaDoc in = getClass().getResourceAsStream("/registryEntries");
63         if (in == null)
64         { // No actions, nothing todo.
65
return;
66         }
67         ObjectInputStream JavaDoc objIn = new ObjectInputStream JavaDoc(in);
68         List JavaDoc allActions = (List JavaDoc) objIn.readObject();
69         objIn.close();
70         in.close();
71         if (allActions == null || allActions.size() < 1) return;
72         try
73         {
74             RegistryHandler registryHandler = initializeRegistryHandler();
75             if (registryHandler == null) return;
76             registryHandler.activateLogging();
77             registryHandler.setLoggingInfo(allActions);
78             registryHandler.rewind();
79         }
80         catch (Exception JavaDoc e)
81         {
82             if (e instanceof NativeLibException)
83             {
84                 throw new WrappedNativeLibException(e);
85             }
86             else
87                 throw e;
88         }
89     }
90
91     private RegistryHandler initializeRegistryHandler() throws Exception JavaDoc
92     {
93         RegistryHandler registryHandler = null;
94         try
95         {
96             registryHandler = (RegistryHandler) (TargetFactory.getInstance()
97                     .makeObject("com.izforge.izpack.util.os.RegistryHandler"));
98         }
99         catch (Throwable JavaDoc exception)
100         {
101             exception.printStackTrace();
102             registryHandler = null; // Do nothing, do not set permissions ...
103
}
104         if (registryHandler != null && (!registryHandler.good() || !registryHandler.doPerform()))
105         {
106             System.out.println("initializeRegistryHandler is Bad " + registryHandler.good()
107                     + registryHandler.doPerform());
108             registryHandler = null;
109         }
110         return (registryHandler);
111     }
112
113 }
114
Popular Tags