KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > operations > PatchCleaner


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.operations;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.update.configuration.*;
15 import org.eclipse.update.core.*;
16
17 /**
18  * This utility class attaches as a listened to the provided
19  * configured site, and for every unconfigured feature
20  * it tests if it is a patch and cleans up its backup configuration.
21  */

22
23 public class PatchCleaner {
24     private IConfiguredSite csite;
25     private SiteListener listener;
26     class SiteListener implements IConfiguredSiteChangedListener {
27         public void featureInstalled(IFeature feature) {
28         }
29         public void featureRemoved(IFeature feature) {
30             cleanSavedConfigs(feature);
31         }
32         public void featureConfigured(IFeature feature) {
33         }
34         public void featureUnconfigured(IFeature feature) {
35             cleanSavedConfigs(feature);
36         }
37     }
38     public PatchCleaner(IConfiguredSite csite, IFeature root) {
39         this.csite = csite;
40         listener = new SiteListener();
41         csite.addConfiguredSiteChangedListener(listener);
42     }
43
44     public void dispose() {
45         csite.removeConfiguredSiteChangedListener(listener);
46     }
47     private void cleanSavedConfigs(IFeature feature) {
48         if (feature.isPatch()) {
49             IInstallConfiguration backupConfig = UpdateUtils.getBackupConfigurationFor(feature);
50             if (backupConfig!=null) {
51                 // clean it
52
remove(backupConfig);
53             }
54         }
55     }
56     private void remove(IInstallConfiguration config) {
57         try {
58             ILocalSite localSite = SiteManager.getLocalSite();
59             localSite.removeFromPreservedConfigurations(config);
60         }
61         catch (CoreException e) {
62         }
63     }
64 }
65
Popular Tags