List of usage examples for org.springframework.beans FatalBeanException FatalBeanException
public FatalBeanException(String msg, @Nullable Throwable cause)
From source file:org.caratarse.auth.model.util.BeanUtils.java
/** * Copy the not-null property values of the given source bean into the given target bean. * <p>//from w w w . j a va2s .com * Note: The source and target classes do not have to match or even be derived from each other, * as long as the properties match. Any bean properties that the source bean exposes but the * target bean does not will silently be ignored. * * @param source the source bean * @param target the target bean * @param editable the class (or interface) to restrict property setting to * @param ignoreProperties array of property names to ignore * @throws BeansException if the copying failed * @see BeanWrapper */ private static void copyNotNullProperties(Object source, Object target, Class<?> editable, String... ignoreProperties) throws BeansException { Assert.notNull(source, "Source must not be null"); Assert.notNull(target, "Target must not be null"); Class<?> actualEditable = target.getClass(); if (editable != null) { if (!editable.isInstance(target)) { throw new IllegalArgumentException("Target class [" + target.getClass().getName() + "] not assignable to Editable class [" + editable.getName() + "]"); } actualEditable = editable; } PropertyDescriptor[] targetPds = org.springframework.beans.BeanUtils.getPropertyDescriptors(actualEditable); List<String> ignoreList = (ignoreProperties != null ? Arrays.asList(ignoreProperties) : null); for (PropertyDescriptor targetPd : targetPds) { Method writeMethod = targetPd.getWriteMethod(); if (writeMethod != null && (ignoreList == null || !ignoreList.contains(targetPd.getName()))) { PropertyDescriptor sourcePd = org.springframework.beans.BeanUtils .getPropertyDescriptor(source.getClass(), targetPd.getName()); if (sourcePd != null) { Method readMethod = sourcePd.getReadMethod(); if (readMethod != null && ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) { try { if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } Object value = readMethod.invoke(source); if (value == null) { continue; } if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(target, value); } catch (Throwable ex) { throw new FatalBeanException( "Could not copy property '" + targetPd.getName() + "' from source to target", ex); } } } } } }
From source file:com.lakeside.data.sqldb.BaseDao.java
/** * ?//from w w w .j ava2s . c om * @param entity * @return */ public T merge(final T entity) { Assert.notNull(entity, "entity?"); Session session = getSession(); String idName = getIdName(); PropertyDescriptor idp = BeanUtils.getPropertyDescriptor(entityClass, idName); PK idvalue = null; try { idvalue = (PK) idp.getReadMethod().invoke(entity); } catch (Exception e) { throw new FatalBeanException("Could not copy properties from source to target", e); } T dest = null; if (idvalue != null) { dest = (T) session.get(entityClass, idvalue); } if (dest != null) { // merge the properties PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(entityClass); for (PropertyDescriptor p : descriptors) { if (p.getWriteMethod() != null) { try { Method readMethod = p.getReadMethod(); if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } Object value = readMethod.invoke(entity); if (value == null) { continue; } Method writeMethod = p.getWriteMethod(); if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(dest, value); } catch (Throwable ex) { throw new FatalBeanException("Could not copy properties from source to target", ex); } } } } else { // destination object is empty, save the entity object parameted dest = entity; } session.saveOrUpdate(dest); logger.debug("merge entity: {}", entity); return dest; }
From source file:org.jboss.spring.facade.ControllerBeanFactory.java
/** * Create the bean./*from w ww . j a v a 2 s. c om*/ * * @param factory the bean factory * @return new bean instance * @throws BeansException for any error */ protected Object createBean(Object factory) throws BeansException { try { return org.jboss.beans.metadata.spi.factory.BeanFactory.class.cast(factory).createBean(); } catch (Throwable t) { throw new FatalBeanException("Cannot create bean: " + factory, t); } }
From source file:net.groupbuy.service.impl.BaseServiceImpl.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void copyProperties(Object source, Object target, String[] ignoreProperties) throws BeansException { Assert.notNull(source, "Source must not be null"); Assert.notNull(target, "Target must not be null"); PropertyDescriptor[] targetPds = BeanUtils.getPropertyDescriptors(target.getClass()); List<String> ignoreList = (ignoreProperties != null) ? Arrays.asList(ignoreProperties) : null; for (PropertyDescriptor targetPd : targetPds) { if (targetPd.getWriteMethod() != null && (ignoreProperties == null || (!ignoreList.contains(targetPd.getName())))) { PropertyDescriptor sourcePd = BeanUtils.getPropertyDescriptor(source.getClass(), targetPd.getName()); if (sourcePd != null && sourcePd.getReadMethod() != null) { try { Method readMethod = sourcePd.getReadMethod(); if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); }/*www. j av a 2 s . com*/ Object sourceValue = readMethod.invoke(source); Object targetValue = readMethod.invoke(target); if (sourceValue != null && targetValue != null && targetValue instanceof Collection) { Collection collection = (Collection) targetValue; collection.clear(); collection.addAll((Collection) sourceValue); } else { Method writeMethod = targetPd.getWriteMethod(); if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } writeMethod.invoke(target, sourceValue); } } catch (Throwable ex) { throw new FatalBeanException("Could not copy properties from source to target", ex); } } } } }
From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractX509CredentialBeanDefinitionParser.java
/** * Parses the CRLs from the credential configuration. * //from w ww .j a v a 2s . c o m * @param configChildren children of the credential element * @param builder credential build */ protected void parseCRLs(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) { List<Element> crlElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "CRL")); if (crlElems == null || crlElems.isEmpty()) { return; } log.debug("Parsing x509 credential CRLs"); ArrayList<X509CRL> crls = new ArrayList<X509CRL>(); byte[] encodedCRL; Collection<X509CRL> decodedCRLs; for (Element crlElem : crlElems) { encodedCRL = getEncodedCRL(DatatypeHelper.safeTrimOrNullString(crlElem.getTextContent())); if (encodedCRL == null) { continue; } try { decodedCRLs = X509Util.decodeCRLs(encodedCRL); crls.addAll(decodedCRLs); } catch (CRLException e) { throw new FatalBeanException("Unable to create X509 credential, unable to parse CRLs", e); } } builder.addPropertyValue("crls", crls); }
From source file:org.okj.commons.annotations.ServiceReferenceInjectionBeanPostProcessor.java
public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { MutablePropertyValues newprops = new MutablePropertyValues(pvs); for (PropertyDescriptor pd : pds) { ServiceReference s = hasServiceProperty(pd); if (s != null && !pvs.contains(pd.getName())) { try { if (logger.isDebugEnabled()) logger.debug(/*w w w . j a v a2 s . co m*/ "Processing annotation [" + s + "] for [" + beanName + "." + pd.getName() + "]"); FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName); // BPPs are created in stageOne(), even though they are run in stageTwo(). This check means that // the call to getObject() will not fail with ServiceUnavailable. This is safe to do because // ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that mandatory services are // satisfied before stageTwo() is run. if (bean instanceof BeanPostProcessor) { ImporterCallAdapter.setCardinality(importer, Cardinality.C_0__1); } newprops.addPropertyValue(pd.getName(), importer.getObject()); } catch (Exception e) { throw new FatalBeanException("Could not create service reference", e); } } } return newprops; }
From source file:org.jboss.spring.facade.ControllerBeanFactory.java
/** * Get the bean class.//www . j a v a 2 s . co m * * @param className the class name * @param context the context * @return bean's class * @throws BeansException for any error */ protected Class<?> getBeanClass(String className, KernelControllerContext context) throws BeansException { try { ClassLoader cl = context.getClassLoader(); return cl.loadClass(className); } catch (Throwable t) { throw new FatalBeanException("Cannot load class: " + className + ", context: " + context, t); } }
From source file:org.codehaus.grepo.core.config.GenericRepositoryScanBeanDefinitionParser.java
/** * @param element The element.// ww w .j a v a 2s.c o m * @param classLoader The class loader. * @return Returns the type filter. */ @SuppressWarnings("unchecked") protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader) { String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE); String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE); try { if ("annotation".equals(filterType)) { return new AnnotationTypeFilter((Class<Annotation>) classLoader.loadClass(expression)); } else if ("assignable".equals(filterType)) { return new AssignableTypeFilter(classLoader.loadClass(expression)); } else if ("aspectj".equals(filterType)) { return new AspectJTypeFilter(expression, classLoader); } else if ("regex".equals(filterType)) { return new RegexPatternTypeFilter(Pattern.compile(expression)); } else if ("custom".equals(filterType)) { Class filterClass = classLoader.loadClass(expression); if (!TypeFilter.class.isAssignableFrom(filterClass)) { throw new IllegalArgumentException( "Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression); } return (TypeFilter) BeanUtils.instantiateClass(filterClass); } else { throw new IllegalArgumentException("Unsupported filter type: " + filterType); } } catch (ClassNotFoundException ex) { throw new FatalBeanException("Type filter class not found: " + expression, ex); } }
From source file:info.sargis.eventbus.config.EventBusHandlerBeanDefinitionParser.java
@SuppressWarnings("unchecked") protected TypeFilter createTypeFilter(Element element, ClassLoader classLoader) { String filterType = element.getAttribute(FILTER_TYPE_ATTRIBUTE); String expression = element.getAttribute(FILTER_EXPRESSION_ATTRIBUTE); try {/* www.ja va2 s.co m*/ if ("annotation".equals(filterType)) { return new AnnotationTypeFilter((Class<Annotation>) classLoader.loadClass(expression)); } else if ("assignable".equals(filterType)) { return new AssignableTypeFilter(classLoader.loadClass(expression)); } else if ("regex".equals(filterType)) { return new RegexPatternTypeFilter(Pattern.compile(expression)); } else if ("custom".equals(filterType)) { Class filterClass = classLoader.loadClass(expression); if (!TypeFilter.class.isAssignableFrom(filterClass)) { throw new IllegalArgumentException( "Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression); } return (TypeFilter) BeanUtils.instantiateClass(filterClass); } else { throw new IllegalArgumentException("Unsupported filter type: " + filterType); } } catch (ClassNotFoundException ex) { throw new FatalBeanException("Type filter class not found: " + expression, ex); } }
From source file:org.apache.james.container.spring.lifecycle.osgi.AbstractOSGIAnnotationBeanPostProcessor.java
@Override @SuppressWarnings("rawtypes") public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException { MutablePropertyValues newprops = new MutablePropertyValues(pvs); for (PropertyDescriptor pd : pds) { A s = hasAnnotatedProperty(pd);//from w w w. j a v a 2 s .co m if (s != null && !pvs.contains(pd.getName())) { try { if (logger.isDebugEnabled()) logger.debug( "Processing annotation [" + s + "] for [" + beanName + "." + pd.getName() + "]"); FactoryBean importer = getServiceImporter(s, pd.getWriteMethod(), beanName); // BPPs are created in stageOne(), even though they are run in stageTwo(). This check means that // the call to getObject() will not fail with ServiceUnavailable. This is safe to do because // ServiceReferenceDependencyBeanFactoryPostProcessor will ensure that mandatory services are // satisfied before stageTwo() is run. if (bean instanceof BeanPostProcessor) { ImporterCallAdapter.setCardinality(importer, Cardinality.C_0__1); } newprops.addPropertyValue(pd.getName(), importer.getObject()); } catch (Exception e) { throw new FatalBeanException("Could not create service reference", e); } } } return newprops; }