1 11 12 package org.eclipse.osgi.framework.internal.core; 13 14 import java.io.File ; 15 import java.io.InputStream ; 16 import java.security.*; 17 import java.util.*; 18 import org.eclipse.osgi.event.BatchBundleListener; 19 import org.eclipse.osgi.framework.debug.Debug; 20 import org.eclipse.osgi.framework.eventmgr.EventDispatcher; 21 import org.eclipse.osgi.framework.eventmgr.EventListeners; 22 import org.eclipse.osgi.internal.profile.Profile; 23 import org.eclipse.osgi.util.NLS; 24 import org.osgi.framework.*; 25 26 32 33 public class BundleContextImpl implements BundleContext, EventDispatcher { 34 public static final String PROP_SCOPE_SERVICE_EVENTS = "osgi.scopeServiceEvents"; public static final boolean scopeEvents = Boolean.valueOf(FrameworkProperties.getProperty(PROP_SCOPE_SERVICE_EVENTS, "true")).booleanValue(); 37 private boolean valid; 38 39 40 protected BundleHost bundle; 44 45 46 protected Framework framework; 47 48 50 protected Hashtable servicesInUse; 51 52 53 protected EventListeners bundleEvent; 54 55 56 protected EventListeners bundleEventSync; 57 58 59 protected EventListeners serviceEvent; 60 61 62 protected EventListeners frameworkEvent; 63 64 65 protected BundleActivator activator; 66 67 68 protected Object contextLock = new Object (); 69 70 76 protected BundleContextImpl(BundleHost bundle) { 77 this.bundle = bundle; 78 valid = true; 79 framework = bundle.framework; 80 bundleEvent = null; 81 bundleEventSync = null; 82 serviceEvent = null; 83 frameworkEvent = null; 84 servicesInUse = null; 85 activator = null; 86 } 87 88 92 protected void close() { 93 valid = false; 94 95 synchronized (framework.serviceEvent) { 96 if (serviceEvent != null) { 97 framework.serviceEvent.removeListener(this); 98 serviceEvent = null; 99 } 100 } 101 synchronized (framework.frameworkEvent) { 102 if (frameworkEvent != null) { 103 framework.frameworkEvent.removeListener(this); 104 frameworkEvent = null; 105 } 106 } 107 synchronized (framework.bundleEvent) { 108 if (bundleEvent != null) { 109 framework.bundleEvent.removeListener(this); 110 bundleEvent = null; 111 } 112 } 113 synchronized (framework.bundleEventSync) { 114 if (bundleEventSync != null) { 115 framework.bundleEventSync.removeListener(this); 116 bundleEventSync = null; 117 } 118 } 119 120 121 ServiceReference[] publishedReferences = null; 122 synchronized (framework.serviceRegistry) { 123 publishedReferences = framework.serviceRegistry.lookupServiceReferences(this); 124 } 125 126 if (publishedReferences != null) { 127 for (int i = 0; i < publishedReferences.length; i++) { 128 try { 129 ((ServiceReferenceImpl) publishedReferences[i]).registration.unregister(); 130 } catch (IllegalStateException e) { 131 132 } 133 } 134 } 135 136 137 if (servicesInUse != null) { 138 int usedSize; 139 ServiceReference[] usedRefs = null; 140 141 synchronized (servicesInUse) { 142 usedSize = servicesInUse.size(); 143 144 if (usedSize > 0) { 145 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 146 Debug.println("Releasing services"); } 148 149 usedRefs = new ServiceReference[usedSize]; 150 151 Enumeration refsEnum = servicesInUse.keys(); 152 for (int i = 0; i < usedSize; i++) { 153 usedRefs[i] = (ServiceReference) refsEnum.nextElement(); 154 } 155 } 156 } 157 158 for (int i = 0; i < usedSize; i++) { 159 ((ServiceReferenceImpl) usedRefs[i]).registration.releaseService(this); 160 } 161 162 servicesInUse = null; 163 } 164 165 bundle = null; 166 } 167 168 175 public String getProperty(String key) { 176 SecurityManager sm = System.getSecurityManager(); 177 178 if (sm != null) { 179 sm.checkPropertyAccess(key); 180 } 181 182 return (framework.getProperty(key)); 183 } 184 185 190 public org.osgi.framework.Bundle getBundle() { 191 checkValid(); 192 193 return (bundle); 194 } 195 196 207 public org.osgi.framework.Bundle installBundle(String location) throws BundleException { 208 checkValid(); 209 return framework.installBundle(location); 211 } 212 213 226 public org.osgi.framework.Bundle installBundle(String location, InputStream in) throws BundleException { 227 checkValid(); 228 return framework.installBundle(location, in); 230 } 231 232 239 public org.osgi.framework.Bundle getBundle(long id) { 240 return (framework.getBundle(id)); 241 } 242 243 250 public AbstractBundle getBundleByLocation(String location) { 251 return (framework.getBundleByLocation(location)); 252 } 253 254 263 public org.osgi.framework.Bundle[] getBundles() { 264 return framework.getAllBundles(); 265 } 266 267 298 public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException { 299 checkValid(); 300 301 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 302 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("addServiceListener[" + bundle + "](" + listenerName + ", \"" + filter + "\")"); } 305 306 ServiceListener filteredListener = new FilteredServiceListener(filter, listener, this); 307 308 synchronized (framework.serviceEvent) { 309 if (serviceEvent == null) { 310 serviceEvent = new EventListeners(); 311 framework.serviceEvent.addListener(this, this); 312 } 313 314 serviceEvent.addListener(listener, filteredListener); 315 } 316 } 317 318 327 public void addServiceListener(ServiceListener listener) { 328 try { 329 addServiceListener(listener, null); 330 } catch (InvalidSyntaxException e) { 331 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 332 Debug.println("InvalidSyntaxException w/ null filter" + e.getMessage()); Debug.printStackTrace(e); 334 } 335 } 336 } 337 338 351 public void removeServiceListener(ServiceListener listener) { 352 checkValid(); 353 354 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 355 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("removeServiceListener[" + bundle + "](" + listenerName + ")"); } 358 359 synchronized (framework.serviceEvent) { 360 if (serviceEvent != null) { 361 serviceEvent.removeListener(listener); 362 } 363 } 364 } 365 366 380 public void addBundleListener(BundleListener listener) { 381 checkValid(); 382 383 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 384 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("addBundleListener[" + bundle + "](" + listenerName + ")"); } 387 388 if (listener instanceof SynchronousBundleListener) { 389 framework.checkAdminPermission(getBundle(), AdminPermission.LISTENER); 390 synchronized (framework.bundleEventSync) { 391 if (bundleEventSync == null) { 392 bundleEventSync = new EventListeners(); 393 framework.bundleEventSync.addListener(this, this); 394 } 395 396 bundleEventSync.addListener(listener, listener); 397 } 398 } else { 399 synchronized (framework.bundleEvent) { 400 if (bundleEvent == null) { 401 bundleEvent = new EventListeners(); 402 framework.bundleEvent.addListener(this, this); 403 } 404 405 bundleEvent.addListener(listener, listener); 406 } 407 } 408 } 409 410 423 public void removeBundleListener(BundleListener listener) { 424 checkValid(); 425 426 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 427 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("removeBundleListener[" + bundle + "](" + listenerName + ")"); } 430 431 if (listener instanceof SynchronousBundleListener) { 432 framework.checkAdminPermission(getBundle(), AdminPermission.LISTENER); 433 434 synchronized (framework.bundleEventSync) { 435 if (bundleEventSync != null) { 436 bundleEventSync.removeListener(listener); 437 } 438 } 439 } else { 440 synchronized (framework.bundleEvent) { 441 if (bundleEvent != null) { 442 bundleEvent.removeListener(listener); 443 } 444 } 445 } 446 } 447 448 461 public void addFrameworkListener(FrameworkListener listener) { 462 checkValid(); 463 464 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 465 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("addFrameworkListener[" + bundle + "](" + listenerName + ")"); } 468 469 synchronized (framework.frameworkEvent) { 470 if (frameworkEvent == null) { 471 frameworkEvent = new EventListeners(); 472 framework.frameworkEvent.addListener(this, this); 473 } 474 475 frameworkEvent.addListener(listener, listener); 476 } 477 } 478 479 492 public void removeFrameworkListener(FrameworkListener listener) { 493 checkValid(); 494 495 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 496 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("removeFrameworkListener[" + bundle + "](" + listenerName + ")"); } 499 500 synchronized (framework.frameworkEvent) { 501 if (frameworkEvent != null) { 502 frameworkEvent.removeListener(listener); 503 } 504 } 505 } 506 507 568 public org.osgi.framework.ServiceRegistration registerService(String [] clazzes, Object service, Dictionary properties) { 569 checkValid(); 570 571 if (service == null) { 572 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 573 Debug.println("Service object is null"); } 575 576 throw new IllegalArgumentException (Msg.SERVICE_ARGUMENT_NULL_EXCEPTION); 577 } 578 579 int size = clazzes.length; 580 581 if (size == 0) { 582 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 583 Debug.println("Classes array is empty"); } 585 586 throw new IllegalArgumentException (Msg.SERVICE_EMPTY_CLASS_LIST_EXCEPTION); 587 } 588 589 590 String [] copy = new String [clazzes.length]; 591 for (int i = clazzes.length - 1; i >= 0; i--) 593 copy[i] = clazzes[i].intern(); 594 clazzes = copy; 595 596 597 framework.checkRegisterServicePermission(clazzes); 598 599 if (!(service instanceof ServiceFactory)) { 600 String invalidService = checkServiceClass(clazzes, service); 601 if (invalidService != null) { 602 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 603 Debug.println("Service object is not an instanceof " + invalidService); } 605 throw new IllegalArgumentException (NLS.bind(Msg.SERVICE_NOT_INSTANCEOF_CLASS_EXCEPTION, invalidService)); 606 } 607 } 608 609 return (createServiceRegistration(clazzes, service, properties)); 610 } 611 612 static String checkServiceClass(final String [] clazzes, final Object serviceObject) { 614 ClassLoader cl = (ClassLoader ) AccessController.doPrivileged(new PrivilegedAction() { 615 public Object run() { 616 return serviceObject.getClass().getClassLoader(); 617 } 618 }); 619 for (int i = 0; i < clazzes.length; i++) { 620 try { 621 Class serviceClazz = cl == null ? Class.forName(clazzes[i]) : cl.loadClass(clazzes[i]); 622 if (!serviceClazz.isInstance(serviceObject)) 623 return clazzes[i]; 624 } catch (ClassNotFoundException e) { 625 if (extensiveCheckServiceClass(clazzes[i], serviceObject.getClass())) 627 return clazzes[i]; 628 } 629 } 630 return null; 631 } 632 633 private static boolean extensiveCheckServiceClass(String clazz, Class serviceClazz) { 634 if (clazz.equals(serviceClazz.getName())) 635 return false; 636 Class [] interfaces = serviceClazz.getInterfaces(); 637 for (int i = 0; i < interfaces.length; i++) 638 if (!extensiveCheckServiceClass(clazz, interfaces[i])) 639 return false; 640 Class superClazz = serviceClazz.getSuperclass(); 641 if (superClazz != null) 642 if (!extensiveCheckServiceClass(clazz, superClazz)) 643 return false; 644 return true; 645 } 646 647 656 protected ServiceRegistrationImpl createServiceRegistration(String [] clazzes, Object service, Dictionary properties) { 657 return (new ServiceRegistrationImpl(this, clazzes, service, properties)); 658 } 659 660 672 public org.osgi.framework.ServiceRegistration registerService(String clazz, Object service, Dictionary properties) { 673 String [] clazzes = new String [] {clazz}; 674 675 return (registerService(clazzes, service, properties)); 676 } 677 678 721 public org.osgi.framework.ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException { 722 checkValid(); 723 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 724 Debug.println("getServiceReferences(" + clazz + ", \"" + filter + "\")"); } 726 return (framework.getServiceReferences(clazz, filter, this, false)); 727 } 728 729 public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException { 730 checkValid(); 731 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 732 Debug.println("getAllServiceReferences(" + clazz + ", \"" + filter + "\")"); } 734 return (framework.getServiceReferences(clazz, filter, this, true)); 735 } 736 737 757 public org.osgi.framework.ServiceReference getServiceReference(String clazz) { 758 checkValid(); 759 760 if (Debug.DEBUG && Debug.DEBUG_SERVICES) { 761 Debug.println("getServiceReference(" + clazz + ")"); } 763 764 try { 765 ServiceReference[] references = framework.getServiceReferences(clazz, null, this, false); 766 767 if (references != null) { 768 int index = 0; 769 770 int length = references.length; 771 772 if (length > 1) { 773 int rankings[] = new int[length]; 774 int count = 0; 775 int maxRanking = Integer.MIN_VALUE; 776 777 for (int i = 0; i < length; i++) { 778 int ranking = ((ServiceReferenceImpl) references[i]).getRanking(); 779 780 rankings[i] = ranking; 781 782 if (ranking > maxRanking) { 783 index = i; 784 maxRanking = ranking; 785 count = 1; 786 } else { 787 if (ranking == maxRanking) { 788 count++; 789 } 790 } 791 } 792 793 if (count > 1) { 794 long minId = Long.MAX_VALUE; 795 796 for (int i = 0; i < length; i++) { 797 if (rankings[i] == maxRanking) { 798 long id = ((ServiceReferenceImpl) references[i]).getId(); 799 800 if (id < minId) { 801 index = i; 802 minId = id; 803 } 804 } 805 } 806 } 807 } 808 809 return (references[index]); 810 } 811 } catch (InvalidSyntaxException e) { 812 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 813 Debug.println("InvalidSyntaxException w/ null filter" + e.getMessage()); Debug.printStackTrace(e); 815 } 816 } 817 818 return (null); 819 } 820 821 871 public Object getService(org.osgi.framework.ServiceReference reference) { 872 checkValid(); 873 874 synchronized (contextLock) { 875 if (servicesInUse == null) 876 servicesInUse = new Hashtable(10); 878 } 879 880 ServiceRegistrationImpl registration = ((ServiceReferenceImpl) reference).registration; 881 882 framework.checkGetServicePermission(registration.clazzes); 883 884 return registration.getService(BundleContextImpl.this); 885 } 886 887 922 public boolean ungetService(org.osgi.framework.ServiceReference reference) { 923 checkValid(); 924 925 ServiceRegistrationImpl registration = ((ServiceReferenceImpl) reference).registration; 926 927 return registration.ungetService(BundleContextImpl.this); 928 } 929 930 954 public File getDataFile(String filename) { 955 checkValid(); 956 957 return (framework.getDataFile(bundle, filename)); 958 } 959 960 969 protected void start() throws BundleException { 970 activator = bundle.loadBundleActivator(); 971 972 if (activator != null) { 973 try { 974 startActivator(activator); 975 } catch (BundleException be) { 976 activator = null; 977 throw be; 978 } 979 } 980 981 983 } 984 985 989 protected void startActivator(final BundleActivator bundleActivator) throws BundleException { 990 if (Profile.PROFILE && Profile.STARTUP) 991 Profile.logEnter("BundleContextImpl.startActivator()", null); try { 993 AccessController.doPrivileged(new PrivilegedExceptionAction() { 994 public Object run() throws Exception { 995 if (bundleActivator != null) { 996 if (Profile.PROFILE && Profile.STARTUP) 997 Profile.logTime("BundleContextImpl.startActivator()", "calling " + bundle.getLocation() + " bundle activator"); 999 bundleActivator.start(BundleContextImpl.this); 1000 if (Profile.PROFILE && Profile.STARTUP) 1001 Profile.logTime("BundleContextImpl.startActivator()", "returned from " + bundle.getLocation() + " bundle activator"); } 1003 return null; 1004 } 1005 }); 1006 } catch (Throwable t) { 1007 if (t instanceof PrivilegedActionException) { 1008 t = ((PrivilegedActionException) t).getException(); 1009 } 1010 1011 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 1012 Debug.printStackTrace(t); 1013 } 1014 1015 String clazz = null; 1016 clazz = bundleActivator.getClass().getName(); 1017 1018 throw new BundleException(NLS.bind(Msg.BUNDLE_ACTIVATOR_EXCEPTION, new Object [] {clazz, "start", bundle.getSymbolicName() == null ? "" + bundle.getBundleId() : bundle.getSymbolicName()}), t); } finally { 1020 if (Profile.PROFILE && Profile.STARTUP) 1021 Profile.logExit("BundleContextImpl.startActivator()"); } 1023 1024 } 1025 1026 1034 protected void stop() throws BundleException { 1035 try { 1036 AccessController.doPrivileged(new PrivilegedExceptionAction() { 1037 public Object run() throws Exception { 1038 if (activator != null) { 1039 1040 activator.stop(BundleContextImpl.this); 1041 } 1042 return null; 1043 } 1044 }); 1045 } catch (Throwable t) { 1046 if (t instanceof PrivilegedActionException) { 1047 t = ((PrivilegedActionException) t).getException(); 1048 } 1049 1050 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 1051 Debug.printStackTrace(t); 1052 } 1053 1054 String clazz = (activator == null) ? "" : activator.getClass().getName(); 1056 throw new BundleException(NLS.bind(Msg.BUNDLE_ACTIVATOR_EXCEPTION, new Object [] {clazz, "stop", bundle.getSymbolicName() == null ? "" + bundle.getBundleId() : bundle.getSymbolicName()}), t); } finally { 1058 activator = null; 1059 } 1060 } 1061 1062 1078 protected ServiceReference[] getRegisteredServices() { 1079 ServiceReference[] services = null; 1080 1081 synchronized (framework.serviceRegistry) { 1082 services = framework.serviceRegistry.lookupServiceReferences(this); 1083 if (services == null) { 1084 return null; 1085 } 1086 int removed = 0; 1087 for (int i = services.length - 1; i >= 0; i--) { 1088 ServiceReferenceImpl ref = (ServiceReferenceImpl) services[i]; 1089 String [] classes = ref.getClasses(); 1090 try { 1091 framework.checkGetServicePermission(classes); 1092 } catch (SecurityException se) { 1093 services[i] = null; 1094 removed++; 1095 } 1096 } 1097 if (removed > 0) { 1098 ServiceReference[] temp = services; 1099 services = new ServiceReference[temp.length - removed]; 1100 for (int i = temp.length - 1; i >= 0; i--) { 1101 if (temp[i] == null) 1102 removed--; 1103 else 1104 services[i - removed] = temp[i]; 1105 } 1106 } 1107 } 1108 return (services); 1109 1110 } 1111 1112 1128 protected ServiceReferenceImpl[] getServicesInUse() { 1129 if (servicesInUse == null) { 1130 return (null); 1131 } 1132 1133 synchronized (servicesInUse) { 1134 int size = servicesInUse.size(); 1135 1136 if (size == 0) { 1137 return (null); 1138 } 1139 1140 ServiceReferenceImpl[] references = new ServiceReferenceImpl[size]; 1141 int refcount = 0; 1142 1143 Enumeration refsEnum = servicesInUse.keys(); 1144 1145 for (int i = 0; i < size; i++) { 1146 ServiceReferenceImpl reference = (ServiceReferenceImpl) refsEnum.nextElement(); 1147 1148 try { 1149 framework.checkGetServicePermission(reference.registration.clazzes); 1150 } catch (SecurityException se) { 1151 continue; 1152 } 1153 1154 references[refcount] = reference; 1155 refcount++; 1156 } 1157 1158 if (refcount < size) { 1159 if (refcount == 0) { 1160 return (null); 1161 } 1162 1163 ServiceReferenceImpl[] refs = references; 1164 references = new ServiceReferenceImpl[refcount]; 1165 1166 System.arraycopy(refs, 0, references, 0, refcount); 1167 } 1168 1169 return (references); 1170 } 1171 } 1172 1173 1181 public void dispatchEvent(Object originalListener, Object l, int action, Object object) { 1182 AbstractBundle tmpBundle = bundle; 1185 try { 1186 if (isValid()) { 1187 switch (action) { 1188 case Framework.BUNDLEEVENT : 1189 case Framework.BUNDLEEVENTSYNC : { 1190 BundleListener listener = (BundleListener) l; 1191 1192 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 1193 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("dispatchBundleEvent[" + tmpBundle + "](" + listenerName + ")"); } 1196 1197 BundleEvent event = (BundleEvent) object; 1198 switch (event.getType()) { 1199 case Framework.BATCHEVENT_BEGIN : { 1200 if (listener instanceof BatchBundleListener) 1201 ((BatchBundleListener) listener).batchBegin(); 1202 break; 1203 } 1204 case Framework.BATCHEVENT_END : { 1205 if (listener instanceof BatchBundleListener) 1206 ((BatchBundleListener) listener).batchEnd(); 1207 break; 1208 } 1209 default : { 1210 listener.bundleChanged((BundleEvent) object); 1211 } 1212 } 1213 break; 1214 } 1215 1216 case Framework.SERVICEEVENT : { 1217 ServiceEvent event = (ServiceEvent) object; 1218 1219 ServiceListener listener = (ServiceListener) l; 1220 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 1221 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("dispatchServiceEvent[" + tmpBundle + "](" + listenerName + ")"); } 1224 listener.serviceChanged(event); 1225 1226 break; 1227 } 1228 1229 case Framework.FRAMEWORKEVENT : { 1230 FrameworkListener listener = (FrameworkListener) l; 1231 1232 if (Debug.DEBUG && Debug.DEBUG_EVENTS) { 1233 String listenerName = listener.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(listener)); Debug.println("dispatchFrameworkEvent[" + tmpBundle + "](" + listenerName + ")"); } 1236 1237 listener.frameworkEvent((FrameworkEvent) object); 1238 break; 1239 } 1240 } 1241 } 1242 } catch (Throwable t) { 1243 if (Debug.DEBUG && Debug.DEBUG_GENERAL) { 1244 Debug.println("Exception in bottom level event dispatcher: " + t.getMessage()); Debug.printStackTrace(t); 1246 } 1247 framework.adaptor.handleRuntimeError(t); 1249 publisherror: { 1250 if (action == Framework.FRAMEWORKEVENT) { 1251 FrameworkEvent event = (FrameworkEvent) object; 1252 if (event.getType() == FrameworkEvent.ERROR) { 1253 break publisherror; } 1255 } 1256 1257 framework.publishFrameworkEvent(FrameworkEvent.ERROR, tmpBundle, t); 1258 } 1259 } 1260 } 1261 1262 1265 protected boolean hasListenServicePermission(ServiceEvent event) { 1266 ProtectionDomain domain = bundle.getProtectionDomain(); 1267 1268 if (domain != null) { 1269 ServiceReferenceImpl reference = (ServiceReferenceImpl) event.getServiceReference(); 1270 1271 String [] names = reference.getClasses(); 1272 1273 int len = names.length; 1274 1275 for (int i = 0; i < len; i++) { 1276 if (domain.implies(new ServicePermission(names[i], ServicePermission.GET))) { 1277 return true; 1278 } 1279 } 1280 1281 return false; 1282 } 1283 1284 return (true); 1285 } 1286 1287 1298 public org.osgi.framework.Filter createFilter(String filter) throws InvalidSyntaxException { 1299 checkValid(); 1300 1301 return (new FilterImpl(filter)); 1302 } 1303 1304 1311 protected void checkValid() { 1312 if (!isValid()) { 1313 throw new IllegalStateException (Msg.BUNDLE_CONTEXT_INVALID_EXCEPTION); 1314 } 1315 } 1316 1317 1322 protected boolean isValid() { 1323 return valid; 1324 } 1325 1326 boolean isAssignableTo(ServiceReferenceImpl reference) { 1327 if (!scopeEvents) 1328 return true; 1329 String [] clazzes = reference.getClasses(); 1330 for (int i = 0; i < clazzes.length; i++) 1331 if (!reference.isAssignableTo(bundle, clazzes[i])) 1332 return false; 1333 return true; 1334 } 1335} 1336 | Popular Tags |