private BeanDefinitionBuilder preInvoke(Element element, Object obj, String method, Object[] args, ParserContext parserContext, boolean factory) { BeanDefinitionBuilder builder = createBeanDefinitionBuilder(element, parserContext, factory ? MethodInvokingFactoryBean.class : BeanMethodInvoker.class); if (obj instanceof Class) { builder.addPropertyValue("staticMethod", ((Class) obj).getName() + "." + method); } else { builder.addPropertyValue("targetMethod", method); } builder.addPropertyValue("arguments", args); if (element != null) { parserContext.getDelegate().parseQualifierElements(element, builder.getRawBeanDefinition()); } return builder; }
@SuppressWarnings("deprecation") @Bean public Object log4jInitializer() { MethodInvokingFactoryBean returnVal = new MethodInvokingFactoryBean(); returnVal .setTargetClass(org.springframework.util.Log4jConfigurer.class); returnVal.setTargetMethod("initLogging"); returnVal.setArguments(new Object[] { propertiesConfig.log4jConfigFile(), Long.valueOf(5000) }); return returnVal; }
@Test public void testAspectsAreApplied() { ClassPathXmlApplicationContext bf = newContext("aspects.xml"); ITestBean tb = (ITestBean) bf.getBean("adrian"); assertEquals(68, tb.getAge()); MethodInvokingFactoryBean factoryBean = (MethodInvokingFactoryBean) bf.getBean("&factoryBean"); assertTrue(AopUtils.isAopProxy(factoryBean.getTargetObject())); assertEquals(68, ((ITestBean) factoryBean.getTargetObject()).getAge()); }
@Bean public MethodInvokingFactoryBean socketFactoryInitialization() { MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean(); methodInvokingFactoryBean.setTargetClass(Protocol.class); methodInvokingFactoryBean.setTargetMethod("registerProtocol"); methodInvokingFactoryBean.setArguments(new Object[]{"https", protocol()}); return methodInvokingFactoryBean; }
@Bean(name = "log4jInitialization") public MethodInvoker log4j() { MethodInvokingFactoryBean methodInvoker = new MethodInvokingFactoryBean(); methodInvoker.setTargetClass(Log4jConfigurer.class); methodInvoker.setTargetMethod("initLogging"); methodInvoker.setArguments(getLog4jArgs()); return methodInvoker; }
@Bean public MethodInvokingFactoryBean setSecurityManager() { MethodInvokingFactoryBean factoryBean = new MethodInvokingFactoryBean(); factoryBean.setStaticMethod("org.apache.shiro.SecurityUtils.setSecurityManager"); factoryBean.setArguments(new Object[] { securityManager() }); return factoryBean; }
@Bean public MethodInvokingFactoryBean socketFactoryInitialization() { MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean(); methodInvokingFactoryBean.setTargetClass(Protocol.class); methodInvokingFactoryBean.setTargetMethod("registerProtocol"); Object[] args = {"https", socketFactoryProtocol()}; methodInvokingFactoryBean.setArguments(args); return methodInvokingFactoryBean; }
@Override protected Class<?> getBeanClass(Element element) { return MethodInvokingFactoryBean.class; }
/** * Registers the specified <code>module</code> to all the loaded modules. * * @param id * the id of the module to be registered * @param module * the <code>module</code> to be registered * * @return <code>true</code> if the <code>module</code> was added, otherwise * <code>false</code> */ protected boolean registerModule(final String id, final Object module) { final Object current; // register the module if (!isModule(id, module)) { if (isAnonymousId(id)) { if (id.contains(MethodInvokingFactoryBean.class.getName()) || id.contains(MethodExecutorBean.class.getName()) || id.contains(net.meisen.general.sbconfigurator.factories.MethodInvokingFactoryBean.class .getName())) { if (LOG.isTraceEnabled()) { LOG.trace("Skipping the bean '" + id + "' as module, because it is an anonymous bean used for MethodInvokation"); } } else if (LOG.isWarnEnabled()) { LOG.warn("Skipping the bean '" + id + "' as module, because it is probably an anonymous bean"); } } else { if (LOG.isTraceEnabled()) { LOG.trace("Skipping the bean '" + id + "' as module"); } } return false; } else if ((current = modules.put(id, module)) != null) { if (LOG.isWarnEnabled() && !Objects.equals(current, module)) { LOG.warn("Overloading the module '" + id + "'"); } return true; } else { if (LOG.isDebugEnabled()) { LOG.debug("Loaded the module '" + id + "' of type '" + module.getClass().getName() + "'"); } return true; } }