Java 类org.osgi.framework.BundleActivator 实例源码

项目:arquillian-extension-liferay    文件:ArquillianBundleActivator.java   
private Set<BundleActivator> loadActivators() {
    String serviceFile =
        _SERVICES + "/" + BundleActivator.class.getCanonicalName();

    Set<BundleActivator> activators = new LinkedHashSet<>();

    ClassLoader classLoader = getClass().getClassLoader();

    try {
        Enumeration<URL> enumeration = classLoader.getResources(
            serviceFile);

        while (enumeration.hasMoreElements()) {
            addBundleActivatorToActivatorsListFromURL(
                activators, enumeration.nextElement());
        }
    }
    catch (Exception e) {
        throw new RuntimeException("Could not load bundle activators", e);
    }

    return activators;
}
项目:gravia    文件:BundleIntegrationTest.java   
@Deployment(name = BUNDLE_B, testable = false, managed = false)
public static Archive<?> bundleB() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, BUNDLE_B);
    archive.addClasses(SimpleBundleActivator.class);
    archive.setManifest(new Asset() {
        @Override
        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleManifestVersion(2);
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleVersion("1.0.0");
            builder.addImportPackages(BundleActivator.class);
            builder.addBundleActivator(SimpleBundleActivator.class);
            return builder.openStream();
        }
    });
    return archive;
}
项目:communote-server    文件:OSGiManagement.java   
private void prepareFramework() {
    fileInstall = new FileInstall();
    propertiesDictionary = new Hashtable<String, String>();
    StartupProperties startupProperties = CommunoteRuntime.getInstance()
            .getConfigurationManager().getStartupProperties();
    propertiesDictionary.put(DirectoryWatcher.DIR, startupProperties.getPluginDir()
            .getAbsolutePath());
    propertiesDictionary.put(DirectoryWatcher.NO_INITIAL_DELAY, Boolean.TRUE.toString());
    propertiesDictionary.put(DirectoryWatcher.START_NEW_BUNDLES, Boolean.TRUE.toString());
    propertiesDictionary.put(DirectoryWatcher.LOG_LEVEL, Integer.toString(4));
    Properties frameworkProperties = loadFrameworkProperties();
    List<BundleActivator> activatorList = new ArrayList<BundleActivator>();
    activatorList.add(fileInstall);
    frameworkProperties.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, activatorList);
    // TODO better add a setSystemBundlesLocation method
    String pathToWebInf = CommunoteRuntime.getInstance().getApplicationInformation()
            .getApplicationRealPath()
            + "WEB-INF" + File.separator;
    initSystemBundles(frameworkProperties, pathToWebInf + "plugins");
    frameworkProperties.put(Constants.FRAMEWORK_STORAGE, OSGiHelper.getBundleBasePath()
            .getAbsolutePath() + File.separator + "bundle-cache");
    try {
        framework = new Felix(frameworkProperties);
        framework.init();
        AutoProcessor.process(frameworkProperties, framework.getBundleContext());
        framework.getBundleContext().addBundleListener(this);
    } catch (BundleException e) {
        throw new BeanCreationException(
                "Starting OSGi framework failed because of a BundleException.", e);
    }
    LOG.info("OSGi Framework initialized.");
}
项目:eclipse-extras    文件:DynamicWorkingSetStartupPDETest.java   
@Test
public void testStartupExtension() {
  Extension extension = getEarlyStartup();

  IStartup startup = extension.createExecutableExtension( "class", IStartup.class );
  assertThat( startup ).isInstanceOf( DynamicWorkingSetStartup.class );
  assertThat( startup ).isNotInstanceOf( BundleActivator.class );
}
项目:eclipse-extras    文件:LaunchExtrasStartupPDETest.java   
@Test
public void testStartupExtension() {
  Extension extension = getEarlyStartup();

  IStartup startup = extension.createExecutableExtension( "class", IStartup.class );
  assertThat( startup ).isInstanceOf( LaunchExtrasStartup.class );
  assertThat( startup ).isNotInstanceOf( BundleActivator.class );
}
项目:AtlasForAndroid    文件:BundleImpl.java   
public synchronized void startBundle() throws BundleException {
    if (this.state == 1) {
        throw new IllegalStateException("Cannot start uninstalled bundle " + toString());
    } else if (this.state != 32) {
        if (this.state == 2) {
            resolveBundle(true);
        }
        this.state = 8;
        try {
            this.context.isValid = true;
            if (!(this.classloader.activatorClassName == null || StringUtils.isBlank(this.classloader.activatorClassName))) {
                Class loadClass = this.classloader.loadClass(this.classloader.activatorClassName);
                if (loadClass == null) {
                    throw new ClassNotFoundException(this.classloader.activatorClassName);
                }
                this.classloader.activator = (BundleActivator) loadClass.newInstance();
                this.classloader.activator.start(this.context);
            }
            this.state = 32;
            Framework.notifyBundleListeners(2, this);
            if (Framework.DEBUG_BUNDLES && log.isInfoEnabled()) {
                log.info("Framework: Bundle " + toString() + " started.");
            }
        } catch (Throwable th) {
            Throwable th2 = th;
            Framework.clearBundleTrace(this);
            this.state = 4;
            String str = "Error starting bundle " + toString();
            if (th2.getCause() != null) {
                th2 = th2.getCause();
            }
            BundleException bundleException = new BundleException(str, th2);
        }
    }
}
项目:SimpleFlatMapper    文件:HostApplication.java   
public HostApplication() throws IOException {
    // Create a configuration property map.
    Map<String, Object> config = new HashMap<String, Object>();
    // Create host activator;
    m_activator = new HostActivator();
    List<BundleActivator> list = new ArrayList<BundleActivator>();
    list.add(m_activator);
    config.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
    config.put(FelixConstants.FRAMEWORK_STORAGE, "target/felix");
    config.put(FelixConstants.LOG_LEVEL_PROP, "5");

    cleanUp("target/felix");

    try
    {
        // Now create an instance of the framework with
        // our configuration properties.
        m_felix = new Felix(config);
        // Now start Felix instance.
        m_felix.start();
    }
    catch (Exception ex)
    {
        System.err.println("Could not create framework: " + ex);
        ex.printStackTrace();
    }
}
项目:arquillian-extension-liferay    文件:ArquillianBundleActivator.java   
@Override
public void start(final BundleContext context) throws Exception {
    final TestClassLoader testClassLoader = new TestClassLoader() {

        @Override
        public Class<?> loadTestClass(String className)
            throws ClassNotFoundException {

            return context.getBundle().loadClass(className);
        }
    };

    // Execute all activators

    bundleActivators = loadActivators();

    for (BundleActivator bundleActivator : bundleActivators) {
        bundleActivator.start(context);
    }

    // Register the JMXTestRunner

    MBeanServer mbeanServer = findOrCreateMBeanServer();

    testRunner = new JMXTestRunner(testClassLoader) {
        @Override
        public byte[] runTestMethod(String className, String methodName) {
            BundleAssociation.setBundle(context.getBundle());
            BundleContextAssociation.setBundleContext(context);

            return super.runTestMethod(className, methodName);
        }
    };
    testRunner.registerMBean(mbeanServer);
}
项目:arquillian-extension-liferay    文件:ArquillianBundleActivator.java   
@Override
public void stop(BundleContext context) throws Exception {

    // Execute all activators

    for (BundleActivator bundleActivator : bundleActivators) {
        bundleActivator.stop(context);
    }

    // Unregister the JMXTestRunner

    MBeanServer mbeanServer = findOrCreateMBeanServer();
    testRunner.unregisterMBean(mbeanServer);
}
项目:arquillian-extension-liferay    文件:ArquillianBundleActivator.java   
private void addBundleActivatorToActivatorsListFromStringLine(
    Set<BundleActivator> activators, String line) {

    ClassLoader classLoader = getClass().getClassLoader();

    if (line.startsWith("!")) {
        return;
    }

    try {
        Class<?> aClass = classLoader.loadClass(line);

        Class<? extends BundleActivator> bundleActivatorClass =
            aClass.asSubclass(BundleActivator.class);

        activators.add(bundleActivatorClass.newInstance());
    }
    catch (ClassNotFoundException cnfe) {
        throw new IllegalStateException(
            "Activator " + line + " class not found", cnfe);
    }
    catch (ClassCastException cce) {
        throw new IllegalStateException(
            "Activator " + line + " does not implement expected type " +
                BundleActivator.class.getCanonicalName(),
            cce);
    }
    catch (Exception e) {
        throw new IllegalStateException(
            "Activator " + line + " can't be created ", e);
    }
}
项目:arquillian-extension-liferay    文件:ArquillianBundleActivator.java   
private void addBundleActivatorToActivatorsListFromURL(
        Set<BundleActivator> activators, URL url)
    throws IOException {

    final InputStream is = url.openStream();

    BufferedReader reader = null;

    try {
        reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

        String line = reader.readLine();

        while (null != line) {
            line = skipCommentAndTrim(line);

            addBundleActivatorToActivatorsListFromStringLine(
                activators, line);

            line = reader.readLine();
        }
    }
    finally {
        if (reader != null) {
            reader.close();
        }
    }
}
项目:gemini.blueprint    文件:ChainActivator.java   
public ChainActivator() {
       final LoggingActivator logStatus = new LoggingActivator();
       final JavaBeansCacheActivator activateJavaBeansCache = new JavaBeansCacheActivator();
       final NamespaceHandlerActivator activateCustomNamespaceHandling = new NamespaceHandlerActivator();
       final NamespaceHandlerActivator activateBlueprintspecificNamespaceHandling = new BlueprintNamespaceHandlerActivator();
       final ExtenderConfiguration initializeExtenderConfiguration = new ExtenderConfiguration();
       final ListenerServiceActivator activateListeners = new ListenerServiceActivator(initializeExtenderConfiguration);
       final ContextLoaderListener listenForSpringDmBundles = new ContextLoaderListener(initializeExtenderConfiguration);
       final BlueprintLoaderListener listenForBlueprintBundles = new BlueprintLoaderListener(initializeExtenderConfiguration, activateListeners);

       if (OsgiPlatformDetector.isR42()) {
        if (BLUEPRINT_AVAILABLE) {
            log.info("Blueprint API detected; enabling Blueprint Container functionality");
            CHAIN = new BundleActivator[] {
                       logStatus,
                       activateJavaBeansCache,
                       activateCustomNamespaceHandling,
                       activateBlueprintspecificNamespaceHandling,
                       initializeExtenderConfiguration,
                       activateListeners,
                       listenForSpringDmBundles,
                       listenForBlueprintBundles
               };
        }
        else {
            log.warn("Blueprint API not found; disabling Blueprint Container functionality");
            CHAIN = new BundleActivator[] {
                       logStatus,
                       activateJavaBeansCache,
                       activateCustomNamespaceHandling,
                       initializeExtenderConfiguration,
                       activateListeners,
                       listenForSpringDmBundles
               };
        }
    } else {
        log.warn("Pre-4.2 OSGi platform detected; disabling Blueprint Container functionality");
           CHAIN = new BundleActivator[] {
                   logStatus,
                   activateJavaBeansCache,
                   activateCustomNamespaceHandling,
                   initializeExtenderConfiguration,
                   activateListeners,
                   listenForSpringDmBundles
           };
       }
}
项目:osgi-jpms-layer    文件:EquinoxJPMSSupport.java   
@Override
public BundleActivator createActivator() {
    return this;
}
项目:osgi-embedded    文件:EmbeddedOSGiContainer.java   
protected void configHostActivator(Map<String, Object> config) {
    List<BundleActivator> activators = new ArrayList<BundleActivator>();
    activators.add(this.hostActivator);
    config.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators);
}
项目:osgi-embedded    文件:EmbeddedOSGiContainer.java   
private BundleActivator createHostActivator() {
    this.hostActivator = new HostActivator(
        this.containerConfiguration.areRemoteShellBundlesEnabled(), this.containerConfiguration.isSlf4jBridgeActivated());
    return this.hostActivator;
}
项目:gravia    文件:AbstractRuntimePlugin.java   
@Override
public void start(ModuleContext context) throws Exception {
    delegate = (BundleActivator) context.getModule().loadClass(getBundleActivator()).newInstance();
    delegate.start(new BundleContextAdaptor(context));
}
项目:gravia    文件:ModuleActivatorBridge.java   
public ModuleActivatorBridge(BundleActivator activator) {
    this.bundleActivator = activator;
}