KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.InputStream JavaDoc;
39 import java.net.URL JavaDoc;
40 import java.util.Dictionary JavaDoc;
41
42 import org.osgi.framework.Bundle;
43 import org.osgi.framework.BundleException;
44 import org.osgi.framework.ServiceReference;
45
46 class BundleImpl implements Bundle
47 {
48     private Oscar m_oscar = null;
49     private BundleInfo m_info = null;
50
51     protected BundleImpl(Oscar oscar, BundleInfo info)
52     {
53         m_oscar = oscar;
54         m_info = info;
55     }
56
57     Oscar getOscar() // package protected
58
{
59         return m_oscar;
60     }
61
62     BundleInfo getInfo() // package protected
63
{
64         return m_info;
65     }
66
67     void setInfo(BundleInfo info) // package protected
68
{
69         m_info = info;
70     }
71
72     public long getBundleId()
73     {
74         return m_oscar.getBundleId(this);
75     }
76
77     public Dictionary JavaDoc getHeaders()
78     {
79         return m_oscar.getBundleHeaders(this);
80     }
81
82     public String JavaDoc getLocation()
83     {
84         return m_oscar.getBundleLocation(this);
85     }
86
87     /**
88      * Returns a URL to a named resource in the bundle.
89      *
90      * @return a URL to named resource, or null if not found.
91     **/

92     public URL JavaDoc getResource(String JavaDoc name)
93     {
94         return m_oscar.getBundleResource(this, name);
95     }
96
97     /**
98      * Returns an array of service references corresponding to
99      * the bundle's registered services.
100      *
101      * @return an array of service references or null.
102     **/

103     public ServiceReference[] getRegisteredServices()
104     {
105         Oscar.debug("BundleImpl.getRegisteredServices()");
106         return m_oscar.getBundleRegisteredServices(this);
107     }
108
109     public ServiceReference[] getServicesInUse()
110     {
111         Oscar.debug("BundleImpl.getServicesInUse()");
112         return m_oscar.getBundleServicesInUse(this);
113     }
114
115     public int getState()
116     {
117         return m_oscar.getBundleState(this);
118     }
119
120     public boolean hasPermission(Object JavaDoc obj)
121     {
122         return m_oscar.bundleHasPermission(this, obj);
123     }
124
125     public void start() throws BundleException
126     {
127         Oscar.debug("BundleImpl.start() for " + getInfo().getLocation());
128         m_oscar.startBundle(this);
129     }
130
131     public void update() throws BundleException
132     {
133         update(null);
134     }
135
136     public void update(InputStream JavaDoc is) throws BundleException
137     {
138         Oscar.debug("BundleImpl.update() for " + getInfo().getLocation());
139         m_oscar.updateBundle(this, is);
140     }
141
142     public void stop() throws BundleException
143     {
144         Oscar.debug("BundleImpl.stop() for " + getInfo().getLocation());
145         m_oscar.stopBundle(this);
146     }
147
148     public void uninstall() throws BundleException
149     {
150         Oscar.debug("BundleImpl.uninstall() for " + getInfo().getLocation());
151         m_oscar.uninstallBundle(this);
152     }
153
154     public String JavaDoc toString()
155     {
156         return "[" + getBundleId() +"]";
157     }
158 }
Popular Tags