List of usage examples for org.springframework.beans FatalBeanException FatalBeanException
public FatalBeanException(String msg, @Nullable Throwable cause)
From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentInstaller.java
private void saveReport(SystemInstallationReport report) throws BeansException { if (null == report || report.getReports().isEmpty()) { return;/* w w w. j a v a 2s . co m*/ } try { InstallationReportDAO dao = new InstallationReportDAO(); DataSource dataSource = (DataSource) this.getBeanFactory().getBean("portDataSource"); dao.setDataSource(dataSource); dao.saveConfigItem(report.toXml(), "production"/*this.getConfigVersion()*/); } catch (Throwable t) { _logger.error("Error saving report", t); throw new FatalBeanException("Error saving report", t); } }
From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentUninstaller.java
private void saveReport(SystemInstallationReport report) throws BeansException { if (null == report || report.getReports().isEmpty()) { return;/* w w w . j a va 2 s .c o m*/ } try { InstallationReportDAO dao = new InstallationReportDAO(); DataSource dataSource = (DataSource) this.getBeanFactory().getBean("portDataSource"); dao.setDataSource(dataSource); dao.saveConfigItem(report.toXml(), this.getConfigVersion()); } catch (Throwable t) { _logger.error("Error saving report", t); throw new FatalBeanException("Error saving report", t); } }
From source file:org.grails.beans.support.CachedIntrospectionResults.java
/** * Create a new CachedIntrospectionResults instance for the given class. * @param beanClass the bean class to analyze * @throws BeansException in case of introspection failure *//* w ww. j a v a2s .c om*/ private CachedIntrospectionResults(Class<?> beanClass) throws BeansException { try { BeanInfo beanInfo = new ExtendedBeanInfo(Introspector.getBeanInfo(beanClass)); if (beanInfo == null) { // If none of the factories supported the class, fall back to the default beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses ? Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) : Introspector.getBeanInfo(beanClass)); } this.beanInfo = beanInfo; this.propertyDescriptorCache = new LinkedHashMap<String, PropertyDescriptor>(); // This call is slow so we do it once. PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { if (Class.class.equals(beanClass) && ("classLoader".equals(pd.getName()) || "protectionDomain".equals(pd.getName()))) { // Ignore Class.getClassLoader() and getProtectionDomain() methods - nobody needs to bind to those continue; } pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd); this.propertyDescriptorCache.put(pd.getName(), pd); } this.typeDescriptorCache = new ConcurrentReferenceHashMap<PropertyDescriptor, TypeDescriptor>(); } catch (IntrospectionException ex) { throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex); } }
From source file:org.hopen.framework.rewrite.CachedIntrospectionResults.java
/** * Create a new CachedIntrospectionResults instance for the given class. * @param beanClass the bean class to analyze * @throws BeansException in case of introspection failure *///www. j a v a 2 s . c om private CachedIntrospectionResults(Class beanClass, boolean cacheFullMetadata) throws BeansException { try { if (logger.isTraceEnabled()) { logger.trace("Getting BeanInfo for class [" + beanClass.getName() + "]"); } BeanInfo beanInfo = null; for (BeanInfoFactory beanInfoFactory : beanInfoFactories) { beanInfo = beanInfoFactory.getBeanInfo(beanClass); if (beanInfo != null) { break; } } if (beanInfo == null) { // If none of the factories supported the class, fall back to the default beanInfo = Introspector.getBeanInfo(beanClass); } this.beanInfo = beanInfo; // Immediately remove class from Introspector cache, to allow for proper // garbage collection on class loader shutdown - we cache it here anyway, // in a GC-friendly manner. In contrast to CachedIntrospectionResults, // Introspector does not use WeakReferences as values of its WeakHashMap! Class classToFlush = beanClass; do { Introspector.flushFromCaches(classToFlush); classToFlush = classToFlush.getSuperclass(); } while (classToFlush != null); if (logger.isTraceEnabled()) { logger.trace("Caching PropertyDescriptors for class [" + beanClass.getName() + "]"); } this.propertyDescriptorCache = new LinkedHashMap<String, PropertyDescriptor>(); // This call is slow so we do it once. PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { if (Class.class.equals(beanClass) && "classLoader".equals(pd.getName())) { // Ignore Class.getClassLoader() method - nobody needs to bind to that continue; } if (logger.isTraceEnabled()) { logger.trace("Found bean property '" + pd.getName() + "'" + (pd.getPropertyType() != null ? " of type [" + pd.getPropertyType().getName() + "]" : "") + (pd.getPropertyEditorClass() != null ? "; editor [" + pd.getPropertyEditorClass().getName() + "]" : "")); } if (cacheFullMetadata) { pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd); } this.propertyDescriptorCache.put(pd.getName(), pd); } } catch (IntrospectionException ex) { throw new FatalBeanException("Failed to obtain BeanInfo for class [" + beanClass.getName() + "]", ex); } }
From source file:org.hopen.framework.rewrite.CachedIntrospectionResults.java
private PropertyDescriptor buildGenericTypeAwarePropertyDescriptor(Class beanClass, PropertyDescriptor pd) { try {/*from w w w . j av a2s.c o m*/ return new GenericTypeAwarePropertyDescriptor(beanClass, pd.getName(), pd.getReadMethod(), pd.getWriteMethod(), pd.getPropertyEditorClass()); } catch (IntrospectionException ex) { throw new FatalBeanException("Failed to re-introspect class [" + beanClass.getName() + "]", ex); } }
From source file:org.jsecurity.spring.LifecycleBeanPostProcessor.java
/** * Calls the <tt>init()</tt> methods on the bean if it implements {@link org.jsecurity.util.Initializable} * * @param object the object being initialized. * @param name the name of the bean being initialized. * @return the initialized bean.// w ww . j a va2 s . c om * @throws BeansException if any exception is thrown during initialization. */ public Object postProcessBeforeInitialization(Object object, String name) throws BeansException { if (object instanceof Initializable) { try { if (log.isDebugEnabled()) { log.debug("Initializing bean [" + name + "]..."); } ((Initializable) object).init(); } catch (Exception e) { throw new FatalBeanException("Error initializing bean [" + name + "]", e); } } return object; }
From source file:org.jsecurity.spring.LifecycleBeanPostProcessor.java
/** * Calls the <tt>destroy()</tt> methods on the bean if it implements {@link org.jsecurity.util.Destroyable} * * @param object the object being initialized. * @param name the name of the bean being initialized. * @throws BeansException if any exception is thrown during initialization. *//*from w w w . ja v a2s . c om*/ public void postProcessBeforeDestruction(Object object, String name) throws BeansException { if (object instanceof Destroyable) { try { if (log.isDebugEnabled()) { log.debug("Destroying bean [" + name + "]..."); } ((Destroyable) object).destroy(); } catch (Exception e) { throw new FatalBeanException("Error destroying bean [" + name + "]", e); } } }
From source file:org.nextframework.controller.CachedIntrospectionResults.java
/** * Create new CachedIntrospectionResults instance fot the given class. *///from ww w. ja va2s. c om @SuppressWarnings("unchecked") private CachedIntrospectionResults(Class clazz) throws BeansException { try { if (logger.isDebugEnabled()) { logger.debug("Getting BeanInfo for class [" + clazz.getName() + "]"); } this.beanInfo = Introspector.getBeanInfo(clazz); // Immediately remove class from Introspector cache, to allow for proper // garbage collection on class loader shutdown - we cache it here anyway, // in a GC-friendly manner. In contrast to CachedIntrospectionResults, // Introspector does not use WeakReferences as values of its WeakHashMap! Class classToFlush = clazz; do { Introspector.flushFromCaches(classToFlush); classToFlush = classToFlush.getSuperclass(); } while (classToFlush != null); if (logger.isDebugEnabled()) { logger.debug("Caching PropertyDescriptors for class [" + clazz.getName() + "]"); } this.propertyDescriptorCache = new HashMap(); // This call is slow so we do it once. PropertyDescriptor[] pds = this.beanInfo.getPropertyDescriptors(); for (int i = 0; i < pds.length; i++) { if (logger.isDebugEnabled()) { logger.debug("Found property '" + pds[i].getName() + "'" + (pds[i].getPropertyType() != null ? " of type [" + pds[i].getPropertyType().getName() + "]" : "") + (pds[i].getPropertyEditorClass() != null ? "; editor [" + pds[i].getPropertyEditorClass().getName() + "]" : "")); } // Set methods accessible if declaring class is not public, for example // in case of package-protected base classes that define bean properties. Method readMethod = pds[i].getReadMethod(); if (readMethod != null && !Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { readMethod.setAccessible(true); } Method writeMethod = pds[i].getWriteMethod(); if (writeMethod != null && !Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) { writeMethod.setAccessible(true); } this.propertyDescriptorCache.put(pds[i].getName(), pds[i]); } } catch (IntrospectionException ex) { throw new FatalBeanException("Cannot get BeanInfo for object of class [" + clazz.getName() + "]", ex); } }
From source file:org.springbyexample.util.log.LoggerBeanPostProcessor.java
/** * Instantiates bean specific loggers and sets them. *//* ww w .ja v a 2s . c o m*/ protected void processLogger(final Object bean, final String methodName) { final Class<?> clazz = bean.getClass(); ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() { public void doWith(Method method) { if (method.getName().equals(methodName)) { try { injectMethod(bean, method); } catch (Throwable e) { throw new FatalBeanException("Problem injecting logger. " + e.getMessage(), e); } } } }); }
From source file:org.springbyexample.util.log.LoggerBeanPostProcessor.java
/** * Processes a property descriptor to inject a logger. *//*from w w w. j a v a2 s . c o m*/ public void injectMethod(Object bean, Method method) { PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method); if (pd != null) { String canonicalName = pd.getPropertyType().getCanonicalName(); Object logger = getLogger(bean.getClass().getName(), canonicalName); if (logger != null) { try { pd.getWriteMethod().invoke(bean, new Object[] { logger }); } catch (Throwable e) { throw new FatalBeanException("Problem injecting logger. " + e.getMessage(), e); } } } }