Example usage for org.springframework.util StringUtils concatenateStringArrays

List of usage examples for org.springframework.util StringUtils concatenateStringArrays

Introduction

In this page you can find the example usage for org.springframework.util StringUtils concatenateStringArrays.

Prototype

@Nullable
public static String[] concatenateStringArrays(@Nullable String[] array1, @Nullable String[] array2) 

Source Link

Document

Concatenate the given String arrays into one, with overlapping array elements included twice.

Usage

From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.startup.MandatoryImporterDependencyFactory.java

public Collection<OsgiServiceDependency> getServiceDependencies(BundleContext bundleContext,
        ConfigurableListableBeanFactory beanFactory)
        throws BeansException, InvalidSyntaxException, BundleException {

    boolean trace = log.isTraceEnabled();

    String[] singleBeans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory,
            OsgiServiceProxyFactoryBean.class, true, false);

    if (trace) {//from   www.j  a  v  a 2 s . co  m
        log.trace("Discovered single proxy importers " + Arrays.toString(singleBeans));
    }
    String[] collectionBeans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory,
            OsgiServiceCollectionProxyFactoryBean.class, true, false);

    if (trace) {
        log.trace("Discovered collection proxy importers " + Arrays.toString(collectionBeans));
    }

    String[] beans = StringUtils.concatenateStringArrays(singleBeans, collectionBeans);

    List<OsgiServiceDependency> beansCollections = new ArrayList<OsgiServiceDependency>(beans.length);

    for (int i = 0; i < beans.length; i++) {
        if (!isLazy(beanFactory, beans[i])) {
            String beanName = (beans[i].startsWith(BeanFactory.FACTORY_BEAN_PREFIX) ? beans[i]
                    : BeanFactory.FACTORY_BEAN_PREFIX + beans[i]);

            SmartFactoryBean<?> reference = beanFactory.getBean(beanName, SmartFactoryBean.class);

            OsgiServiceDependency dependency;
            if (reference instanceof OsgiServiceProxyFactoryBean) {
                OsgiServiceProxyFactoryBean importer = (OsgiServiceProxyFactoryBean) reference;

                dependency = new DefaultOsgiServiceDependency(beanName, importer.getUnifiedFilter(),
                        Availability.MANDATORY.equals(importer.getAvailability()));
            } else {
                OsgiServiceCollectionProxyFactoryBean importer = (OsgiServiceCollectionProxyFactoryBean) reference;

                dependency = new DefaultOsgiServiceDependency(beanName, importer.getUnifiedFilter(),
                        Availability.MANDATORY.equals(importer.getAvailability()));
            }

            if (trace)
                log.trace("Eager importer " + beanName + " implies dependecy " + dependency);

            beansCollections.add(dependency);
        } else {
            String name = (beans[i].startsWith(BeanFactory.FACTORY_BEAN_PREFIX) ? beans[i].substring(1)
                    : beans[i]);
            if (beanFactory.containsBeanDefinition(name)) {
                BeanDefinition def = beanFactory.getBeanDefinition(name);
                MutablePropertyValues values = def.getPropertyValues();
                // figure out if it's a mandatory bean
                PropertyValue value = values.getPropertyValue(AVAILABILITY_PROP);
                if (value != null && Availability.MANDATORY.equals(value.getValue())) {
                    String[] intfs = getInterfaces(values.getPropertyValue(INTERFACES_PROP));
                    String beanName = getString(values.getPropertyValue(SERVICE_BEAN_NAME_PROP));
                    String filterProp = getString(values.getPropertyValue(FILTER_PROP));

                    // create filter
                    Filter filter = createFilter(intfs, beanName, filterProp);
                    OsgiServiceDependency dependency;
                    dependency = new DefaultOsgiServiceDependency(name, filter, true);

                    if (trace)
                        log.trace("Lazy importer " + beanName + " implies dependecy " + dependency);

                    beansCollections.add(dependency);
                }
            } else {
                if (trace)
                    log.trace("Bean " + name
                            + " is marked as lazy but does not provide a bean definition; ignoring...");
            }
        }
    }

    return beansCollections;
}

From source file:org.eclipse.gemini.blueprint.service.dependency.internal.DefaultMandatoryDependencyManager.java

/**
 * Discover all the importers for the given exporter. Since the importers are already created before the exporter
 * instance is created, this method only does filtering based on the mandatory imports.
 *//*  w  ww .j a  v  a  2 s . co  m*/
protected void discoverDependentImporterFor(String exporterBeanName, Object exporter) {

    boolean trace = log.isTraceEnabled();

    // determine exporters
    String[] importerA = BeanFactoryUtils.getTransitiveDependenciesForBean(beanFactory, exporterBeanName, true,
            OsgiServiceProxyFactoryBean.class);

    String[] importerB = BeanFactoryUtils.getTransitiveDependenciesForBean(beanFactory, exporterBeanName, true,
            OsgiServiceCollectionProxyFactoryBean.class);

    String[] importerNames = StringUtils.concatenateStringArrays(importerA, importerB);

    // create map of associated importers
    Map<Object, String> dependingImporters = new LinkedHashMap<Object, String>(importerNames.length);

    if (trace)
        log.trace("Exporter [" + exporterBeanName + "] depends (transitively) on the following importers:"
                + ObjectUtils.nullSafeToString(importerNames));

    // first create a listener for the exporter
    ImporterStateListener listener = new ImporterDependencyListener(exporter);
    exporterListener.put(exporter, listener);

    // exclude non-mandatory importers
    // non-singletons get added only once (as one instance is enough)
    for (int i = 0; i < importerNames.length; i++) {
        if (beanFactory.isSingleton(importerNames[i])) {
            Object importer = beanFactory.getBean(importerNames[i]);

            // create an importer -> exporter association
            if (isMandatory(importer)) {
                dependingImporters.put(importer, importerNames[i]);
                importerToName.putIfAbsent(importer, importerNames[i]);
            }

            else if (trace)
                log.trace("Importer [" + importerNames[i] + "] is optional; skipping it");
        } else if (trace)
            log.trace("Importer [" + importerNames[i] + "] is a non-singleton; ignoring it");
    }

    if (trace)
        log.trace("After filtering, exporter [" + exporterBeanName + "] depends on importers:"
                + dependingImporters.values());

    Collection<Object> filteredImporters = dependingImporters.keySet();

    // add the importers and their status to the collection
    synchronized (exporter) {
        Map<Object, Boolean> importerStatuses = new LinkedHashMap<Object, Boolean>(filteredImporters.size());

        for (Iterator<Object> iter = filteredImporters.iterator(); iter.hasNext();) {
            Object importer = iter.next();
            importerStatuses.put(importer, Boolean.valueOf(isSatisfied(importer)));
            // add the listener after the importer status has been recorded
            addListener(importer, listener);
        }
        exporterToImporterDeps.put(exporter, importerStatuses);
        if (!checkIfExporterShouldStart(exporter, importerStatuses)) {
            callUnregisterOnStartup(exporter);
        }
    }
}

From source file:org.springframework.cloud.config.server.support.AbstractScmAccessor.java

protected String[] getSearchLocations(File dir, String application, String profile, String label) {
    String[] locations = this.searchPaths;
    if (locations == null || locations.length == 0) {
        locations = DEFAULT_LOCATIONS;/*from   ww  w.  j ava  2  s.  c om*/
    } else if (locations != DEFAULT_LOCATIONS) {
        locations = StringUtils.concatenateStringArrays(DEFAULT_LOCATIONS, locations);
    }
    Collection<String> output = new LinkedHashSet<String>();
    for (String location : locations) {
        String[] profiles = new String[] { profile };
        if (profile != null) {
            profiles = StringUtils.commaDelimitedListToStringArray(profile);
        }
        String[] apps = new String[] { application };
        if (application != null) {
            apps = StringUtils.commaDelimitedListToStringArray(application);
        }
        for (String prof : profiles) {
            for (String app : apps) {
                String value = location;
                if (app != null) {
                    value = value.replace("{application}", app);
                }
                if (prof != null) {
                    value = value.replace("{profile}", prof);
                }
                if (label != null) {
                    value = value.replace("{label}", label);
                }
                if (!value.endsWith("/")) {
                    value = value + "/";
                }
                output.addAll(matchingDirectories(dir, value));
            }
        }
    }
    return output.toArray(new String[0]);
}