List of usage examples for org.springframework.util ObjectUtils isEmpty
@SuppressWarnings("rawtypes") public static boolean isEmpty(@Nullable Object obj)
From source file:org.springframework.mock.web.MockServletContext.java
@Override @Nullable/*from w w w . j a v a 2s . c om*/ public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try { File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { logger.warn("Couldn't get resource paths for " + resource, ex); return null; } }
From source file:org.springframework.osgi.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 a va 2s . com 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.springframework.osgi.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) { String bundleToString = null; if (trace) { bundleToString = OsgiStringUtils.nullSafeSymbolicName(bundle); }//from ww w.ja v a 2 s .c om 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); } } } Collections.sort(unused, ReverseBundleIdSorter.INSTANCE); return unused; }
From source file:org.springframework.osgi.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);//from 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.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); }
From source file:org.springframework.osgi.service.importer.support.AbstractOsgiServiceImportFactoryBean.java
/** * Assembles the configuration properties into one unified OSGi filter. Note that this implementation creates the * filter on the first call and caches it afterwards. * /*w w w .jav a 2 s .co m*/ * @return unified filter based on this factory bean configuration */ public Filter getUnifiedFilter() { if (unifiedFilter != null) { return unifiedFilter; } String filterWithClasses = (!ObjectUtils.isEmpty(interfaces) ? OsgiFilterUtils.unifyFilter(interfaces, filter) : filter); boolean trace = log.isTraceEnabled(); if (trace) log.trace("Unified classes=" + ObjectUtils.nullSafeToString(interfaces) + " and filter=[" + filter + "] in=[" + filterWithClasses + "]"); // 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.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(); } if (trace) log.trace("Unified serviceBeanName [" + ObjectUtils.nullSafeToString(serviceBeanName) + "] and filter=[" + filterWithClasses + "] in=[" + filterWithServiceBeanName + "]"); // create (which implies validation) the actual filter unifiedFilter = OsgiFilterUtils.createFilter(filterWithServiceBeanName); return unifiedFilter; }
From source file:org.springframework.osgi.web.deployer.internal.util.JasperUtils.java
public static URL[] createTaglibClasspathJars(Bundle bundle) { List urls = new ArrayList(2); boolean trace = log.isTraceEnabled(); try {/* ww w. j a v a2 s .c om*/ // create taglib jar for tlds inside the bundle classpath Resource[] res = getBundleTagLibs(bundle); if (!ObjectUtils.isEmpty(res)) { urls.add(createTaglibJar(res, null)); } if (trace) log.trace("Bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) + " has the following tlds in its classpath " + ObjectUtils.nullSafeToString(res)); // create taglib jar for tlds from imported bundles BundleContext ctx = OsgiBundleUtils.getBundleContext(bundle); Resource[] importedTLDs = getImportedBundlesTagLibs(ctx, bundle); if (!ObjectUtils.isEmpty(importedTLDs)) { urls.add(createTaglibJar(importedTLDs, null)); } if (trace) log.trace("Bundle " + OsgiStringUtils.nullSafeNameAndSymName(bundle) + " has the following tlds in its imported bundles " + ObjectUtils.nullSafeToString(importedTLDs)); return (URL[]) urls.toArray(new URL[urls.size()]); } catch (IOException ex) { throw (RuntimeException) new IllegalStateException("Cannot create taglib jars").initCause(ex); } }
From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java
@Override public void afterPropertiesSet() throws Exception { boolean hasContextPath = StringUtils.hasLength(this.contextPath); boolean hasClassesToBeBound = !ObjectUtils.isEmpty(this.classesToBeBound); boolean hasPackagesToScan = !ObjectUtils.isEmpty(this.packagesToScan); if (hasContextPath && (hasClassesToBeBound || hasPackagesToScan) || (hasClassesToBeBound && hasPackagesToScan)) { throw new IllegalArgumentException( "Specify either 'contextPath', 'classesToBeBound', " + "or 'packagesToScan'"); }// w ww . ja v a2s .c o m if (!hasContextPath && !hasClassesToBeBound && !hasPackagesToScan) { throw new IllegalArgumentException( "Setting either 'contextPath', 'classesToBeBound', " + "or 'packagesToScan' is required"); } if (!this.lazyInit) { getJaxbContext(); } if (!ObjectUtils.isEmpty(this.schemaResources)) { this.schema = loadSchema(this.schemaResources, this.schemaLanguage); } }
From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java
/** * Return the JAXBContext used by this marshaller, lazily building it if necessary. *//* w w w . j av a2s. c om*/ public JAXBContext getJaxbContext() { JAXBContext context = this.jaxbContext; if (context != null) { return context; } synchronized (this.jaxbContextMonitor) { context = this.jaxbContext; if (context == null) { try { if (StringUtils.hasLength(this.contextPath)) { context = createJaxbContextFromContextPath(this.contextPath); } else if (!ObjectUtils.isEmpty(this.classesToBeBound)) { context = createJaxbContextFromClasses(this.classesToBeBound); } else if (!ObjectUtils.isEmpty(this.packagesToScan)) { context = createJaxbContextFromPackages(this.packagesToScan); } else { context = JAXBContext.newInstance(); } this.jaxbContext = context; } catch (JAXBException ex) { throw convertJaxbException(ex); } } return context; } }
From source file:org.springframework.oxm.jaxb.Jaxb2Marshaller.java
private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement) { if (checkForXmlRootElement && AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) == null) { return false; }/*from w w w. j a v a2 s.c o m*/ if (StringUtils.hasLength(this.contextPath)) { String packageName = ClassUtils.getPackageName(clazz); String[] contextPaths = StringUtils.tokenizeToStringArray(this.contextPath, ":"); for (String contextPath : contextPaths) { if (contextPath.equals(packageName)) { return true; } } return false; } else if (!ObjectUtils.isEmpty(this.classesToBeBound)) { return Arrays.asList(this.classesToBeBound).contains(clazz); } return false; }
From source file:org.springframework.scheduling.backportconcurrent.ScheduledExecutorFactoryBean.java
public void afterPropertiesSet() { if (logger.isInfoEnabled()) { logger.info("Initializing ScheduledExecutorService" + (this.beanName != null ? " '" + this.beanName + "'" : "")); }//from w w w . java 2 s.c o m ScheduledExecutorService executor = createExecutor(this.poolSize, this.threadFactory, this.rejectedExecutionHandler); // Register specified ScheduledExecutorTasks, if necessary. if (!ObjectUtils.isEmpty(this.scheduledExecutorTasks)) { registerTasks(this.scheduledExecutorTasks, executor); } // Wrap executor with an unconfigurable decorator. this.executor = (this.exposeUnconfigurableExecutor ? Executors.unconfigurableScheduledExecutorService(executor) : executor); }