KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > adaptor > core > AbstractBundleData


1 /*******************************************************************************
2  * Copyright (c) 2004, 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.adaptor.core;
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.net.MalformedURLException JavaDoc;
17 import java.net.URL JavaDoc;
18 import java.util.*;
19 import org.eclipse.osgi.framework.adaptor.*;
20 import org.eclipse.osgi.framework.debug.Debug;
21 import org.eclipse.osgi.framework.internal.core.Constants;
22 import org.eclipse.osgi.framework.internal.protocol.bundleentry.Handler;
23 import org.eclipse.osgi.framework.util.Headers;
24 import org.eclipse.osgi.util.ManifestElement;
25 import org.eclipse.osgi.util.NLS;
26 import org.osgi.framework.*;
27
28 /**
29  * An abstract BundleData class that has default implementations that most
30  * BundleData implementations can use.
31  * <p>
32  * Clients may extend this class.
33  * </p>
34  * @since 3.1
35  */

36 public abstract class AbstractBundleData implements BundleData, Cloneable JavaDoc {
37
38     /** the Adaptor for this BundleData */
39     protected AbstractFrameworkAdaptor adaptor;
40
41     /**
42      * The Bundle Manifest for this BundleData.
43      */

44     protected Dictionary manifest = null;
45
46     /**
47      * The Bundle object for this BundleData.
48      */

49     protected Bundle bundle;
50
51     /** bundle id */
52     protected long id;
53
54     /** The top level storage directory for the BundleData */
55     protected File JavaDoc bundleStoreDir;
56
57     /** The base BundleFile object for this BundleData */
58     protected BundleFile baseBundleFile;
59     ///////////////////// Begin Meta Data for the Bundle /////////////////////
60

61     /** bundle location */
62     private String JavaDoc location;
63
64     /** bundle's file name */
65     private String JavaDoc fileName;
66
67     /** native code paths for this BundleData */
68     private String JavaDoc[] nativePaths;
69
70     /** bundle generation */
71     private int generation = 1;
72
73     /** the bundles start level */
74     private int startLevel = -1;
75
76     /**
77      * The BundleData data directory
78      */

79     protected File JavaDoc dirData;
80
81     /** the bundles status */
82     private int status = 0;
83
84     /** Is bundle a reference */
85     private boolean reference;
86
87     /** the bundles last modified timestamp */
88     private long lastModified;
89
90     ///////////////////// End Meta Data for the Bundle /////////////////////
91

92     ///////////////////// Begin values from Manifest /////////////////////
93
private String JavaDoc symbolicName;
94     private Version version;
95     private String JavaDoc activator;
96     private String JavaDoc classpath;
97     private String JavaDoc executionEnvironment;
98     private String JavaDoc dynamicImports;
99     private int type;
100
101     ///////////////////// End values from Manifest /////////////////////
102

103     /**
104      * Constructor for AbstractBundleData
105      * @param adaptor The adaptor for this bundle data
106      * @param id The bundle id for this bundle data
107      */

108     public AbstractBundleData(AbstractFrameworkAdaptor adaptor, long id) {
109         this.adaptor = adaptor;
110         this.id = id;
111         initBundleStoreDirs(String.valueOf(id));
112     }
113
114     /**
115      * @see BundleData#getManifest()
116      */

117     public Dictionary getManifest() throws BundleException {
118         if (manifest == null) {
119             synchronized (this) {
120                 // make sure the manifest is still null after we have aquired the lock.
121
if (manifest == null) {
122                     URL JavaDoc url = getEntry(Constants.OSGI_BUNDLE_MANIFEST);
123                     if (url == null) {
124                         throw new BundleException(NLS.bind(AdaptorMsg.MANIFEST_NOT_FOUND_EXCEPTION, Constants.OSGI_BUNDLE_MANIFEST, getLocation()));
125                     }
126                     try {
127                         manifest = Headers.parseManifest(url.openStream());
128                     } catch (IOException JavaDoc e) {
129                         throw new BundleException(NLS.bind(AdaptorMsg.MANIFEST_NOT_FOUND_EXCEPTION, Constants.OSGI_BUNDLE_MANIFEST, getLocation()), e);
130                     }
131                 }
132             }
133         }
134         return manifest;
135     }
136
137     /**
138      * @see BundleData#setBundle(Bundle)
139      */

140     public void setBundle(Bundle bundle) {
141         this.bundle = bundle;
142     }
143
144     /**
145      * Returns the Bundle object for this BundleData.
146      * @return the Bundle object for this BundleData.
147      */

148     public Bundle getBundle() {
149         return bundle;
150     }
151
152     /**
153      * @see BundleData#getBundleID()
154      */

155     public long getBundleID() {
156         return (id);
157     }
158
159     /**
160      * @see BundleData#getEntry(String)
161      */

162     public URL JavaDoc getEntry(String JavaDoc path) {
163         BundleEntry entry = getBaseBundleFile().getEntry(path);
164         if (entry == null) {
165             return null;
166         }
167         if (path.length() == 0 || path.charAt(0) != '/')
168             path = path = '/' + path;
169         try {
170             //use the constant string for the protocol to prevent duplication
171
return new URL JavaDoc(Constants.OSGI_ENTRY_URL_PROTOCOL, Long.toString(id), 0, path, new Handler(entry));
172         } catch (MalformedURLException JavaDoc e) {
173             return null;
174         }
175     }
176
177     /**
178      * @see BundleData#getEntryPaths(String)
179      */

180     public Enumeration getEntryPaths(String JavaDoc path) {
181         return getBaseBundleFile().getEntryPaths(path);
182     }
183
184     /**
185      * @see BundleData#createClassLoader(ClassLoaderDelegate, BundleProtectionDomain, String[])
186      */

187     public org.eclipse.osgi.framework.adaptor.BundleClassLoader createClassLoader(ClassLoaderDelegate delegate, BundleProtectionDomain domain, String JavaDoc[] bundleclasspath) {
188         return getAdaptor().getElementFactory().createClassLoader(delegate, domain, bundleclasspath, this);
189     }
190
191     /**
192      * Returns the adaptor for this bundle data.
193      * @return the adaptor for this bundle data.
194      */

195     public AbstractFrameworkAdaptor getAdaptor() {
196         return adaptor;
197     }
198
199     /**
200      * Returns a list of classpath entries from a list of manifest elements
201      * @param classpath a list of ManifestElement objects
202      * @return a list of classpath entries from a list of manifest elements
203      */

204     static String JavaDoc[] getClassPath(ManifestElement[] classpath) {
205         if (classpath == null) {
206             if (Debug.DEBUG && Debug.DEBUG_LOADER)
207                 Debug.println(" no classpath"); //$NON-NLS-1$
208
/* create default BundleClassPath */
209             return new String JavaDoc[] {"."}; //$NON-NLS-1$
210
}
211
212         ArrayList result = new ArrayList(classpath.length);
213         for (int i = 0; i < classpath.length; i++) {
214             if (Debug.DEBUG && Debug.DEBUG_LOADER)
215                 Debug.println(" found classpath entry " + classpath[i].getValueComponents()); //$NON-NLS-1$
216
String JavaDoc[] paths = classpath[i].getValueComponents();
217             for (int j = 0; j < paths.length; j++) {
218                 result.add(paths[j]);
219             }
220         }
221
222         return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
223     }
224
225     ///////////////////// Begin Meta Data Accessor Methods ////////////////////
226
/**
227      * @see BundleData#getLocation()
228      */

229     public String JavaDoc getLocation() {
230         return location;
231     }
232     /**
233      * Sets the location for this bundle data
234      * @param location the location string
235      */

236     public void setLocation(String JavaDoc location) {
237         this.location = location;
238     }
239
240     /**
241      * Returns the filename for the base file of this bundle data
242      * @return the filename for the base file of this bundle data
243      */

244     public String JavaDoc getFileName() {
245         return fileName;
246     }
247
248     /**
249      * Sets the filename for the base file of this bundle data
250      * @param fileName the name of the base file of this bundle data
251      */

252     public void setFileName(String JavaDoc fileName) {
253         this.fileName = fileName;
254     }
255
256     /**
257      * Returns the list of native file paths to install for this bundle
258      * @return the list of native file paths to install for this bundle
259      */

260     public String JavaDoc[] getNativePaths() {
261         return nativePaths;
262     }
263
264     /**
265      * Returns a comma separated list of native file paths to install for this bundle
266      * @return a comma separated list of native file paths to install for this bundle
267      */

268     public String JavaDoc getNativePathsString() {
269         if (nativePaths == null || nativePaths.length == 0)
270             return null;
271         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
272         for (int i = 0; i < nativePaths.length; i++) {
273             sb.append(nativePaths[i]);
274             if (i < nativePaths.length - 1)
275                 sb.append(',');
276         }
277         return sb.toString();
278     }
279
280     /**
281      * Sets the list of native file paths to install for this bundle
282      * @param nativePaths the list of native file paths to install for this bundle
283      */

284     public void setNativePaths(String JavaDoc[] nativePaths) {
285         this.nativePaths = nativePaths;
286     }
287
288     /**
289      * Sets the comma separated list of native file paths to install for this bundle
290      * @param nativePaths the comma separated list of native file paths to install for this bundle
291      */

292     public void setNativePaths(String JavaDoc nativePaths) {
293         if (nativePaths == null)
294             return;
295         ArrayList result = new ArrayList(5);
296         StringTokenizer st = new StringTokenizer(nativePaths, ","); //$NON-NLS-1$
297
while (st.hasMoreTokens()) {
298             String JavaDoc path = st.nextToken();
299             result.add(path);
300         }
301         setNativePaths((String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]));
302     }
303
304     /**
305      * Returns the generation number for this bundle
306      * @return the generation number for this bundle
307      */

308     public int getGeneration() {
309         return generation;
310     }
311
312     /**
313      * Sets the generation number for this bundle
314      * @param generation the generation number for this bundle
315      */

316     public void setGeneration(int generation) {
317         this.generation = generation;
318     }
319
320     /**
321      * @see BundleData#getLastModified()
322      */

323     public long getLastModified() {
324         return lastModified;
325     }
326
327     /**
328      * Sets the last modified timestamp for this bundle
329      * @param lastModified the last modified timestamp for this bundle
330      */

331     public void setLastModified(long lastModified) {
332         this.lastModified = lastModified;
333     }
334
335     /**
336      * @see BundleData#getStartLevel()
337      */

338     public int getStartLevel() {
339         return startLevel;
340     }
341
342     /**
343      * @see BundleData#setStartLevel(int)
344      */

345     public void setStartLevel(int startLevel) {
346         this.startLevel = startLevel;
347     }
348
349     /**
350      * @see BundleData#getStatus()
351      */

352     public int getStatus() {
353         return status;
354     }
355
356     /**
357      * @see BundleData#setStatus(int)
358      */

359     public void setStatus(int status) {
360         this.status = status;
361     }
362
363     /**
364      * Returns if this bundle is installed by reference
365      * @return true if this bundle is installed by reference
366      */

367     public boolean isReference() {
368         return reference;
369     }
370
371     /**
372      * Sets if this bundle is installed by reference
373      * @param reference indicates if this bundle is installed by reference
374      */

375     public void setReference(boolean reference) {
376         this.reference = reference;
377     }
378
379     ///////////////////// End Meta Data Accessor Methods ////////////////////
380

381     ///////////////////// Begin Manifest Value Accessor Methods /////////////////////
382

383     /**
384      * @see BundleData#getSymbolicName()
385      */

386     public String JavaDoc getSymbolicName() {
387         return symbolicName;
388     }
389
390     /**
391      * Returns the base storage directory for this bundle
392      * @return the base storage directory for this bundle
393      */

394     public File JavaDoc getBundleStoreDir() {
395         return bundleStoreDir;
396     }
397
398     /**
399      * Sets the symbolic name of this bundle
400      * @param symbolicName the symbolic name of this bundle
401      */

402     public void setSymbolicName(String JavaDoc symbolicName) {
403         this.symbolicName = symbolicName;
404     }
405
406     /**
407      * Loads all metadata for this bundle from the bundle manifest
408      * @throws BundleException
409      */

410     protected void loadFromManifest() throws BundleException {
411         getManifest();
412         if (manifest == null)
413             throw new BundleException(NLS.bind(AdaptorMsg.ADAPTOR_ERROR_GETTING_MANIFEST, getLocation())); //$NON-NLS-1$
414
setVersion(Version.parseVersion((String JavaDoc) manifest.get(Constants.BUNDLE_VERSION)));
415         ManifestElement[] bsnHeader = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, (String JavaDoc) manifest.get(Constants.BUNDLE_SYMBOLICNAME));
416         int bundleType = 0;
417         if (bsnHeader != null) {
418             setSymbolicName(bsnHeader[0].getValue());
419             String JavaDoc singleton = bsnHeader[0].getDirective(Constants.SINGLETON_DIRECTIVE);
420             if (singleton == null)
421                 singleton = bsnHeader[0].getAttribute(Constants.SINGLETON_DIRECTIVE);
422             if ("true".equals(singleton)) //$NON-NLS-1$
423
bundleType |= TYPE_SINGLETON;
424         }
425         setClassPathString((String JavaDoc) manifest.get(Constants.BUNDLE_CLASSPATH));
426         setActivator((String JavaDoc) manifest.get(Constants.BUNDLE_ACTIVATOR));
427         String JavaDoc host = (String JavaDoc) manifest.get(Constants.FRAGMENT_HOST);
428         if (host != null) {
429             bundleType |= TYPE_FRAGMENT;
430             ManifestElement[] hostElement = ManifestElement.parseHeader(Constants.FRAGMENT_HOST, host);
431             if (Constants.getInternalSymbolicName().equals(hostElement[0].getValue()) || Constants.OSGI_SYSTEM_BUNDLE.equals(hostElement[0].getValue())) {
432                 String JavaDoc extensionType = hostElement[0].getDirective("extension"); //$NON-NLS-1$
433
if (extensionType == null || extensionType.equals("framework")) //$NON-NLS-1$
434
bundleType |= TYPE_FRAMEWORK_EXTENSION;
435                 else
436                     bundleType |= TYPE_BOOTCLASSPATH_EXTENSION;
437             }
438         }
439         setType(bundleType);
440         setExecutionEnvironment((String JavaDoc) manifest.get(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT));
441         setDynamicImports((String JavaDoc) manifest.get(Constants.DYNAMICIMPORT_PACKAGE));
442     }
443
444     /**
445      * @see BundleData#getVersion()
446      */

447     public Version getVersion() {
448         return version;
449     }
450
451     /**
452      * Sets the version of this bundle
453      * @param version the version of this bundle
454      */

455     public void setVersion(Version version) {
456         this.version = version;
457     }
458
459     /**
460      * @see BundleData#getActivator()
461      */

462     public String JavaDoc getActivator() {
463         return activator;
464     }
465
466     /**
467      * Returns the data storage directory for this bundle
468      * @return the data storage directory for this bundle
469      */

470     protected File JavaDoc getDataDir() {
471         return dirData;
472     }
473
474     /**
475      * Sets the bundle store directory for this bundle
476      * @param bundleStoreDir the store directory for this bundle
477      */

478     protected void setBundleStoreDir(File JavaDoc bundleStoreDir) {
479         this.bundleStoreDir = bundleStoreDir;
480     }
481
482     /**
483      * Sets the initial bundle store directory according to the bundle ID
484      * @param bundleID the bundle ID
485      */

486     protected void initBundleStoreDirs(String JavaDoc bundleID) {
487         setBundleStoreDir(new File JavaDoc(((AbstractFrameworkAdaptor) adaptor).getBundleStoreRootDir(), bundleID));
488     }
489
490     /**
491      * Sets the activator for this bundle
492      * @param activator the activator for this bundle
493      */

494     public void setActivator(String JavaDoc activator) {
495         this.activator = activator;
496     }
497
498     /**
499      * @see BundleData#getClassPath()
500      */

501     public String JavaDoc[] getClassPath() throws BundleException {
502         ManifestElement[] classpathElements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, classpath);
503         return getClassPath(classpathElements);
504     }
505
506     /**
507      * Returns the Bundle-ClassPath value as specified in the bundle manifest file.
508      * @return the Bundle-ClassPath value as specified in the bundle manifest file.
509      */

510     public String JavaDoc getClassPathString() {
511         return classpath;
512     }
513
514     /**
515      * Sets the bundle classpath value of this bundle data.
516      * @param classpath the bundle classpath
517      */

518     public void setClassPathString(String JavaDoc classpath) {
519         this.classpath = classpath;
520     }
521
522     /**
523      * @see BundleData#getExecutionEnvironment()
524      */

525     public String JavaDoc getExecutionEnvironment() {
526         return executionEnvironment;
527     }
528
529     /**
530      * Sets the execution environment for this bundle
531      * @param executionEnvironment the execution environment for this bundle
532      */

533     public void setExecutionEnvironment(String JavaDoc executionEnvironment) {
534         this.executionEnvironment = executionEnvironment;
535     }
536
537     /**
538      * @see BundleData#getDynamicImports()
539      */

540     public String JavaDoc getDynamicImports() {
541         return dynamicImports;
542     }
543
544     /**
545      * Sets the dynamic imports of this bundle data.
546      * @param dynamicImports the dynamic imports
547      */

548     public void setDynamicImports(String JavaDoc dynamicImports) {
549         this.dynamicImports = dynamicImports;
550     }
551
552     /**
553      * @see BundleData#getType()
554      */

555     public int getType() {
556         return type;
557     }
558
559     /**
560      * Sets the type of this bundle
561      * @param type the type of this bundle
562      */

563     public void setType(int type) {
564         this.type = type;
565     }
566
567     ///////////////////// End Manifest Value Accessor Methods /////////////////////
568

569     /**
570      * @see BundleData#matchDNChain(String)
571      */

572     public boolean matchDNChain(String JavaDoc pattern) {
573         if (System.getSecurityManager() == null)
574             return false;
575
576         if (getBaseBundleFile() instanceof SignedBundle)
577             return ((SignedBundle) getBaseBundleFile()).matchDNChain(pattern);
578         return false;
579     }
580
581     /**
582      * Return a copy of this object with the
583      * generation dependent fields updated to
584      * the next free generation level.
585      *
586      * @throws IOException If there are no more available generation levels.
587      */

588     protected AbstractBundleData nextGeneration(String JavaDoc referenceFile) throws IOException JavaDoc {
589         int nextGeneration = getGeneration();
590
591         while (nextGeneration < Integer.MAX_VALUE) {
592             nextGeneration++;
593
594             File JavaDoc nextDirGeneration = new File JavaDoc(getBundleStoreDir(), String.valueOf(nextGeneration));
595
596             if (nextDirGeneration.exists()) {
597                 continue;
598             }
599
600             AbstractBundleData next;
601             try {
602                 next = (AbstractBundleData) clone();
603             } catch (CloneNotSupportedException JavaDoc e) {
604                 // this shouldn't happen, since we are Cloneable
605
throw new InternalError JavaDoc();
606             }
607
608             next.setGeneration(nextGeneration);
609
610             if (referenceFile != null) {
611                 next.setReference(true);
612                 next.setFileName(referenceFile);
613             } else {
614                 if (next.isReference()) {
615                     next.setReference(false);
616                     next.setFileName(AbstractFrameworkAdaptor.BUNDLEFILE_NAME);
617                 }
618             }
619
620             // null out the manifest to force it to be re-read.
621
next.manifest = null;
622             return (next);
623         }
624
625         throw new IOException JavaDoc(AdaptorMsg.ADAPTOR_STORAGE_EXCEPTION);
626     }
627
628     /**
629      * Initializes a new bundle and loads all its metadata from the bundle manifest
630      * @throws IOException
631      * @throws BundleException
632      */

633     public void initializeNewBundle() throws IOException JavaDoc, BundleException {
634         createBaseBundleFile();
635         loadFromManifest();
636     }
637
638     /**
639      * Creates the base BundleFile for this bundle
640      * @return the base BundleFile for this bundle
641      * @throws IOException if an IOExceptions occurs
642      */

643     protected BundleFile createBaseBundleFile() throws IOException JavaDoc {
644         baseBundleFile = getAdaptor().createBaseBundleFile(getBaseFile(), this);
645         return baseBundleFile;
646     }
647
648     /**
649      * Return the base File for the bundle.
650      * Attempt to create the bundle generation directory if it does not exist.
651      *
652      * @return the base File object for the bundle.
653      */

654     protected File JavaDoc getBaseFile() {
655         return isReference() ? new File JavaDoc(getFileName()) : new File JavaDoc(createGenerationDir(), getFileName());
656     }
657
658     /**
659      * Returns a list of files used for the classpath of this bundle data.
660      * the contents of the bundle are searched for the classpath entries.
661      * @param classpaths the classpath entries to search for
662      * @return a list of files used for the classpath of this bundle data.
663      */

664     protected File JavaDoc[] getClasspathFiles(String JavaDoc[] classpaths) {
665         ArrayList results = new ArrayList(classpaths.length);
666         for (int i = 0; i < classpaths.length; i++) {
667             if (".".equals(classpaths[i])) //$NON-NLS-1$
668
results.add(getBaseFile());
669             else {
670                 File JavaDoc result = getBaseBundleFile().getFile(classpaths[i]);
671                 if (result != null)
672                     results.add(result);
673             }
674         }
675         return (File JavaDoc[]) results.toArray(new File JavaDoc[results.size()]);
676     }
677
678     /**
679      * Sets the data directory for this bundle
680      * @param dirData the data directory for this bundle
681      */

682     protected void setDataDir(File JavaDoc dirData) {
683         this.dirData = dirData;
684     }
685
686     /**
687      * @see BundleData#findLibrary(String)
688      */

689     public String JavaDoc findLibrary(String JavaDoc libname) {
690         String JavaDoc mappedName = System.mapLibraryName(libname);
691         String JavaDoc path = null;
692
693         if (Debug.DEBUG && Debug.DEBUG_LOADER) {
694             Debug.println(" mapped library name: " + mappedName); //$NON-NLS-1$
695
}
696
697         path = findNativePath(mappedName);
698
699         if (path == null) {
700             if (Debug.DEBUG && Debug.DEBUG_LOADER) {
701                 Debug.println(" library does not exist: " + mappedName); //$NON-NLS-1$
702
}
703             path = findNativePath(libname);
704         }
705
706         if (Debug.DEBUG && Debug.DEBUG_LOADER) {
707             Debug.println(" returning library: " + path); //$NON-NLS-1$
708
}
709         return path;
710     }
711
712     /**
713      * @see BundleData#open()
714      */

715     public void open() throws IOException JavaDoc {
716         baseBundleFile.open();
717     }
718
719     /**
720      * Searches the native paths for a match against the specified libname.
721      * If a match is found then the native path is returned; otherwise a
722      * <code>null</code> value is returned.
723      * @param libname a library name
724      * @return a matching native path or <code>null</code>.
725      */

726     protected String JavaDoc findNativePath(String JavaDoc libname) {
727         if (!libname.startsWith("/")) { //$NON-NLS-1$
728
libname = '/' + libname;
729         }
730         String JavaDoc[] nativepaths = getNativePaths();
731         if (nativepaths != null) {
732             for (int i = 0; i < nativepaths.length; i++) {
733                 if (nativepaths[i].endsWith(libname)) {
734                     File JavaDoc nativeFile = baseBundleFile.getFile(nativepaths[i]);
735                     if (nativeFile != null)
736                         return nativeFile.getAbsolutePath();
737                 }
738             }
739         }
740         return null;
741     }
742
743     /**
744      * Return the generation directory for the bundle data. The generation
745      * directory can be used by the framework to cache files from the bundle
746      * to the file system. Attempt to create the directory if it does not exist.
747      * @return The generation directory for the bundle data or null if not
748      * supported.
749      */

750     public File JavaDoc createGenerationDir() {
751         File JavaDoc generationDir = getGenerationDir();
752         if (!generationDir.exists() && (!adaptor.canWrite() || !generationDir.mkdirs())) {
753             if (Debug.DEBUG && Debug.DEBUG_GENERAL) {
754                 Debug.println("Unable to create bundle generation directory: " + generationDir.getPath()); //$NON-NLS-1$
755
}
756         }
757
758         return generationDir;
759     }
760
761     /**
762      * Return the base BundleFile for this BundleData. The base BundleFile
763      * is the BundleFile that contains all the content of the bundle.
764      * @return the base BundleFile.
765      */

766     public BundleFile getBaseBundleFile() {
767         return baseBundleFile;
768     }
769
770     /**
771      * Close all resources for this BundleData
772      */

773     public void close() throws IOException JavaDoc {
774         if (baseBundleFile != null) {
775             baseBundleFile.close();
776         }
777     }
778
779     /**
780      * Return the bundle data directory.
781      * Attempt to create the directory if it does not exist.
782      *
783      * @return Bundle data directory.
784      */

785     public File JavaDoc getDataFile(String JavaDoc path) {
786         // lazily initialize dirData to prevent early access to configuration location
787
if (getDataDir() == null) {
788             File JavaDoc dataRoot = adaptor.getDataRootDir();
789             if (dataRoot == null)
790                 throw new IllegalStateException JavaDoc(AdaptorMsg.ADAPTOR_DATA_AREA_NOT_SET);
791             setDataDir(new File JavaDoc(dataRoot, id + "/" + AbstractFrameworkAdaptor.DATA_DIR_NAME)); //$NON-NLS-1$
792
}
793         if (!getDataDir().exists() && (!adaptor.canWrite() || !getDataDir().mkdirs())) {
794             if (Debug.DEBUG && Debug.DEBUG_GENERAL) {
795                 Debug.println("Unable to create bundle data directory: " + getDataDir().getPath()); //$NON-NLS-1$
796
}
797         }
798
799         return (new File JavaDoc(getDataDir(), path));
800     }
801
802     /**
803      * @see BundleData#installNativeCode(String[])
804      */

805     public void installNativeCode(String JavaDoc[] nativepaths) throws BundleException {
806         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
807         for (int i = 0; i < nativepaths.length; i++) {
808             // extract the native code
809
File JavaDoc nativeFile = baseBundleFile.getFile(nativepaths[i]);
810             if (nativeFile == null) {
811                 throw new BundleException(NLS.bind(AdaptorMsg.BUNDLE_NATIVECODE_EXCEPTION, nativepaths[i]));
812             }
813             sb.append(nativepaths[i]);
814             if (i < nativepaths.length - 1) {
815                 sb.append(","); //$NON-NLS-1$
816
}
817         }
818         if (sb.length() > 0)
819             setNativePaths(sb.toString());
820     }
821
822     /**
823      * Returns the generation directory for the bundle data. The returned
824      * file may not exist.
825      * @return the generation directory for the bundle data.
826      */

827     protected File JavaDoc getGenerationDir() {
828         return new File JavaDoc(getBundleStoreDir(), String.valueOf(getGeneration()));
829     }
830
831     /**
832      * Returns the parent generation directory for the bundle data. The returned
833      * file may not exist. A value of <code>null</code> is returned if there is
834      * no parent generation directory.
835      * @return the parent gneration directory for the bundle data.
836      */

837     public File JavaDoc getParentGenerationDir() {
838         return null;
839     }
840 }
841
Popular Tags