org.osgi.framework.Bundle#getBundleId ( )源码实例Demo

下面列出了org.osgi.framework.Bundle#getBundleId ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: knopflerfish.org   文件: PackageManager.java
/**
 * 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;
}
 
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;
}
 
源代码3 项目: knopflerfish.org   文件: LogTableModel.java
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;
    }
  }
 
源代码4 项目: knopflerfish.org   文件: FilterEventTableModel.java
/**
 * 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;
  }
}
 
源代码5 项目: knopflerfish.org   文件: PermissionTestSuite.java
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;
 }
 
源代码6 项目: eclipse.jdt.ls   文件: BundleUtils.java
/**
 * @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;

}
 
源代码7 项目: knopflerfish.org   文件: ManifestHTMLDisplayer.java
public ResourceUrl(final Bundle bundle, final String path,
                   final boolean isSCR)
{
  this.bid = bundle.getBundleId();
  this.path = path;
  this.isScr = isSCR;
}
 
源代码8 项目: knopflerfish.org   文件: Resolver.java
/**
 * 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;
}
 
源代码9 项目: knopflerfish.org   文件: LogConfigImpl.java
/**
 * 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();
}
 
源代码10 项目: knopflerfish.org   文件: JCMInfo.java
String getBundleSelectedHeader(Bundle b)
{
  if (b==null) {
    return "No bundle selected";
  }
  return "#" + b.getBundleId() + "  " + Util.getBundleName(b);
}
 
源代码11 项目: knopflerfish.org   文件: InternalAdminEvent.java
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);
}
 
源代码12 项目: knopflerfish.org   文件: JHTMLBundle.java
/**
 * 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)" : "");
}
 
源代码13 项目: knopflerfish.org   文件: Util.java
@Override
public int compare(Bundle b1, Bundle b2)
{
  return (int) (b1.getBundleId() - b2.getBundleId());
}
 
源代码14 项目: knopflerfish.org   文件: CMDisplayer.java
static boolean isSystemBundle(final Bundle bundle) {
  return bundle != null && bundle.getBundleId() == 0L;
}
 
源代码15 项目: knopflerfish.org   文件: TableDisplayer.java
@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);
}
 
源代码16 项目: knopflerfish.org   文件: GraphDisplayer.java
String makeBundleItemText(final Bundle bundle)
{
  return Util.getBundleName(bundle) + " #" + bundle.getBundleId();
}
 
源代码17 项目: knopflerfish.org   文件: PackageHTMLDisplayer.java
@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;
}
 
源代码18 项目: knopflerfish.org   文件: WiringHTMLDisplayer.java
public WiringUrl(final Bundle bundle)
{
  bid = bundle.getBundleId();
  bidToBundle.put(bid, bundle);
}
 
源代码19 项目: knopflerfish.org   文件: GraphDisplayer.java
String makeTitle(Bundle b) {
  return "OSGi Garden: " +
    (b != null
     ? ("#" + b.getBundleId() + " " + Util.getBundleName(b))
     : "no bundle");
}
 
源代码20 项目: concierge   文件: AbstractBundle.java
/**
 * @see java.lang.Comparable#compareTo(java.lang.Object)
 * @category Bundle
 */
public final int compareTo(final Bundle o) {
	return (int) (o.getBundleId() - bundleId);
}