KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > defaultadaptor > DefaultBundleData


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 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
12 package org.eclipse.osgi.framework.internal.defaultadaptor;
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import org.eclipse.osgi.framework.adaptor.core.AbstractBundleData;
17 import org.eclipse.osgi.framework.debug.Debug;
18 import org.osgi.framework.BundleException;
19
20 /**
21  * The <code>BundleData</code> represents a single bundle that is persistently
22  * stored by a <code>FrameworkAdaptor</code>. A <code>BundleData</code> creates
23  * the ClassLoader for a bundle, finds native libraries installed in the
24  * FrameworkAdaptor for the bundle, creates data files for the bundle,
25  * used to access bundle entries, manifest information, and getting and saving
26  * metadata.
27  *
28  */

29 public class DefaultBundleData extends AbstractBundleData {
30     /**
31      * Read data from an existing directory.
32      * This constructor is used by getInstalledBundles.
33      *
34      * @throws NumberFormatException if the directory is not a
35      * number, the directory contains a ".delete" file or
36      * the directory does not contain a ".bundle" file.
37      * @throws IOException If an error occurs initializing the bundle data.
38      */

39     public void initializeExistingBundle() throws BundleException, IOException JavaDoc {
40         File JavaDoc delete = new File JavaDoc(getBundleStoreDir(), ".delete"); //$NON-NLS-1$
41

42         /* and the directory is not marked for delete */
43         if (delete.exists())
44             throw new IOException JavaDoc();
45
46         createBaseBundleFile();
47
48         loadFromManifest();
49     }
50
51     /**
52      * Constructs a DefaultBundleData for the DefaultAdaptor.
53      *
54      * @param adaptor the DefaultAdaptor for this DefaultBundleData
55      * @param id the Bundle ID for this DefaultBundleData
56      */

57     public DefaultBundleData(DefaultAdaptor adaptor, long id) {
58         super(adaptor, id);
59     }
60
61     public String JavaDoc toString() {
62         return getLocation();
63     }
64
65     /**
66      * Save the bundle data in the data file.
67      *
68      * @throws IOException if a write error occurs.
69      */

70     public synchronized void save() throws IOException JavaDoc {
71         if (adaptor.canWrite())
72             ((DefaultAdaptor) adaptor).saveMetaDataFor(this);
73     }
74
75     /**
76      * Return the top level bundle directory.
77      *
78      * @return Top level bundle directory.
79      */

80     protected File JavaDoc createBundleStoreDir() {
81         if (!getBundleStoreDir().exists() && !getBundleStoreDir().mkdirs()) {
82             if (Debug.DEBUG && Debug.DEBUG_GENERAL) {
83                 Debug.println("Unable to create bundle store directory: " + getBundleStoreDir().getPath()); //$NON-NLS-1$
84
}
85         }
86         return getBundleStoreDir();
87     }
88
89 }
90
Popular Tags