Examples of PackageAdmin


Examples of org.osgi.service.packageadmin.PackageAdmin

      final Desktop desktop = Activator.desktop;
      if (null!=desktop) {
        final PackageManager pm = desktop.pm;
        if (null!=pm) {
          final PackageAdmin pkgAdmin = pm.getPackageAdmin();

          if(pkgAdmin == null) {
            sb.append("No PackageAdmin service found");
          } else {
            // Array with all bundles that can be required.
            RequiredBundle[] rbl = pkgAdmin.getRequiredBundles(null);
            boolean useParagraph = false;

            Bundle[] fragmentBundles = pm.getFragments(b); // pkgAdmin.getFragments(b);
            if (fragmentBundles.length>0) {
              if (useParagraph) {
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

 
  void beforeRestart() {
    System.out.println("In beforeRestart!");
    ServiceTracker tracker = new ServiceTracker(bc, PackageAdmin.class.getName(), null);
    tracker.open();
    PackageAdmin pa = (PackageAdmin)tracker.getService();
    Bundle extensionBC = null;
    Bundle extensionFW = null;
   
    try {
      extensionBC = Util.installBundle(bc, "bundleExt1_test-1.0.0.jar");
      extensionFW = Util.installBundle(bc, "bundleExt2_test-1.0.0.jar");
    } catch (BundleException e1) {
      e1.printStackTrace();
      failed();
    }
   
    File flag = bc.getDataFile(RESTART_FLAG_FILE);
    FileOutputStream fout;
   
    try {
      fout = new FileOutputStream(flag);
      fout.write("slirkeslork".getBytes());
      fout.close();
    } catch (FileNotFoundException e) {
      failed();
      e.printStackTrace();
    } catch (IOException e) {
      failed();
      e.printStackTrace();
    }
   
    pa.refreshPackages(new Bundle[] { extensionBC, extensionFW });
  }
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

        if (sl == null) {
            System.out.println("StartLevel service is unavailable.");
        }

        ServiceReference pkgref = getBundleContext().getServiceReference(PackageAdmin.class.getName());
        PackageAdmin admin = null;
        if (pkgref != null) {
            admin = (PackageAdmin) getBundleContext().getService(pkgref);
            if (admin == null) {
                System.out.println("PackageAdmin service is unavailable.");
            }
        }

        Bundle[] bundles = getBundleContext().getBundles();
        if (bundles != null) {
            // Determine threshold
            final String sbslProp = bundleContext.getProperty("karaf.systemBundlesStartLevel");
            if (sbslProp != null) {
                try {
                   if (bundleLevelThreshold < 0) {
                       bundleLevelThreshold = Integer.valueOf( sbslProp );
                   }
                }
                catch( Exception ignore ) {
                   // ignore
                }
            }
            // Display active start level.
            if (sl != null) {
                System.out.println("START LEVEL " + sl.getStartLevel() +
                                   " , List Threshold: " + bundleLevelThreshold);
            }

            // Print column headers.
            String msg = " Name";
            if (showLoc) {
               msg = " Location";
            }
            else if (showSymbolic) {
               msg = " Symbolic name";
            }
            else if (showUpdate) {
               msg = " Update location";
            }
            String level = (sl == null) ? "" : "  Level ";
            String headers = "   ID   State       ";
            for (BundleStateListener.Factory factory : bundleStateListenerFactories) {
                BundleStateListener listener = factory.getListener();
                if (listener != null) {
                    headers += "  " + listener.getName() + " ";
                }
            }
            headers += level + msg;
            System.out.println(headers);
            for (int i = 0; i < bundles.length; i++) {
              if (sl.getBundleStartLevel(bundles[i]) >= bundleLevelThreshold) {
                  // Get the bundle name or location.
                  String name = (String) bundles[i].getHeaders().get(Constants.BUNDLE_NAME);
                  // If there is no name, then default to symbolic name.
                  name = (name == null) ? bundles[i].getSymbolicName() : name;
                  // If there is no symbolic name, resort to location.
                  name = (name == null) ? bundles[i].getLocation() : name;
 
                  // Overwrite the default value is the user specifically
                  // requested to display one or the other.
                  if (showLoc) {
                      name = bundles[i].getLocation();
                  }
                  else if (showSymbolic) {
                      name = bundles[i].getSymbolicName();
                      name = (name == null) ? "<no symbolic name>" : name;
                  }
                  else if (showUpdate) {
                      name = (String) bundles[i].getHeaders().get(Constants.BUNDLE_UPDATELOCATION);
                      name = (name == null) ? bundles[i].getLocation() : name;
                  }
                  // Show bundle version if not showing location.
                  String version = (String) bundles[i].getHeaders().get(Constants.BUNDLE_VERSION);
                  name = (!showLoc && !showUpdate && (version != null)) ? name + " (" + version + ")" : name;
                  long l = bundles[i].getBundleId();
                  String id = String.valueOf(l);
                  if (sl == null) {
                      level = "1";
                  }
                  else {
                      level = String.valueOf(sl.getBundleStartLevel(bundles[i]));
                  }
                  while (level.length() < 5) {
                      level = " " + level;
                  }
                  while (id.length() < 4) {
                      id = " " + id;
                  }
                  String line = "[" + id + "] [" + getStateString(bundles[i]) + "]";
                  for (BundleStateListener.Factory factory : bundleStateListenerFactories) {
                      BundleStateListener listener = factory.getListener();
                      if (listener != null) {
                          String state = listener.getState(bundles[i]);
                          line += " [" + getStateString(state, listener.getName().length()) + "]";
                      }
                  }
                  line += " [" + level + "] " + name;
                  System.out.println(line);
 
                  if (admin != null) {
                      Bundle[] fragments = admin.getFragments(bundles[i]);
                      Bundle[] hosts = admin.getHosts(bundles[i]);
 
                      if (fragments != null) {
                          System.out.print("                                       Fragments: ");
                          int ii = 0;
                          for (Bundle fragment : fragments) {
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

        if (ref == null) {
            System.out.println("PackageAdmin service is unavailable.");
            return;
        }
        try {
            PackageAdmin pa = (PackageAdmin) getBundleContext().getService(ref);
            if (pa == null) {
                System.out.println("PackageAdmin service is unavailable.");
                return;
            }
            if (bundles.isEmpty()) {
                pa.resolveBundles(null);
            } else {
                pa.resolveBundles(bundles.toArray(new Bundle[bundles.size()]));
            }
        }
        finally {
            getBundleContext().ungetService(ref);
        }
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

        if (ref == null) {
            System.out.println("PackageAdmin service is unavailable.");
            return;
        }
        try {
            PackageAdmin pa = (PackageAdmin) getBundleContext().getService(ref);
            if (pa == null) {
                System.out.println("PackageAdmin service is unavailable.");
                return;
            }
            if (bundles.isEmpty()) {
                pa.refreshPackages(null);
            }
            else {
                pa.refreshPackages(bundles.toArray(new Bundle[bundles.size()]));
            }
        }
        finally {
            getBundleContext().ungetService(ref);
        }
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

    protected final Mockery context = new JUnit4Mockery();

    @org.junit.Before public void setUp() throws Exception {
        am = new AdapterManagerImpl();
        final PackageAdmin pa = this.context.mock(PackageAdmin.class);
        final ExportedPackage ep = this.context.mock(ExportedPackage.class);
        this.context.checking(new Expectations(){{
            allowing(pa).getExportedPackage(with(any(String.class)));
            will(returnValue(ep));
        }});
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

     * The returned class changes from map to array list.
     */
    @Test public void testLoading() throws Exception {
        final Sequence sequence = this.context.sequence("load-sequence");
        final BundleContext bundleContext = this.context.mock(BundleContext.class);
        final PackageAdmin packageAdmin = this.context.mock(PackageAdmin.class);
        final ExportedPackage ep = this.context.mock(ExportedPackage.class);
        final Bundle bundle = this.context.mock(Bundle.class);
        this.context.checking(new Expectations() {{
            allowing(bundleContext).createFilter(with(any(String.class)));
            will(returnValue(null));
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

    {
        ServiceReference ref = fw.getBundleContext().getServiceReference(
            PackageAdmin.class.getName());
        if (ref != null)
        {
            PackageAdmin pa = (PackageAdmin) fw.getBundleContext().getService(ref);
            if (pa != null)
            {
                try
                {
                    pa.refreshPackages(null);
                }
                finally
                {
                    fw.getBundleContext().ungetService(ref);
                }
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

            logger.log( LogService.LOG_DEBUG,
                "getParameterClass: Not found through component class, using PackageAdmin service", null );
        }

        // try to load the class with the help of the PackageAdmin service
        PackageAdmin pa = ( PackageAdmin ) Activator.getPackageAdmin();
        if ( pa != null )
        {
            final String referenceClassPackage = m_referenceClassName.substring( 0, m_referenceClassName
                .lastIndexOf( '.' ) );
            ExportedPackage[] pkg = pa.getExportedPackages( referenceClassPackage );
            if ( pkg != null )
            {
                for ( int i = 0; i < pkg.length; i++ )
                {
                    try
View Full Code Here

Examples of org.osgi.service.packageadmin.PackageAdmin

                        "Unable to obtain PackageAdmin service.", "Error",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                }

                PackageAdmin pa = (PackageAdmin) m_context.getService(ref);
                if (pa == null)
                {
                    JOptionPane.showMessageDialog(
                        JOptionPane.getFrameForComponent(BundleListPlugin.this),
                        "Unable to obtain PackageAdmin service.", "Error",
                        JOptionPane.ERROR_MESSAGE);
                    return;
                }

                pa.refreshPackages(null);
            }
        });

        m_uninstallButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.