KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ungoverned > oscar > ExportedPackageImpl


1 /*
2  * Oscar - An implementation of the OSGi framework.
3  * Copyright (c) 2004, Richard S. Hall
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  * * Neither the name of the ungoverned.org nor the names of its
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Contact: Richard S. Hall (heavy@ungoverned.org)
33  * Contributor(s):
34  *
35 **/

36 package org.ungoverned.oscar;
37
38 import org.osgi.framework.Bundle;
39 import org.osgi.service.packageadmin.ExportedPackage;
40
41 class ExportedPackageImpl implements ExportedPackage
42 {
43     private Oscar m_oscar = null;
44     private BundleImpl m_exporter = null;
45     private String JavaDoc m_name = null;
46     private int[] m_version = null;
47     private String JavaDoc m_toString = null;
48     private String JavaDoc m_versionString = null;
49
50     public ExportedPackageImpl(
51         Oscar oscar, BundleImpl exporter, String JavaDoc name, int[] version)
52     {
53         m_oscar = oscar;
54         m_exporter = exporter;
55         m_name = name;
56         m_version = version;
57     }
58
59     public Bundle getExportingBundle()
60     {
61         // If remove is pending due to a bundle update, then
62
// return null per the spec.
63
if (m_exporter.getInfo().isRemovalPending())
64         {
65             return null;
66         }
67         return m_exporter;
68     }
69
70     /**
71      * Returns the exporting bundle whether the package is state or
72      * not. This is called internally to get access to the exporting
73      * bundle during a refresh operation, which is not possible using
74      * <tt>getExportingBundle</tt> since the specification says that
75      * method must return <tt>null</tt> for stale packages.
76      * @return the exporting bundle for the package.
77     **/

78     protected Bundle getExportingBundleInternal()
79     {
80         return m_exporter;
81     }
82     
83     public Bundle[] getImportingBundles()
84     {
85         // If remove is pending due to a bundle update, then
86
// return null per the spec.
87
if (m_exporter.getInfo().isRemovalPending())
88         {
89             return null;
90         }
91         return m_oscar.getImportingBundles(this);
92     }
93
94     public String JavaDoc getName()
95     {
96         return m_name;
97     }
98
99     public String JavaDoc getSpecificationVersion()
100     {
101         if (m_versionString == null)
102         {
103             if (m_version == null)
104             {
105                 m_versionString = "0.0.0";
106             }
107             else
108             {
109                 m_versionString =
110                     "" + m_version[0] + "." + m_version[1] + "." + m_version[2];
111             }
112         }
113         return m_versionString;
114     }
115
116     public boolean isRemovalPending()
117     {
118         return m_exporter.getInfo().isRemovalPending();
119     }
120
121     public String JavaDoc toString()
122     {
123         if (m_toString == null)
124         {
125             m_toString = m_name
126                 + "; specification-version=" + getSpecificationVersion();
127         }
128         return m_toString;
129     }
130 }
Popular Tags