01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.text.bundle;
11:
12: import java.io.IOException;
13: import java.io.InputStream;
14:
15: import org.eclipse.core.runtime.CoreException;
16: import org.eclipse.jface.text.IDocument;
17: import org.eclipse.osgi.util.ManifestElement;
18: import org.eclipse.pde.internal.core.NLResourceHelper;
19: import org.eclipse.pde.internal.core.ibundle.IBundle;
20: import org.eclipse.pde.internal.core.ibundle.IBundleModel;
21: import org.eclipse.pde.internal.core.ibundle.IBundleModelFactory;
22: import org.eclipse.pde.internal.core.text.AbstractEditingModel;
23: import org.osgi.framework.BundleException;
24: import org.osgi.framework.Constants;
25:
26: public class BundleModel extends AbstractEditingModel implements
27: IBundleModel {
28:
29: private IBundle fBundle;
30: private IBundleModelFactory fFactory;
31:
32: /**
33: * @param document
34: * @param isReconciling
35: */
36: public BundleModel(IDocument document, boolean isReconciling) {
37: super (document, isReconciling);
38: fBundle = new Bundle(this );
39: }
40:
41: /* (non-Javadoc)
42: * @see org.eclipse.pde.internal.ui.model.AbstractEditingModel#createNLResourceHelper()
43: */
44: protected NLResourceHelper createNLResourceHelper() {
45: return null;
46: }
47:
48: /* (non-Javadoc)
49: * @see org.eclipse.pde.internal.core.ibundle.IBundleModel#isFragmentModel()
50: */
51: public boolean isFragmentModel() {
52: return getBundle().getHeader(Constants.FRAGMENT_HOST) != null;
53: }
54:
55: /* (non-Javadoc)
56: * @see org.eclipse.pde.core.IModel#load(java.io.InputStream, boolean)
57: */
58: public void load(InputStream source, boolean outOfSync)
59: throws CoreException {
60: try {
61: fLoaded = true;
62: ((Bundle) getBundle()).clearHeaders();
63: ((Bundle) getBundle()).load(ManifestElement
64: .parseBundleManifest(source, null));
65: } catch (BundleException e) {
66: fLoaded = false;
67: } catch (IOException e) {
68: fLoaded = false;
69: }
70: }
71:
72: /* (non-Javadoc)
73: * @see org.eclipse.pde.internal.ui.model.AbstractEditingModel#adjustOffsets(org.eclipse.jface.text.IDocument)
74: */
75: public void adjustOffsets(IDocument document) {
76: ((Bundle) getBundle()).clearOffsets();
77: ((Bundle) getBundle()).adjustOffsets(document);
78: }
79:
80: /* (non-Javadoc)
81: * @see org.eclipse.pde.internal.core.ibundle.IBundleModel#getBundle()
82: */
83: public IBundle getBundle() {
84: return fBundle;
85: }
86:
87: public IBundleModelFactory getFactory() {
88: if (fFactory == null)
89: fFactory = new BundleModelFactory(this);
90: return fFactory;
91: }
92:
93: }
|