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.springframework.scripting.support.ScriptFactoryPostProcessor.java

@Override
@Nullable//from   ww  w  .  j  a  va 2s  . c o m
public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
    // We only apply special treatment to ScriptFactory implementations here.
    if (!ScriptFactory.class.isAssignableFrom(beanClass)) {
        return null;
    }

    Assert.state(this.beanFactory != null, "No BeanFactory set");
    BeanDefinition bd = this.beanFactory.getMergedBeanDefinition(beanName);

    try {
        String scriptFactoryBeanName = SCRIPT_FACTORY_NAME_PREFIX + beanName;
        String scriptedObjectBeanName = SCRIPTED_OBJECT_NAME_PREFIX + beanName;
        prepareScriptBeans(bd, scriptFactoryBeanName, scriptedObjectBeanName);

        ScriptFactory scriptFactory = this.scriptBeanFactory.getBean(scriptFactoryBeanName,
                ScriptFactory.class);
        ScriptSource scriptSource = getScriptSource(scriptFactoryBeanName,
                scriptFactory.getScriptSourceLocator());
        Class<?>[] interfaces = scriptFactory.getScriptInterfaces();

        Class<?> scriptedType = scriptFactory.getScriptedObjectType(scriptSource);
        if (scriptedType != null) {
            return scriptedType;
        } else if (!ObjectUtils.isEmpty(interfaces)) {
            return (interfaces.length == 1 ? interfaces[0] : createCompositeInterface(interfaces));
        } else {
            if (bd.isSingleton()) {
                return this.scriptBeanFactory.getBean(scriptedObjectBeanName).getClass();
            }
        }
    } catch (Exception ex) {
        if (ex instanceof BeanCreationException && ((BeanCreationException) ex)
                .getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
            if (logger.isTraceEnabled()) {
                logger.trace("Could not determine scripted object type for bean '" + beanName + "': "
                        + ex.getMessage());
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("Could not determine scripted object type for bean '" + beanName + "'", ex);
            }
        }
    }

    return null;
}

From source file:org.springframework.security.authentication.jaas.AbstractJaasAuthenticationProvider.java

/**
 * Validates the required properties are set. In addition, if
 * {@link #setCallbackHandlers(JaasAuthenticationCallbackHandler[])} has not been
 * called with valid handlers, initializes to use {@link JaasNameCallbackHandler} and
 * {@link JaasPasswordCallbackHandler}./*  w w w  .  java 2s.c  o  m*/
 */
public void afterPropertiesSet() throws Exception {
    Assert.hasLength(this.loginContextName, "loginContextName cannot be null or empty");
    Assert.notEmpty(this.authorityGranters, "authorityGranters cannot be null or empty");
    if (ObjectUtils.isEmpty(this.callbackHandlers)) {
        setCallbackHandlers(new JaasAuthenticationCallbackHandler[] { new JaasNameCallbackHandler(),
                new JaasPasswordCallbackHandler() });
    }
    Assert.notNull(this.loginExceptionResolver, "loginExceptionResolver cannot be null");
}

From source file:org.springframework.security.jackson2.SecurityJacksonModules.java

public static void enableDefaultTyping(ObjectMapper mapper) {
    if (!ObjectUtils.isEmpty(mapper)) {
        TypeResolverBuilder<?> typeBuilder = mapper.getDeserializationConfig().getDefaultTyper(null);
        if (ObjectUtils.isEmpty(typeBuilder)) {
            mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
        }/*from ww  w  . jav  a2  s  .  c o m*/
    }
}

From source file:org.springframework.security.jackson2.SecurityJacksonModules.java

private static Module loadAndGetInstance(String className) {
    Module instance = null;//from w  w w  .j av  a2s.  co  m
    try {
        logger.debug("Loading module " + className);
        Class<? extends Module> securityModule = (Class<? extends Module>) ClassUtils.forName(className,
                ClassUtils.getDefaultClassLoader());
        if (!ObjectUtils.isEmpty(securityModule)) {
            logger.debug("Loaded module " + className + ", now registering");
            instance = securityModule.newInstance();
        }
    } catch (ClassNotFoundException e) {
        logger.warn("Module class not found : " + e.getMessage());
    } catch (InstantiationException e) {
        logger.error(e.getMessage());
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
    }
    return instance;
}

From source file:org.springframework.security.jackson2.SecurityJacksonModules.java

/**
 * @return List of available security modules in classpath.
 *//*from w w w. jav a  2s . c  om*/
public static List<Module> getModules() {
    List<Module> modules = new ArrayList<Module>();
    for (String className : securityJackson2ModuleClasses) {
        Module module = loadAndGetInstance(className);
        if (!ObjectUtils.isEmpty(module)) {
            modules.add(module);
        }
    }
    return modules;
}

From source file:org.springframework.security.web.method.ResolvableMethod.java

private static ResolvableType toResolvableType(Class<?> type, Class<?>... generics) {
    return ObjectUtils.isEmpty(generics) ? ResolvableType.forClass(type)
            : ResolvableType.forClassWithGenerics(type, generics);
}

From source file:org.springframework.security.web.savedrequest.DefaultSavedRequest.java

/**
 * @since 4.2/*from   w w w .  ja  v  a  2 s .  c  o m*/
 */
private void addParameters(Map<String, String[]> parameters) {
    if (!ObjectUtils.isEmpty(parameters)) {
        for (String paramName : parameters.keySet()) {
            Object paramValues = parameters.get(paramName);
            if (paramValues instanceof String[]) {
                this.addParameter(paramName, (String[]) paramValues);
            } else {
                if (logger.isWarnEnabled()) {
                    logger.warn("ServletRequest.getParameterMap() returned non-String array");
                }
            }
        }
    }
}

From source file:org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration.java

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    if (ClassUtils.isPresent("org.springframework.security.web.authentication.RememberMeServices", null)) {
        this.usesSpringSessionRememberMeServices = !ObjectUtils
                .isEmpty(applicationContext.getBeanNamesForType(SpringSessionRememberMeServices.class));
    }//from   w ww. j av  a 2s . c o  m
}

From source file:org.springframework.test.AbstractSpringContextTests.java

/**
 * Obtain an ApplicationContext for the given key, potentially cached.
 * @param locations the context key; may be {@code null}.
 * @return the corresponding ApplicationContext instance (potentially cached),
 * or {@code null} if the provided {@code key} is <em>empty</em>
 *///  w  w w.j av  a2 s .  c  o  m
protected final ConfigurableApplicationContext getContext(String... locations) throws Exception {
    if (ObjectUtils.isEmpty(locations)) {
        return null;
    }
    String key = contextKey(locations);
    ConfigurableApplicationContext ctx = contextKeyToContextMap.get(key);
    if (ctx == null) {
        ctx = loadContext(locations);
        ctx.registerShutdownHook();
        contextKeyToContextMap.put(key, ctx);
    }
    return ctx;
}

From source file:org.springframework.test.context.ContextConfigurationAttributes.java

/**
 * Construct a new {@link ContextConfigurationAttributes} instance for the
 * {@linkplain Class test class} that declared the
 * {@link ContextConfiguration @ContextConfiguration} annotation and its
 * corresponding attributes.//from   w ww .  ja va 2s  .c  o  m
 * @param declaringClass the test class that declared {@code @ContextConfiguration}
 * @param locations the resource locations declared via {@code @ContextConfiguration}
 * @param classes the annotated classes declared via {@code @ContextConfiguration}
 * @param inheritLocations the {@code inheritLocations} flag declared via {@code @ContextConfiguration}
 * @param initializers the context initializers declared via {@code @ContextConfiguration}
 * @param inheritInitializers the {@code inheritInitializers} flag declared via {@code @ContextConfiguration}
 * @param name the name of level in the context hierarchy, or {@code null} if not applicable
 * @param contextLoaderClass the {@code ContextLoader} class declared via {@code @ContextConfiguration}
 * @throws IllegalArgumentException if the {@code declaringClass} or {@code contextLoaderClass} is
 * {@code null}
 */
public ContextConfigurationAttributes(Class<?> declaringClass, String[] locations, Class<?>[] classes,
        boolean inheritLocations, Class<? extends ApplicationContextInitializer<?>>[] initializers,
        boolean inheritInitializers, @Nullable String name, Class<? extends ContextLoader> contextLoaderClass) {

    Assert.notNull(declaringClass, "'declaringClass' must not be null");
    Assert.notNull(contextLoaderClass, "'contextLoaderClass' must not be null");

    if (!ObjectUtils.isEmpty(locations) && !ObjectUtils.isEmpty(classes) && logger.isDebugEnabled()) {
        logger.debug(String.format(
                "Test class [%s] has been configured with @ContextConfiguration's 'locations' (or 'value') %s "
                        + "and 'classes' %s attributes. Most SmartContextLoader implementations support "
                        + "only one declaration of resources per @ContextConfiguration annotation.",
                declaringClass.getName(), ObjectUtils.nullSafeToString(locations),
                ObjectUtils.nullSafeToString(classes)));
    }

    this.declaringClass = declaringClass;
    this.locations = locations;
    this.classes = classes;
    this.inheritLocations = inheritLocations;
    this.initializers = initializers;
    this.inheritInitializers = inheritInitializers;
    this.name = (StringUtils.hasText(name) ? name : null);
    this.contextLoaderClass = contextLoaderClass;
}