@Override
 public String toString() {
   return getClass().getName()
       + ": patterns "
       + ObjectUtils.nullSafeToString(this.patterns)
       + ", excluded patterns "
       + ObjectUtils.nullSafeToString(this.excludedPatterns);
 }
  public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(
      BundleContext bundleContext) throws Exception {
    Bundle bundle = bundleContext.getBundle();
    ApplicationContextConfiguration config = new BlueprintContainerConfig(bundle);
    String bundleName = OsgiStringUtils.nullSafeNameAndSymName(bundle);
    if (log.isTraceEnabled())
      log.trace("Created configuration " + config + " for bundle " + bundleName);

    // it's not a spring bundle, ignore it
    if (!config.isSpringPoweredBundle()) {
      if (log.isDebugEnabled())
        log.debug("No blueprint configuration found in bundle " + bundleName + "; ignoring it...");
      return null;
    }

    log.info(
        "Discovered configurations "
            + ObjectUtils.nullSafeToString(config.getConfigurationLocations())
            + " in bundle ["
            + bundleName
            + "]");

    DelegatedExecutionOsgiBundleApplicationContext sdoac =
        new OsgiBundleXmlApplicationContext(config.getConfigurationLocations());
    sdoac.setBundleContext(bundleContext);
    sdoac.setPublishContextAsService(config.isPublishContextAsService());

    return sdoac;
  }
 public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() {
   if (this.persistenceUnitInfoNames.isEmpty()) {
     throw new IllegalStateException(
         "No persistence units parsed from "
             + ObjectUtils.nullSafeToString(this.persistenceXmlLocations));
   }
   if (this.persistenceUnitInfos.isEmpty()) {
     throw new IllegalStateException(
         "All persistence units from "
             + ObjectUtils.nullSafeToString(this.persistenceXmlLocations)
             + " already obtained");
   }
   if (this.persistenceUnitInfos.size() > 1) {
     return obtainPersistenceUnitInfo(this.defaultPersistenceUnitName);
   }
   PersistenceUnitInfo pui = this.persistenceUnitInfos.values().iterator().next();
   this.persistenceUnitInfos.clear();
   return pui;
 }
  private static void dispatchServiceRegistrationEvents(
      ServiceReference[] alreadyRegistered, ServiceListener listener) {
    if (log.isTraceEnabled())
      log.trace(
          "Calling listener for already registered services: "
              + ObjectUtils.nullSafeToString(alreadyRegistered));

    if (alreadyRegistered != null) {
      for (int i = 0; i < alreadyRegistered.length; i++) {
        listener.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, alreadyRegistered[i]));
      }
    }
  }
 /**
  * Create a new conversion exception.
  *
  * @param sourceType the value's original type
  * @param targetType the value's target type
  * @param value the value we tried to convert
  * @param cause the cause of the conversion failure
  */
 public ConversionFailedException(
     TypeDescriptor sourceType, TypeDescriptor targetType, Object value, Throwable cause) {
   super(
       "Failed to convert from type "
           + sourceType
           + " to type "
           + targetType
           + " for value '"
           + ObjectUtils.nullSafeToString(value)
           + "'",
       cause);
   this.sourceType = sourceType;
   this.targetType = targetType;
   this.value = value;
 }
Example #6
0
 /**
  * Convenience method to return a String array as a delimited (e.g. CSV) String. E.g. useful for
  * {@code toString()} implementations.
  *
  * @param arr the array to display
  * @param delim the delimiter to use (probably a ",")
  * @return the delimited String
  */
 public static String arrayToDelimitedString(Object[] arr, String delim) {
   if (org.springframework.util.ObjectUtils.isEmpty(arr)) {
     return "";
   }
   if (arr.length == 1) {
     return org.springframework.util.ObjectUtils.nullSafeToString(arr[0]);
   }
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < arr.length; i++) {
     if (i > 0) {
       sb.append(delim);
     }
     sb.append(arr[i]);
   }
   return sb.toString();
 }
  private void addImportPackage(Manifest manifest) {
    String[] rawImports = determineImports();

    boolean trace = logger.isTraceEnabled();

    if (trace) logger.trace("Discovered raw imports " + ObjectUtils.nullSafeToString(rawImports));

    Collection specialImportsOut = eliminateSpecialPackages(rawImports);
    Collection imports = eliminatePackagesAvailableInTheJar(specialImportsOut);

    if (trace) logger.trace("Filtered imports are " + imports);

    manifest
        .getMainAttributes()
        .putValue(Constants.IMPORT_PACKAGE, StringUtils.collectionToCommaDelimitedString(imports));
  }
 /**
  * Provide a String representation of the {@linkplain #getTestClass() test class}, {@linkplain
  * #getLocations() locations}, {@linkplain #getClasses() annotated classes}, {@linkplain
  * #getContextInitializerClasses() context initializer classes}, {@linkplain #getActiveProfiles()
  * active profiles}, {@linkplain #getPropertySourceLocations() property source locations},
  * {@linkplain #getPropertySourceProperties() property source properties}, {@linkplain
  * #getContextCustomizers() context customizers}, the name of the {@link #getContextLoader()
  * ContextLoader}, and the {@linkplain #getParent() parent configuration}.
  */
 @Override
 public String toString() {
   return new ToStringCreator(this)
       .append("testClass", this.testClass)
       .append("locations", ObjectUtils.nullSafeToString(this.locations))
       .append("classes", ObjectUtils.nullSafeToString(this.classes))
       .append(
           "contextInitializerClasses",
           ObjectUtils.nullSafeToString(this.contextInitializerClasses))
       .append("activeProfiles", ObjectUtils.nullSafeToString(this.activeProfiles))
       .append(
           "propertySourceLocations", ObjectUtils.nullSafeToString(this.propertySourceLocations))
       .append(
           "propertySourceProperties", ObjectUtils.nullSafeToString(this.propertySourceProperties))
       .append("contextCustomizers", this.contextCustomizers)
       .append("contextLoader", nullSafeToString(this.contextLoader))
       .append("parent", this.parent)
       .toString();
 }
Example #9
0
 protected void assertResourceArray(Object[] array, int expectedSize) {
   System.out.println(ObjectUtils.nullSafeToString(array));
   assertTrue("found only " + ObjectUtils.nullSafeToString(array), array.length == expectedSize);
 }
 public String getAsText() {
   return ObjectUtils.nullSafeToString(getValue()).toUpperCase();
 }
  /**
   * Constructs a new <code>ExtenderConfiguration</code> instance. Locates the extender
   * configuration, creates an application context which will returned the extender items.
   *
   * @param bundleContext extender OSGi bundle context
   */
  public ExtenderConfiguration(BundleContext bundleContext, Log log) {
    this.log = log;
    Bundle bundle = bundleContext.getBundle();
    Properties properties = new Properties(createDefaultProperties());

    Enumeration<?> enm = bundle.findEntries(EXTENDER_CFG_LOCATION, XML_PATTERN, false);

    if (enm == null) {
      log.info("No custom extender configuration detected; using defaults...");

      synchronized (lock) {
        taskExecutor = createDefaultTaskExecutor();
        shutdownTaskExecutor = createDefaultShutdownTaskExecutor();
        eventMulticaster = createDefaultEventMulticaster();
        contextCreator = createDefaultApplicationContextCreator();
        contextEventListener = createDefaultApplicationContextListener();
      }
      classLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle);
    } 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(TASK_EXECUTOR_NAME, TaskExecutor.class)
                : createDefaultTaskExecutor();

        shutdownTaskExecutor =
            extenderConfiguration.containsBean(SHUTDOWN_TASK_EXECUTOR_NAME)
                ? (TaskExecutor)
                    extenderConfiguration.getBean(SHUTDOWN_TASK_EXECUTOR_NAME, TaskExecutor.class)
                : createDefaultShutdownTaskExecutor();

        eventMulticaster =
            extenderConfiguration.containsBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
                ? (OsgiBundleApplicationContextEventMulticaster)
                    extenderConfiguration.getBean(
                        APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
                        OsgiBundleApplicationContextEventMulticaster.class)
                : createDefaultEventMulticaster();

        contextCreator =
            extenderConfiguration.containsBean(CONTEXT_CREATOR_NAME)
                ? (OsgiApplicationContextCreator)
                    extenderConfiguration.getBean(
                        CONTEXT_CREATOR_NAME, OsgiApplicationContextCreator.class)
                : createDefaultApplicationContextCreator();

        contextEventListener =
            extenderConfiguration.containsBean(CONTEXT_LISTENER_NAME)
                ? (OsgiBundleApplicationContextListener)
                    extenderConfiguration.getBean(
                        CONTEXT_LISTENER_NAME, OsgiBundleApplicationContextListener.class)
                : createDefaultApplicationContextListener();
      }

      // get post processors
      postProcessors.addAll(
          extenderConfiguration.getBeansOfType(OsgiBeanFactoryPostProcessor.class).values());

      // get dependency factories
      dependencyFactories.addAll(
          extenderConfiguration.getBeansOfType(OsgiServiceDependencyFactory.class).values());

      classLoader = extenderConfiguration.getClassLoader();
      // extender properties using the defaults as backup
      if (extenderConfiguration.containsBean(PROPERTIES_NAME)) {
        Properties customProperties =
            (Properties) extenderConfiguration.getBean(PROPERTIES_NAME, Properties.class);
        Enumeration<?> propertyKey = customProperties.propertyNames();
        while (propertyKey.hasMoreElements()) {
          String property = (String) propertyKey.nextElement();
          properties.setProperty(property, customProperties.getProperty(property));
        }
      }
    }

    synchronized (lock) {
      shutdownWaitTime = getShutdownWaitTime(properties);
      dependencyWaitTime = getDependencyWaitTime(properties);
      processAnnotation = getProcessAnnotations(properties);
    }

    // load default dependency factories
    addDefaultDependencyFactories();

    // allow post processing
    contextCreator = postProcess(contextCreator);
  }