001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.core.bundle;
011:
012: import java.io.InputStream;
013:
014: import org.eclipse.core.resources.IFile;
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.pde.core.IEditableModel;
017: import org.eclipse.pde.core.plugin.IPluginBase;
018: import org.eclipse.pde.core.plugin.ISharedExtensionsModel;
019: import org.eclipse.pde.internal.core.ibundle.IBundle;
020: import org.eclipse.pde.internal.core.ibundle.IBundleModel;
021: import org.eclipse.pde.internal.core.ibundle.IBundlePluginModelBase;
022: import org.eclipse.pde.internal.core.plugin.WorkspaceExtensionsModel;
023: import org.eclipse.pde.internal.core.plugin.WorkspacePluginModelBase;
024:
025: public abstract class WorkspaceBundlePluginModelBase extends
026: WorkspacePluginModelBase implements IBundlePluginModelBase {
027:
028: private static final long serialVersionUID = 1L;
029: private ISharedExtensionsModel fExtensionsModel = null;
030: private IBundleModel fBundleModel = null;
031: private IFile fPluginFile;
032:
033: public WorkspaceBundlePluginModelBase(IFile manifestFile,
034: IFile pluginFile) {
035: super (manifestFile, false);
036: fPluginFile = pluginFile;
037: }
038:
039: abstract public IPluginBase createPluginBase();
040:
041: public void load(InputStream stream, boolean outOfSync)
042: throws CoreException {
043: if (fPluginBase == null)
044: fPluginBase = createPluginBase();
045:
046: if (fBundleModel == null) {
047: fBundleModel = new WorkspaceBundleModel(
048: (IFile) getUnderlyingResource());
049: }
050: fBundleModel.load(stream, outOfSync);
051: }
052:
053: public void save() {
054: if (fExtensionsModel != null
055: && fExtensionsModel.getExtensions().getExtensions().length > 0) {
056: ((BundlePluginBase) fPluginBase).updateSingleton(true);
057: if (((IEditableModel) fExtensionsModel).isDirty())
058: ((IEditableModel) fExtensionsModel).save();
059: }
060:
061: if (fBundleModel != null
062: && ((IEditableModel) fBundleModel).isDirty())
063: ((IEditableModel) fBundleModel).save();
064: }
065:
066: public String getContents() {
067: if (fBundleModel != null
068: && fBundleModel instanceof WorkspaceBundleModel)
069: return ((WorkspaceBundleModel) fBundleModel).getContents();
070: return null;
071: }
072:
073: public String getBundleLocalization() {
074: IBundle bundle = fBundleModel != null ? fBundleModel
075: .getBundle() : null;
076: return bundle != null ? bundle.getLocalization() : null;
077: }
078:
079: public IBundleModel getBundleModel() {
080: if (fBundleModel == null) {
081: IFile file = (IFile) getUnderlyingResource();
082: fBundleModel = new WorkspaceBundleModel(
083: (IFile) getUnderlyingResource());
084: if (file.exists()) {
085: try {
086: fBundleModel.load();
087: } catch (CoreException e) {
088: }
089: }
090: }
091: return fBundleModel;
092: }
093:
094: public ISharedExtensionsModel getExtensionsModel() {
095: if (fExtensionsModel == null && fPluginFile != null) {
096: fExtensionsModel = new WorkspaceExtensionsModel(fPluginFile);
097: ((WorkspaceExtensionsModel) fExtensionsModel)
098: .setBundleModel(this );
099: ((WorkspaceExtensionsModel) fExtensionsModel)
100: .setEditable(isEditable());
101: if (fPluginFile.exists())
102: try {
103: fExtensionsModel.load();
104: } catch (CoreException e) {
105: }
106: }
107: return fExtensionsModel;
108: }
109:
110: public void setBundleModel(IBundleModel bundleModel) {
111: if (bundleModel instanceof IEditableModel)
112: fBundleModel = bundleModel;
113: }
114:
115: public void setExtensionsModel(
116: ISharedExtensionsModel extensionsModel) {
117: if (extensionsModel instanceof IEditableModel)
118: fExtensionsModel = extensionsModel;
119: }
120:
121: }
|