Example usage for org.springframework.util ObjectUtils isEmpty

List of usage examples for org.springframework.util ObjectUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util ObjectUtils isEmpty.

Prototype

@SuppressWarnings("rawtypes")
public static boolean isEmpty(@Nullable Object obj) 

Source Link

Document

Determine whether the given object is empty.

Usage

From source file:org.eclipse.gemini.blueprint.compendium.internal.cm.ManagedServiceFactoryFactoryBean.java

public void afterPropertiesSet() throws Exception {

    synchronized (monitor) {
        Assert.notNull(factoryPid, "factoryPid required");
        Assert.notNull(bundleContext, "bundleContext is required");
        Assert.notNull(templateDefinition, "templateDefinition is required");

        Assert.isTrue(!DefaultInterfaceDetector.DISABLED.equals(detector) || !ObjectUtils.isEmpty(interfaces),
                "No service interface(s) specified and auto-export "
                        + "discovery disabled; change at least one of these properties");
    }//www . j a  va  2 s .c  om

    processTemplateDefinition();
    createEmbeddedBeanFactory();

    updateCallback = CMUtils.createCallback(autowireOnUpdate, updateMethod, beanFactory);

    registerService();
}

From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.activator.support.BlueprintConfigurationScanner.java

public String[] getConfigurations(Bundle bundle) {
    String bundleName = OsgiStringUtils.nullSafeName(bundle);

    boolean trace = log.isTraceEnabled();
    boolean debug = log.isDebugEnabled();

    if (debug)/*w  w  w  . j  ava2  s  . co m*/
        log.debug("Scanning bundle '" + bundleName + "' for blueprint configurations...");

    String[] locations = BlueprintConfigUtils.getBlueprintHeaderLocations(bundle.getHeaders());

    // if no location is specified in the header, try the defaults
    if (locations == null) {
        if (trace) {
            log.trace(
                    "Bundle '" + bundleName + "' has no declared locations; trying default " + DEFAULT_CONFIG);
        }
        locations = new String[] { DEFAULT_CONFIG };
    } else {
        // check whether the header is empty
        if (ObjectUtils.isEmpty(locations)) {
            log.info("Bundle '" + bundleName + "' has an empty blueprint header - ignoring bundle...");
            return new String[0];
        }
    }

    String[] configs = findValidBlueprintConfigs(bundle, locations);
    if (debug)
        log.debug("Discovered in bundle '" + bundleName + "' blueprint configurations="
                + Arrays.toString(configs));
    return configs;
}

From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.activator.support.BlueprintConfigurationScanner.java

/**
 * Checks if the given bundle contains existing configurations. The absolute paths are returned without performing
 * any checks./* w ww  .  j  a va  2  s .  c  om*/
 * 
 * @return
 */
private String[] findValidBlueprintConfigs(Bundle bundle, String[] locations) {
    List<String> configs = new ArrayList<String>(locations.length);
    ResourcePatternResolver loader = new OsgiBundleResourcePatternResolver(bundle);

    boolean debug = log.isDebugEnabled();
    for (String location : locations) {
        if (isAbsolute(location)) {
            configs.add(location);
        }
        // resolve the location to check if it's present
        else {
            try {
                String loc = location;
                if (loc.endsWith("/")) {
                    loc = loc + "*.xml";
                }
                Resource[] resources = loader.getResources(loc);
                if (!ObjectUtils.isEmpty(resources)) {
                    for (Resource resource : resources) {
                        if (resource.exists()) {
                            String value = resource.getURL().toString();
                            if (debug)
                                log.debug("Found location " + value);
                            configs.add(value);
                        }
                    }
                }
            } catch (IOException ex) {
                if (debug)
                    log.debug("Cannot resolve location " + location, ex);
            }
        }
    }
    return (String[]) configs.toArray(new String[configs.size()]);
}

From source file:org.eclipse.gemini.blueprint.extender.internal.blueprint.event.OsgiEventDispatcher.java

private void initDependencies(Dictionary<String, Object> props, BlueprintEvent event) {
    String[] deps = event.getDependencies();
    if (!ObjectUtils.isEmpty(deps)) {
        props.put(DEPENDENCIES, deps);//w  w  w  . j a  v  a  2  s . c o  m
        // props.put(SERVICE_FILTER, deps[0]);
        // props.put(SERVICE_FILTER_2, deps[0]);
        // props.put(SERVICE_OBJECTCLASS, extractObjectClassFromFilter(deps[0]));
        props.put(ALL_DEPENDENCIES, deps);
    }
}

From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.BundleDependencyComparator.java

private static ServiceReference[] excludeNonSpringManagedServices(ServiceReference[] references) {
    if (ObjectUtils.isEmpty(references))
        return references;

    int count = 0;
    for (int i = 0; i < references.length; i++) {
        if (!isSpringManagedService(references[i]))
            references[i] = null;/*  w ww  .ja v a  2  s .  c  o m*/
        else
            count++;
    }

    if (count == references.length)
        return references;

    ServiceReference[] refs = new ServiceReference[count];
    int j = 0;
    for (int i = 0; i < references.length; i++) {
        if (references[i] != null) {
            refs[j] = references[i];
            j++;
        }
    }

    return refs;
}

From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.BundleDependencyComparator.java

/**
 * Answer whether Bundle a is higher or lower depending on the ranking and id of its exported services. This is used
 * as a tie-breaker for circular references.
 *//*from  ww w .  j  a va  2  s  .com*/
protected static int compareUsingServiceRankingAndId(Bundle a, Bundle b) {
    ServiceReference[] aservices = excludeNonSpringManagedServices(a.getRegisteredServices());
    ServiceReference[] bservices = excludeNonSpringManagedServices(b.getRegisteredServices());

    boolean trace = log.isTraceEnabled();

    // this case should not occur
    if (ObjectUtils.isEmpty(aservices) && ObjectUtils.isEmpty(bservices)) {
        if (trace)
            log.trace("both services have 0 services; sorting based on id");
        return signum((int) (a.getBundleId() - b.getBundleId()));
    } else if (aservices == null) {
        return -1;
    } else if (bservices == null) {
        return 1;
    }

    // Look for the *lowest* highest ranked service in each bundle
    // i.e. take a look at each bundle, find the highest ranking service
    // and compare it to the other bundle
    // this means that the service with the highest ranking service will
    // be shutdown last

    int aRank = findHighestServiceRanking(aservices);
    int bRank = findHighestServiceRanking(bservices);

    // since we are looking for the minimum, invert the substraction
    // (the higher bundle is the one with the lowest rank)
    if (aRank != bRank) {
        int compare = -(bRank - aRank);
        if (trace) {
            int min = (compare > 0 ? (int) bRank : (int) aRank);
            log.trace("sorting based on lowest-service-ranking won by bundle" + (compare > 0 ? "1" : "2")
                    + " w/ service id " + min);
        }

        return signum(-(bRank - aRank));
    }

    // Look for the highest id in each bundle (i.e. started last).
    long aMaxId = findHighestServiceId(aservices);
    long bMaxId = findHighestServiceId(bservices);

    if (aMaxId != bMaxId) {
        int compare = (int) (bMaxId - aMaxId);
        if (trace) {
            int max = (compare > 0 ? (int) bMaxId : (int) aMaxId);
            log.trace("sorting based on highest-service-id won by bundle " + (compare > 0 ? "1" : "2")
                    + " w/ service id " + max);
        }

        return signum(compare);
    }

    return signum((int) (a.getBundleId() - b.getBundleId()));
}

From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.ShutdownSorter.java

private static List<Bundle> unusedBundles(Collection<Bundle> unsorted) {
    List<Bundle> unused = new ArrayList<Bundle>();

    boolean trace = log.isTraceEnabled();

    for (Bundle bundle : unsorted) {
        try {/*  w w  w  . java  2 s.co m*/
            String bundleToString = null;
            if (trace) {
                bundleToString = OsgiStringUtils.nullSafeSymbolicName(bundle);
            }
            ServiceReference[] services = bundle.getRegisteredServices();
            if (ObjectUtils.isEmpty(services)) {
                if (trace) {
                    log.trace("Bundle " + bundleToString + " has no registered services; added for shutdown");
                }
                unused.add(bundle);
            } else {
                boolean unusedBundle = true;
                for (ServiceReference serviceReference : services) {
                    Bundle[] usingBundles = serviceReference.getUsingBundles();
                    if (!ObjectUtils.isEmpty(usingBundles)) {
                        if (trace)
                            log.trace("Bundle " + bundleToString
                                    + " has registered services in use; postponing shutdown. The using bundles are "
                                    + Arrays.toString(usingBundles));
                        unusedBundle = false;
                        break;
                    }

                }
                if (unusedBundle) {
                    if (trace) {
                        log.trace("Bundle " + bundleToString
                                + " has unused registered services; added for shutdown");
                    }
                    unused.add(bundle);
                }
            }
        } catch (IllegalStateException _) {
            unused.add(bundle);
        }
    }

    Collections.sort(unused, ReverseBundleIdSorter.INSTANCE);

    return unused;
}

From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.ShutdownSorter.java

private static int getRegisteredServiceInUseLowestRanking(Bundle bundle) {
    ServiceReference[] services = bundle.getRegisteredServices();
    int min = Integer.MAX_VALUE;
    if (!ObjectUtils.isEmpty(services)) {
        for (ServiceReference ref : services) {
            // make sure somebody is using the service
            if (!ObjectUtils.isEmpty(ref.getUsingBundles())) {
                int localRank = OsgiServiceReferenceUtils.getServiceRanking(ref);
                if (localRank < min) {
                    min = localRank;/*from w  ww .  j ava2 s. com*/
                }
            }
        }
    }
    return min;
}

From source file:org.eclipse.gemini.blueprint.extender.internal.dependencies.shutdown.ShutdownSorter.java

private static long getHighestServiceId(Bundle bundle) {
    ServiceReference[] services = bundle.getRegisteredServices();
    long max = Long.MIN_VALUE;
    if (!ObjectUtils.isEmpty(services)) {
        for (ServiceReference ref : services) {
            long id = OsgiServiceReferenceUtils.getServiceId(ref);
            if (id > max) {
                max = id;/*from   w  ww .  ja v a2  s. c  o  m*/
            }
        }
    }
    return max;
}

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

private Filter createFilter(String[] intfs, String serviceBeanName, String filter) {
    String filterWithClasses = (!ObjectUtils.isEmpty(intfs) ? OsgiFilterUtils.unifyFilter(intfs, filter)
            : filter);/* w  w w .  j  av a  2s  .  c  o  m*/

    // add the serviceBeanName/Blueprint component name constraint
    String nameFilter;
    if (StringUtils.hasText(serviceBeanName)) {
        StringBuilder nsFilter = new StringBuilder("(|(");
        nsFilter.append(OsgiServicePropertiesResolver.BEAN_NAME_PROPERTY_KEY);
        nsFilter.append("=");
        nsFilter.append(serviceBeanName);
        nsFilter.append(")(");
        nsFilter.append(OsgiServicePropertiesResolver.SPRING_DM_BEAN_NAME_PROPERTY_KEY);
        nsFilter.append("=");
        nsFilter.append(serviceBeanName);
        nsFilter.append(")(");
        nsFilter.append(OsgiServicePropertiesResolver.BLUEPRINT_COMP_NAME);
        nsFilter.append("=");
        nsFilter.append(serviceBeanName);
        nsFilter.append("))");
        nameFilter = nsFilter.toString();
    } else {
        nameFilter = null;
    }

    String filterWithServiceBeanName = filterWithClasses;
    if (nameFilter != null) {
        StringBuilder finalFilter = new StringBuilder();
        finalFilter.append("(&");
        finalFilter.append(filterWithClasses);
        finalFilter.append(nameFilter);
        finalFilter.append(")");
        filterWithServiceBeanName = finalFilter.toString();
    }

    return OsgiFilterUtils.createFilter(filterWithServiceBeanName);
}