KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > text > bundle > BundleModel


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.pde.internal.core.text.bundle;
12
13 import java.io.IOException JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.osgi.util.ManifestElement;
19 import org.eclipse.pde.internal.core.NLResourceHelper;
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.IBundleModelFactory;
23 import org.eclipse.pde.internal.core.text.AbstractEditingModel;
24 import org.osgi.framework.BundleException;
25 import org.osgi.framework.Constants;
26
27 public class BundleModel extends AbstractEditingModel implements IBundleModel {
28
29     private IBundle fBundle;
30     private IBundleModelFactory fFactory;
31     /**
32      * @param document
33      * @param isReconciling
34      */

35     public BundleModel(IDocument document, boolean isReconciling) {
36         super(document, isReconciling);
37         fBundle = new Bundle(this);
38     }
39     /* (non-Javadoc)
40      * @see org.eclipse.pde.internal.ui.model.AbstractEditingModel#createNLResourceHelper()
41      */

42     protected NLResourceHelper createNLResourceHelper() {
43         return null;
44     }
45     /* (non-Javadoc)
46      * @see org.eclipse.pde.internal.core.ibundle.IBundleModel#isFragmentModel()
47      */

48     public boolean isFragmentModel() {
49         return getBundle().getHeader(Constants.FRAGMENT_HOST) != null;
50     }
51     
52     /* (non-Javadoc)
53      * @see org.eclipse.pde.core.IModel#load(java.io.InputStream, boolean)
54      */

55     public void load(InputStream JavaDoc source, boolean outOfSync) throws CoreException {
56         try {
57             fLoaded = true;
58             ((Bundle)getBundle()).clearHeaders();
59             ((Bundle)getBundle()).load(ManifestElement.parseBundleManifest(source, null));
60         } catch (BundleException e) {
61             fLoaded = false;
62         } catch (IOException JavaDoc e) {
63             fLoaded = false;
64         }
65     }
66     
67     /* (non-Javadoc)
68      * @see org.eclipse.pde.internal.ui.model.AbstractEditingModel#adjustOffsets(org.eclipse.jface.text.IDocument)
69      */

70     public void adjustOffsets(IDocument document) {
71         ((Bundle)getBundle()).clearOffsets();
72         ((Bundle)getBundle()).adjustOffsets(document);
73     }
74     /* (non-Javadoc)
75      * @see org.eclipse.pde.internal.core.ibundle.IBundleModel#getBundle()
76      */

77     public IBundle getBundle() {
78         return fBundle;
79     }
80     public IBundleModelFactory getFactory() {
81         if (fFactory == null)
82             fFactory = new BundleModelFactory(this);
83         return fFactory;
84     }
85     
86 }
87
Popular Tags