Java Code Examples for org.osgi.framework.Bundle

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Archimedes, under directory /br.org.archimedes.core.tests/test/br/org/archimedes/.

Source file: FileLoader.java

  32 
vote

/** 
 * To be used when loading files so that they can be found both as plugin tests and normal unit tests.
 * @param filePath The filePath to the file to be loaded
 * @return An input stream for that file
 * @throws FileNotFoundException Thrown if the file cannot be found directly under that path.
 */
public static InputStream getReaderForFile(String filePath) throws FileNotFoundException {
  InputStream fileInput;
  try {
    Bundle bundle=Platform.getBundle(TESTS_PLUGIN_ID);
    IPath file=new Path(filePath);
    fileInput=FileLocator.openStream(bundle,file,false);
  }
 catch (  Throwable t) {
    fileInput=new FileInputStream("resources/" + filePath);
  }
  return fileInput;
}
 

Example 2

From project arkadiko, under directory /test/com/liferay/arkadiko/test/.

Source file: TestFive.java

  32 
vote

public void testExcludeClassNames() throws Exception {
  Bundle installedBundle=installAndStart(_context,"/bundles/bundle-one/bundle-one.jar");
  InterfaceOne interfaceOne=null;
  HasDependencyOnInterfaceOne bean=(HasDependencyOnInterfaceOne)_context.getBean(HasDependencyOnInterfaceOne.class.getName());
  try {
    interfaceOne=bean.getInterfaceOne();
    assertFalse("interfaceOne is a proxy",Proxy.isProxyClass(interfaceOne.getClass()));
  }
  finally {
    installedBundle.uninstall();
  }
  assertFalse("interfaceOne is a proxy",Proxy.isProxyClass(interfaceOne.getClass()));
}
 

Example 3

From project arquillian-container-osgi, under directory /container-embedded/src/main/java/org/jboss/arquillian/container/osgi/embedded/.

Source file: EmbeddedDeployableContainer.java

  32 
vote

public void undeploy(Archive<?> archive) throws DeploymentException {
  try {
    Bundle bundle=bundleInst.get();
    if (bundle != null) {
      int state=bundle.getState();
      if (state != Bundle.UNINSTALLED)       bundle.uninstall();
    }
  }
 catch (  BundleException ex) {
    log.log(Level.SEVERE,"Cannot undeploy: " + archive,ex);
  }
}
 

Example 4

From project arquillian_deprecated, under directory /containers/osgi-embedded-4.2/src/main/java/org/jboss/arquillian/container/osgi/embedded_4_2/.

Source file: OSGiEmbeddedContainer.java

  32 
vote

public void undeploy(Archive<?> archive) throws DeploymentException {
  try {
    Bundle bundle=bundleInst.get();
    if (bundle != null)     bundle.uninstall();
  }
 catch (  BundleException ex) {
    log.error("Cannot undeploy: " + archive,ex);
  }
}
 

Example 5

From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.core/src/com/amazonaws/eclipse/core/ui/overview/.

Source file: OverviewResources.java

  32 
vote

/** 
 * Initializes image resources 
 */
private void initializeImages(){
  Bundle bundle=AwsToolkitCore.getDefault().getBundle();
  imageRegistry.put(IMAGE_GRADIENT,ImageDescriptor.createFromURL(bundle.getEntry("icons/overview/header-gradient.png")));
  imageRegistry.put(IMAGE_GRADIENT_WITH_LOGO,ImageDescriptor.createFromURL(bundle.getEntry("icons/overview/logo-header-gradient.png")));
  imageRegistry.put(IMAGE_CONFIGURE_BUTTON,ImageDescriptor.createFromURL(bundle.getEntry("icons/overview/configure-button.png")));
  imageRegistry.put(IMAGE_BULLET,ImageDescriptor.createFromURL(bundle.getEntry("icons/overview/bullet.png")));
}
 

Example 6

From project blueprint-namespaces, under directory /blueprint/blueprint-cm/src/main/java/org/apache/aries/blueprint/compendium/cm/.

Source file: CmPropertyPlaceholder.java

  32 
vote

public void init() throws Exception {
  LOGGER.debug("Initializing CmPropertyPlaceholder");
  Configuration config=CmUtils.getConfiguration(configAdmin,persistentId);
  if (config != null) {
    properties=config.getProperties();
  }
  Properties props=new Properties();
  props.put(Constants.SERVICE_PID,persistentId);
  Bundle bundle=blueprintContainer.getBundleContext().getBundle();
  props.put(Constants.BUNDLE_SYMBOLICNAME,bundle.getSymbolicName());
  props.put(Constants.BUNDLE_VERSION,bundle.getHeaders().get(Constants.BUNDLE_VERSION));
  managedObjectManager.register(this,props);
}
 

Example 7

From project bundlemaker, under directory /main/org.bundlemaker.core/src/org/bundlemaker/core/internal/projectdescription/.

Source file: JaxbCompoundClassLoader.java

  32 
vote

/** 
 * <p> Creates a new instance of type  {@link JaxbCompoundClassLoader}. </p>
 * @throws CoreException
 */
public JaxbCompoundClassLoader() throws CoreException {
  _compoundClassLoader=new CompoundClassLoader();
  Bundle bundle=Platform.getBundle("org.bundlemaker.core");
  _compoundClassLoader.getMap().put(ObjectFactory.class.getPackage().getName(),new BundleDelegatingClassLoader(bundle));
  for (  ProjectContentProviderExtension extension : ProjectContentProviderExtension.getAllProjectContentProviderExtension()) {
    String packageName=extension.createJaxbObjectFactory().getClass().getPackage().getName();
    bundle=Platform.getBundle(extension.getExtension().getContributor().getName());
    _compoundClassLoader.getMap().put(packageName,new BundleDelegatingClassLoader(bundle));
  }
}
 

Example 8

From project camel-osgi, under directory /component/src/test/java/org/apache/camel/osgi/service/.

Source file: OsgiDefaultEndpointTest.java

  32 
vote

@Test public void testCreateClassLoaderHasGetBundle() throws Exception {
  Bundle bundle=mock(Bundle.class);
  ClassLoader classLoader=new BundleDelegatingClassLoader(bundle,getClass().getClassLoader());
  CamelContext camelContext=mock(CamelContext.class);
  when(camelContext.getApplicationContextClassLoader()).thenReturn(classLoader);
  Component component=mock(Component.class);
  when(component.getCamelContext()).thenReturn(camelContext);
  new OsgiDefaultEndpoint("osgi:test",component);
}
 

Example 9

From project ccw, under directory /ccw.util/src/java/ccw/util/.

Source file: BundleUtils.java

  32 
vote

public static Bundle loadAndGetBundle(String bundleSymbolicName) throws CoreException {
  try {
    Bundle b=Platform.getBundle(bundleSymbolicName);
    if ((b.getState() != Bundle.STARTING) && (b.getState() != Bundle.ACTIVE)) {
      b.start();
    }
    return b;
  }
 catch (  BundleException e) {
    IStatus status=new Status(IStatus.ERROR,bundleSymbolicName,"Unable to start bundle",e);
    throw new CoreException(status);
  }
}
 

Example 10

From project cilia-workbench, under directory /cilia-workbench-monitoring/src/fr/liglab/adele/cilia/workbench/monitoring/.

Source file: EarlyStartupManager.java

  32 
vote

@Override public void earlyStartup(){
  for (  String bundleName : bundles) {
    try {
      Bundle bundleObject=findBundle(bundleName);
      if (bundleObject == null)       System.out.println(bundleName + " is null");
 else {
        bundleObject.start();
      }
    }
 catch (    BundleException e) {
      e.printStackTrace();
    }
  }
}
 

Example 11

From project CIShell, under directory /clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/.

Source file: LogView.java

  32 
vote

private boolean goodEntry(LogEntry entry){
  Bundle sourceBundle=entry.getBundle();
  if (sourceBundle != null && sourceBundle.getSymbolicName().startsWith("org.eclipse.equinox.metatype")) {
    return false;
  }
  if (entry.getLevel() >= LogService.LOG_DEBUG) {
    return false;
  }
  String msg=entry.getMessage();
  if (msg == null || msg.startsWith("ServiceEvent ") || msg.startsWith("BundleEvent ") || msg.startsWith("FrameworkEvent ")) {
    return false;
  }
  return true;
}
 

Example 12

From project cxf-dosgi, under directory /discovery/local/src/test/java/org/apache/cxf/dosgi/discovery/local/.

Source file: LocalDiscoveryUtilsTest.java

  32 
vote

public void testNoRemoteServicesXMLFiles(){
  Bundle b=EasyMock.createNiceMock(Bundle.class);
  EasyMock.replay(b);
  List<Element> rsElements=LocalDiscoveryUtils.getAllDescriptionElements(b);
  assertEquals(0,rsElements.size());
}
 

Example 13

From project acceleo-webapp-generator, under directory /plugins/org.eclipse.acceleo.tutorial.extension.ui/src/org/eclipse/acceleo/tutorial/extension/ui/common/.

Source file: GenerateAll.java

  31 
vote

/** 
 * Finds the template in the plug-in. Returns the template plug-in URI.
 * @param bundleID is the plug-in ID
 * @param relativePath is the relative path of the template in the plug-in
 * @return the template URI
 * @throws IOException
 * @generated
 */
@SuppressWarnings("unchecked") private URI getTemplateURI(String bundleID,IPath relativePath) throws IOException {
  Bundle bundle=Platform.getBundle(bundleID);
  if (bundle == null) {
    return URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(),false);
  }
  URL url=bundle.getEntry(relativePath.toString());
  if (url == null && relativePath.segmentCount() > 1) {
    Enumeration<URL> entries=bundle.findEntries("/","*.emtl",true);
    if (entries != null) {
      String[] segmentsRelativePath=relativePath.segments();
      while (url == null && entries.hasMoreElements()) {
        URL entry=entries.nextElement();
        IPath path=new Path(entry.getPath());
        if (path.segmentCount() > relativePath.segmentCount()) {
          path=path.removeFirstSegments(path.segmentCount() - relativePath.segmentCount());
        }
        String[] segmentsPath=path.segments();
        boolean equals=segmentsPath.length == segmentsRelativePath.length;
        for (int i=0; equals && i < segmentsPath.length; i++) {
          equals=segmentsPath[i].equals(segmentsRelativePath[i]);
        }
        if (equals) {
          url=bundle.getEntry(entry.getPath());
        }
      }
    }
  }
  URI result;
  if (url != null) {
    result=URI.createPlatformPluginURI(new Path(bundleID).append(new Path(url.getPath())).toString(),false);
  }
 else {
    result=URI.createPlatformResourceURI(new Path(bundleID).append(relativePath).toString(),false);
  }
  return result;
}
 

Example 14

From project al.gov.asp.smc.osgi.vaadin.siemens, under directory /com.siemens.ct.osgi.vaadin.pm.bundleview/src/com/siemens/ct/osgi/vaadin/pm/bundleview/.

Source file: BundleView.java

  31 
vote

private void refreshTable(){
  Bundle[] bundles=Activator.getBundles();
  table.removeAllItems();
  int i=1;
  for (  Bundle bundle : bundles) {
    final Bundle selectedBundle=bundle;
    CheckBox checkBox=new CheckBox();
    checkBox.setImmediate(true);
    checkBox.setValue(bundle.getState() == Bundle.ACTIVE);
    checkBox.addListener(new ValueChangeListener(){
      private static final long serialVersionUID=1L;
      @Override public void valueChange(      com.vaadin.data.Property.ValueChangeEvent event){
        if (selectedBundle.getState() == Bundle.ACTIVE) {
          try {
            selectedBundle.stop();
            refreshTable();
          }
 catch (          BundleException e1) {
            e1.printStackTrace();
          }
        }
 else         if (selectedBundle.getState() == Bundle.RESOLVED) {
          try {
            selectedBundle.start();
            refreshTable();
          }
 catch (          BundleException e1) {
            e1.printStackTrace();
          }
        }
      }
    }
);
    table.addItem(new Object[]{bundle.getSymbolicName(),bundle.getVersion(),getStateString(bundle),checkBox},i++);
  }
  table.sort();
}
 

Example 15

From project BHT-FPA, under directory /patterns-codebeispiele/de.bht.fpa.examples.icashbox/src/de/bht/fpa/icashbox/.

Source file: ExecutableExtensionFactory.java

  31 
vote

@SuppressWarnings("rawtypes") @Override public Object create() throws CoreException {
  final Bundle bundle=Activator.getDefault().getBundle();
  final Injector injector=Activator.getDefault().getInjector();
  try {
    final Class<?> clazz=bundle.loadClass(clazzName);
    final Object result=injector.getInstance(clazz);
    if (result instanceof IExecutableExtension) {
      ((IExecutableExtension)result).setInitializationData(config,null,null);
    }
 else     if (result instanceof BasePresenter) {
      return ((BasePresenter)result).getView();
    }
    return result;
  }
 catch (  Exception e) {
    throw new CoreException(new Status(IStatus.ERROR,bundle.getSymbolicName(),e.getMessage(),e));
  }
}
 

Example 16

From project bndtools, under directory /bndtools.core/src/bndtools/editor/project/.

Source file: OSGiFrameworkContentProvider.java

  31 
vote

public void inputChanged(Viewer viewer,Object oldInput,Object newInput){
  frameworks.clear();
  Workspace workspace=(Workspace)newInput;
  IConfigurationElement[] configElements=Platform.getExtensionRegistry().getConfigurationElementsFor(Plugin.PLUGIN_ID,"osgiFrameworks");
  for (  IConfigurationElement element : configElements) {
    String frameworkName=element.getAttribute("name");
    String bsn=element.getAttribute("bsn");
    URL iconUrl=null;
    String iconPath=element.getAttribute("icon");
    if (iconPath != null) {
      Bundle contributorBundle=BundleUtils.findBundle(Plugin.getDefault().getBundleContext(),element.getContributor().getName(),null);
      if (contributorBundle != null)       iconUrl=contributorBundle.getEntry(iconPath);
    }
    List<RepositoryPlugin> repositories=(workspace != null) ? workspace.getRepositories() : Collections.<RepositoryPlugin>emptyList();
    for (    RepositoryPlugin repo : repositories) {
      try {
        SortedSet<Version> versions=repo.versions(bsn);
        if (versions != null)         for (        Version version : versions) {
          try {
            File framework=repo.get(bsn,version,null);
            if (framework != null)             frameworks.add(new OSGiFramework(frameworkName,bsn,version,iconUrl));
          }
 catch (          Exception e) {
            logger.logError(String.format("Error finding repository entry for OSGi framework %s, version %s.",bsn,version.toString()),e);
          }
        }
      }
 catch (      Exception e) {
        logger.logError(String.format("Error searching repository for OSGi framework %s.",bsn),e);
      }
    }
  }
}
 

Example 17

From project ceylon-ide-eclipse, under directory /plugins/com.redhat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/code/hover/.

Source file: DocHover.java

  31 
vote

/** 
 * Loads and returns the Javadoc hover style sheet.
 * @return the style sheet, or <code>null</code> if unable to load
 * @since 3.4
 */
public static String loadStyleSheet(){
  Bundle bundle=Platform.getBundle(JavaPlugin.getPluginId());
  URL styleSheetURL=bundle.getEntry("/JavadocHoverStyleSheet.css");
  if (styleSheetURL != null) {
    BufferedReader reader=null;
    try {
      reader=new BufferedReader(new InputStreamReader(styleSheetURL.openStream()));
      StringBuffer buffer=new StringBuffer(1500);
      String line=reader.readLine();
      while (line != null) {
        buffer.append(line);
        buffer.append('\n');
        line=reader.readLine();
      }
      return buffer.toString();
    }
 catch (    IOException ex) {
      JavaPlugin.log(ex);
      return "";
    }
 finally {
      try {
        if (reader != null)         reader.close();
      }
 catch (      IOException e) {
      }
    }
  }
  return null;
}
 

Example 18

From project adt-cdt, under directory /com.android.ide.eclipse.adt.cdt/src/com/android/ide/eclipse/adt/cdt/internal/.

Source file: Activator.java

  29 
vote

public static Bundle getBundle(String id){
  for (  Bundle bundle : plugin.getBundle().getBundleContext().getBundles()) {
    if (bundle.getSymbolicName().equals(id)) {
      return bundle;
    }
  }
  return null;
}
 

Example 19

From project agile, under directory /agile-framework/src/main/java/org/headsupdev/agile/framework/.

Source file: HeadsUpClassResolver.java

  29 
vote

public Class resolveClass(String s) throws ClassNotFoundException {
  try {
    return parent.resolveClass(s);
  }
 catch (  ClassNotFoundException e) {
    for (    Bundle bundle : AppTracker.getBundles()) {
      try {
        return bundle.loadClass(s);
      }
 catch (      ClassNotFoundException e2) {
      }
    }
    throw e;
  }
}
 

Example 20

From project arquillian-showcase, under directory /osgi/src/test/java/com/acme/osgi/.

Source file: SimpleOSGiServiceTestCase.java

  29 
vote

@Test public void testBundleInjection() throws Exception {
  assertNotNull("Bundle injected",bundle);
  assertEquals("Bundle RESOLVED",Bundle.RESOLVED,bundle.getState());
  bundle.start();
  assertEquals("Bundle ACTIVE",Bundle.ACTIVE,bundle.getState());
  BundleContext context=bundle.getBundleContext();
  assertNotNull("BundleContext available",context);
  ServiceReference sref=context.getServiceReference(SimpleService.class.getName());
  assertNotNull("ServiceReference not null",sref);
  SimpleService service=(SimpleService)context.getService(sref);
  assertNotNull("Service not null",service);
  int sum=service.sum(1,2,3);
  assertEquals(6,sum);
  bundle.stop();
  assertEquals("Bundle RESOLVED",Bundle.RESOLVED,bundle.getState());
}