Example usage for org.springframework.beans.factory BeanDefinitionStoreException BeanDefinitionStoreException

List of usage examples for org.springframework.beans.factory BeanDefinitionStoreException BeanDefinitionStoreException

Introduction

In this page you can find the example usage for org.springframework.beans.factory BeanDefinitionStoreException BeanDefinitionStoreException.

Prototype

public BeanDefinitionStoreException(String msg) 

Source Link

Document

Create a new BeanDefinitionStoreException.

Usage

From source file:biz.c24.io.spring.config.C24ModelBeanDefinitionParser.java

@Override
public AbstractBeanDefinition parseInternal(Element element, ParserContext context) {

    String basePackage = element.getAttribute("base-package");
    String baseElement = element.getAttribute("base-element");

    if (StringUtils.hasText(baseElement) && StringUtils.hasText(basePackage)) {
        throw new BeanDefinitionStoreException("Either base-package or base-element are allowed!");
    }/*from  w ww  .j a  v  a 2s.c  o  m*/

    Object source = context.extractSource(element);
    AbstractBeanDefinition modelDefinition = StringUtils.hasText(baseElement)
            ? getC24ModelFromElement(baseElement, context, source)
            : getC24ModelFromPackage(basePackage, context, source);

    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(C24Model.class);
    builder.addConstructorArgValue(modelDefinition);

    return getSourcedBeanDefinition(builder, context.extractSource(element));
}

From source file:com.gwtplatform.dispatch.rpc.server.spring.utils.SpringUtils.java

private static String generateName(ConfigurableListableBeanFactory registry, RootBeanDefinition definition) {
    String generatedBeanName = definition.getBeanClassName();
    if (generatedBeanName == null) {
        if (definition.getParentName() != null) {
            generatedBeanName = definition.getParentName() + "$child";
        } else if (definition.getFactoryBeanName() != null) {
            generatedBeanName = definition.getFactoryBeanName() + "$created";
        }// ww  w  .  j a  v  a 2  s  . co  m
    }
    if (!StringUtils.hasText(generatedBeanName)) {
        throw new BeanDefinitionStoreException(
                "Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't "
                        + "generate bean name");
    }

    String id = generatedBeanName;

    // Top-level bean: use plain class name.
    // Increase counter until the id is unique.
    int counter = -1;
    while (counter == -1 || (registry.containsSingleton(id))) {
        counter++;
        id = generatedBeanName + "#" + counter;
    }

    return id;
}

From source file:com.trigonic.utils.spring.beans.ImportHelper.java

private static void importAbsoluteResource(XmlBeanDefinitionReader reader, String location,
        Set<Resource> actualResources) {
    ResourceLoader resourceLoader = reader.getResourceLoader();
    if (resourceLoader == null) {
        throw new BeanDefinitionStoreException(
                "Cannot import bean definitions from location [" + location + "]: no ResourceLoader available");
    }//  w w  w .j a v  a  2  s . com

    if (resourceLoader instanceof ResourcePatternResolver) {
        importAbsoluteResourcePattern(reader, location, actualResources,
                (ResourcePatternResolver) resourceLoader);
    } else {
        importSingleAbsoluteResource(reader, location, actualResources, resourceLoader);
    }
}

From source file:com.gwtplatform.dispatch.server.spring.utils.SpringUtils.java

private static String generateName(ConfigurableListableBeanFactory registry, RootBeanDefinition definition) {
    String generatedBeanName = definition.getBeanClassName();
    if (generatedBeanName == null) {
        if (definition.getParentName() != null) {
            generatedBeanName = definition.getParentName() + "$child";
        } else if (definition.getFactoryBeanName() != null) {
            generatedBeanName = definition.getFactoryBeanName() + "$created";
        }// www.  j  av  a 2 s .  co  m
    }
    if (!StringUtils.hasText(generatedBeanName)) {
        throw new BeanDefinitionStoreException("Unnamed bean definition specifies neither "
                + "'class' nor 'parent' nor 'factory-bean' - can't generate bean name");
    }

    String id = generatedBeanName;

    // Top-level bean: use plain class name.
    // Increase counter until the id is unique.
    int counter = -1;
    while (counter == -1 || (registry.containsSingleton(id))) {
        counter++;
        id = generatedBeanName + "#" + counter;
    }

    return id;
}

From source file:org.ff4j.spring.placeholder.PropertiesPlaceHolderBeanDefinitionVisitor.java

/**
 * Parsing value to handle//ww w.  java 2  s . co  m
 * @param strVal
 * @param uriMap
 * @param visitedPlaceholders
 * @return
 * @throws BeanDefinitionStoreException
 */
protected String parseStringValue(String strVal, Map<String, Property<?>> propertiesMap,
        Map<String, Feature> featureMap, Set<String> visitedPlaceholders) throws BeanDefinitionStoreException {
    StringBuilder builder = new StringBuilder(strVal);

    // @ff4jProperty{}
    int startIndex = strVal.indexOf(PLACEHOLDER_PROPERTY_PREFIX);
    while (startIndex != -1) {
        int endIndex = builder.toString().indexOf(PLACEHOLDER_SUFFIX,
                startIndex + PLACEHOLDER_PROPERTY_PREFIX.length());
        if (endIndex != -1) {
            String placeholder = builder.substring(startIndex + PLACEHOLDER_PROPERTY_PREFIX.length(), endIndex);
            if (!visitedPlaceholders.add(placeholder)) {
                throw new BeanDefinitionStoreException(
                        "Circular placeholder reference '" + placeholder + "' in property definitions");
            }
            if (propertiesMap == null || !propertiesMap.containsKey(placeholder)) {
                throw new PropertyNotFoundException(
                        PLACEHOLDER_PROPERTY_PREFIX + ": Cannot perform placeholding on " + placeholder);
            }
            String propVal = propertiesMap.get(placeholder).asString();
            if (propVal != null) {
                propVal = parseStringValue(propVal, propertiesMap, featureMap, visitedPlaceholders);
                builder.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal);
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Resolved placeholder '{}' to value '{}'", placeholder, propVal);
                }
                startIndex = builder.toString().indexOf(PLACEHOLDER_PROPERTY_PREFIX,
                        startIndex + propVal.length());
            } else {
                throw new BeanDefinitionStoreException("Could not resolve placeholder '" + placeholder + "'");
            }
            visitedPlaceholders.remove(placeholder);
        } else {
            startIndex = -1;
        }
    }

    // @ff4jFeature{}
    startIndex = strVal.indexOf(PLACEHOLDER_FEATURE_PREFIX);
    while (startIndex != -1) {
        int endIndex = builder.toString().indexOf(PLACEHOLDER_SUFFIX,
                startIndex + PLACEHOLDER_FEATURE_PREFIX.length());
        if (endIndex != -1) {
            String placeholder = builder.substring(startIndex + PLACEHOLDER_FEATURE_PREFIX.length(), endIndex);
            if (!visitedPlaceholders.add(placeholder)) {
                throw new BeanDefinitionStoreException(
                        "Circular placeholder reference '" + placeholder + "' in property definitions");
            }
            if (featureMap == null || !featureMap.containsKey(placeholder)) {
                throw new FeatureNotFoundException(
                        PLACEHOLDER_FEATURE_PREFIX + ": Cannot perform placeholding on " + placeholder);
            }
            String propVal = String.valueOf(featureMap.get(placeholder).isEnable());
            if (propVal != null) {
                propVal = parseStringValue(propVal, propertiesMap, featureMap, visitedPlaceholders);
                builder.replace(startIndex, endIndex + PLACEHOLDER_FEATURE_PREFIX.length(), propVal);
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Resolved placeholder '{}' to value '{}'", placeholder, propVal);
                }
                startIndex = builder.toString().indexOf(PLACEHOLDER_FEATURE_PREFIX,
                        startIndex + propVal.length());
            } else {
                throw new BeanDefinitionStoreException("Could not resolve placeholder '" + placeholder + "'");
            }
            visitedPlaceholders.remove(placeholder);
        } else {
            startIndex = -1;
        }
    }

    return builder.toString();
}

From source file:com.trigonic.utils.spring.cmdline.CommandLineMetaData.java

private <T extends Annotation> void checkWriteableProperty(T annotation, Class<?> beanClass, Field field) {
    PropertyDescriptor property = BeanUtils.getPropertyDescriptor(beanClass, field.getName());
    if (property == null || property.getWriteMethod() == null) {
        throw new BeanDefinitionStoreException("@" + annotation.getClass().getSimpleName()
                + " annotation cannot be applied to fields without matching setters");
    }/* ww w  .  ja v  a  2  s .  c o m*/
}

From source file:com.trigonic.utils.spring.cmdline.CommandLineMetaData.java

private PropertyDescriptor getPropertyForMethod(String annotationType, Annotation annotation, Method method) {
    PropertyDescriptor property = BeanUtils.findPropertyForMethod(method);
    if (property == null) {
        throw new BeanDefinitionStoreException(
                annotationType + " annotation cannot be applied to non-property methods");
    }/*w  w  w.  j ava  2  s .  com*/
    return property;
}

From source file:org.zalando.spring.data.businesskey.jpa.config.JpaBusinessKeyRegistrar.java

/**
 * @param  registry,  the {@link BeanDefinitionRegistry} to be used to register the
 *                    {@link AnnotationBeanConfigurerAspect}.
 *//* w  w w .java  2s. c  o  m*/
private void registerBeanConfigurerAspectIfNecessary(final BeanDefinitionRegistry registry) {

    if (registry.containsBeanDefinition(BEAN_CONFIGURER_ASPECT_CLASS_NAME)) {
        return;
    }

    if (!ClassUtils.isPresent(BEAN_CONFIGURER_ASPECT_CLASS_NAME, getClass().getClassLoader())) {
        throw new BeanDefinitionStoreException(BEAN_CONFIGURER_ASPECT_CLASS_NAME + " not found. \n"
                + "Could not configure Spring Data JPA auditing-feature because"
                + " spring-aspects.jar is not on the classpath!\n"
                + "If you want to use auditing please add spring-aspects.jar to the classpath.");
    }

    RootBeanDefinition def = new RootBeanDefinition();
    def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);
    def.setFactoryMethodName("aspectOf");
    def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

    registry.registerBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME,
            new BeanComponentDefinition(def, BEAN_CONFIGURER_ASPECT_BEAN_NAME).getBeanDefinition());
}

From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java

/**
 * Get the refresh check delay for the given {@link ScriptFactory} {@link BeanDefinition}.
 * If the {@link BeanDefinition} has a/*from w ww. ja  va  2s . co  m*/
 * {@link org.springframework.core.AttributeAccessor metadata attribute}
 * under the key {@link #REFRESH_CHECK_DELAY_ATTRIBUTE} which is a valid {@link Number}
 * type, then this value is used. Otherwise, the the {@link #defaultRefreshCheckDelay}
 * value is used.
 * @param beanDefinition the BeanDefinition to check
 * @return the refresh check delay
 */
protected long resolveRefreshCheckDelay(BeanDefinition beanDefinition) {
    long refreshCheckDelay = this.defaultRefreshCheckDelay;
    Object attributeValue = beanDefinition.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE);
    if (attributeValue instanceof Number) {
        refreshCheckDelay = ((Number) attributeValue).longValue();
    } else if (attributeValue instanceof String) {
        refreshCheckDelay = Long.parseLong((String) attributeValue);
    } else if (attributeValue != null) {
        throw new BeanDefinitionStoreException(
                "Invalid refresh check delay attribute [" + REFRESH_CHECK_DELAY_ATTRIBUTE + "] with value '"
                        + attributeValue + "': needs to be of type Number or String");
    }
    return refreshCheckDelay;
}

From source file:org.iff.infra.util.spring.script.ScriptFactoryPostProcessor.java

protected boolean resolveProxyTargetClass(BeanDefinition beanDefinition) {
    boolean proxyTargetClass = this.defaultProxyTargetClass;
    Object attributeValue = beanDefinition.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE);
    if (attributeValue instanceof Boolean) {
        proxyTargetClass = (Boolean) attributeValue;
    } else if (attributeValue instanceof String) {
        proxyTargetClass = Boolean.valueOf((String) attributeValue);
    } else if (attributeValue != null) {
        throw new BeanDefinitionStoreException(
                "Invalid proxy target class attribute [" + PROXY_TARGET_CLASS_ATTRIBUTE + "] with value '"
                        + attributeValue + "': needs to be of type Boolean or String");
    }/*from w  w w .  jav a2  s  . c o  m*/
    return proxyTargetClass;
}