org.springframework.beans.factory.support.ManagedList Java Examples

The following examples show how to use org.springframework.beans.factory.support.ManagedList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ManagedList<?> getCallableInterceptors(
		Element element, @Nullable Object source, ParserContext context) {

	ManagedList<Object> interceptors = new ManagedList<>();
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	if (asyncElement != null) {
		Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "callable-interceptors");
		if (interceptorsElement != null) {
			interceptors.setSource(source);
			for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
				BeanDefinitionHolder beanDef = context.getDelegate().parseBeanDefinitionElement(converter);
				if (beanDef != null) {
					beanDef = context.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
					interceptors.add(beanDef);
				}
			}
		}
	}
	return interceptors;
}
 
Example #2
Source File: ViewResolversBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private BeanDefinition createContentNegotiatingViewResolver(Element resolverElement, ParserContext context) {
	RootBeanDefinition beanDef = new RootBeanDefinition(ContentNegotiatingViewResolver.class);
	beanDef.setSource(context.extractSource(resolverElement));
	beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	MutablePropertyValues values = beanDef.getPropertyValues();

	List<Element> elements = DomUtils.getChildElementsByTagName(resolverElement, "default-views");
	if (!elements.isEmpty()) {
		ManagedList<Object> list = new ManagedList<>();
		for (Element element : DomUtils.getChildElementsByTagName(elements.get(0), "bean", "ref")) {
			list.add(context.getDelegate().parsePropertySubElement(element, null));
		}
		values.add("defaultViews", list);
	}
	if (resolverElement.hasAttribute("use-not-acceptable")) {
		values.add("useNotAcceptableStatusCode", resolverElement.getAttribute("use-not-acceptable"));
	}
	Object manager = MvcNamespaceUtils.getContentNegotiationManager(context);
	if (manager != null) {
		values.add("contentNegotiationManager", manager);
	}
	return beanDef;
}
 
Example #3
Source File: DictionaryBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Iterates through the list values and calls helpers to process the value
 *
 * @param listVal the list to process
 * @param propertyName name of the property which has the list value
 * @param nestedBeanStack stack of bean containers which contains the list property
 */
protected void visitList(List<?> listVal, String propertyName, Stack<BeanDefinitionHolder> nestedBeanStack) {
    boolean isMergeEnabled = false;
    if (listVal instanceof ManagedList) {
        isMergeEnabled = ((ManagedList) listVal).isMergeEnabled();
    }

    ManagedList newList = new ManagedList();
    newList.setMergeEnabled(isMergeEnabled);

    for (int i = 0; i < listVal.size(); i++) {
        Object elem = listVal.get(i);

        if (isStringValue(elem)) {
            elem = processListStringPropertyValue(propertyName, listVal, getString(elem), i, nestedBeanStack,
                    beanProcessors);
        } else {
            elem = visitPropertyValue(propertyName, elem, nestedBeanStack);
        }

        newList.add(i, elem);
    }

    listVal.clear();
    listVal.addAll(newList);
}
 
Example #4
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private ManagedList<?> getCallableInterceptors(
		Element element, @Nullable Object source, ParserContext context) {

	ManagedList<Object> interceptors = new ManagedList<>();
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	if (asyncElement != null) {
		Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "callable-interceptors");
		if (interceptorsElement != null) {
			interceptors.setSource(source);
			for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
				BeanDefinitionHolder beanDef = context.getDelegate().parseBeanDefinitionElement(converter);
				if (beanDef != null) {
					beanDef = context.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
					interceptors.add(beanDef);
				}
			}
		}
	}
	return interceptors;
}
 
Example #5
Source File: ResourcesBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void parseResourceChain(
		RootBeanDefinition resourceHandlerDef, ParserContext context, Element element, @Nullable Object source) {

	String autoRegistration = element.getAttribute("auto-registration");
	boolean isAutoRegistration = !(StringUtils.hasText(autoRegistration) && "false".equals(autoRegistration));

	ManagedList<Object> resourceResolvers = new ManagedList<>();
	resourceResolvers.setSource(source);
	ManagedList<Object> resourceTransformers = new ManagedList<>();
	resourceTransformers.setSource(source);

	parseResourceCache(resourceResolvers, resourceTransformers, element, source);
	parseResourceResolversTransformers(
			isAutoRegistration, resourceResolvers, resourceTransformers, context, element, source);

	if (!resourceResolvers.isEmpty()) {
		resourceHandlerDef.getPropertyValues().add("resourceResolvers", resourceResolvers);
	}
	if (!resourceTransformers.isEmpty()) {
		resourceHandlerDef.getPropertyValues().add("resourceTransformers", resourceTransformers);
	}
}
 
Example #6
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Register default TablePanel Actions
 * @param element current element
 * @param parserContext parserContext
 * @return a new ComponentDefinition with default table action list.
 */
private ComponentDefinition registerDefaultTableActions(Element element, ParserContext parserContext) {
	ManagedList<Object> actions = new ManagedList<Object>(7);
	actions.add(createBeanDefinition(AddAction.class, parserContext));
	actions.add(createBeanDefinition(RefreshAction.class, parserContext));
	actions.add(createBeanDefinition(RemoveAction.class, parserContext));
	actions.add(createBeanDefinition(FindAction.class, parserContext));
	actions.add(createBeanDefinition(ClearFilterAction.class, parserContext));
	
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(ListFactoryBean.class);
	bdb.getRawBeanDefinition().setSource(parserContext.extractSource(element));
	bdb.addPropertyValue("sourceList", actions);
	bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), 
			DEFAULT_TABLE_ACTIONS);
	registerBeanComponentDefinition(element, parserContext, bcd);
	return bcd;
}
 
Example #7
Source File: GroovyBeanDefinitionReader.java    From blog_demos with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether there are any {@link RuntimeBeanReference}s inside the List
 * and converts it to a ManagedList if necessary.
 * @param list the original List
 * @return either the original list or a managed copy of it
 */
private Object manageListIfNecessary(List<?> list) {
	boolean containsRuntimeRefs = false;
	for (Object element : list) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		List<Object> managedList = new ManagedList<Object>();
		managedList.addAll(list);
		return managedList;
	}
	return list;
}
 
Example #8
Source File: AspectJAutoProxyBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) {
	ManagedList<TypedStringValue> includePatterns = new ManagedList<>();
	NodeList childNodes = element.getChildNodes();
	for (int i = 0; i < childNodes.getLength(); i++) {
		Node node = childNodes.item(i);
		if (node instanceof Element) {
			Element includeElement = (Element) node;
			TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name"));
			valueHolder.setSource(parserContext.extractSource(includeElement));
			includePatterns.add(valueHolder);
		}
	}
	if (!includePatterns.isEmpty()) {
		includePatterns.setSource(parserContext.extractSource(element));
		beanDef.getPropertyValues().add("includePatterns", includePatterns);
	}
}
 
Example #9
Source File: AspectJAutoProxyBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) {
	ManagedList<TypedStringValue> includePatterns = new ManagedList<TypedStringValue>();
	NodeList childNodes = element.getChildNodes();
	for (int i = 0; i < childNodes.getLength(); i++) {
		Node node = childNodes.item(i);
		if (node instanceof Element) {
			Element includeElement = (Element) node;
			TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name"));
			valueHolder.setSource(parserContext.extractSource(includeElement));
			includePatterns.add(valueHolder);
		}
	}
	if (!includePatterns.isEmpty()) {
		includePatterns.setSource(parserContext.extractSource(element));
		beanDef.getPropertyValues().add("includePatterns", includePatterns);
	}
}
 
Example #10
Source File: GroovyBeanDefinitionReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Checks whether there are any {@link RuntimeBeanReference RuntimeBeanReferences}
 * inside the {@link List} and converts it to a {@link ManagedList} if necessary.
 * @param list the original List
 * @return either the original list or a managed copy of it
 */
private Object manageListIfNecessary(List<?> list) {
	boolean containsRuntimeRefs = false;
	for (Object element : list) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		List<Object> managedList = new ManagedList<>();
		managedList.addAll(list);
		return managedList;
	}
	return list;
}
 
Example #11
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPrototypeWithArrayConversionForConstructor() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	List<String> list = new ManagedList<>();
	list.add("myName");
	list.add("myBeanName");
	RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bd.getConstructorArgumentValues().addGenericArgumentValue(list);
	lbf.registerBeanDefinition("test", bd);
	DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
	assertEquals("myName", tb.getName());
	assertEquals("myBeanName", tb.getBeanName());
	DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
	assertTrue(tb != tb2);
	assertEquals("myName", tb2.getName());
	assertEquals("myBeanName", tb2.getBeanName());
}
 
Example #12
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testPrototypeWithArrayConversionForFactoryMethod() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	List<String> list = new ManagedList<>();
	list.add("myName");
	list.add("myBeanName");
	RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bd.setFactoryMethodName("create");
	bd.getConstructorArgumentValues().addGenericArgumentValue(list);
	lbf.registerBeanDefinition("test", bd);
	DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
	assertEquals("myName", tb.getName());
	assertEquals("myBeanName", tb.getBeanName());
	DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
	assertTrue(tb != tb2);
	assertEquals("myName", tb2.getName());
	assertEquals("myBeanName", tb2.getBeanName());
}
 
Example #13
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testPrototypeWithArrayConversionForFactoryMethod() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	List<String> list = new ManagedList<String>();
	list.add("myName");
	list.add("myBeanName");
	RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
	bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bd.setFactoryMethodName("create");
	bd.getConstructorArgumentValues().addGenericArgumentValue(list);
	lbf.registerBeanDefinition("test", bd);
	DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
	assertEquals("myName", tb.getName());
	assertEquals("myBeanName", tb.getBeanName());
	DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
	assertTrue(tb != tb2);
	assertEquals("myName", tb2.getName());
	assertEquals("myBeanName", tb2.getBeanName());
}
 
Example #14
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private ManagedList<?> getCallableInterceptors(Element element, Object source, ParserContext parserContext) {
	ManagedList<? super Object> interceptors = new ManagedList<Object>();
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	if (asyncElement != null) {
		Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "callable-interceptors");
		if (interceptorsElement != null) {
			interceptors.setSource(source);
			for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
				BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(converter);
				beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
				interceptors.add(beanDef);
			}
		}
	}
	return interceptors;
}
 
Example #15
Source File: ResourcesBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void parseResourceChain(
		RootBeanDefinition resourceHandlerDef, ParserContext context, Element element, @Nullable Object source) {

	String autoRegistration = element.getAttribute("auto-registration");
	boolean isAutoRegistration = !(StringUtils.hasText(autoRegistration) && "false".equals(autoRegistration));

	ManagedList<Object> resourceResolvers = new ManagedList<>();
	resourceResolvers.setSource(source);
	ManagedList<Object> resourceTransformers = new ManagedList<>();
	resourceTransformers.setSource(source);

	parseResourceCache(resourceResolvers, resourceTransformers, element, source);
	parseResourceResolversTransformers(
			isAutoRegistration, resourceResolvers, resourceTransformers, context, element, source);

	if (!resourceResolvers.isEmpty()) {
		resourceHandlerDef.getPropertyValues().add("resourceResolvers", resourceResolvers);
	}
	if (!resourceTransformers.isEmpty()) {
		resourceHandlerDef.getPropertyValues().add("resourceTransformers", resourceTransformers);
	}
}
 
Example #16
Source File: ShardingJdbcDataSourceBeanDefinitionParser.java    From sharding-jdbc-1.5.1 with Apache License 2.0 6 votes vote down vote up
private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
//        获取到这个binding-table-rules节点对象
        Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
        if (null == bindingTableRulesElement) {
            return Collections.emptyList();
        }
//        获取子节点binding-table-rule的节点对象
        List<Element> bindingTableRuleElements = DomUtils.getChildElementsByTagName(bindingTableRulesElement, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULE_TAG);
//        初始化BindingTableRuleConfig对象
        BeanDefinitionBuilder bindingTableRuleFactory = BeanDefinitionBuilder.rootBeanDefinition(BindingTableRuleConfig.class);
        List<BeanDefinition> result = new ManagedList<>(bindingTableRuleElements.size());
        for (Element bindingTableRuleElement : bindingTableRuleElements) {
//            解析logic-tables节点并对BindingTableRuleConfig对象的tableNames属性赋值
            bindingTableRuleFactory.addPropertyValue("tableNames", bindingTableRuleElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLES_ATTRIBUTE));
            result.add(bindingTableRuleFactory.getBeanDefinition());
        }
        return result;
    }
 
Example #17
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ManagedList<?> getDeferredResultInterceptors(
		Element element, @Nullable Object source, ParserContext context) {

	ManagedList<Object> interceptors = new ManagedList<>();
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	if (asyncElement != null) {
		Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "deferred-result-interceptors");
		if (interceptorsElement != null) {
			interceptors.setSource(source);
			for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
				BeanDefinitionHolder beanDef = context.getDelegate().parseBeanDefinitionElement(converter);
				if (beanDef != null) {
					beanDef = context.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
					interceptors.add(beanDef);
				}
			}
		}
	}
	return interceptors;
}
 
Example #18
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Assert.notNull(className, "No resolver class");
			Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
			if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
				RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
				adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
				result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
				continue;
			}
		}
		result.add(object);
	}
	return result;
}
 
Example #19
Source File: Jaxb2MarshallerBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
	String contextPath = element.getAttribute("context-path");
	if (StringUtils.hasText(contextPath)) {
		beanDefinitionBuilder.addPropertyValue("contextPath", contextPath);
	}

	List<Element> classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound");
	if (!classes.isEmpty()) {
		ManagedList<String> classesToBeBound = new ManagedList<>(classes.size());
		for (Element classToBeBound : classes) {
			String className = classToBeBound.getAttribute("name");
			classesToBeBound.add(className);
		}
		beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound);
	}
}
 
Example #20
Source File: GroovyBeanDefinitionReader.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Checks whether there are any {@link RuntimeBeanReference RuntimeBeanReferences}
 * inside the {@link List} and converts it to a {@link ManagedList} if necessary.
 * @param list the original List
 * @return either the original list or a managed copy of it
 */
private Object manageListIfNecessary(List<?> list) {
	boolean containsRuntimeRefs = false;
	for (Object element : list) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		List<Object> managedList = new ManagedList<>();
		managedList.addAll(list);
		return managedList;
	}
	return list;
}
 
Example #21
Source File: AbstractInterfaceBeanDefinitionParser.java    From joyrpc with Apache License 2.0 6 votes vote down vote up
@Override
public void parse(final BeanDefinition definition, final String id, final Element element, final String name,
                  final ParserContext context) {
    NodeList nodes = element.getChildNodes();
    if (nodes != null && nodes.getLength() > 0) {
        ManagedList methods = new ManagedList();
        Node node;
        String methodName;
        MethodBeanDefinitionParser parser = new MethodBeanDefinitionParser();
        for (int i = 0; i < nodes.getLength(); i++) {
            node = nodes.item(i);
            if (node instanceof Element && (METHOD.equals(node.getNodeName()) || METHOD.equals(node.getLocalName()))) {
                methodName = ((Element) node).getAttribute("name");
                if (isEmpty(methodName)) {
                    throw new IllegalStateException("method name attribute == null");
                }
                methods.add(new BeanDefinitionHolder(
                        parser.parse(((Element) node), context), id + "." + methodName));
            }
        }
        if (!methods.isEmpty()) {
            definition.getPropertyValues().addPropertyValue(name, methods);
        }
    }
}
 
Example #22
Source File: DatasourceBeanDefinitionParser.java    From compass with Apache License 2.0 6 votes vote down vote up
private void parseSlaveDataSources(
		List<Element> slaveElements,
		BeanDefinitionBuilder masterSlaveDataSourceBeanDefinitionBuilder,
		ParserContext parserContext,
		String masterSlaveDataSourceId,
		String dataSourcePrototypeAttributeValue)
{
	ManagedList<AbstractBeanDefinition> slaveBeanDefinitions = new ManagedList<AbstractBeanDefinition>(slaveElements.size()); 
	int index=0;
	for (Element slaveElement : slaveElements) 
	{
		index++;
		AbstractBeanDefinition slaveBeanDefinition=this.createSlaveBeanDefinition(
				index, 
				slaveElement, 
				masterSlaveDataSourceId, 
				dataSourcePrototypeAttributeValue, 
				parserContext);
		
		slaveBeanDefinitions.add(slaveBeanDefinition);
		
	}
	
	masterSlaveDataSourceBeanDefinitionBuilder.addPropertyValue(MasterSlaveDataSource.SLAVE_DATA_SOURCES_PROPERTY_NAME, slaveBeanDefinitions);
}
 
Example #23
Source File: ContextDependencyLister.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void addRefIfNeeded(Object v, List<String> refs) {
         if(v == null) return;
         
         if(v instanceof RuntimeBeanReference) {
            RuntimeBeanReference r = (RuntimeBeanReference)v;
            String name = r.getBeanName();
            
            addRefIfNeeded(name, refs);
            
            if(name == null || name.length() == 0) {
               System.err.println("Warning - empty reference " + r);
            }
         } else if(v instanceof BeanDefinitionHolder) {
            // Nested bean definition
            BeanDefinitionHolder bdh = (BeanDefinitionHolder)v;
            processBeanDefinition(bdh.getBeanName(), bdh.getBeanDefinition());
         } else if(v instanceof ManagedList<?>) {
            ManagedList<?> ml = (ManagedList<?>)v;
            for(Object le : ml) {
               addRefIfNeeded(le, refs);
            }
//       } else {
//          System.err.println(v.getClass());
         }
      }
 
Example #24
Source File: ViewResolversBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private BeanDefinition createContentNegotiatingViewResolver(Element resolverElement, ParserContext context) {
	RootBeanDefinition beanDef = new RootBeanDefinition(ContentNegotiatingViewResolver.class);
	beanDef.setSource(context.extractSource(resolverElement));
	beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	MutablePropertyValues values = beanDef.getPropertyValues();

	List<Element> elements = DomUtils.getChildElementsByTagName(resolverElement, new String[] {"default-views"});
	if (!elements.isEmpty()) {
		ManagedList<Object> list = new ManagedList<Object>();
		for (Element element : DomUtils.getChildElementsByTagName(elements.get(0), "bean", "ref")) {
			list.add(context.getDelegate().parsePropertySubElement(element, null));
		}
		values.add("defaultViews", list);
	}
	if (resolverElement.hasAttribute("use-not-acceptable")) {
		values.add("useNotAcceptableStatusCode", resolverElement.getAttribute("use-not-acceptable"));
	}
	Object manager = MvcNamespaceUtils.getContentNegotiationManager(context);
	if (manager != null) {
		values.add("contentNegotiationManager", manager);
	}
	return beanDef;
}
 
Example #25
Source File: ResourcesBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void parseResourceChain(RootBeanDefinition resourceHandlerDef, ParserContext parserContext,
		Element element, Object source) {

	String autoRegistration = element.getAttribute("auto-registration");
	boolean isAutoRegistration = !(StringUtils.hasText(autoRegistration) && "false".equals(autoRegistration));

	ManagedList<? super Object> resourceResolvers = new ManagedList<Object>();
	resourceResolvers.setSource(source);
	ManagedList<? super Object> resourceTransformers = new ManagedList<Object>();
	resourceTransformers.setSource(source);

	parseResourceCache(resourceResolvers, resourceTransformers, element, source);
	parseResourceResolversTransformers(isAutoRegistration, resourceResolvers, resourceTransformers,
			parserContext, element, source);

	if (!resourceResolvers.isEmpty()) {
		resourceHandlerDef.getPropertyValues().add("resourceResolvers", resourceResolvers);
	}
	if (!resourceTransformers.isEmpty()) {
		resourceHandlerDef.getPropertyValues().add("resourceTransformers", resourceTransformers);
	}
}
 
Example #26
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ManagedList<?> getCallableInterceptors(Element element, Object source, ParserContext parserContext) {
	ManagedList<? super Object> interceptors = new ManagedList<Object>();
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	if (asyncElement != null) {
		Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "callable-interceptors");
		if (interceptorsElement != null) {
			interceptors.setSource(source);
			for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
				BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(converter);
				beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
				interceptors.add(beanDef);
			}
		}
	}
	return interceptors;
}
 
Example #27
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<Object>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
			if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
				RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
				adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
				result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
				continue;
			}
		}
		result.add(object);
	}
	return result;
}
 
Example #28
Source File: GroovyBeanDefinitionReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks whether there are any {@link RuntimeBeanReference}s inside the {@link List}
 * and converts it to a {@link ManagedList} if necessary.
 * @param list the original List
 * @return either the original list or a managed copy of it
 */
private Object manageListIfNecessary(List<?> list) {
	boolean containsRuntimeRefs = false;
	for (Object element : list) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		List<Object> managedList = new ManagedList<Object>();
		managedList.addAll(list);
		return managedList;
	}
	return list;
}
 
Example #29
Source File: AspectJAutoProxyBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) {
	ManagedList<TypedStringValue> includePatterns = new ManagedList<TypedStringValue>();
	NodeList childNodes = element.getChildNodes();
	for (int i = 0; i < childNodes.getLength(); i++) {
		Node node = childNodes.item(i);
		if (node instanceof Element) {
			Element includeElement = (Element) node;
			TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name"));
			valueHolder.setSource(parserContext.extractSource(includeElement));
			includePatterns.add(valueHolder);
		}
	}
	if (!includePatterns.isEmpty()) {
		includePatterns.setSource(parserContext.extractSource(element));
		beanDef.getPropertyValues().add("includePatterns", includePatterns);
	}
}
 
Example #30
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) {
	ManagedList<Object> result = new ManagedList<Object>();
	for (Object object : list) {
		if (object instanceof BeanDefinitionHolder) {
			BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object;
			String className = beanDef.getBeanDefinition().getBeanClassName();
			Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader());
			if (WebArgumentResolver.class.isAssignableFrom(clazz)) {
				RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class);
				adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef);
				result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter"));
				continue;
			}
		}
		result.add(object);
	}
	return result;
}