List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory autowire
Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;
From source file:org.hbird.business.configurator.ConfiguratorComponentDriver.java
/** * Request to start a component.//w w w .j a va2s. co m * * @param command The start component request * @param context The camel context in which the component is running. * @throws Exception */ public synchronized void startComponent(@Body StartComponent command, CamelContext context) throws Exception { IStartableEntity entity = command.getEntity(); String id = entity.getID(); String name = entity.getName(); String driverName = entity.getDriverName(); entity.setContext(context); LOG.info( "Received start request for IStartableEntity ID: '{}', name: '{}'. Will use driver '{}' and CamelContex '{}'.", new Object[] { id, name, driverName, context.getName() }); if (components.containsKey(id)) { LOG.error("Received second request for start of the same IStartableEntity - '{}'.", id); } else { /* Find the component builder and get it to setup and start the component. */ if (driverName == null) { LOG.error("Cannot start IStartableEntity '{}'. No driver set.", id); } else { try { AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory(); SoftwareComponentDriver<?> builder = (SoftwareComponentDriver<?>) factory.autowire( Class.forName(driverName), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false); builder.setCommand(command); builder.setContext((ModelCamelContext) context); context.addRoutes(builder); /* Register component in list of components maintained by this configurator. */ components.put(id, builder.getRouteCollection()); context.createProducerTemplate().asyncSendBody(ENDPOINT_TO_EVENTS, createStartEvent(this.entity.getID(), id)); } catch (Exception e) { LOG.error("Failed to start IStartableEntity '{}'", id, e); } } } }
From source file:com.meidusa.venus.frontend.http.VenusPoolFactory.java
@SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { logger.trace("current Venus Client id=" + PacketConstant.VENUS_CLIENT_ID); beanContext = new BeanContext() { public Object getBean(String beanName) { if (beanFactory != null) { return beanFactory.getBean(beanName); } else { return null; }//w w w . ja v a 2 s . c o m } public Object createBean(Class clazz) throws Exception { if (beanFactory instanceof AutowireCapableBeanFactory) { AutowireCapableBeanFactory factory = (AutowireCapableBeanFactory) beanFactory; return factory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); } return null; } }; BeanContextBean.getInstance().setBeanContext(beanContext); VenusBeanUtilsBean.setInstance(new BeanUtilsBean(new ConvertUtilsBean(), new PropertyUtilsBean()) { public void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException { if (value instanceof String) { PropertyDescriptor descriptor = null; try { descriptor = getPropertyUtils().getPropertyDescriptor(bean, name); if (descriptor == null) { return; // Skip this property setter } else { if (descriptor.getPropertyType().isEnum()) { Class<Enum> clazz = (Class<Enum>) descriptor.getPropertyType(); value = Enum.valueOf(clazz, (String) value); } else { Object temp = null; try { temp = ConfigUtil.filter((String) value, beanContext); } catch (Exception e) { } if (temp == null) { temp = ConfigUtil.filter((String) value); } value = temp; } } } catch (NoSuchMethodException e) { return; // Skip this property setter } } super.setProperty(bean, name, value); } }); reloadConfiguration(); __RELOAD: { if (enableReload) { File[] files = new File[this.configFiles.length]; for (int i = 0; i < this.configFiles.length; i++) { try { files[i] = ResourceUtils.getFile(configFiles[i].trim()); } catch (FileNotFoundException e) { logger.warn(e.getMessage()); enableReload = false; logger.warn("venus serviceFactory configuration reload disabled!"); break __RELOAD; } } VenusFileWatchdog dog = new VenusFileWatchdog(files); dog.setDelay(1000 * 10); dog.start(); } } }
From source file:com.jeroensteenbeeke.hyperion.events.DefaultEventDispatcher.java
@SuppressWarnings("unchecked") @Override// ww w . j a v a 2 s.c om public void dispatchEvent(@Nonnull Event<?> event) { AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory(); List<Event<?>> queue = Lists.<Event<?>>newArrayList(event); while (!queue.isEmpty()) { Event<?> evt = queue.remove(0); for (Class<? extends EventHandler<?>> eventHandler : handlers .get((Class<? extends Event<?>>) evt.getClass())) { EventHandler<Event<?>> handler = (EventHandler<Event<?>>) factory.autowire(eventHandler, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); EventResult result = handler.onEvent(evt); if (result.isAbort()) { throw new RuntimeException(String.format("Handler %s aborted event %s with message: %s", handler, evt, result.getMessage())); } queue.addAll(result.getTriggeredEvents()); } } }