KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > core > FeatureExecutableContentConsumer


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.core;
12
13  
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.update.core.ContentReference;
20 import org.eclipse.update.core.IContentConsumer;
21 import org.eclipse.update.core.IFeature;
22 import org.eclipse.update.core.IFeatureContentConsumer;
23 import org.eclipse.update.core.IFeatureReference;
24 import org.eclipse.update.core.INonPluginEntry;
25 import org.eclipse.update.core.IPluginEntry;
26
27 /**
28  * ContentConsumer Implementation for a FeatureExecutable
29  */

30
31 public class FeatureExecutableContentConsumer extends FeatureContentConsumer {
32
33     private IFeature feature;
34     private boolean closed= false;
35     private boolean aborted= false;
36     private ISiteContentConsumer contentConsumer;
37     private IFeatureContentConsumer parent = null;
38     private List JavaDoc /* of IFeatureContentCOnsumer */ children;
39
40     /*
41      * @see IContentConsumer#open(INonPluginEntry)
42      */

43     public IContentConsumer open(INonPluginEntry nonPluginEntry)
44         throws CoreException {
45         ContentConsumer cons = new NonPluginEntryContentConsumer(
46             getContentConsumer().open(nonPluginEntry));
47         return cons;
48     }
49
50     /*
51      * @see IContentConsumer#open(IPluginEntry)
52      */

53     public IContentConsumer open(IPluginEntry pluginEntry) throws CoreException {
54         ContentConsumer cons = new PluginEntryContentConsumer(getContentConsumer().open(pluginEntry));
55         return cons;
56     }
57
58     /*
59      * @see IContentConsumer#addChild(IFeature)
60      */

61     public void addChild(IFeature child) throws CoreException {
62         IFeatureContentConsumer childConsumer = child.getFeatureContentConsumer();
63         childConsumer.setParent(this);
64         if (children==null) children = new ArrayList JavaDoc();
65         children.add(childConsumer);
66         return;
67     }
68
69
70     /*
71      * @see IFeatureContentConsumer#store(ContentReference, IProgressMonitor)
72      */

73     public void store(ContentReference contentReference, IProgressMonitor monitor)
74         throws CoreException {
75         getContentConsumer().store(contentReference, monitor);
76     }
77
78     /*
79      * @see IFeatureContentConsumer#close()
80      */

81     public IFeatureReference close() throws CoreException {
82         
83         if (!closed && getParent()!=null){
84             closed=true;
85             return null;
86         }
87         
88         // parent consumer, log we are about to rename
89
// log files have been downloaded
90
if (getParent()==null){
91             ErrorRecoveryLog.getLog().append(ErrorRecoveryLog.ALL_INSTALLED);
92         }
93         
94         IFeatureReference ref= null;
95         if (contentConsumer != null)
96             ref = contentConsumer.close();
97         
98         // close nested feature
99
IFeatureContentConsumer[] children = getChildren();
100         for (int i = 0; i < children.length; i++) {
101             children[i].close();
102         }
103                             
104         return ref;
105     }
106
107     /*
108      * @see IFeatureContentConsumer#setFeature(IFeature)
109      */

110     public void setFeature(IFeature feature) {
111         this.feature= feature;
112     }
113
114     /*
115      * Sets the parent
116      */

117     public void setParent(IFeatureContentConsumer featureContentConsumer) {
118         this.parent= featureContentConsumer;
119     }
120
121     /*
122      * returns the Content Consumer for the feature
123      *
124      * Right now we are the only one to implement SiteContentConsumer
125      * Need to be exposed as API post v2.0
126      */

127     private ISiteContentConsumer getContentConsumer() throws CoreException {
128         if (contentConsumer == null)
129             if (feature.getSite() instanceof SiteFile) {
130                 SiteFile site= (SiteFile) feature.getSite();
131                 contentConsumer= site.createSiteContentConsumer(feature);
132             } else {
133                 throw new UnsupportedOperationException JavaDoc();
134             }
135         return contentConsumer;
136     }
137
138     /*
139      * @see IFeatureContentConsumer#abort()
140      */

141     public void abort() throws CoreException {
142
143         if (aborted) return;
144         
145         IFeatureContentConsumer[] children = getChildren();
146         for (int i = 0; i < children.length; i++) {
147             try {
148             children[i].abort();
149             } catch (Exception JavaDoc e){
150                 //do Nothing
151
}
152         }
153
154         // do not close plugin and non plugin content consumer
155
// the contentConsumer will abort them
156
// we do not need to abort the NonPluginEntryContentConsumer and PluginEntryContentConsume
157

158         //implement the cleanup
159
if (contentConsumer!=null)
160             contentConsumer.abort();
161         
162         aborted = true;
163     }
164
165     /*
166      * @see IFeatureContentConsumer#getFeature()
167      */

168     public IFeature getFeature(){
169         return feature;
170     }
171
172     /*
173      * @see IFeatureContentConsumer#getParent()
174      */

175     public IFeatureContentConsumer getParent(){
176         return parent;
177     }
178
179     /*
180      * @see IFeatureContentConsumer#getChildren()
181      */

182     public IFeatureContentConsumer[] getChildren(){
183         if (children==null || children.size() == 0)
184             return new IFeatureContentConsumer[0];
185
186         return (IFeatureContentConsumer[]) children.toArray(arrayTypeFor(children));
187     }
188 }
189
Popular Tags