List of usage examples for org.springframework.util ObjectUtils isEmpty
@SuppressWarnings("rawtypes") public static boolean isEmpty(@Nullable Object obj)
From source file:org.eclipse.gemini.blueprint.util.OsgiServiceReferenceUtils.java
/** * Returns references to <em>all</em> services matching the given class names and OSGi filter. * /* w w w . j av a 2 s. co m*/ * @param bundleContext OSGi bundle context * @param classes array of fully qualified class names * @param filter valid OSGi filter (can be <code>null</code>) * @return non-<code>null</code> array of references to matching services */ public static ServiceReference[] getServiceReferences(BundleContext bundleContext, String[] classes, String filter) { // use #getServiceReferences(BundleContext, String, String) method to // speed the service lookup process by // giving one class as a hint to the OSGi implementation // additionally this allows type filtering String clazz = (ObjectUtils.isEmpty(classes) ? null : classes[0]); return getServiceReferences(bundleContext, clazz, OsgiFilterUtils.unifyFilter(classes, filter)); }
From source file:org.eclipse.gemini.blueprint.util.OsgiServiceReferenceUtils.java
/** * Checks if the given filter matches at least one OSGi service or not. * /*from ww w . j ava2 s . co m*/ * @param bundleContext OSGi bundle context * @param filter valid OSGi filter (can be <code>null</code>) * @return true if the filter matches at least one OSGi service, false otherwise */ public static boolean isServicePresent(BundleContext bundleContext, String filter) { return !ObjectUtils.isEmpty(getServiceReferences(bundleContext, filter)); }
From source file:org.mifosplatform.portfolio.group.service.GroupWritePlatformServiceJpaRepositoryImpl.java
private Set<Client> assembleSetOfClients(final Long officeId, final JsonCommand command) { final Set<Client> clientMembers = new HashSet<Client>(); final String[] clientMembersArray = command.arrayValueOfParameterNamed("clientMembers"); if (!ObjectUtils.isEmpty(clientMembersArray)) { for (final String clientId : clientMembersArray) { final Long id = Long.valueOf(clientId); final Client client = this.clientRepository.findOne(id); if (client == null || client.isDeleted()) { throw new ClientNotFoundException(id); }//from w ww .j ava 2 s .co m if (!client.isOfficeIdentifiedBy(officeId)) { final String errorMessage = "Group and Client must have the same office."; throw new InvalidOfficeException("client", "attach.to.group", errorMessage); } clientMembers.add(client); } } return clientMembers; }
From source file:org.mifosplatform.portfolio.group.service.GroupWritePlatformServiceJpaRepositoryImpl.java
private Set<Group> assembleSetOfChildGroups(final Long officeId, final JsonCommand command) { final Set<Group> childGroups = new HashSet<Group>(); final String[] childGroupsArray = command.arrayValueOfParameterNamed("childGroups"); if (!ObjectUtils.isEmpty(childGroupsArray)) { for (final String groupId : childGroupsArray) { final Long id = Long.valueOf(groupId); final Group group = this.groupRepository.findOne(id); if (group == null || group.isDeleted()) { throw new GroupNotFoundException(id); }/*from w w w. j a v a 2s . c o m*/ if (!group.isOfficeIdentifiedBy(officeId)) { final String errorMessage = "Group and child groups must have the same office."; throw new InvalidOfficeException("group", "attach.to.parent.group", errorMessage); } childGroups.add(group); } } return childGroups; }
From source file:org.rill.bpm.api.finder.support.RoleTagRelationManFinderInterceptorAdapter.java
public Object invoke(MethodInvocation arg0) throws Throwable { boolean firstMatch = false; try {// w w w .java 2 s . c om // Check the return value is empty or not String[] foundMans = null; for (RoleTagRelationalManFinder f : this.finder) { // Set finder component boolean internalFirstMatch = setMatchFinderComponent(f); if (!firstMatch && internalFirstMatch) { firstMatch = true; } String[] fm = f.findTaskExemans((String) arg0.getArguments()[0], (String) arg0.getArguments()[1], (String) arg0.getArguments()[2], (Long) arg0.getArguments()[3]); if (!ObjectUtils.isEmpty(fm)) { for (String s : fm) { foundMans = (String[]) ObjectUtils.addObjectToArray(foundMans, s); } } } if (!ObjectUtils.isEmpty(foundMans)) { if (log.isDebugEnabled()) log.debug("Found result " + ObjectUtils.getDisplayString(foundMans) + " by " + this.finder.getClass().getName()); List<String> list = Arrays.asList(foundMans); Set<String> afterFilter = new LinkedHashSet<String>(list); return afterFilter.toArray(new String[afterFilter.size()]); } // Let next intercepter do it. return arg0.proceed(); } finally { if (firstMatch) { clearFirstMatchFinderComponent(); } } }
From source file:org.springframework.aop.framework.ProxyFactoryBean.java
/** * Check the interceptorNames list whether it contains a target name as final element. * If found, remove the final name from the list and set it as targetName. *//*from w w w .jav a2 s. co m*/ private void checkInterceptorNames() { if (!ObjectUtils.isEmpty(this.interceptorNames)) { String finalName = this.interceptorNames[this.interceptorNames.length - 1]; if (this.targetName == null && this.targetSource == EMPTY_TARGET_SOURCE) { // The last name in the chain may be an Advisor/Advice or a target/TargetSource. // Unfortunately we don't know; we must look at type of the bean. if (!finalName.endsWith(GLOBAL_SUFFIX) && !isNamedBeanAnAdvisorOrAdvice(finalName)) { // The target isn't an interceptor. this.targetName = finalName; if (logger.isDebugEnabled()) { logger.debug("Bean with name '" + finalName + "' concluding interceptor chain " + "is not an advisor class: treating it as a target or TargetSource"); } String[] newNames = new String[this.interceptorNames.length - 1]; System.arraycopy(this.interceptorNames, 0, newNames, 0, newNames.length); this.interceptorNames = newNames; } } } }
From source file:org.springframework.aop.framework.ProxyFactoryBean.java
/** * Create the advisor (interceptor) chain. Advisors that are sourced * from a BeanFactory will be refreshed each time a new prototype instance * is added. Interceptors added programmatically through the factory API * are unaffected by such changes./* w ww . j a v a2 s . co m*/ */ private synchronized void initializeAdvisorChain() throws AopConfigException, BeansException { if (this.advisorChainInitialized) { return; } if (!ObjectUtils.isEmpty(this.interceptorNames)) { if (this.beanFactory == null) { throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " + "- cannot resolve interceptor names " + Arrays.asList(this.interceptorNames)); } // Globals can't be last unless we specified a targetSource using the property... if (this.interceptorNames[this.interceptorNames.length - 1].endsWith(GLOBAL_SUFFIX) && this.targetName == null && this.targetSource == EMPTY_TARGET_SOURCE) { throw new AopConfigException("Target required after globals"); } // Materialize interceptor chain from bean names. for (String name : this.interceptorNames) { if (logger.isTraceEnabled()) { logger.trace("Configuring advisor or advice '" + name + "'"); } if (name.endsWith(GLOBAL_SUFFIX)) { if (!(this.beanFactory instanceof ListableBeanFactory)) { throw new AopConfigException( "Can only use global advisors or interceptors with a ListableBeanFactory"); } addGlobalAdvisor((ListableBeanFactory) this.beanFactory, name.substring(0, name.length() - GLOBAL_SUFFIX.length())); } else { // If we get here, we need to add a named interceptor. // We must check if it's a singleton or prototype. Object advice; if (this.singleton || this.beanFactory.isSingleton(name)) { // Add the real Advisor/Advice to the chain. advice = this.beanFactory.getBean(name); } else { // It's a prototype Advice or Advisor: replace with a prototype. // Avoid unnecessary creation of prototype bean just for advisor chain initialization. advice = new PrototypePlaceholderAdvisor(name); } addAdvisorOnChainCreation(advice, name); } } } this.advisorChainInitialized = true; }
From source file:org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.java
/** * Define an inner bean definition.//from www. j a v a 2 s .com * @param type the bean type * @param args the constructors arguments and closure configurer * @return the bean definition */ public AbstractBeanDefinition bean(Class<?> type, Object... args) { GroovyBeanDefinitionWrapper current = this.currentBeanDefinition; try { Closure callable = null; Collection constructorArgs = null; if (!ObjectUtils.isEmpty(args)) { int index = args.length; Object lastArg = args[index - 1]; if (lastArg instanceof Closure) { callable = (Closure) lastArg; index--; } if (index > -1) { constructorArgs = resolveConstructorArguments(args, 0, index); } } this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, type, constructorArgs); if (callable != null) { callable.call(this.currentBeanDefinition); } return this.currentBeanDefinition.getBeanDefinition(); } finally { this.currentBeanDefinition = current; } }
From source file:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java
/** * Determine the target type for the given bean definition. * @param beanName the name of the bean (for error handling purposes) * @param mbd the merged bean definition for the bean * @param typesToMatch the types to match in case of internal type matching purposes * (also signals that the returned {@code Class} will never be exposed to application code) * @return the type for the bean if determinable, or {@code null} otherwise *//*w w w . ja v a2s . com*/ @Nullable protected Class<?> determineTargetType(String beanName, RootBeanDefinition mbd, Class<?>... typesToMatch) { Class<?> targetType = mbd.getTargetType(); if (targetType == null) { targetType = (mbd.getFactoryMethodName() != null ? getTypeForFactoryMethod(beanName, mbd, typesToMatch) : resolveBeanClass(mbd, beanName, typesToMatch)); if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) { mbd.resolvedTargetType = targetType; } } return targetType; }
From source file:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java
/** * Create a new instance for the specified bean, using an appropriate instantiation strategy: * factory method, constructor autowiring, or simple instantiation. * @param beanName the name of the bean//from w w w . j a v a 2 s . co m * @param mbd the bean definition for the bean * @param args explicit arguments to use for constructor or factory method invocation * @return a BeanWrapper for the new instance * @see #obtainFromSupplier * @see #instantiateUsingFactoryMethod * @see #autowireConstructor * @see #instantiateBean */ protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) { // Make sure bean class is actually resolved at this point. Class<?> beanClass = resolveBeanClass(mbd, beanName); if (beanClass != null && !Modifier.isPublic(beanClass.getModifiers()) && !mbd.isNonPublicAccessAllowed()) { throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Bean class isn't public, and non-public access not allowed: " + beanClass.getName()); } Supplier<?> instanceSupplier = mbd.getInstanceSupplier(); if (instanceSupplier != null) { return obtainFromSupplier(instanceSupplier, beanName); } if (mbd.getFactoryMethodName() != null) { return instantiateUsingFactoryMethod(beanName, mbd, args); } // Shortcut when re-creating the same bean... boolean resolved = false; boolean autowireNecessary = false; if (args == null) { synchronized (mbd.constructorArgumentLock) { if (mbd.resolvedConstructorOrFactoryMethod != null) { resolved = true; autowireNecessary = mbd.constructorArgumentsResolved; } } } if (resolved) { if (autowireNecessary) { return autowireConstructor(beanName, mbd, null, null); } else { return instantiateBean(beanName, mbd); } } // Need to determine the constructor... Constructor<?>[] ctors = determineConstructorsFromBeanPostProcessors(beanClass, beanName); if (ctors != null || mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR || mbd.hasConstructorArgumentValues() || !ObjectUtils.isEmpty(args)) { return autowireConstructor(beanName, mbd, ctors, args); } // No special handling: simply use no-arg constructor. return instantiateBean(beanName, mbd); }