List of usage examples for org.springframework.beans.factory.config BeanDefinition getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:uk.org.ponder.rsac.support.BeanDefUtil.java
static String getParentDefinitionName(BeanDefinition bd) { try {/*from w ww. java 2 s.com*/ if (ReflectUtils.hasMethod(bd, "getParentName")) { Method method = bd.getClass().getMethod("getParentName", SAXAccessMethod.emptyclazz); return (String) method.invoke(bd, SAXAccessMethod.emptyobj); } } catch (Exception e) { } return null; }
From source file:uk.org.ponder.rsac.support.BeanDefUtil.java
static AbstractBeanDefinition getMergedBeanDefinition(ConfigurableListableBeanFactory factory, String beanName, BeanDefinition bd) throws BeansException { if (!(bd instanceof AbstractBeanDefinition)) { throw new IllegalArgumentException("Bean definition " + beanName + " of " + bd.getClass() + " which is not descended from AbstractBeanDefinition can not be recognised"); }//from ww w . ja v a 2 s. c o m AbstractBeanDefinition abd = (AbstractBeanDefinition) bd; String parentName = getParentDefinitionName(abd); if (parentName == null) { return abd; } else { AbstractBeanDefinition pbd = null; if (!beanName.equals(parentName)) { pbd = getMergedBeanDefinition(factory, parentName, true); } else { if (factory.getParentBeanFactory() instanceof ConfigurableListableBeanFactory) { ConfigurableListableBeanFactory parentFactory = (ConfigurableListableBeanFactory) factory .getParentBeanFactory(); pbd = getMergedBeanDefinition(parentFactory, parentName, true); } else { throw new NoSuchBeanDefinitionException(parentName, "Parent name '" + parentName + "' is equal to bean name '" + beanName + "' - cannot be resolved without an AbstractBeanFactory parent"); } } // deep copy with overridden values pbd.overrideFrom(abd); return pbd; } }
From source file:org.brekka.stillingar.spring.pc.ConstructorArgDefChangeListener.java
@Override protected void onChange(String newValue) { ConfigurableListableBeanFactory beanFactory = beanFactoryRef.get(); if (beanFactory == null) { return;//from w w w.jav a 2 s.co m } BeanDefinition beanDef = beanFactory.getMergedBeanDefinition(beanName); ConstructorArgumentValues mutableConstructorValues = beanDef.getConstructorArgumentValues(); ValueHolder valueHolder = null; List<ValueHolder> genericArgumentValues = mutableConstructorValues.getGenericArgumentValues(); if (constructorArgIndex != null) { valueHolder = mutableConstructorValues.getIndexedArgumentValues().get(constructorArgIndex); if (valueHolder == null) { throw new IllegalStateException( String.format("Failed to find constructor arg at index %d", constructorArgIndex)); } } else if (genericArgumentValues.size() == 1) { valueHolder = genericArgumentValues.get(0); } else { for (ValueHolder vh : genericArgumentValues) { if (vh.getType().equals(constructorArgType)) { valueHolder = vh; } } if (valueHolder == null) { throw new IllegalStateException( String.format("Failed to find constructor arg with type '%s'", constructorArgType)); } } if (!ObjectUtils.nullSafeEquals(newValue, valueHolder.getValue())) { valueHolder.setValue(newValue); try { /* * Spring implements caching of constructor values, which can be reset by clearing the package-private * field 'resolvedConstructorOrFactoryMethod' on RootBeanDefinition. Naturally this will fail if a * security manager is present but there doesn't seem to be any other way to do it. Make sure to warn * about this in the documentation! */ Field field = beanDef.getClass().getDeclaredField("resolvedConstructorOrFactoryMethod"); field.setAccessible(true); field.set(beanDef, null); } catch (Exception e) { throw new ConfigurationException(String.format( "Unable to update value for constructor argument '%s'. " + "Failed to reset the cached constructor state for bean '%s'", (constructorArgIndex != null ? constructorArgIndex.toString() : constructorArgType), beanName), e); } } }
From source file:org.apache.camel.spring.handler.CamelNamespaceHandler.java
private void addDependsOnToRouteBuilder(Element childElement, ParserContext parserContext, String contextId) { // setting the depends-on explicitly is required since Spring 3.0 String routeBuilderName = childElement.getAttribute("ref"); if (ObjectHelper.isNotEmpty(routeBuilderName)) { // set depends-on to the context for a routeBuilder bean try {// w w w . j a va2s. c o m BeanDefinition definition = parserContext.getRegistry().getBeanDefinition(routeBuilderName); Method getDependsOn = definition.getClass().getMethod("getDependsOn", new Class[] {}); String[] dependsOn = (String[]) getDependsOn.invoke(definition, new Object[] {}); if (dependsOn == null || dependsOn.length == 0) { dependsOn = new String[] { contextId }; } else { String[] temp = new String[dependsOn.length + 1]; System.arraycopy(dependsOn, 0, temp, 0, dependsOn.length); temp[dependsOn.length] = contextId; dependsOn = temp; } Method method = definition.getClass().getMethod("setDependsOn", String[].class); method.invoke(definition, (Object) dependsOn); } catch (Exception e) { // Do nothing here } } }
From source file:org.apache.camel.spring.handler.CamelNamespaceHandler.java
private void registerEndpoint(Element childElement, ParserContext parserContext, String contextId) { String id = childElement.getAttribute("id"); // must have an id to be registered if (ObjectHelper.isNotEmpty(id)) { BeanDefinition definition = endpointParser.parse(childElement, parserContext); definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId)); // Need to add this dependency of CamelContext for Spring 3.0 try {// w w w . j a v a2 s . c om Method method = definition.getClass().getMethod("setDependsOn", String[].class); method.invoke(definition, (Object) new String[] { contextId }); } catch (Exception e) { // Do nothing here } parserContext.registerBeanComponent(new BeanComponentDefinition(definition, id)); } }
From source file:org.directwebremoting.spring.DwrNamespaceHandler.java
/** * Try getting the beanClassName from the definition and if that fails try to get it from * the parent (and even parent BeanFactory if we have to). * @param definition//from w ww .j av a 2 s. c om * @param registry * @return class name or null if not found */ protected static String resolveBeanClassname(BeanDefinition definition, BeanDefinitionRegistry registry) { String beanClassName = definition.getBeanClassName(); while (!StringUtils.hasText(beanClassName)) { try { Method m = definition.getClass().getMethod("getParentName", new Class[0]); String parentName = (String) m.invoke(definition, new Object[0]); BeanDefinition parentDefinition = findParentDefinition(parentName, registry); beanClassName = parentDefinition.getBeanClassName(); definition = parentDefinition; } catch (Exception e) { throw new FatalBeanException("No parent bean could be found for " + definition, e); } } return beanClassName; }