Package org.springframework.osgi.context

Examples of org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext


    else {
      String[] configs = copyEnumerationToList(enm);

      log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs));
      // create OSGi specific XML context
      ConfigurableOsgiBundleApplicationContext extenderAppCtx = new OsgiBundleXmlApplicationContext(configs);
      extenderAppCtx.setBundleContext(bundleContext);
      extenderAppCtx.refresh();

      synchronized (lock) {
        extenderConfiguration = extenderAppCtx;
        // initialize beans
        taskExecutor = extenderConfiguration.containsBean(TASK_EXECUTOR_NAME) ? (TaskExecutor) extenderConfiguration.getBean(
View Full Code Here


    // destroy bundles
    Bundle[] bundles = new Bundle[managedContexts.size()];

    int i = 0;
    for (Iterator it = managedContexts.values().iterator(); it.hasNext();) {
      ConfigurableOsgiBundleApplicationContext context = (ConfigurableOsgiBundleApplicationContext) it.next();
      bundles[i++] = context.getBundle();
    }

    bundles = shutdownDependencySorter.computeServiceDependencyGraph(bundles);

    boolean debug = log.isDebugEnabled();

    StringBuffer buffer = new StringBuffer();
    if (debug) {
      buffer.append("Shutdown order is: {");
      for (i = 0; i < bundles.length; i++) {
        buffer.append("\nBundle [" + bundles[i].getSymbolicName() + "]");
      }
      buffer.append("\n}");
      log.debug(buffer);
    }

    final List taskList = new ArrayList(managedContexts.size());
    final List closedContexts = Collections.synchronizedList(new ArrayList());
    final Object[] contextClosingDown = new Object[1];

    for (i = 0; i < bundles.length; i++) {
      Long id = new Long(bundles[i].getBundleId());
      final ConfigurableOsgiBundleApplicationContext context = (ConfigurableOsgiBundleApplicationContext) managedContexts.get(id);
      if (context != null) {
        closedContexts.add(context);
        // add a new runnable
        taskList.add(new Runnable() {

          private final String toString = "Closing runnable for context " + context.getDisplayName();


          public void run() {
            contextClosingDown[0] = context;
            // eliminate context
            closedContexts.remove(context);
            if (log.isDebugEnabled())
              log.debug("Closing appCtx " + context.getDisplayName());
            context.close();
          }

          public String toString() {
            return toString;
          }
View Full Code Here

   * BundleContext object is not valid once we return from this method.
   *
   * @param bundle
   */
  protected void maybeCloseApplicationContextFor(Bundle bundle) {
    final ConfigurableOsgiBundleApplicationContext context = (ConfigurableOsgiBundleApplicationContext) managedContexts.remove(new Long(
      bundle.getBundleId()));
    if (context == null) {
      return;
    }

    RunnableTimedExecution.execute(new Runnable() {

      private final String toString = "Closing runnable for context " + context.getDisplayName();


      public void run() {
        if (context.isActive()) {
          context.close();
        }
      }

      public String toString() {
        return toString;
View Full Code Here

    else {
      String[] configs = copyEnumerationToList(enm);

      log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs));
      // create OSGi specific XML context
      ConfigurableOsgiBundleApplicationContext context = new OsgiBundleXmlApplicationContext(configs);
      context.setBundleContext(bundleContext);
      context.refresh();

      synchronized (lock) {
        extenderConfiguration = context;
      }

      warScanner = context.containsBean(WAR_SCANNER_NAME) ? (WarScanner) context.getBean(WAR_SCANNER_NAME,
        WarScanner.class) : createDefaultWarScanner();

      warDeployer = context.containsBean(WAR_DEPLOYER_NAME) ? (WarDeployer) context.getBean(WAR_DEPLOYER_NAME,
        WarDeployer.class) : createDefaultWarDeployer(bundleContext);

      contextPathStrategy = context.containsBean(CONTEXT_PATH_STRATEGY_NAME) ? (ContextPathStrategy) context.getBean(
        CONTEXT_PATH_STRATEGY_NAME, ContextPathStrategy.class)
          : createDefaultContextPathStrategy();

      // extender properties using the defaults as backup
      if (context.containsBean(PROPERTIES_NAME)) {
        Properties customProperties = (Properties) context.getBean(PROPERTIES_NAME, Properties.class);
        Enumeration propertyKey = customProperties.propertyNames();
        while (propertyKey.hasMoreElements()) {
          String property = (String) propertyKey.nextElement();
          properties.setProperty(property, customProperties.getProperty(property));
        }
View Full Code Here

   * <p/>This implementation will create an empty bundle context in case no
   * locations are specified.
   */
  protected ConfigurableApplicationContext createApplicationContext(String[] locations) {

    ConfigurableOsgiBundleApplicationContext context = null;

    if (ObjectUtils.isEmpty(locations))
      context = new EmptyOsgiApplicationContext();
    else
      context = new OsgiBundleXmlApplicationContext(locations);

    context.setBundleContext(bundleContext);
    context.refresh();
    return context;
  }
View Full Code Here

  }

  public void testSetServletContextWOBundleContextWithParent() throws Exception {
    servletContext = new MockServletContext();
    BundleContext bc = new MockBundleContext();
    ConfigurableOsgiBundleApplicationContext parent = new OsgiBundleXmlApplicationContext();
    parent.setBundleContext(bc);
    context.setParent(parent);
    context.setServletContext(servletContext);
    assertSame(servletContext, context.getServletContext());
    assertSame(bc, parent.getBundleContext());
    assertSame(bc, context.getBundleContext());
    assertSame(parent, context.getParent());
  }
View Full Code Here

    else {
      String[] configs = copyEnumerationToList(enm);

      log.info("Detected extender custom configurations at " + ObjectUtils.nullSafeToString(configs));
      // create OSGi specific XML context
      ConfigurableOsgiBundleApplicationContext extenderAppCtx = new OsgiBundleXmlApplicationContext(configs);
      extenderAppCtx.setBundleContext(bundleContext);
      extenderAppCtx.refresh();

      synchronized (lock) {
        extenderConfiguration = extenderAppCtx;
        // initialize beans
        taskExecutor = extenderConfiguration.containsBean(TASK_EXECUTOR_NAME) ? (TaskExecutor) extenderConfiguration.getBean(
View Full Code Here

    // destroy bundles
    Bundle[] bundles = new Bundle[managedContexts.size()];

    int i = 0;
    for (Iterator it = managedContexts.values().iterator(); it.hasNext();) {
      ConfigurableOsgiBundleApplicationContext context = (ConfigurableOsgiBundleApplicationContext) it.next();
      bundles[i++] = context.getBundle();
    }

    bundles = shutdownDependencySorter.computeServiceDependencyGraph(bundles);

    boolean debug = log.isDebugEnabled();

    StringBuffer buffer = new StringBuffer();

    if (debug) {
      buffer.append("Shutdown order is: {");
      for (i = 0; i < bundles.length; i++) {
        buffer.append("\nBundle [" + bundles[i].getSymbolicName() + "]");
        ServiceReference[] services = bundles[i].getServicesInUse();
        HashSet usedBundles = new HashSet();
        if (services != null) {
          for (int j = 0; j < services.length; j++) {
            if (BundleDependencyComparator.isSpringManagedService(services[j])) {
              Bundle used = services[j].getBundle();
              if (!used.equals(bundleContext.getBundle()) && !usedBundles.contains(used)) {
                usedBundles.add(used);
                buffer.append("\n  Using [" + used.getSymbolicName() + "]");
              }
            }

          }
        }
      }
      buffer.append("\n}");
      log.debug(buffer);
    }

    final List taskList = new ArrayList(managedContexts.size());
    final List closedContexts = Collections.synchronizedList(new ArrayList());
    final Object[] contextClosingDown = new Object[1];

    for (i = 0; i < bundles.length; i++) {
      Long id = new Long(bundles[i].getBundleId());
      final ConfigurableOsgiBundleApplicationContext context = (ConfigurableOsgiBundleApplicationContext) managedContexts.get(id);
      if (context != null) {
        closedContexts.add(context);
        // add a new runnable
        taskList.add(new Runnable() {

          private final String toString = "Closing runnable for context " + context.getDisplayName();


          public void run() {
            contextClosingDown[0] = context;
            // eliminate context
            closedContexts.remove(context);
            if (log.isDebugEnabled())
              log.debug("Closing appCtx " + context.getDisplayName());
            context.close();
          }

          public String toString() {
            return toString;
          }
View Full Code Here

   * BundleContext object is not valid once we return from this method.
   *
   * @param bundle
   */
  protected void maybeCloseApplicationContextFor(Bundle bundle) {
    final ConfigurableOsgiBundleApplicationContext context = (ConfigurableOsgiBundleApplicationContext) managedContexts.remove(new Long(
      bundle.getBundleId()));
    if (context == null) {
      return;
    }

    RunnableTimedExecution.execute(new Runnable() {

      private final String toString = "Closing runnable for context " + context.getDisplayName();


      public void run() {
        if (context.isActive()) {
          context.close();
        }
      }

      public String toString() {
        return toString;
View Full Code Here

        // Start reading the configuration
        is = securityConfiguration.openStream();

        // Turn the stream into a Spring Security filter chain
        ConfigurableOsgiBundleApplicationContext springContext = null;
        springContext = new OsgiBundleXmlApplicationContext(new String[] { securityConfiguration.toExternalForm() });
        springContext.setBundleContext(bundle.getBundleContext());
        springContext.refresh();

        // Register the security filter chain
        Filter siteSecurityFilter = (Filter) springContext.getBean("springSecurityFilterChain");
        logger.info("Registering custom security filter for site '{}'", site.getIdentifier());
        siteFilters.put(site, siteSecurityFilter);
      } catch (IOException e) {
        throw new IllegalStateException("Security configuration " + securityConfiguration + " of site '" + site.getIdentifier() + "' cannot be read: " + e.getMessage(), e);
      } catch (Throwable t) {
View Full Code Here

TOP

Related Classes of org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext

Copyright © 2018 www.massapicom. 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.