Java Code Examples for org.osgi.framework.Bundle#getBundleId()

The following examples show how to use org.osgi.framework.Bundle#getBundleId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageManager.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Get the RequiredBundle object for this bundle.
 *
 * @param rbl
 *          List of required bundles as returend by package admin.
 * @param bundle
 *          The bundle to get requiring bundles for.
 * @return The RequiredBundle object for the given bundle or <tt>null</tt> if
 *         the bundle is not required.
 */
public RequiredBundle getRequiredBundle(final RequiredBundle[] rbl,
                                        final Bundle b)
{
  final RequiredBundle rb = requiredBundleMap.get(b);
  if (rb != null) {
    return rb;
  }
  for (int i = 0; rbl != null && i < rbl.length; i++) {
    final Bundle rbb = rbl[i].getBundle();
    if (rbb != null && rbb.getBundleId() == b.getBundleId()) {
      requiredBundleMap.put(b, rbl[i]);
      return rbl[i];
    }
  }
  requiredBundleMap.put(b, null);
  return null;
}
 
Example 2
Source File: ServiceComponentRuntimeImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private ServiceReferenceDTO getServiceReferenceDTO(ServiceReference<?> sr) {
  ServiceReferenceDTO res = new ServiceReferenceDTO();
  res.properties = new HashMap<String, Object>();
  for (String key : sr.getPropertyKeys()) {
    Object val = safeDTOObject(sr.getProperty(key));
    res.properties.put(key, val);
  }
  res.id = ((Long)sr.getProperty(Constants.SERVICE_ID)).longValue();
  Bundle [] using = sr.getUsingBundles();
  if (using != null) {
    res.usingBundles = new long [using.length];
    for (int i = 0; i < using.length; i++) {
      res.usingBundles[i] = using[i].getBundleId();
    }
  } else {
    res.usingBundles = new long [0];
  }
  Bundle b = sr.getBundle();
  if (b == null) {
    return null;
  }
  res.bundle = b.getBundleId();
  return res;
}
 
Example 3
Source File: FilterEventTableModel.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Return true if an entry matches any of the filter bundles.
 */
boolean isValidEntry(Event e) {
  synchronized(lock) {
    if(bundles.size() == 0) {
      return true;
    }

    for(Iterator<Bundle> it = bundles.iterator(); it.hasNext();) {
      Bundle b = it.next();
      if((Util.getBundle(e) != null) &&
         (b.getBundleId() == Util.getBundle(e).getBundleId())) {
        return true;
      }
    }

    return false;
  }
}
 
Example 4
Source File: LogTableModel.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Object getValueAt(ExtLogEntry e, int col) {

    if(col >= getColumnCount()) {
      throw new ArrayIndexOutOfBoundsException
        ("Column " +col +" is larger than " +(getColumnCount() - 1));
    }

    switch(col) {
    case COL_ID:
      return new Long(e.getId());
    case COL_BID:
      final Bundle b = e.getBundle();
      return null!=b ? (Object) new Long(b.getBundleId()) : (Object)"";
    case COL_LEVEL:
      return Util.levelString(e.getLevel());
    case COL_TIME:
      return new Date(e.getTime());
    case COL_MESSAGE:
      return e.getMessage();
    case COL_EXCEPTION:
      return e.getException();
    default:
      return null;
    }
  }
 
Example 5
Source File: BundleUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param array
 */
private static IStatus startBundles(Collection<Bundle> bundles) {
	final BundleContext context = JavaLanguageServerPlugin.getBundleContext();
	MultiStatus status = new MultiStatus(context.getBundle().getSymbolicName(), IStatus.OK, "Starting added bundles", null);
	for (Bundle bundle : bundles) {
		if (bundle.getState() == Bundle.UNINSTALLED) {
			status.add(new Status(IStatus.ERROR, context.getBundle().getSymbolicName(), "Could not start: " + bundle.getSymbolicName() + '(' + bundle.getLocation() + ':' + bundle.getBundleId() + ')' + ". It's state is uninstalled."));
			continue;
		}
		if (bundle.getState() == Bundle.STARTING) {
			continue;
		}
		if (bundle.getBundleId() == 0) {
			continue;
		}

		try {
			// set to the default value for osgi.bundles.defaultStartLevel
			bundle.adapt(BundleStartLevel.class).setStartLevel(4);
			bundle.start(Bundle.START_ACTIVATION_POLICY);
			JavaLanguageServerPlugin.logInfo("Started " + bundle.getLocation());
		} catch (BundleException e) {
			status.add(new Status(IStatus.ERROR, context.getBundle().getSymbolicName(), "Bundle startup failed " + bundle.getLocation(), e));
		}
	}
	return status;

}
 
Example 6
Source File: PermissionTestSuite.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean checkExportVersion (Object _out, Bundle exporter, Bundle importer, String packName, String version) {
   String packServiceName = "org.osgi.service.packageadmin.PackageAdmin";
   PackageAdmin packService = (PackageAdmin) bc.getService(bc.getServiceReference(packServiceName));
   boolean teststatus = true;
   if (packService == null) {
     teststatus  = false;
     out.println("Got null service " + packServiceName + " in FRAME215A:FAIL");
   } else {
     // Now get the array of exported packages from exporting bundle,
     // with one expected package
     long expId = exporter.getBundleId();
     long impId = importer.getBundleId();
     
     ExportedPackage [] exp2 = packService.getExportedPackages(exporter);

     // For all exported packages in exporter bundle, (with the specified version)
     // look for if they are imported by the importer bundle
     //
     if (exp2 != null) {
for (int i = 0; i < exp2.length ; i++ ) {
  // out.println("Got exported package " + exp2[i].getName() + " spev ver. " + exp2[i].getSpecificationVersion() + " in FRAME215A");
  if (version.equals(exp2[i].getSpecificationVersion()) && packName.equals(exp2[i].getName())) {
    Bundle [] ib = exp2[i].getImportingBundles();
    for (int j = 0; j < ib.length ; j++ ) {
      // out.println("   Importing bundle: " + ib[j].getBundleId());
      if (ib[j].getBundleId() ==  impId) {
	// out.println ("MATCH p2 p2 hurrah");
	teststatus = true;
      }
    }
  }
}
     } else {
teststatus  = false;
// out.println("Got null exported package array from bundle " + exporter.getBundleId()  +" in FRAME215A");
     }
   }
   return teststatus;
 }
 
Example 7
Source File: ManifestHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public ResourceUrl(final Bundle bundle, final String path,
                   final boolean isSCR)
{
  this.bid = bundle.getBundleId();
  this.path = path;
  this.isScr = isSCR;
}
 
Example 8
Source File: Resolver.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get bundles affected by zombie packages.
 *
 * Compute a graph of bundles starting with the specified bundles. If no
 * bundles are specified, compute a graph of bundles starting with all
 * exporting a zombie package. Any bundle that imports a package that is
 * currently exported by a bundle in the graph (or requires a bundle that is
 * in the graph) is added to the graph. The graph is fully constructed when
 * there is no bundle outside the graph that imports a package from a bundle
 * in the graph (and there is no bundle outside the graph that requires a
 * bundle in the graph). The graph may contain <tt>UNINSTALLED</tt> bundles
 * that are currently still exporting packages.
 *
 * @param bundles Initial bundle set.
 * @return List of bundles affected.
 */
synchronized TreeSet<Bundle> getZombieAffected(Bundle[] bundles) {
  // set of affected bundles will be in start-level/bundle-id order
  final TreeSet<Bundle> affected = new TreeSet<Bundle>(new Comparator<Bundle>() {
    public int compare(Bundle b1, Bundle b2) {
      int dif = ((BundleImpl) b1).getStartLevel() - ((BundleImpl) b2).getStartLevel();
      if (dif == 0) {
        dif = (int)(b1.getBundleId() - b2.getBundleId());
      }
      return dif;
    }

    public boolean equals(Object o) {
      return ((o != null) && getClass().equals(o.getClass()));
    }
  });

  if (bundles == null) {
    if (framework.debug.resolver) {
      framework.debug.println("getZombieAffected: check - null");
    }
    framework.bundles.getRemovalPendingBundles(affected);
    framework.bundles.getUnattachedBundles(affected);
  } else {
    for (final Bundle bundle : bundles) {
      final BundleImpl tmp = (BundleImpl)bundle;
      if (tmp != null) {
        if (framework.debug.resolver) {
          framework.debug.println("getZombieAffected: check - " + bundle);
        }
        affected.add(tmp);
      }
    }
  }
  closure(affected);
  return affected;
}
 
Example 9
Source File: LogConfigImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Return the log filter level for the given bundle.
 */
int getLevel(final Bundle bundle) {
  final Long key = new Long(bundle.getBundleId());
  Integer level = null;
  synchronized (bidFilters) {
    level = bidFilters.get(key);
  }

  // final PrintStream out = (null!=origOut) ? origOut : System.out;
  // out.println("LogConfigImpl.getLevel(" +key +"): " +level);

  return (level != null) ? level.intValue() : getFilter();
}
 
Example 10
Source File: JCMInfo.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
String getBundleSelectedHeader(Bundle b)
{
  if (b==null) {
    return "No bundle selected";
  }
  return "#" + b.getBundleId() + "  " + Util.getBundleName(b);
}
 
Example 11
Source File: InternalAdminEvent.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void log(TrackedEventHandler handler, String txt)
{
  final ServiceReference<EventHandler> sr = handler.getServiceReference();
  final Bundle b = sr.getBundle();
  String binfo = (b != null) ?
    "  bundle.id=" + b.getBundleId() + "  bundle.name=" + b.getSymbolicName()
    : " No bundle info";
  Activator.log.error(txt + "  Service.id="
                      + sr.getProperty(Constants.SERVICE_ID) + binfo +
                      " topic=" + event.getTopic(), sr);
}
 
Example 12
Source File: JHTMLBundle.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get header text for selected bundle page.
 */
public static String getBundleSelectedHeader(Bundle b)
{
  final BundleRevision rev = b.adapt(BundleRevision.class);
  final boolean isFragment =
    rev != null
      ? (rev.getTypes() & BundleRevision.TYPE_FRAGMENT) != 0
      : false;

  return "#" + b.getBundleId() + "  " + Util.getBundleName(b)
         + (isFragment ? "  (fragment)" : "");
}
 
Example 13
Source File: GraphDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
String makeTitle(Bundle b) {
  return "OSGi Garden: " +
    (b != null
     ? ("#" + b.getBundleId() + " " + Util.getBundleName(b))
     : "no bundle");
}
 
Example 14
Source File: WiringHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public WiringUrl(final Bundle bundle)
{
  bid = bundle.getBundleId();
  bidToBundle.put(bid, bundle);
}
 
Example 15
Source File: PackageHTMLDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public StringBuffer  bundleInfo(Bundle b) {
  final StringBuffer sb = new StringBuffer();


  startFont(sb);

  final Desktop desktop = Activator.desktop;
  if (null!=desktop) {
    final PackageManager pm = desktop.getPackageManager();
    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.
        final RequiredBundle[] rbl = pkgAdmin.getRequiredBundles(null);
        boolean useParagraph = false;

        final Bundle[] fragmentBundles = pm.getFragments(b); // pkgAdmin.getFragments(b);
        if (fragmentBundles.length>0) {
          if (useParagraph) {
            sb.append("<p>");
          }
          sb.append("<b>Host bundle with attached fragments</b>");
          for (final Bundle fragmentBundle : fragmentBundles) {
            sb.append("<br>");
            sb.append("&nbsp;&nbsp");
            Util.bundleLink(sb, fragmentBundle);
            final Bundle[] hosts = pm.getHosts(fragmentBundle);
            if (hosts.length==0 || b.getBundleId()!=hosts[0].getBundleId()) {
              sb.append("&nbsp;<i>pending refresh</i>");
            }
          }
          if (useParagraph) {
            sb.append("</p>");
          }
          useParagraph = true;
        }

        final Bundle[] hostBundles = pm.getHosts(b);
        if (hostBundles.length>0) {
          if (useParagraph) {
            sb.append("<p>");
          }
          sb.append("<b>Fragment attached to</b>");
          for (final Bundle hostBundle : hostBundles) {
            sb.append("<br>");
            sb.append("&nbsp;&nbsp");
            Util.bundleLink(sb, hostBundle);
          }
          if (useParagraph) {
            sb.append("</p>");
          }
          useParagraph = true;
        }

        final RequiredBundle rb = pm.getRequiredBundle(rbl, b);
        final Bundle[] requiringBundles = rb!=null
          ? rb.getRequiringBundles() : null;
        if (requiringBundles!=null && requiringBundles.length>0) {
          if (useParagraph) {
            sb.append("<p>");
          }
          sb.append("<b>Required by</b>");
          if (rb.isRemovalPending()) {
            sb.append(" (<i>pending removal on refresh</i>)");
          }
          for (int j=0; requiringBundles!=null && j<requiringBundles.length;
               j++) {
            sb.append("<br>");
            sb.append("&nbsp;&nbsp");
            Util.bundleLink(sb, requiringBundles[j]);
          }
          if (useParagraph) {
            sb.append("</p>");
          }
          useParagraph = true;
        }
      }

      appendExportedPackages(sb, b, true);
      appendImportedPackages(sb, b, true);
      appendMissingImports(sb, b);
      appendRequiredPackages(sb, b, true);
    }

  }

  sb.append("</font>");

  return sb;
}
 
Example 16
Source File: GraphDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
String makeBundleItemText(final Bundle bundle)
{
  return Util.getBundleName(bundle) + " #" + bundle.getBundleId();
}
 
Example 17
Source File: TableDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void bundleChanged(BundleEvent ev)
{
  final Bundle cBundle = null != ev ? ev.getBundle() : null;
  final long cBid = null != cBundle ? cBundle.getBundleId() : -1;
  super.bundleChanged(ev);
  final Bundle[] newBl = getBundleArray();

  // Fire table change events for the changes
  for (int row = 0; row < newBl.length; row++) {
    if (row < bundleList.length) {
      if (bundleList[row].getBundleId() != newBl[row].getBundleId()) {
        // Fire row change for rows that now presents another bundle.
        model.fireTableRowsUpdated(row, row);
      }
      if (cBid == newBl[row].getBundleId()) {
        // Fire row change since the bundle on this row was changed.
        model.fireTableRowsUpdated(row, row);
      }
    } else {
      // The remainder are new rows.
      model.fireTableRowsInserted(row, newBl.length);
      break;
    }
  }
  if (newBl.length < bundleList.length) {
    // Some rows was removed
    model.fireTableRowsDeleted(newBl.length, bundleList.length - 1);
  }

  bundleList = newBl;

  // Update column widths to handle columns with dynamic max-width.
  for (final JComponent jComp : components) {
    final JBundleTable table = (JBundleTable) jComp;
    table.setColumnWidth();
  }

  // Update table selections to match new rows of selected bundles
  valueChanged(-1);
}
 
Example 18
Source File: CMDisplayer.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static boolean isSystemBundle(final Bundle bundle) {
  return bundle != null && bundle.getBundleId() == 0L;
}
 
Example 19
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public int compare(Bundle b1, Bundle b2)
{
  return (int) (b1.getBundleId() - b2.getBundleId());
}
 
Example 20
Source File: AbstractBundle.java    From concierge with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * @see java.lang.Comparable#compareTo(java.lang.Object)
 * @category Bundle
 */
public final int compareTo(final Bundle o) {
	return (int) (o.getBundleId() - bundleId);
}