Example usage for org.springframework.util CollectionUtils mergeArrayIntoCollection

List of usage examples for org.springframework.util CollectionUtils mergeArrayIntoCollection

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils mergeArrayIntoCollection.

Prototype

@SuppressWarnings("unchecked")
public static <E> void mergeArrayIntoCollection(@Nullable Object array, Collection<E> collection) 

Source Link

Document

Merge the given array into the given Collection.

Usage

From source file:au.org.ala.biocache.dao.SearchDAOImpl.java

public Set<String> getAuthIndexFields() {
    if (authIndexFields == null) {
        //set up the hash set of the fields that need to have the authentication service substitute
        logger.debug("Auth substitution fields to use: " + authServiceFields);
        authIndexFields = new java.util.HashSet<String>();
        CollectionUtils.mergeArrayIntoCollection(authServiceFields.split(","), authIndexFields);
    }/*  w w  w .  j a  v a  2s . c o  m*/
    return authIndexFields;
}

From source file:spring.osgi.io.OsgiBundleResourcePatternResolver.java

/**
 * Special classpath method. Will try to detect the imported bundles (which
 * are part of the classpath) and look for resources in all of them. This
 * implementation will try to determine the bundles that compose the current
 * bundle classpath and then it will inspect the bundle space of each of
 * them individually./*from  w  ww  .java  2  s .co  m*/
 * <p/>
 * <p/> Since the bundle space is considered, runtime classpath entries such
 * as dynamic imports are not supported (yet).
 *
 * @param locationPattern locationPattern
 * @param type            type
 * @return classpath resources
 */
private Resource[] findClassPathMatchingResources(String locationPattern, int type) throws IOException {

    //TODO REMOVE
    //        if (resolver == null)
    //            throw new IllegalArgumentException(
    //                    "PackageAdmin service/a started bundle is required for classpath matching");
    //
    //        final ImportedBundle[] importedBundles = resolver.getImportedBundles(bundle);
    //
    //        // eliminate classpath path
    //        final String path = OsgiResourceUtils.stripPrefix(locationPattern);
    //
    //        final Collection<String> foundPaths = new LinkedHashSet<>();
    //
    //        // 1. search the imported packages
    //
    //        // find folder path matching
    //        final String rootDirPath = determineFolderPattern(path);
    //
    //        if (System.getSecurityManager() != null) {
    //            try {
    //                AccessController.doPrivileged(new PrivilegedExceptionAction() {
    //
    //                    public Object run() throws IOException {
    //                        for (final ImportedBundle importedBundle : importedBundles) {
    //                            if (!bundle.equals(importedBundle.getBundle())) {
    //                                findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
    //                            }
    //                        }
    //                        return null;
    //                    }
    //                });
    //            } catch (PrivilegedActionException pe) {
    //                throw (IOException) pe.getException();
    //            }
    //        } else {
    //            for (final ImportedBundle importedBundle : importedBundles) {
    //                if (!bundle.equals(importedBundle.getBundle())) {
    //                    findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
    //                }
    //            }
    //        }

    // eliminate classpath path
    final String path = OsgiResourceUtils.stripPrefix(locationPattern);

    final Collection<String> foundPaths = new LinkedHashSet<>();
    // 2. search the target bundle
    findSyntheticClassPathMatchingResource(bundle, path, foundPaths);

    // 3. resolve the entries using the official class-path method (as some of them might be hidden)
    List<Resource> resources = new ArrayList<>(foundPaths.size());

    for (String resourcePath : foundPaths) {
        // classpath*: -> getResources()
        if (OsgiResourceUtils.PREFIX_TYPE_CLASS_ALL_SPACE == type) {
            CollectionUtils.mergeArrayIntoCollection(
                    convertURLEnumerationToResourceArray(bundle.getResources(resourcePath), resourcePath),
                    resources);
        }
        // classpath -> getResource()
        else {
            URL url = bundle.getResource(resourcePath);
            if (url != null)
                resources.add(new UrlContextResource(url, resourcePath));
        }
    }

    if (logger.isTraceEnabled()) {
        logger.trace("Fitered " + foundPaths + " to " + resources);
    }

    return resources.toArray(new Resource[resources.size()]);
}

From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java

/**
 * Determine imports for the given bundle. Based on the user settings, this
 * method will consider only the the test hierarchy until the testing
 * framework is found or all classes available inside the test bundle. <p/>
 * Note that split packages are not supported.
 * /*w w w .j  a  v a2  s  .com*/
 * @return
 */
private String[] determineImports() {

    boolean useTestClassOnly = false;

    // no jar entry present, bail out.
    if (jarEntries == null || jarEntries.isEmpty()) {
        logger.debug("No test jar content detected, generating bundle imports from the test class");
        useTestClassOnly = true;
    }

    else if (createManifestOnlyFromTestClass()) {
        logger.info("Using the test class for generating bundle imports");
        useTestClassOnly = true;
    } else
        logger.info("Using all classes in the jar for the generation of bundle imports");

    // className, class resource
    Map entries;

    if (useTestClassOnly) {

        entries = new LinkedHashMap(4);

        // get current class (test class that bootstraps the OSGi infrastructure)
        Class<?> clazz = getClass();
        String clazzPackage = null;
        String endPackage = AbstractOnTheFlyBundleCreatorTests.class.getPackage().getName();

        do {

            // consider inner classes as well
            List classes = new ArrayList(4);
            classes.add(clazz);
            CollectionUtils.mergeArrayIntoCollection(clazz.getDeclaredClasses(), classes);

            for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
                Class<?> classToInspect = (Class) iterator.next();

                Package pkg = classToInspect.getPackage();
                if (pkg != null) {
                    clazzPackage = pkg.getName();
                    String classFile = ClassUtils.getClassFileName(classToInspect);
                    entries.put(classToInspect.getName().replace('.', '/').concat(ClassUtils.CLASS_FILE_SUFFIX),
                            new InputStreamResource(classToInspect.getResourceAsStream(classFile)));
                }
                // handle default package
                else {
                    logger.warn("Could not find package for class " + classToInspect + "; ignoring...");
                }
            }

            clazz = clazz.getSuperclass();

        } while (!endPackage.equals(clazzPackage));
    } else
        entries = jarEntries;

    return determineImportsFor(entries);

}

From source file:jun.learn.scene.handlerMapping.HandlerExecutionChain.java

/**
 * Create a new HandlerExecutionChain./*from   w w w . j ava  2  s  .  com*/
 * @param handler the handler object to execute
 * @param interceptors the array of interceptors to apply
 * (in the given order) before the handler itself executes
 */
public HandlerExecutionChain(Object handler, HandlerInterceptor... interceptors) {
    if (handler instanceof HandlerExecutionChain) {
        HandlerExecutionChain originalChain = (HandlerExecutionChain) handler;
        this.handler = originalChain.getHandler();
        this.interceptorList = new ArrayList<HandlerInterceptor>();
        CollectionUtils.mergeArrayIntoCollection(originalChain.getInterceptors(), this.interceptorList);
        CollectionUtils.mergeArrayIntoCollection(interceptors, this.interceptorList);
    } else {
        this.handler = handler;
        this.interceptors = interceptors;
    }
}

From source file:org.eclipse.gemini.blueprint.iandt.clogging.CommonsLogging104Test.java

protected String[] getTestFrameworkBundlesNames() {
    String[] bundles = super.getTestFrameworkBundlesNames();

    // remove slf4j
    Collection bnds = new ArrayList(bundles.length);
    CollectionUtils.mergeArrayIntoCollection(bundles, bnds);

    for (Iterator iterator = bnds.iterator(); iterator.hasNext();) {
        String object = (String) iterator.next();
        // remove slf4j
        if (object.startsWith("org.slf4j"))
            iterator.remove();/* w  w  w  . java2  s. c o m*/
    }
    // add commons logging
    bnds.add("org.eclipse.bundles,commons-logging,20070611");

    return (String[]) bnds.toArray(new String[bnds.size()]);
}

From source file:org.eclipse.gemini.blueprint.io.OsgiBundleResourcePatternResolver.java

/**
 * Special classpath method. Will try to detect the imported bundles (which are part of the classpath) and look for
 * resources in all of them. This implementation will try to determine the bundles that compose the current bundle
 * classpath and then it will inspect the bundle space of each of them individually.
 * //  w w  w.j ava2  s  . c  om
 * <p/> Since the bundle space is considered, runtime classpath entries such as dynamic imports are not supported
 * (yet).
 * 
 * @param locationPattern
 * @param type
 * @return classpath resources
 */
@SuppressWarnings("unchecked")
private Resource[] findClassPathMatchingResources(String locationPattern, int type) throws IOException {

    if (resolver == null)
        throw new IllegalArgumentException(
                "PackageAdmin service/a started bundle is required for classpath matching");

    final ImportedBundle[] importedBundles = resolver.getImportedBundles(bundle);

    // eliminate classpath path
    final String path = OsgiResourceUtils.stripPrefix(locationPattern);

    final Collection<String> foundPaths = new LinkedHashSet<String>();

    // 1. search the imported packages

    // find folder path matching
    final String rootDirPath = determineFolderPattern(path);

    if (System.getSecurityManager() != null) {
        try {
            AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                public Object run() throws IOException {
                    for (int i = 0; i < importedBundles.length; i++) {
                        final ImportedBundle importedBundle = importedBundles[i];
                        if (!bundle.equals(importedBundle.getBundle())) {
                            findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
                        }
                    }
                    return null;
                }
            });
        } catch (PrivilegedActionException pe) {
            throw (IOException) pe.getException();
        }
    } else {
        for (int i = 0; i < importedBundles.length; i++) {
            final ImportedBundle importedBundle = importedBundles[i];
            if (!bundle.equals(importedBundle.getBundle())) {
                findImportedBundleMatchingResource(importedBundle, rootDirPath, path, foundPaths);
            }
        }
    }

    // 2. search the target bundle
    findSyntheticClassPathMatchingResource(bundle, path, foundPaths);

    // 3. resolve the entries using the official class-path method (as some of them might be hidden)
    List<Resource> resources = new ArrayList<Resource>(foundPaths.size());

    for (String resourcePath : foundPaths) {
        // classpath*: -> getResources()
        if (OsgiResourceUtils.PREFIX_TYPE_CLASS_ALL_SPACE == type) {
            CollectionUtils.mergeArrayIntoCollection(
                    convertURLEnumerationToResourceArray(bundle.getResources(resourcePath), resourcePath),
                    resources);
        }
        // classpath -> getResource()
        else {
            URL url = bundle.getResource(resourcePath);
            if (url != null)
                resources.add(new UrlContextResource(url, resourcePath));
        }
    }

    if (logger.isTraceEnabled()) {
        logger.trace("Fitered " + foundPaths + " to " + resources);
    }

    return (Resource[]) resources.toArray(new Resource[resources.size()]);
}

From source file:org.eclipse.gemini.blueprint.service.exporter.support.OsgiServiceFactoryBean.java

/**
 * Publishes the given object as an OSGi service. It simply assembles the classes required for publishing and then
 * delegates the actual registration to a dedicated method.
 *//*from  w w  w.j a va 2  s .  c  o  m*/
@Override
void registerService() {

    synchronized (lock) {
        if (serviceRegistered || !registerService)
            return;
        else
            serviceRegistered = true;
    }

    // if we have a nested bean / non-Spring managed object
    String beanName = (!hasNamedBean ? null : targetBeanName);

    Dictionary serviceProperties = mergeServiceProperties(this.serviceProperties, beanName);

    Class<?>[] intfs = interfaces;

    // filter classes based on visibility
    ClassLoader beanClassLoader = ClassUtils.getClassLoader(targetClass);
    Class<?>[] autoDetectedClasses = ClassUtils.getVisibleClasses(interfaceDetector.detect(targetClass),
            beanClassLoader);

    if (log.isTraceEnabled())
        log.trace("Autoexport mode [" + interfaceDetector + "] discovered on class [" + targetClass
                + "] classes " + ObjectUtils.nullSafeToString(autoDetectedClasses));

    // filter duplicates
    Set<Class<?>> classes = new LinkedHashSet<Class<?>>(intfs.length + autoDetectedClasses.length);

    CollectionUtils.mergeArrayIntoCollection(intfs, classes);
    CollectionUtils.mergeArrayIntoCollection(autoDetectedClasses, classes);

    Class<?>[] mergedClasses = (Class[]) classes.toArray(new Class[classes.size()]);

    ServiceRegistration reg = registerService(mergedClasses, serviceProperties);
    serviceRegistration = new ServiceRegistrationDecorator(reg);
    safeServiceRegistration.swap(serviceRegistration);

    resolver.setDecorator(serviceRegistration);
    resolver.notifyIfPossible();
}

From source file:org.springframework.data.hadoop.fs.DistCp.java

/**
 * Copies the given resources using the given parameters.
 * //from   ww  w.j  a v  a2 s.com
 * @param preserveReplication preserveReplication
 * @param preserveBlockSize preserveBlockSize
 * @param preserveUser preserveUser
 * @param preserveGroup preserveGroup
 * @param preservePermission preservePermission
 * @param ignoreFailures ignoreFailures
 * @param skipCrc skipCrc
 * @param logDir logDir
 * @param mappers mappers
 * @param overwrite overwrite
 * @param update update
 * @param delete delete
 * @param fileLimit fileLimit
 * @param sizeLimit sizeLimit
 * @param fileList fileList
 * @param uris uris
 */
public void copy(Boolean preserveReplication, Boolean preserveBlockSize, Boolean preserveUser,
        Boolean preserveGroup, Boolean preservePermission, Boolean ignoreFailures, Boolean skipCrc,
        String logDir, Integer mappers, Boolean overwrite, Boolean update, Boolean delete, Long fileLimit,
        Long sizeLimit, String fileList, String... uris) {

    List<String> args = new ArrayList<String>();

    args.add(Preserve.toString(preserveReplication, preserveBlockSize, preserveUser, preserveGroup,
            preservePermission));

    if (Boolean.TRUE.equals(ignoreFailures)) {
        args.add("-i");
    }
    if (Boolean.TRUE.equals(skipCrc)) {
        args.add("-skipcrccheck");
    }
    if (logDir != null) {
        args.add("-log " + logDir);
    }
    if (mappers != null) {
        args.add("-m " + mappers.intValue());
    }
    if (Boolean.TRUE.equals(overwrite)) {
        args.add("-overwrite");
    }
    if (Boolean.TRUE.equals(update)) {
        args.add("-update");
    }
    if (Boolean.TRUE.equals(delete)) {
        args.add("-delete");
    }
    if (fileLimit != null) {
        log.warn("Hadoop DistCp v2 will ignore fileLimit argument");
        args.add("-filelimit " + fileLimit);
    }
    if (sizeLimit != null) {
        log.warn("Hadoop DistCp v2 will ignore sizeLimit argument");
        args.add("-sizelimit " + sizeLimit);
    }
    if (StringUtils.hasText(fileList)) {
        args.add("-f " + fileList);
    }

    CollectionUtils.mergeArrayIntoCollection(uris, args);
    copy(args.toArray(new String[args.size()]));
}

From source file:org.springframework.web.servlet.HandlerExecutionChain.java

/**
 * Create a new HandlerExecutionChain./*  w ww  . ja  v a  2  s .c  om*/
 * @param handler the handler object to execute
 * @param interceptors the array of interceptors to apply
 * (in the given order) before the handler itself executes
 */
public HandlerExecutionChain(Object handler, @Nullable HandlerInterceptor... interceptors) {
    if (handler instanceof HandlerExecutionChain) {
        HandlerExecutionChain originalChain = (HandlerExecutionChain) handler;
        this.handler = originalChain.getHandler();
        this.interceptorList = new ArrayList<>();
        CollectionUtils.mergeArrayIntoCollection(originalChain.getInterceptors(), this.interceptorList);
        CollectionUtils.mergeArrayIntoCollection(interceptors, this.interceptorList);
    } else {
        this.handler = handler;
        this.interceptors = interceptors;
    }
}

From source file:org.springframework.web.servlet.HandlerExecutionChain.java

public void addInterceptors(HandlerInterceptor... interceptors) {
    if (!ObjectUtils.isEmpty(interceptors)) {
        CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList());
    }//from  w ww .j av  a2 s . c o  m
}