1 11 12 package org.eclipse.osgi.framework.internal.core; 13 14 import org.osgi.framework.Bundle; 15 import org.osgi.framework.ServiceReference; 16 17 33 34 public class ServiceReferenceImpl implements ServiceReference, Comparable { 35 36 protected ServiceRegistrationImpl registration; 37 38 42 protected ServiceReferenceImpl(ServiceRegistrationImpl registration) { 43 this.registration = registration; 44 } 45 46 58 public Object getProperty(String key) { 59 return (registration.getProperty(key)); 60 } 61 62 72 public String [] getPropertyKeys() { 73 return (registration.getPropertyKeys()); 74 } 75 76 85 public org.osgi.framework.Bundle getBundle() { 86 return (registration.getBundle()); 87 } 88 89 99 public org.osgi.framework.Bundle[] getUsingBundles() { 100 return (registration.getUsingBundles()); 101 } 102 103 108 protected String [] getClasses() { 109 return (registration.clazzes); 110 } 111 112 117 protected long getId() { 118 return (registration.serviceid); 119 } 120 121 126 protected int getRanking() { 127 return (registration.serviceranking); 128 } 129 130 135 public int hashCode() { 136 return (registration.hashCode()); 137 } 138 139 146 public boolean equals(Object obj) { 147 if (obj == this) { 148 return (true); 149 } 150 151 if (!(obj instanceof ServiceReferenceImpl)) { 152 return (false); 153 } 154 155 ServiceReferenceImpl other = (ServiceReferenceImpl) obj; 156 157 return (registration == other.registration); 158 } 159 160 165 public String toString() { 166 return (registration.toString()); 167 } 168 169 206 public int compareTo(Object object) { 207 ServiceReferenceImpl other = (ServiceReferenceImpl) object; 208 if (this.getRanking() != other.getRanking()) 209 return this.getRanking() > other.getRanking() ? -1 : 1; 210 return this.getId() == other.getId() ? 0 : this.getId() > other.getId() ? 1 : -1; 211 } 212 213 public boolean isAssignableTo(Bundle bundle, String className) { 214 AbstractBundle consumer = (AbstractBundle) bundle; 215 if (consumer.isFragment()) 217 return false; 218 BundleHost producer = (BundleHost) registration.bundle; 219 if (consumer == producer) 221 return true; 222 String pkgName = BundleLoader.getPackageName(className); 224 if (pkgName.startsWith("java.")) return true; 226 BundleLoader producerBL = producer.getBundleLoader(); 227 if (producerBL == null) 228 return false; 229 BundleLoader consumerBL = consumer.getBundleLoader(); 230 if (consumerBL == null) 231 return false; 232 PackageSource consumerSource = consumerBL.getPackageSource(pkgName); 234 if (consumerSource == null) 235 return true; 236 if (producerBL.isBootDelegationPackage(pkgName)) { 238 SystemBundleLoader systemLoader = (SystemBundleLoader) registration.framework.systemBundle.getBundleLoader(); 239 if (systemLoader.isEEPackage(pkgName)) 240 return true; } 242 PackageSource producerSource = producerBL.getPackageSource(pkgName); 244 if (producerSource == null) { 245 producerSource = getPackageSource(registration.service.getClass(), pkgName); 247 if (producerSource == null) 248 return false; 249 } 250 return producerSource.hasCommonSource(consumerSource); 252 } 253 254 private PackageSource getPackageSource(Class serviceClass, String pkgName) { 255 if (serviceClass == null) 256 return null; 257 AbstractBundle serviceBundle = (AbstractBundle) registration.framework.packageAdmin.getBundle(serviceClass); 258 if (serviceBundle == null) 259 return null; 260 BundleLoader producerBL = serviceBundle.getBundleLoader(); 261 if (producerBL == null) 262 return null; 263 PackageSource producerSource = producerBL.getPackageSource(pkgName); 264 if (producerSource != null) 265 return producerSource; 266 Class [] interfaces = serviceClass.getInterfaces(); 268 for (int i = 0; i < interfaces.length; i++) { 270 producerSource = getPackageSource(interfaces[i], pkgName); 271 if (producerSource != null) 272 return producerSource; 273 } 274 return getPackageSource(serviceClass.getSuperclass(), pkgName); 276 } 277 } 278 | Popular Tags |