KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > osgi > framework > internal > core > ExportedPackageImpl


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 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.osgi.framework.internal.core;
12
13 import java.util.ArrayList JavaDoc;
14 import org.eclipse.osgi.service.resolver.BundleDescription;
15 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
16 import org.osgi.framework.*;
17 import org.osgi.framework.Constants;
18 import org.osgi.service.packageadmin.ExportedPackage;
19
20 public class ExportedPackageImpl implements ExportedPackage {
21
22     String JavaDoc specVersion;
23     ExportPackageDescription exportedPackage;
24     BundleLoaderProxy supplier;
25
26     public ExportedPackageImpl(ExportPackageDescription exportedPackage, BundleLoaderProxy supplier) {
27         this.exportedPackage = exportedPackage;
28         this.supplier = supplier;
29         Version version = exportedPackage.getVersion();
30         if (version != null)
31             this.specVersion = version.toString();
32     }
33
34     public String JavaDoc getName() {
35         return exportedPackage.getName();
36     }
37
38     public org.osgi.framework.Bundle getExportingBundle() {
39         if (supplier.isStale())
40             return null;
41         return supplier.getBundleHost();
42     }
43
44     public Bundle[] getImportingBundles() {
45         if (supplier.isStale())
46             return null;
47         AbstractBundle bundle = (AbstractBundle) getExportingBundle();
48         if (bundle == null)
49             return null;
50         AbstractBundle[] bundles = bundle.framework.getAllBundles();
51         ArrayList JavaDoc importers = new ArrayList JavaDoc(10);
52         PackageSource supplierSource = supplier.createPackageSource(exportedPackage, false);
53         for (int i = 0; i < bundles.length; i++) {
54             if (!(bundles[i] instanceof BundleHost))
55                 continue;
56             BundleLoader loader = ((BundleHost) bundles[i]).getBundleLoader();
57             if (loader == null)
58                 continue;
59             PackageSource importerSource = loader.getPackageSource(getName());
60             if (supplierSource != null && supplierSource.hasCommonSource(importerSource))
61                 importers.add(bundles[i]);
62         }
63         return (Bundle[]) importers.toArray(new Bundle[importers.size()]);
64     }
65
66     public String JavaDoc getSpecificationVersion() {
67         return specVersion;
68     }
69
70     public Version getVersion() {
71         return exportedPackage.getVersion();
72     }
73
74     public boolean isRemovalPending() {
75         BundleDescription exporter = exportedPackage.getExporter();
76         if (exporter != null)
77             return exporter.isRemovalPending();
78         return true;
79     }
80
81     public String JavaDoc toString() {
82         StringBuffer JavaDoc result = new StringBuffer JavaDoc(getName());
83         if (specVersion != null) {
84             result.append("; ").append(Constants.VERSION_ATTRIBUTE); //$NON-NLS-1$
85
result.append("=\"").append(specVersion).append("\""); //$NON-NLS-1$//$NON-NLS-2$
86
}
87         return result.toString();
88     }
89 }
90
Popular Tags