| 1 26 27 package com.opensugar.cube; 28 29 import com.opensugar.cube.java2.PackageHelper; 30 import com.opensugar.cube.packageAdmin.PackageAdminImpl; 31 import com.opensugar.cube.packageAdmin.PackageImport; 32 import com.opensugar.cube.serviceRegistry.ServiceRegistry; 33 import com.opensugar.cube.serviceRegistry.ServiceRegistryException; 34 import com.opensugar.cube.ldap.LDAPFilter; 35 36 import org.osgi.framework.Bundle; 37 import org.osgi.framework.BundleException; 38 import org.osgi.framework.FrameworkEvent; 39 import org.osgi.framework.ServiceEvent; 40 import org.osgi.framework.BundleEvent; 41 import org.osgi.framework.FrameworkListener; 42 import org.osgi.framework.ServiceListener; 43 import org.osgi.framework.BundleListener; 44 import org.osgi.framework.SynchronousBundleListener; 45 import org.osgi.framework.ServiceReference; 46 import org.osgi.framework.InvalidSyntaxException; 47 import org.osgi.framework.Constants; 48 import org.osgi.framework.ServicePermission; 49 import org.osgi.service.permissionadmin.PermissionAdmin; 50 51 import java.io.File; 52 import java.io.InputStream; 53 import java.io.FileOutputStream; 54 import java.io.FileInputStream; 55 import java.io.IOException; 56 import java.net.URL; 57 import java.util.Hashtable; 58 import java.util.Enumeration; 59 import java.util.Vector; 60 import java.util.Locale; 61 import java.util.Observer; 62 63 public abstract class AbstractCube { 68 69 public static final String VERSION = "2.1.3"; 70 public static final String VENDOR = "Opensugar S.A."; 71 public static final String OSGI_RELEASE = "2"; 72 73 private static final String SYSTEM_PROPERTY_CUBE_VERSION = "com.opensugar.cube.version"; 74 private static final String SYSTEM_PROPERTY_CUBE_DIR = "com.opensugar.cube.dir"; 75 private static final String SYSTEM_PROPERTY_SYSTEM_BUNDLE_JAR_FILE = "com.opensugar.cube.systemBundleJarFile"; 77 private static final String SYSTEM_PROPERTY_CUBE_STARTED_FLAG_FILE = "com.opensugar.cube.startedFlagFile"; 78 79 private static final String FLASH_URL_FILE = "flash.url"; 80 81 private static final String defaultCubeDir = "osc/bs"; 82 private static final String defaultPermanentStorageDir = "osc/.opensugar"; 83 private static final String defaultSystemBundleJarFile = "systemBundle.jar"; 84 85 86 protected static final String bundleDirNameBase = "b"; 87 protected static final String bundleJarNameBase = "bundle"; 88 protected static final String bundleJarNameExtension = ".jar"; 89 protected static final String bundleLocationFileName = "location"; 90 protected static final String bundleUninstalledFlagFileName = "uninstalled.flag"; 91 protected static final String bundleStartedFlagFileName = "started.flag"; 92 protected static final String bundleInnerFilesDirName = "inner"; 93 protected static final String bundleDataDirName = "data"; 94 protected static final String bundleIdFileName = ".bid"; 95 96 private int reasonableTimeToWait = 5000; 100 101 private Hashtable id_bundle; 103 private PackageAdminImpl packageAdmin; 105 private ServiceRegistry serviceRegistry; 107 108 private ServiceListeners serviceListeners; 110 private BundleListeners bundleListeners; 112 private FrameworkListeners frameworkListeners; 114 private boolean handlingEvents = false; 116 117 private long largestBundleId = -1; 119 120 private Hashtable bundleInnerFileDirectories; 122 123 private int state = Bundle.RESOLVED; 129 130 private File baseDirectory; 132 133 137 protected AbstractCube() { 138 this( null ); 139 } 140 141 protected AbstractCube( File baseDirectory ) { 142 this.baseDirectory = baseDirectory; 144 145 System.out.println( "Opensugar cube " + VERSION ); 146 System.out.println( "Implements OSGi Service Platform, Specification Release " + OSGI_RELEASE ); 147 148 System.out.println( "Copyright (c) 2001, Opensugar S.A. All Rights Reserved." ); 149 System.out.println( "Opensugar is a Registered Trademark." ); 150 System.out.println( "" ); 151 152 System.getProperties().put( Constants.FRAMEWORK_VENDOR, getProperty( Constants.FRAMEWORK_VENDOR ) ); 154 System.getProperties().put( Constants.FRAMEWORK_VERSION, getProperty( Constants.FRAMEWORK_VERSION ) ); 155 156 System.getProperties().put( SYSTEM_PROPERTY_CUBE_VERSION, VERSION ); 158 159 165 initLog(); 166 } 167 168 public void flash( String flashURL ) throws IOException { 169 writeFile( new File( FLASH_URL_FILE ), flashURL ); 170 shutdown( false ); 171 } 172 173 public synchronized void startup( Observer progressListener ) { 174 176 deleteUninstalledBundleDirectories(); 178 deleteObsoleteBundleFiles(); 179 180 serviceListeners = new ServiceListeners(); 182 bundleListeners = new BundleListeners(); 183 frameworkListeners = new FrameworkListeners(); 184 handlingEvents = true; 185 186 state = Bundle.STARTING; 188 189 id_bundle = new Hashtable(); 191 192 bundleInnerFileDirectories = new Hashtable(); 194 195 packageAdmin = new PackageAdminImpl( this ); 197 198 serviceRegistry = new ServiceRegistry( this ); 200 201 getBaseDirectory().mkdirs(); 203 installSystemBundle( new File( System.getProperty( SYSTEM_PROPERTY_SYSTEM_BUNDLE_JAR_FILE, defaultSystemBundleJarFile ) ) ); 205 206 reinstallBundles(); 211 Bundle[] bs = getBundles(); 215 Vector v = new Vector(); 216 for ( int i = 0; i < bs.length; i++ ) { 217 v.addElement( bs[ i ] ); 218 } 219 v.removeElement( getBundle( (long)0 ) ); 220 bs = new Bundle[ v.size() ]; 221 v.copyInto( bs ); 222 packageAdmin.doRefreshPackages( bs ); 224 restartBundles( progressListener ); 229 230 state = Bundle.ACTIVE; 232 233 fireFrameworkStartedEvent(); 234 235 System.out.println( "Cube started" ); 236 237 String startedFlagFile = System.getProperty( SYSTEM_PROPERTY_CUBE_STARTED_FLAG_FILE ); 238 if ( startedFlagFile != null ) { 239 File file = new File( startedFlagFile ); 240 try { 241 writeFile( file, "" ); 242 } 243 catch ( IOException e ) { 244 log( LOG_ERROR, "Unable to create started flag file: " + file.getAbsolutePath(), e ); 245 } 246 } 247 } 248 249 public synchronized void shutdown( boolean exitJVM ) { 250 state = Bundle.STOPPING; 252 253 BundleImpl[] bundles = getBundles(); 258 for ( int i = bundles.length - 1; i >= 0; i-- ) { 259 if ( bundles[ i ].getBundleId() != 0 && bundles[ i ].getState() == bundles[ i ].ACTIVE ) { 260 try { 261 bundles[ i ].stop( true ); 262 } 263 catch( BundleException e ) { 264 fireFrameworkEvent( FrameworkEvent.ERROR, bundles[ i ], e ); 265 } 266 } 267 } 268 269 handlingEvents = false; 271 272 state = Bundle.RESOLVED; 273 274 System.out.println( "Cube stopped" ); 275 276 281 if ( exitJVM ) { 282 System.exit( 0 ); 283 } 284 } 285 286 protected abstract boolean enforcesPermissions(); 287 288 292 protected Bundle reinstallBundle( long id ) throws BundleException, IOException { 293 File jarFile = getCurrentBundleJarFile( id ); 294 String location = readStoredBundleLocation( id ); 295 return installBundle( id, location, jarFile ); 296 } 297 298 public Bundle installBundle( String location ) throws BundleException { 299 Util.checkNullParameter( location, getClass().getName(), "installBundle", "location" ); 300 return installBundle( location, null ); 301 } 302 303 protected Bundle installBundle( String location, InputStream in ) throws BundleException { 304 Util.checkNullParameter( location, getClass().getName(), "installBundle", "location" ); 305 306 try { 309 Bundle bundle = getBundle( location ); 310 if ( bundle != null && bundle.getState() != bundle.UNINSTALLED ) { 311 return getBundle( location ); 312 } 313 } 314 catch( IllegalArgumentException ignore ) { 315 } 317 318 long id = generateNewBundleId(); 320 321 File bundleDirectory = null; 334 while ( bundleDirectory == null ) { 335 bundleDirectory = createFreshBundleDirectory( id ); 337 if ( bundleDirectory.list() == null ) { 338 bundleDirectory = null; 339 id++; 340 } 341 } 342 343 try { 344 if ( in == null ) { 346 URL url = new URL( location ); 347 in = url.openStream(); 348 } 349 File bundleJar = getNewBundleJarFile( id ); 350 Util.transferData( in, new FileOutputStream( bundleJar ) ); 351 352 if ( id != 0 ) { 354 recordBundleLocation( id, location ); 355 } 356 357 return installBundle( id, location, bundleJar ); 358 } 359 catch( Exception e ) { 360 if ( !Util.recursiveFileDelete( bundleDirectory ) ) { 362 log( LOG_WARNING, "Unable to delete bundle directory after bundle installation failure" ); 363 } 364 365 if ( e instanceof BundleException ) { 366 throw (BundleException)e; 367 } 368 else { 369 throw new BundleException( "Unable to install bundle: " + location, e ); 370 } 371 } 372 } 373 374 private Bundle installSystemBundle( File bundleJar ) { 375 try { 376 if ( !bundleJar.exists() ) { 377 throw new BundleException( "System bundle jar file not found: " + bundleJar.getAbsolutePath() ); 378 } 379 return installBundle( (long)0, Constants.SYSTEM_BUNDLE_LOCATION, bundleJar ); 380 } 381 catch( BundleException e ) { 382 Throwable rootCause = e; 384 if ( e.getNestedException() != null ) { 385 rootCause = e.getNestedException(); 386 } 387 log( LOG_ERROR, "FATAL ERROR: System bundle could not be installed", rootCause ); 388 389 System.exit( 1 ); 390 return null; 391 } 392 } 393 394 private Bundle installBundle( long id, String location, File bundleJar ) throws BundleException { 399 if ( id > largestBundleId ) { 400 largestBundleId = id; 401 } 402 403 try { 404 BundleImpl bundle; 409 if ( id == 0 ) { 410 bundle = new SystemBundle( this, bundleJar ); 411 } 412 else { 413 bundle = new BundleImpl( this, id, location, bundleJar ); 414 } 415 416 fireBundleEvent( BundleEvent.INSTALLED, bundle ); 418 419 id_bundle.put( new Long( bundle.getBundleId() ), bundle ); 420 packageAdmin.resolveBundles(); 421 422 log( LOG_INFO, bundle.getLocation() + " installed (bundle id: " + bundle.getBundleId() + ")" ); 423 424 return bundle; 426 } 427 catch( Exception e ) { 428 e.printStackTrace(); 429 throw new BundleException( "Unable to install bundle: " + location, e ); 430 } 431 } 432 433 protected void bundleUninstalled( long id ) throws BundleException { 434 440 443 log( LOG_INFO, "Bundle " + id + " uninstalled" ); 444 } 445 446 public void wipeUninstalledBundles( Bundle[] bundlesToCheck ) { 447 if ( bundlesToCheck == null ) { 448 bundlesToCheck = getBundles(); 449 } 450 451 long bundleId; 452 for ( int i = 0; i < bundlesToCheck.length; i++ ) { 453 if ( bundlesToCheck[ i ].getState() == bundlesToCheck[ i ].UNINSTALLED ) { 454 bundleId = bundlesToCheck[ i ].getBundleId(); 455 id_bundle.remove( new Long( bundleId ) ); 456 deleteBundleDirectory( bundleId ); 457 } 458 } 459 } 460 461 463 protected String getProperty( String key ) { 464 Util.checkNullParameter( key, getClass().getName(), "getProperty", "key" ); 465 466 if ( key.equals( Constants.FRAMEWORK_LANGUAGE ) ) { 467 return Locale.getDefault().getLanguage(); 468 } 469 else if ( key.equals( Constants.FRAMEWORK_OS_NAME ) ) { 470 String osName = System.getProperty( "os.name" ); 471 if ( osName.equals( "OS/2" ) ) { 472 return "OS2"; 473 } 474 else if ( osName.equals( "procnto" ) ) { 475 return "QNX"; 476 } 477 else if ( osName.equals( "Win95" ) 478 || osName.equals( "Windows 95" ) ) { 479 return "Windows95"; 480 } 481 else if ( osName.equals( "Win98" ) 482 || osName.equals( "Windows 98" ) ) { 483 return "Windows98"; 484 } 485 else if ( osName.equals( "WinNT" ) 486 || osName.equals( "Windows NT" ) ) { 487 return "WindowsNT"; 488 } 489 else if ( osName.equals( "WinCE" ) 490 || osName.equals( "Windows CE" ) ) { 491 return "WindowsCE"; 492 } 493 else if ( osName.equals( "Win2000" ) 494 || osName.equals( "Windows 2000" ) ) { 495 return "Windows2000"; 496 } 497 else if ( osName.equals( "Mac OS X" ) ) { 498 return "MacOS"; 499 } 500 else { 501 return osName; 502 } 503 } 504 else if ( key.equals( Constants.FRAMEWORK_OS_VERSION ) ) { 505 return System.getProperty( "os.version" ); 506 } 507 else if ( key.equals( Constants.FRAMEWORK_PROCESSOR ) ) { 508 String processorName = System.getProperty( "os.arch" ); 509 if ( processorName.equals( "psc1k" ) ) { 510 return "Ignite"; 511 } 512 else if ( processorName.equals( "power" ) 513 || processorName.equals( "ppc" ) ) { 514 return "PowerPC"; 515 } 516 else if ( processorName.equals( "pentium" ) 517 || processorName.equals( "i386" ) 518 || processorName.equals( "i486" ) 519 || processorName.equals( "i586" ) 520 || processorName.equals( "i686" ) ) { 521 return "x86"; 522 } 523 else { 524 return processorName; 525 } 526 } 527 else if ( key.equals( Constants.FRAMEWORK_VENDOR ) ) { 528 return VENDOR; 529 } 530 else if ( key.equals( Constants.FRAMEWORK_VERSION ) ) { 531 return VERSION; 532 } 533 else { 534 return null; 535 } 536 } 537 538 protected long generateNewBundleId() { 539 541 long newBundleId = 0; 543 try { 544 newBundleId = Long.valueOf( readFile( getLastBundleIdFile() ) ).longValue() + 1; 545 } 546 catch ( Exception ignore ) { 547 551 long thousands = largestBundleId / 1000 + 1; 556 newBundleId = thousands * 1000 + 1; 557 } 558 559 while ( id_bundle.get( new Long( newBundleId ) ) != null ) { 560 newBundleId++; 561 } 562 563 largestBundleId = newBundleId; 564 try { 565 writeFile( getLastBundleIdFile(), "" + largestBundleId ); 566 } 567 catch ( IOException ignore ) {} 568 569 return newBundleId; 570 581 } 582 583 public BundleImpl getBundle( String location ) { 584 Enumeration bundles = id_bundle.elements(); 585 BundleImpl bundle; 586 while ( bundles.hasMoreElements() ) { 587 bundle = (BundleImpl)bundles.nextElement(); 588 if ( bundle.getLocation().equals( location ) ) { 589 return bundle; 590 } 591 } 592 throw new IllegalArgumentException( "Bundle with requested location does not exist: " + location ); 593 } 594 595 public BundleImpl getBundle( long id ) { 596 BundleImpl bundle = (BundleImpl)id_bundle.get( new Long( id ) ); 597 if ( bundle == null ) { 598 throw new IllegalArgumentException( "Bundle with requested id does not exist: " + id ); 599 } 600 return bundle; 601 } 602 603 public BundleImpl[] getBundles() { 604 Number[] ids = new Number[ id_bundle.size() ]; 605 Enumeration enum = id_bundle.keys(); 606 int i = 0; 607 while ( enum.hasMoreElements() ) { 608 ids[ i++ ] = (Long)enum.nextElement(); 609 } 610 ids = Util.sortNumbers( ids ); 611 612 BundleImpl[] bundles = new BundleImpl[ ids.length ]; 613 for ( i = 0; i < ids.length; i++ ) { 614 bundles[ i ] = (BundleImpl)id_bundle.get( ids[ i ] ); 615 } 616 return bundles; 617 } 618 619 public PackageAdminImpl getPackageAdmin() { 620 return packageAdmin; 621 } 622 623 public PermissionAdmin getPermissionAdmin() { 624 return null; 625 } 626 627 protected ServiceRegistry getServiceRegistry() { 628 return serviceRegistry; 629 } 630 631 protected File createFreshBundleDirectory( long id ) { 632 File bundleDirectory = generateBundleDirectory( id ); 633 634 if ( bundleDirectory.exists() ) { 636 if ( !Util.recursiveFileDelete( bundleDirectory ) ) { 637 log( LOG_WARNING, "Could not delete directory: " + bundleDirectory.getAbsolutePath() ); 638 } 639 } 640 641 bundleDirectory.mkdirs(); 643 return bundleDirectory; 644 } 645 646 public File getBundleInnerFilesDirectory( long id ) { 647 File bundleInnerFilesDirectory = (File)bundleInnerFileDirectories.get( new Long( id ) ); 648 if ( bundleInnerFilesDirectory == null ) { 649 bundleInnerFilesDirectory = new File( generateBundleDirectory( id ), bundleInnerFilesDirName + getLargestBundleJarIndex( id ) ); 651 bundleInnerFileDirectories.put( new Long( id ), bundleInnerFilesDirectory ); 652 if ( bundleInnerFilesDirectory.exists() ) { 653 Util.recursiveFileDelete( bundleInnerFilesDirectory ); 655 } 656 bundleInnerFilesDirectory.mkdirs(); 657 } 658 return bundleInnerFilesDirectory; 659 } 660 661 public File getBundleDataDirectory( long id ) { 662 File dataDirectory = new File( generateBundleDirectory( id ), bundleDataDirName ); 663 if ( !dataDirectory.exists() ) { 664 dataDirectory.mkdirs(); 665 } 666 return dataDirectory; 667 } 668 669 protected int getLargestBundleJarIndex( long id ) { 670 File bundleDir = generateBundleDirectory( id ); 671 String[] listing = bundleDir.list(); 672 String indexString; 673 int index; 674 int largestBundleJarIndex = -1; 675 for ( int i = 0; i < listing.length; i++ ) { 676 if ( listing[ i ].startsWith( bundleJarNameBase ) && listing[ i ].endsWith( bundleJarNameExtension ) ) { 677 indexString = listing[ i ].substring( bundleJarNameBase.length(), listing[ i ].length() - bundleJarNameExtension.length() ); 678 try { 679 index = Integer.valueOf( indexString ).intValue(); 680 if ( largestBundleJarIndex < index ) { 681 largestBundleJarIndex = index; 682 } 683 } 684 catch( NumberFormatException ignore ) {} 685 } 686 } 687 if ( largestBundleJarIndex > -1 ) { 688 return largestBundleJarIndex; 689 } 690 throw new IllegalArgumentException( "No bundle jar file found for requested bundle id: " + id ); 691 } 692 693 protected File getCurrentBundleJarFile( long id ) { 694 int jarIndex = getLargestBundleJarIndex( id ); 695 return new File( generateBundleDirectory( id ), bundleJarNameBase + jarIndex + bundleJarNameExtension ); 696 } 697 698 protected File getNewBundleJarFile( long id ) { 699 int index; 700 try { 701 int jarIndex = getLargestBundleJarIndex( id ); 702 index = jarIndex + 1; 703 } 704 catch( IllegalArgumentException e ) { 705 index = 0; 706 } 707 708 return new File( generateBundleDirectory( id ), bundleJarNameBase + index + bundleJarNameExtension ); 709 } 710 711 protected boolean deleteBundleJarFile( File file ) { 713 if ( file.exists() ) { 714 return file.delete(); 715 } 716 return true; 717 } 718 719 protected boolean deleteBundleDirectory( long id ) { 720 File bundleDir = generateBundleDirectory( id ); 721 return bundleDir.delete(); 722 } 723 724 protected void setBundleUninstalled( long id ) throws IOException { 725 File uninstalledFlagFile = generateBundleUninstalledFlagFile( id ); 726 writeFile( uninstalledFlagFile, "" ); 727 } 728 729 protected void registerBundleAsStarted( long bundleId ) throws IOException { 730 File startedFlagFile = generateBundleStartedFlagFile( bundleId ); 731 writeFile( startedFlagFile, "" ); 732 } 733 734 protected void recordBundleLocation( long bundleId, String location ) throws IOException { 735 File file = generateBundleLocationFile( bundleId ); 736 writeFile( file, location ); 737 } 738 739 protected String readStoredBundleLocation( long id ) throws IOException { 740 File file = generateBundleLocationFile( id ); 741 if ( !file.exists() ) { 742 throw new IllegalArgumentException( "No location file found for bundle: " + id ); 743 } 744 745 return readFile( file ); 746 } 747 748 protected boolean unregisterBundleAsStarted( Bundle bundle ) { 749 File startedFlagFile = generateBundleStartedFlagFile( bundle.getBundleId() ); 750 if ( !startedFlagFile.exists() ) { 751 return true; 752 } 753 else { 754 return startedFlagFile.delete(); 755 } 756 } 757 758 protected int getReasonableTimeToWait() { 759 return reasonableTimeToWait; 760 } 761 762 766 public abstract void checkAdminPermission() throws SecurityException; 767 public abstract void checkFilePermission( String file, String permissionToCheck ) throws SecurityException; 768 public abstract void checkPackagePermission( NamedPropertySet[] packages, String permissionToCheck, Object codeSource ) throws SecurityException; 769 public abstract void checkPropertyPermission( String property, String permissionToCheck ) throws SecurityException; 770 public abstract void checkServicePermission( String className, String permissionToCheck ) throws SecurityException; 771 public abstract void checkServicePermissionForAll( String[] classNames, String permissionToCheck ) throws SecurityException; 773 public abstract void checkServicePermissionForAtLeastOne( String[] classNames, String permissionToCheck ) throws SecurityException; 775 protected abstract boolean hasPermission( BundleImpl bundle, Object permission ); 776 protected abstract BundleClassLoader createClassLoaderForBundle( BundleImpl bundle, File bundleJarFile, NamedPropertySet[] nativeLibraries, NamedPropertySet[] classPath ) throws IOException; 777 778 779 783 protected void addServiceListener( BundleImpl bundle, ServiceListener serviceListener, String filterString ) throws InvalidSyntaxException { 784 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " adding a service listener" ); 785 if ( filterString == null ) { 786 addServiceListener( bundle, serviceListener ); 787 } 788 else { 789 serviceListeners.addListener( bundle, serviceListener, new LDAPFilter( filterString, false ) ); 791 } 792 } 793 794 protected void addServiceListener( BundleImpl bundle, ServiceListener serviceListener ) { 795 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " adding a service listener" ); 796 serviceListeners.addListener( bundle, serviceListener ); 797 } 798 799 protected void removeServiceListener( BundleImpl bundle, ServiceListener serviceListener ) { 800 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " removing a service listener" ); 801 serviceListeners.removeListener( bundle, serviceListener ); 802 } 803 804 protected void removeServiceListenersRegisteredBy( BundleImpl bundle ) { 805 int n = serviceListeners.getListenersRegisteredBy( bundle ).length; 806 if ( n > 0 ) { 807 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " removing " + n + " service listener(s)" ); 808 } 809 serviceListeners.removeAllListenersRegisteredBy( bundle ); 810 } 811 812 protected void addBundleListener( BundleImpl bundle, BundleListener bundleListener ) { 813 if ( bundleListener instanceof SynchronousBundleListener ) { 814 checkAdminPermission(); 816 } 817 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " adding a bundle listener" ); 818 bundleListeners.addListener( bundle, bundleListener ); 819 } 820 821 protected void removeBundleListener( BundleImpl bundle, BundleListener bundleListener ) { 822 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " removing a bundle listener" ); 823 bundleListeners.removeListener( bundle, bundleListener ); 824 } 825 826 protected void removeBundleListenersRegisteredBy( BundleImpl bundle ) { 827 int n = bundleListeners.getListenersRegisteredBy( bundle ).length; 828 if ( n > 0 ) { 829 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " removing " + n + " bundle listener(s)" ); 830 } 831 bundleListeners.removeAllListenersRegisteredBy( bundle ); 832 } 833 834 protected void addFrameworkListener( BundleImpl bundle, FrameworkListener frameworkListener ) { 835 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " adding a framework listener" ); 836 frameworkListeners.addListener( bundle, frameworkListener ); 837 } 838 839 protected void removeFrameworkListener( BundleImpl bundle, FrameworkListener frameworkListener ) { 840 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " removing a framework listeners" ); 841 frameworkListeners.removeListener( bundle, frameworkListener ); 842 } 843 844 protected void removeFrameworkListenersRegisteredBy( BundleImpl bundle ) { 845 int n = frameworkListeners.getListenersRegisteredBy( bundle ).length; 846 if ( n > 0 ) { 847 log( LOG_DEBUG, bundle.getLocationWithoutAdminPermissionCheck() + " removing " + n + " framework listener(s)" ); 848 } 849 frameworkListeners.removeAllListenersRegisteredBy( bundle ); 850 } 851 852 protected void fireServiceEvent( int type, ServiceReference serviceReference ) { 853 if ( handlingEvents ) { 854 final ServiceEvent event = new ServiceEvent( type, serviceReference ); 855 String[] serviceObjectClasses = (String[])serviceReference.getProperty( Constants.OBJECTCLASS ); 856 ServicePermission[] permissions = new ServicePermission[ serviceObjectClasses.length ]; 857 for ( int i = 0; i < serviceObjectClasses.length; i++ ) { 858 permissions[ i ] = new ServicePermission( serviceObjectClasses[ i ], ServicePermission.GET ); 859 } 860 861 Enumeration bundles = serviceListeners.getBundles(); 862 BundleImpl bundle; 863 boolean permissionOk; 864 Object[] bundleListeners; 865 Vector listeners = new Vector(); 866 while ( bundles.hasMoreElements() ) { 867 bundle = (BundleImpl)bundles.nextElement(); 868 |