1 11 package org.eclipse.pde.internal.core.bundle; 12 13 import java.io.InputStream ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.pde.core.IEditableModel; 18 import org.eclipse.pde.core.plugin.IPluginBase; 19 import org.eclipse.pde.core.plugin.ISharedExtensionsModel; 20 import org.eclipse.pde.internal.core.ibundle.IBundle; 21 import org.eclipse.pde.internal.core.ibundle.IBundleModel; 22 import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase; 23 import org.eclipse.pde.internal.core.plugin.WorkspaceExtensionsModel; 24 import org.eclipse.pde.internal.core.plugin.WorkspacePluginModelBase; 25 26 public abstract class WorkspaceBundlePluginModelBase extends WorkspacePluginModelBase implements IBundlePluginModelBase{ 27 28 private static final long serialVersionUID = 1L; 29 private ISharedExtensionsModel fExtensionsModel = null; 30 private IBundleModel fBundleModel = null; 31 private IFile fPluginFile; 32 33 public WorkspaceBundlePluginModelBase(IFile manifestFile, IFile pluginFile) { 34 super(manifestFile, false); 35 fPluginFile = pluginFile; 36 } 37 38 abstract public IPluginBase createPluginBase(); 39 40 public void load(InputStream stream, boolean outOfSync) throws CoreException { 41 if (fPluginBase == null) 42 fPluginBase = createPluginBase(); 43 44 if (fBundleModel == null) { 45 fBundleModel = new WorkspaceBundleModel((IFile)getUnderlyingResource()); 46 } 47 fBundleModel.load(stream, outOfSync); 48 } 49 50 public void save() { 51 if (fExtensionsModel != null && fExtensionsModel.getExtensions().getExtensions().length > 0) { 52 ((BundlePluginBase)fPluginBase).updateSingleton(true); 53 if (((IEditableModel) fExtensionsModel).isDirty()) 54 ((IEditableModel) fExtensionsModel).save(); 55 } 56 57 if (fBundleModel != null && ((IEditableModel)fBundleModel).isDirty()) 58 ((IEditableModel)fBundleModel).save(); 59 } 60 61 public String getContents() { 62 if (fBundleModel != null && fBundleModel instanceof WorkspaceBundleModel) 63 return ((WorkspaceBundleModel)fBundleModel).getContents(); 64 return null; 65 } 66 67 public String getBundleLocalization() { 68 IBundle bundle = fBundleModel != null ? fBundleModel.getBundle() : null; 69 return bundle != null ? bundle.getLocalization() : null; 70 } 71 72 public IBundleModel getBundleModel() { 73 if (fBundleModel == null) { 74 IFile file = (IFile)getUnderlyingResource(); 75 fBundleModel = new WorkspaceBundleModel((IFile)getUnderlyingResource()); 76 if (file.exists()) { 77 try { 78 fBundleModel.load(); 79 } catch (CoreException e) { 80 } 81 } 82 } 83 return fBundleModel; 84 } 85 86 public ISharedExtensionsModel getExtensionsModel() { 87 if (fExtensionsModel == null && fPluginFile != null) { 88 fExtensionsModel = new WorkspaceExtensionsModel(fPluginFile); 89 if (fPluginFile.exists()) 90 try { 91 fExtensionsModel.load(); 92 } catch (CoreException e) { 93 } 94 } 95 return fExtensionsModel; 96 } 97 98 public void setBundleModel(IBundleModel bundleModel) { 99 if (bundleModel instanceof IEditableModel) 100 fBundleModel = bundleModel; 101 } 102 103 104 public void setExtensionsModel(ISharedExtensionsModel extensionsModel) { 105 if (extensionsModel instanceof IEditableModel) 106 fExtensionsModel = extensionsModel; 107 } 108 109 } 110 | Popular Tags |