KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.update.configuration.*;
17 import org.eclipse.update.core.*;
18 import org.eclipse.update.operations.*;
19
20 public class JobRoot {
21     private IInstallFeatureOperation job;
22     private FeatureHierarchyElement[] elements;
23
24     public JobRoot(IInstallFeatureOperation job) {
25         this.job = job;
26     }
27
28     public IInstallFeatureOperation getJob() {
29         return job;
30     }
31
32     public FeatureHierarchyElement[] getElements() {
33         if (elements == null)
34             computeElements();
35         return elements;
36     }
37
38     /**
39      * Returns unconfigured features before an install.
40      * After installing the features, the caller must get the local features that match
41      * these unconfigured features and unconfigure them.
42      * @param config
43      * @param targetSite
44      * @return
45      */

46     public IFeature[] getUnconfiguredOptionalFeatures(
47         IInstallConfiguration config,
48         IConfiguredSite targetSite) {
49
50         ArrayList JavaDoc unconfiguredOptionalFeatures = new ArrayList JavaDoc();
51         getUnconfiguredOptionalFeatures(unconfiguredOptionalFeatures, config, targetSite, getElements(), UpdateUtils.isPatch(job.getFeature()));
52         IFeature[] unconfiguredOptionalFeaturesArray =
53             new IFeature[unconfiguredOptionalFeatures.size()];
54         unconfiguredOptionalFeatures.toArray(unconfiguredOptionalFeaturesArray);
55         return unconfiguredOptionalFeaturesArray;
56     }
57
58     private void getUnconfiguredOptionalFeatures(
59         ArrayList JavaDoc unconfiguredOptionalFeatures,
60         IInstallConfiguration config,
61         IConfiguredSite targetSite,
62         FeatureHierarchyElement[] optionalElements,
63         boolean isPatch) {
64         for (int i = 0; i < optionalElements.length; i++) {
65             FeatureHierarchyElement[] children =
66                 optionalElements[i].getChildren(true, isPatch, config);
67             getUnconfiguredOptionalFeatures(
68                 unconfiguredOptionalFeatures,
69                 config,
70                 targetSite,
71                 children,
72                 isPatch);
73             if (!optionalElements[i].isEnabled(config)) {
74                 unconfiguredOptionalFeatures.add(optionalElements[i].getFeature());
75             }
76         }
77     }
78
79     private void computeElements() {
80         try {
81             IFeature oldFeature = job.getOldFeature();
82             IFeature newFeature = job.getFeature();
83             ArrayList JavaDoc list = new ArrayList JavaDoc();
84             boolean patch = UpdateUtils.isPatch(newFeature);
85             FeatureHierarchyElement.computeElements(
86                 oldFeature,
87                 newFeature,
88                 oldFeature != null,
89                 patch,
90                 SiteManager.getLocalSite().getCurrentConfiguration(),
91                 list);
92             elements = new FeatureHierarchyElement[list.size()];
93             list.toArray(elements);
94             for (int i = 0; i < elements.length; i++) {
95                 elements[i].setRoot(this);
96             }
97         } catch (CoreException e) {
98             UpdateUtils.logException(e);
99         }
100     }
101 }
102
Popular Tags