Example usage for org.springframework.beans FatalBeanException FatalBeanException

List of usage examples for org.springframework.beans FatalBeanException FatalBeanException

Introduction

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

Prototype

public FatalBeanException(String msg) 

Source Link

Document

Create a new FatalBeanException with the specified message.

Usage

From source file:org.jasig.cas.util.annotation.NotNullAnnotationBeanPostProcessor.java

protected void processField(final Field field, final Annotation annotation, final Object bean, String beanName)
        throws IllegalAccessException {
    if (field.get(bean) == null) {
        throw new FatalBeanException("Field " + field.getName() + " cannot be null on bean: " + beanName);
    }/*  w w w.j  ava 2 s.c om*/
}

From source file:org.jasig.cas.util.annotation.NotEmptyAnnotationBeanPostProcessor.java

protected void processField(final Field field, final Annotation annotation, final Object bean,
        final String beanName) throws IllegalAccessException {

    final Object obj = field.get(bean);

    if (obj == null) {
        throw new FatalBeanException(constructMessage(field, beanName));
    }/*from  ww w  .  jav a  2  s .  c o m*/

    if (obj instanceof Collection) {
        final Collection<?> c = (Collection<?>) obj;

        if (c.isEmpty()) {
            throw new FatalBeanException(constructMessage(field, beanName));
        }
    }

    if (obj.getClass().isArray()) {
        if (Array.getLength(obj) == 0) {
            throw new FatalBeanException(constructMessage(field, beanName));
        }
    }

    if (obj instanceof Map) {
        final Map<?, ?> m = (Map<?, ?>) obj;

        if (m.isEmpty()) {
            throw new FatalBeanException(constructMessage(field, beanName));
        }
    }
}

From source file:org.jasig.cas.util.annotation.IsInAnnotationBeanPostProcessor.java

protected void processField(final Field field, final Annotation annotation, final Object bean,
        final String beanName) throws IllegalAccessException {
    final IsIn isIn = (IsIn) annotation;

    final int val = field.getInt(bean);

    for (int i = 0; i < isIn.value().length; i++) {
        if (val == isIn.value()[i]) {
            return;
        }//  www  .  j  a  va 2s . c  o  m
    }

    throw new FatalBeanException("field '" + field.getName() + "' does not contain a value of '" + isIn.value()
            + "' on bean '" + beanName + "'");
}

From source file:org.jasig.cas.util.annotation.GreaterThanAnnotationBeanPostProcessor.java

protected void processField(final Field field, final Annotation annotation, final Object bean,
        final String beanName) throws IllegalAccessException {
    final GreaterThan greaterThan = (GreaterThan) annotation;

    final int value = greaterThan.value();
    final int val = field.getInt(bean);

    if (val <= value) {
        throw new FatalBeanException("value of field \"" + field.getName() + "\" must be greater than \""
                + value + "\" on bean \"" + beanName + "\"");
    }//from w ww .j ava 2 s .  co m
}

From source file:org.bytesoft.bytetcc.supports.dubbo.validator.ApplicationConfigValidator.java

public void validate() throws BeansException {
    if (this.definitionList == null || this.definitionList.isEmpty()) {
        throw new FatalBeanException("There is no application name specified!");
    } else if (this.definitionList.size() > 1) {
        throw new FatalBeanException("There are more than one application name specified!");
    }//from w  ww .  ja v a 2s.c  om
}

From source file:org.bytesoft.bytetcc.supports.dubbo.validator.ProtocolConfigValidator.java

public void validate() throws BeansException {
    MutablePropertyValues mpv = this.beanDefinition.getPropertyValues();
    PropertyValue pv = mpv.getPropertyValue("port");
    Object value = pv == null ? null : pv.getValue();
    if (pv == null || value == null) {
        throw new FatalBeanException(
                "The value of the attribute 'port' (<dubbo:protocol port='...' />) must be explicitly specified.");
    } else if ("-1".equals(value)) {
        throw new FatalBeanException(
                "The value of the attribute 'port' (<dubbo:protocol port='...' />) must be explicitly specified and not equal to -1.");
    }//from  ww  w  .  j  a v a  2  s  .c o  m
}

From source file:org.bytesoft.bytetcc.supports.dubbo.validator.ServiceConfigValidator.java

public void validate() throws BeansException {
    MutablePropertyValues mpv = this.beanDefinition.getPropertyValues();
    PropertyValue retries = mpv.getPropertyValue("retries");
    PropertyValue loadbalance = mpv.getPropertyValue("loadbalance");
    PropertyValue cluster = mpv.getPropertyValue("cluster");
    PropertyValue filter = mpv.getPropertyValue("filter");
    PropertyValue group = mpv.getPropertyValue("group");

    if (retries == null || retries.getValue() == null || "0".equals(retries.getValue()) == false) {
        throw new FatalBeanException(
                String.format("The value of attr 'retries'(beanId= %s) should be '0'.", this.beanName));
    } else if (loadbalance == null || loadbalance.getValue() == null
            || "compensable".equals(loadbalance.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attr 'loadbalance'(beanId= %s) should be 'compensable'.", this.beanName));
    } else if (cluster == null || cluster.getValue() == null
            || "failfast".equals(cluster.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attribute 'cluster' (beanId= %s) must be 'failfast'.", this.beanName));
    } else if (filter == null || filter.getValue() == null
            || "compensable".equals(filter.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attr 'filter'(beanId= %s) should be 'compensable'.", this.beanName));
    } else if (group == null || group.getValue() == null
            || "org.bytesoft.bytetcc".equals(group.getValue()) == false) {
        throw new FatalBeanException(String.format(
                "The value of attr 'group'(beanId= %s) should be 'org.bytesoft.bytetcc'.", this.beanName));
    }//from w w  w .j a  v a 2  s . c om
}

From source file:org.jboss.windup.config.spring.namespace.java.SpringNamespaceHandlerUtil.java

public static BeanDefinition resolveBeanDefinition(BeanDefinition beanDef, Element element,
        ParserContext context) {//from  ww w.j  a v  a  2s  .  com
    BeanDefinitionParserDelegate delegate = context.getDelegate();
    String namespace = element.getNamespaceURI();

    // check to see whether it is the default Spring bean decorator...
    if (StringUtils.equals(namespace, BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
        BeanDefinitionHolder holder = delegate.parseBeanDefinitionElement(element, beanDef);
        return holder.getBeanDefinition();
    }

    // otherwise, see if it is supported based on our namespace resolver...
    NamespaceHandler namespaceHandler = delegate.getReaderContext().getNamespaceHandlerResolver()
            .resolve(namespace);
    if (namespaceHandler == null) {
        throw new FatalBeanException("Unable to find parser for bean with namespace: " + namespace);
    }

    return namespaceHandler.parse(element, new ParserContext(delegate.getReaderContext(), delegate, beanDef));
}

From source file:org.bytesoft.bytetcc.supports.spring.TransactionConfigPostProcessor.java

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] beanNameArray = beanFactory.getBeanDefinitionNames();
    for (int i = 0; i < beanNameArray.length; i++) {
        String beanName = beanNameArray[i];
        BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        if (org.springframework.transaction.interceptor.TransactionProxyFactoryBean.class.getName()
                .equals(beanClassName)) {
            throw new FatalBeanException(String.format(
                    "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
                    beanName));//ww w  .j av  a2s.c  o m
        }

        if (org.springframework.transaction.interceptor.TransactionInterceptor.class.getName()
                .equals(beanClassName)) {
            boolean errorExists = true;

            MutablePropertyValues mpv = beanDef.getPropertyValues();
            PropertyValue pv = mpv.getPropertyValue("transactionAttributeSource");
            Object value = pv == null ? null : pv.getValue();
            if (value != null && RuntimeBeanReference.class.isInstance(value)) {
                RuntimeBeanReference reference = (RuntimeBeanReference) value;
                BeanDefinition refBeanDef = beanFactory.getBeanDefinition(reference.getBeanName());
                String refBeanClassName = refBeanDef.getBeanClassName();
                errorExists = AnnotationTransactionAttributeSource.class.getName()
                        .equals(refBeanClassName) == false;
            }

            if (errorExists) {
                throw new FatalBeanException(String.format(
                        "Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
                        beanName));
            }

        }
    }
}

From source file:org.bytesoft.bytetcc.supports.dubbo.validator.ReferenceConfigValidator.java

public void validate() throws BeansException {
    MutablePropertyValues mpv = this.beanDefinition.getPropertyValues();
    PropertyValue retries = mpv.getPropertyValue("retries");
    PropertyValue loadbalance = mpv.getPropertyValue("loadbalance");
    PropertyValue cluster = mpv.getPropertyValue("cluster");
    PropertyValue filter = mpv.getPropertyValue("filter");

    if (retries == null || retries.getValue() == null || "0".equals(retries.getValue()) == false) {
        throw new FatalBeanException(
                String.format("The value of attr 'retries'(beanId= %s) should be '0'.", this.beanName));
    } else if (loadbalance == null || loadbalance.getValue() == null
            || "compensable".equals(loadbalance.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attr 'loadbalance'(beanId= %s) should be 'compensable'.", this.beanName));
    } else if (cluster == null || cluster.getValue() == null
            || "failfast".equals(cluster.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attribute 'cluster' (beanId= %s) must be 'failfast'.", this.beanName));
    } else if (filter == null || filter.getValue() == null
            || "compensable".equals(filter.getValue()) == false) {
        throw new FatalBeanException(String
                .format("The value of attr 'filter'(beanId= %s) should be 'compensable'.", this.beanName));
    }/*w w  w  .j  a  v a2s. com*/

    PropertyValue pv = mpv.getPropertyValue("interface");
    String clazzName = String.valueOf(pv.getValue());
    ClassLoader cl = Thread.currentThread().getContextClassLoader();

    Class<?> clazz = null;
    try {
        clazz = cl.loadClass(clazzName);
    } catch (Exception ex) {
        throw new FatalBeanException(String.format("Cannot load class %s.", clazzName));
    }

    Method[] methodArray = clazz.getMethods();
    for (int i = 0; i < methodArray.length; i++) {
        Method method = methodArray[i];
        boolean declared = false;
        Class<?>[] exceptionTypeArray = method.getExceptionTypes();
        for (int j = 0; j < exceptionTypeArray.length; j++) {
            Class<?> exceptionType = exceptionTypeArray[j];
            if (RemotingException.class.isAssignableFrom(exceptionType)) {
                declared = true;
                break;
            }
        }

        if (declared == false) {
            // throw new FatalBeanException(String.format(
            // "The remote call method(%s) must be declared to throw a remote exception:
            // org.bytesoft.compensable.RemotingException!",
            // method));
            logger.warn("The remote call method({}) should be declared to throw a remote exception: {}!",
                    method, RemotingException.class.getName());
        }

    }

}