1 11 package org.eclipse.update.internal.core; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 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 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 children; 39 40 43 public IContentConsumer open(INonPluginEntry nonPluginEntry) 44 throws CoreException { 45 ContentConsumer cons = new NonPluginEntryContentConsumer( 46 getContentConsumer().open(nonPluginEntry)); 47 return cons; 48 } 49 50 53 public IContentConsumer open(IPluginEntry pluginEntry) throws CoreException { 54 ContentConsumer cons = new PluginEntryContentConsumer(getContentConsumer().open(pluginEntry)); 55 return cons; 56 } 57 58 61 public void addChild(IFeature child) throws CoreException { 62 IFeatureContentConsumer childConsumer = child.getFeatureContentConsumer(); 63 childConsumer.setParent(this); 64 if (children==null) children = new ArrayList (); 65 children.add(childConsumer); 66 return; 67 } 68 69 70 73 public void store(ContentReference contentReference, IProgressMonitor monitor) 74 throws CoreException { 75 getContentConsumer().store(contentReference, monitor); 76 } 77 78 81 public IFeatureReference close() throws CoreException { 82 83 if (!closed && getParent()!=null){ 84 closed=true; 85 return null; 86 } 87 88 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 IFeatureContentConsumer[] children = getChildren(); 100 for (int i = 0; i < children.length; i++) { 101 children[i].close(); 102 } 103 104 return ref; 105 } 106 107 110 public void setFeature(IFeature feature) { 111 this.feature= feature; 112 } 113 114 117 public void setParent(IFeatureContentConsumer featureContentConsumer) { 118 this.parent= featureContentConsumer; 119 } 120 121 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 (); 134 } 135 return contentConsumer; 136 } 137 138 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 e){ 150 } 152 } 153 154 158 if (contentConsumer!=null) 160 contentConsumer.abort(); 161 162 aborted = true; 163 } 164 165 168 public IFeature getFeature(){ 169 return feature; 170 } 171 172 175 public IFeatureContentConsumer getParent(){ 176 return parent; 177 } 178 179 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 |