List of usage examples for org.springframework.beans.factory.support GenericBeanDefinition setInitMethodName
@Override public void setInitMethodName(@Nullable String initMethodName)
From source file:org.jdal.beans.DefaultsBeanDefinitionParser.java
/** * @param clazz//from w w w . j a va2 s .c o m * @return */ @SuppressWarnings("rawtypes") private BeanDefinitionHolder createBeanDefinition(Class clazz, ParserContext parserContext) { GenericBeanDefinition gbd = new GenericBeanDefinition(); gbd.setBeanClass(clazz); gbd.setInitMethodName(INIT_METHOD_NAME); BeanDefinitionHolder holder = new BeanDefinitionHolder(gbd, parserContext.getReaderContext().generateBeanName(gbd)); return holder; }
From source file:com.dianping.avatar.cache.spring.CacheBeanDefinitionParser.java
/** * @param parserContext// ww w. j a v a 2 s . c om * @param serviceName TODO * @param serviceInterface TODO */ private void registerCacheWebService(BeanDefinitionRegistry beanDefinitionRegistry, String beanName, String serviceName, String serviceInterface, boolean isOneWay) { GenericBeanDefinition definition = new GenericBeanDefinition(); definition.setBeanClassName("com.dianping.dpsf.spring.ProxyBeanFactory"); definition.setLazyInit(true); definition.setInitMethodName("init"); MutablePropertyValues propertyValues = definition.getPropertyValues(); propertyValues.addPropertyValue("serviceName", serviceName); propertyValues.addPropertyValue("iface", serviceInterface); propertyValues.addPropertyValue("serialize", "hessian"); propertyValues.addPropertyValue("callMethod", isOneWay ? "oneway" : "sync"); propertyValues.addPropertyValue("timeout", "10000"); propertyValues.addPropertyValue("hosts", getRemoteService()); BeanDefinitionReaderUtils.registerBeanDefinition(new BeanDefinitionHolder(definition, beanName), beanDefinitionRegistry); }
From source file:org.romaz.spring.scripting.ext.ExtScriptBeanDefinitionParser.java
/** * Parses the dynamic object element and returns the resulting bean definition. * Registers a {@link ScriptFactoryPostProcessor} if needed. *///from ww w . j a v a2 s .com @Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { // Resolve the script source. String value = resolveScriptSource(element, parserContext.getReaderContext()); if (value == null) { return null; } // Set up infrastructure. LangNamespaceUtils.registerScriptFactoryPostProcessorIfNecessary(parserContext.getRegistry()); // Create script factory bean definition. GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClassName(this.scriptFactoryClassName); bd.setSource(parserContext.extractSource(element)); // Determine bean scope. String scope = element.getAttribute(SCOPE_ATTRIBUTE); if (StringUtils.hasLength(scope)) { bd.setScope(scope); } // Determine autowire mode. String autowire = element.getAttribute(AUTOWIRE_ATTRIBUTE); int autowireMode = parserContext.getDelegate().getAutowireMode(autowire); // Only "byType" and "byName" supported, but maybe other default inherited... if (autowireMode == GenericBeanDefinition.AUTOWIRE_AUTODETECT) { autowireMode = GenericBeanDefinition.AUTOWIRE_BY_TYPE; } else if (autowireMode == GenericBeanDefinition.AUTOWIRE_CONSTRUCTOR) { autowireMode = GenericBeanDefinition.AUTOWIRE_NO; } bd.setAutowireMode(autowireMode); // Determine dependency check setting. String dependencyCheck = element.getAttribute(DEPENDENCY_CHECK_ATTRIBUTE); bd.setDependencyCheck(parserContext.getDelegate().getDependencyCheck(dependencyCheck)); // Retrieve the defaults for bean definitions within this parser context BeanDefinitionDefaults beanDefinitionDefaults = parserContext.getDelegate().getBeanDefinitionDefaults(); // Determine init method and destroy method. String initMethod = element.getAttribute(INIT_METHOD_ATTRIBUTE); if (StringUtils.hasLength(initMethod)) { bd.setInitMethodName(initMethod); } else if (beanDefinitionDefaults.getInitMethodName() != null) { bd.setInitMethodName(beanDefinitionDefaults.getInitMethodName()); } String destroyMethod = element.getAttribute(DESTROY_METHOD_ATTRIBUTE); if (StringUtils.hasLength(destroyMethod)) { bd.setDestroyMethodName(destroyMethod); } else if (beanDefinitionDefaults.getDestroyMethodName() != null) { bd.setDestroyMethodName(beanDefinitionDefaults.getDestroyMethodName()); } // Attach any refresh metadata. String refreshCheckDelay = element.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE); if (StringUtils.hasText(refreshCheckDelay)) { bd.setAttribute(ScriptFactoryPostProcessor.REFRESH_CHECK_DELAY_ATTRIBUTE, new Long(refreshCheckDelay)); } // Add constructor arguments. ConstructorArgumentValues cav = bd.getConstructorArgumentValues(); int constructorArgNum = 0; cav.addIndexedArgumentValue(constructorArgNum++, value); if (element.hasAttribute(SCRIPT_INTERFACES_ATTRIBUTE)) { cav.addIndexedArgumentValue(constructorArgNum++, element.getAttribute(SCRIPT_INTERFACES_ATTRIBUTE)); } if (element.hasAttribute(SCRIPT_CONFIG_ATTRIBUTE)) { cav.addIndexedArgumentValue(constructorArgNum++, new RuntimeBeanReference(element.getAttribute(SCRIPT_CONFIG_ATTRIBUTE))); } // Add any property definitions that need adding. parserContext.getDelegate().parsePropertyElements(element, bd); return bd; }