KickJava   Java API By Example, From Geeks To Geeks.

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


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.framework.ServiceReference;
40
41 class ServiceReferenceImpl implements ServiceReference
42 {
43     private ServiceRegistrationImpl m_registration = null;
44     private Bundle m_bundle = null;
45
46     public ServiceReferenceImpl(ServiceRegistrationImpl reg, Bundle bundle)
47     {
48         m_registration = reg;
49         m_bundle = bundle;
50     }
51
52     protected ServiceRegistrationImpl getServiceRegistration()
53     {
54         return m_registration;
55     }
56
57     public Object JavaDoc getProperty(String JavaDoc s)
58     {
59         Oscar.debug("ServiceReference.getProperty(\"" + s + "\")");
60         return m_registration.getProperty(s);
61     }
62
63     public String JavaDoc[] getPropertyKeys()
64     {
65         Oscar.debug("ServiceReference.getPropertyKeys()");
66         return m_registration.getPropertyKeys();
67     }
68
69     public Bundle getBundle()
70     {
71         return m_bundle;
72     }
73
74     public Bundle[] getUsingBundles()
75     {
76         return m_registration.getUsingBundles();
77     }
78
79     public boolean equals(Object JavaDoc obj)
80     {
81         try {
82             ServiceReferenceImpl ref = (ServiceReferenceImpl) obj;
83             return ref.m_registration == m_registration;
84         } catch (ClassCastException JavaDoc ex) {
85             // Ignore and return false.
86
} catch (NullPointerException JavaDoc ex) {
87             // Ignore and return false.
88
}
89
90         return false;
91     }
92
93     public int hashCode()
94     {
95         if (m_registration.getReference() != null)
96         {
97             if (m_registration.getReference() != this)
98                 return m_registration.getReference().hashCode();
99             return super.hashCode();
100         }
101         return 0;
102     }
103
104     public String JavaDoc toString()
105     {
106         String JavaDoc[] ocs = (String JavaDoc[]) getProperty("objectClass");
107         String JavaDoc oc = "[";
108         for(int i = 0; i < ocs.length; i++)
109         {
110             oc = oc + ocs[i];
111             if (i < ocs.length - 1)
112                 oc = oc + ", ";
113         }
114         oc = oc + "]";
115         return oc;
116     }
117 }
Popular Tags