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

The following examples show how to use org.springframework.beans.factory.support.ManagedMap. 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: HandlersBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addIndexedArgumentValue(0, handlerReference);
	if (this.handshakeHandlerReference != null) {
		cavs.addIndexedArgumentValue(1, this.handshakeHandlerReference);
	}
	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cavs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		urlMap.put(mapping, requestHandlerRef);
	}
}
 
Example #2
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 Map} and converts it to a {@link ManagedMap} if necessary.
 * @param map the original Map
 * @return either the original map or a managed copy of it
 */
private Object manageMapIfNecessary(Map<?, ?> map) {
	boolean containsRuntimeRefs = false;
	for (Object element : map.values()) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		Map<Object, Object> managedMap = new ManagedMap<>();
		managedMap.putAll(map);
		return managedMap;
	}
	return map;
}
 
Example #3
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private ManagedMap<String, Object> registerHandlerMapping(
		Element element, ParserContext context, @Nullable Object source) {

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
	handlerMappingDef.getPropertyValues().add("order", order);

	String pathHelper = element.getAttribute("path-helper");
	if (StringUtils.hasText(pathHelper)) {
		handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<>();
	urlMap.setSource(source);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	registerBeanDef(handlerMappingDef, context, source);
	return urlMap;
}
 
Example #4
Source File: HandlersBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService");
	cargs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler");

	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		String pathPattern = (mapping.endsWith("/") ? mapping + "**" : mapping + "/**");
		urlMap.put(pathPattern, requestHandlerRef);
	}
}
 
Example #5
Source File: HandlersBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, handlerReference);
	cargs.addIndexedArgumentValue(1, this.handshakeHandlerReference);
	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		urlMap.put(mapping, requestHandlerRef);
	}
}
 
Example #6
Source File: UifBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Retrieves the expression graph map set on the bean with given name. If the bean has not been processed
 * by the bean factory post processor, that is done before retrieving the map
 *
 * @param parentBeanName name of the parent bean to retrieve map for (if empty a new map will be returned)
 * @param beanFactory bean factory to retrieve bean definition from
 * @param processedBeanNames set of bean names that have been processed so far
 * @return expression graph map from parent or new instance
 */
protected Map<String, String> getExpressionGraphFromParent(String parentBeanName,
        ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) {
    Map<String, String> expressionGraph = new HashMap<String, String>();
    if (StringUtils.isBlank(parentBeanName) || !beanFactory.containsBeanDefinition(parentBeanName)) {
        return expressionGraph;
    }

    BeanDefinition beanDefinition = beanFactory.getBeanDefinition(parentBeanName);
    if (!processedBeanNames.contains(parentBeanName)) {
        processBeanDefinition(parentBeanName, beanDefinition, beanFactory, processedBeanNames);
    }

    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    PropertyValue propertyExpressionsPV = pvs.getPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH);
    if (propertyExpressionsPV != null) {
        Object value = propertyExpressionsPV.getValue();
        if ((value != null) && (value instanceof ManagedMap)) {
            expressionGraph.putAll((ManagedMap) value);
        }
    }

    return expressionGraph;
}
 
Example #7
Source File: CustomSchemaParser.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Parses a list of elements into a map of beans/standard content.
 *
 * @param grandChildren - The list of beans/content in a bean property
 * @param child - The property tag for the parent.
 * @param parent - The parent bean that the tag is nested in.
 * @param parserContext - Provided information and functionality regarding current bean set.
 * @return A managedSet of the nested content.
 */
protected ManagedMap parseMap(ArrayList<Element> grandChildren, Element child, BeanDefinitionBuilder parent,
        ParserContext parserContext) {
    ManagedMap map = new ManagedMap();

    String merge = child.getAttribute("merge");
    if (merge != null) {
        map.setMergeEnabled(Boolean.valueOf(merge));
    }

    for (int j = 0; j < grandChildren.size(); j++) {
        Object key = findKey(grandChildren.get(j), parent, parserContext);
        Object value = findValue(grandChildren.get(j), parent, parserContext);

        map.put(key, value);
    }

    return map;
}
 
Example #8
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private ManagedMap<String, Object> registerHandlerMapping(Element element,
		ParserContext context, Object source) {

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
	handlerMappingDef.getPropertyValues().add("order", order);

	String pathHelper = element.getAttribute("path-helper");
	if (StringUtils.hasText(pathHelper)) {
		handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>();
	urlMap.setSource(source);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	registerBeanDef(handlerMappingDef, context, source);
	return urlMap;
}
 
Example #9
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 Map}
 * and converts it to a {@link ManagedMap} if necessary.
 * @param map the original Map
 * @return either the original map or a managed copy of it
 */
private Object manageMapIfNecessary(Map<?, ?> map) {
	boolean containsRuntimeRefs = false;
	for (Object element : map.values()) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		Map<Object, Object> managedMap = new ManagedMap<Object, Object>();
		managedMap.putAll(map);
		return managedMap;
	}
	return map;
}
 
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 Map} and converts it to a {@link ManagedMap} if necessary.
 * @param map the original Map
 * @return either the original map or a managed copy of it
 */
private Object manageMapIfNecessary(Map<?, ?> map) {
	boolean containsRuntimeRefs = false;
	for (Object element : map.values()) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		Map<Object, Object> managedMap = new ManagedMap<>();
		managedMap.putAll(map);
		return managedMap;
	}
	return map;
}
 
Example #11
Source File: MessageBrokerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private ManagedMap<String, Object> registerHandlerMapping(
		Element element, ParserContext context, @Nullable Object source) {

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);
	handlerMappingDef.getPropertyValues().add("order", order);

	String pathHelper = element.getAttribute("path-helper");
	if (StringUtils.hasText(pathHelper)) {
		handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<>();
	urlMap.setSource(source);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	registerBeanDef(handlerMappingDef, context, source);
	return urlMap;
}
 
Example #12
Source File: BeanDefinitionWriterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private XStream createStream() {
	XStream stream = new XStream();
	stream.registerConverter(new BeanDefinitionConverter(stream.getMapper()));
	stream.registerConverter(new BeanDefinitionHolderConverter(stream.getMapper()));
	stream.registerConverter(new TypedStringValueConverter());
	stream.registerConverter(new ManagedCollectionConverter(stream.getMapper()));
	stream.registerConverter(new ManagedMapConverter(stream.getMapper()));
	stream.registerConverter(new RuntimeBeanReferenceConverter());
	stream.alias("map", ManagedMap.class);
	stream.alias("list", ManagedList.class);
	stream.alias("set", ManagedSet.class);
	stream.alias("array", ManagedArray.class);
	stream.aliasType("bean", BeanDefinition.class);
	stream.alias("bean", BeanDefinitionHolder.class);
	stream.alias("ref", RuntimeBeanReference.class);
	return stream;
}
 
Example #13
Source File: HandlersBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService");
	cargs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler");

	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		String pathPattern = (mapping.endsWith("/") ? mapping + "**" : mapping + "/**");
		urlMap.put(pathPattern, requestHandlerRef);
	}
}
 
Example #14
Source File: HandlersBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, handlerReference);
	cargs.addIndexedArgumentValue(1, this.handshakeHandlerReference);
	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		urlMap.put(mapping, requestHandlerRef);
	}
}
 
Example #15
Source File: BeanDefinitionWriterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
	ManagedMap<?, ?> map = (ManagedMap<?, ?>) source;
	for (Map.Entry<?, ?> entry : map.entrySet()) {
		writer.startNode("entry");
		writer.startNode("key");
		if (entry.getKey().getClass().equals(TypedStringValue.class)) {
			writer.startNode("value");
			writer.setValue(((TypedStringValue) entry.getKey()).getValue());
			writer.endNode();
		} else {
			writeItem(entry.getKey(), context, writer);
		}
		writer.endNode();
		if (entry.getValue().getClass().equals(TypedStringValue.class)) {
			writer.startNode("value");
			writer.setValue(((TypedStringValue) entry.getValue()).getValue());
			writer.endNode();
		} else {
			writeItem(entry.getValue(), context, writer);
		}
		writer.endNode();
	}
}
 
Example #16
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 Map
 * and converts it to a ManagedMap if necessary.
 * @param map the original Map
 * @return either the original map or a managed copy of it
 */
private Object manageMapIfNecessary(Map<?, ?> map) {
	boolean containsRuntimeRefs = false;
	for (Object element : map.values()) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		Map<Object, Object> managedMap = new ManagedMap<Object, Object>();
		managedMap.putAll(map);
		return managedMap;
	}
	return map;
}
 
Example #17
Source File: GroovyBeanDefinitionReader.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether there are any {@link RuntimeBeanReference}s inside the {@link Map}
 * and converts it to a {@link ManagedMap} if necessary.
 * @param map the original Map
 * @return either the original map or a managed copy of it
 */
private Object manageMapIfNecessary(Map<?, ?> map) {
	boolean containsRuntimeRefs = false;
	for (Object element : map.values()) {
		if (element instanceof RuntimeBeanReference) {
			containsRuntimeRefs = true;
			break;
		}
	}
	if (containsRuntimeRefs) {
		Map<Object, Object> managedMap = new ManagedMap<Object, Object>();
		managedMap.putAll(map);
		return managedMap;
	}
	return map;
}
 
Example #18
Source File: DefaultsBeanDefinitionParser.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * @return
 */
private ComponentDefinition registerAccessorFactory(Element element, ParserContext parserContext) {
	BeanDefinitionBuilder bdb = BeanDefinitionBuilder.genericBeanDefinition(
			ConfigurableControlAccessorFactory.class);
	
	Map<Class<?>, Class<?extends ControlAccessor>> accessors = 
			new ManagedMap<Class<?>,Class<?extends ControlAccessor>>();
	accessors.put(JTextComponent.class, TextComponentAccessor.class);
	accessors.put(JList.class, ListAccessor.class);
	accessors.put(Selector.class, SelectorAccessor.class);
	accessors.put(JToggleButton.class, ToggleButtonAccessor.class);
	accessors.put(JComboBox.class, ComboAccessor.class);
	accessors.put(View.class, ViewAccessor.class);
	accessors.put(JLabel.class, LabelAccessor.class);
	accessors.put(TablePanel.class, TablePanelAccessor.class);
	bdb.addPropertyValue("accessors", accessors);
	
	BeanComponentDefinition bcd = new BeanComponentDefinition(bdb.getBeanDefinition(), ACCESSOR_FACTORY_BEAN_NAME);
	
	registerBeanComponentDefinition(element, parserContext, bcd);	
	return bcd;
}
 
Example #19
Source File: HandlersBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService");
	cavs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler");

	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cavs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		String pathPattern = (mapping.endsWith("/") ? mapping + "**" : mapping + "/**");
		urlMap.put(pathPattern, requestHandlerRef);
	}
}
 
Example #20
Source File: DataSourceBeanDefinitionParser.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
    List<String> dataSources = Splitter.on(",").trimResults().splitToList(element.getAttribute(DataSourceBeanDefinitionTag.DATA_SOURCE_NAMES_TAG));
    Map<String, RuntimeBeanReference> result = new ManagedMap<>(dataSources.size());
    for (String each : dataSources) {
        result.put(each, new RuntimeBeanReference(each));
    }
    return result;
}
 
Example #21
Source File: ShardingSphereAlgorithmBeanRegistry.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
/**
 * Get algorithm bean references.
 * 
 * @param parserContext parser context for spring application context
 * @param algorithmFactoryBeanClass ShardingSphere algorithm factory bean class
 * @return ShardingSphere algorithm bean references
 */
public static Map<String, RuntimeBeanReference> getAlgorithmBeanReferences(final ParserContext parserContext, final Class<? extends ShardingSphereAlgorithmFactoryBean> algorithmFactoryBeanClass) {
    String[] beanDefinitionNames = parserContext.getRegistry().getBeanDefinitionNames();
    String algorithmFactoryBeanClassName = algorithmFactoryBeanClass.getName();
    Map<String, RuntimeBeanReference> result = new ManagedMap<>(beanDefinitionNames.length);
    for (String each : beanDefinitionNames) {
        if (parserContext.getRegistry().getBeanDefinition(each).getBeanClassName().equals(algorithmFactoryBeanClassName)) {
            result.put(each, new RuntimeBeanReference(each));
        }
    }
    return result;
}
 
Example #22
Source File: DefaultServletHandlerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	String defaultServletName = element.getAttribute("default-servlet-name");
	RootBeanDefinition defaultServletHandlerDef = new RootBeanDefinition(DefaultServletHttpRequestHandler.class);
	defaultServletHandlerDef.setSource(source);
	defaultServletHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	if (StringUtils.hasText(defaultServletName)) {
		defaultServletHandlerDef.getPropertyValues().add("defaultServletName", defaultServletName);
	}
	String defaultServletHandlerName = parserContext.getReaderContext().generateBeanName(defaultServletHandlerDef);
	parserContext.getRegistry().registerBeanDefinition(defaultServletHandlerName, defaultServletHandlerDef);
	parserContext.registerComponent(new BeanComponentDefinition(defaultServletHandlerDef, defaultServletHandlerName));

	Map<String, String> urlMap = new ManagedMap<String, String>();
	urlMap.put("/**", defaultServletHandlerName);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	String handlerMappingBeanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
	parserContext.getRegistry().registerBeanDefinition(handlerMappingBeanName, handlerMappingDef);
	parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingBeanName));

	// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
	MvcNamespaceUtils.registerDefaultComponents(parserContext, source);

	return null;
}
 
Example #23
Source File: DefaultServletHandlerBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	String defaultServletName = element.getAttribute("default-servlet-name");
	RootBeanDefinition defaultServletHandlerDef = new RootBeanDefinition(DefaultServletHttpRequestHandler.class);
	defaultServletHandlerDef.setSource(source);
	defaultServletHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	if (StringUtils.hasText(defaultServletName)) {
		defaultServletHandlerDef.getPropertyValues().add("defaultServletName", defaultServletName);
	}
	String defaultServletHandlerName = parserContext.getReaderContext().generateBeanName(defaultServletHandlerDef);
	parserContext.getRegistry().registerBeanDefinition(defaultServletHandlerName, defaultServletHandlerDef);
	parserContext.registerComponent(new BeanComponentDefinition(defaultServletHandlerDef, defaultServletHandlerName));

	Map<String, String> urlMap = new ManagedMap<String, String>();
	urlMap.put("/**", defaultServletHandlerName);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	String handlerMappingBeanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
	parserContext.getRegistry().registerBeanDefinition(handlerMappingBeanName, handlerMappingDef);
	parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingBeanName));

	// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
	MvcNamespaceUtils.registerDefaultComponents(parserContext, source);

	return null;
}
 
Example #24
Source File: ReferenceBeanDefinitionParser.java    From Thunder with Apache License 2.0 5 votes vote down vote up
private Map parseMethodElements(Element referenceElement, ParserContext parserContext, BeanDefinitionBuilder builder) {
    String methodElementName = ThunderConstant.METHOD_ELEMENT_NAME;
    String methodAttributeName = ThunderConstant.METHOD_ATTRIBUTE_NAME;
    String parameterTypesAttributeName = ThunderConstant.PARAMETER_TYPES_ATTRIBUTE_NAME;

    List<Element> methodElements = DomUtils.getChildElementsByTagName(referenceElement, methodElementName);

    ManagedMap methodMap = new ManagedMap(methodElements.size());
    methodMap.setMergeEnabled(true);
    methodMap.setSource(parserContext.getReaderContext().extractSource(referenceElement));

    for (Element methodElement : methodElements) {
        String method = methodElement.getAttribute(methodAttributeName);
        String parameterTypes = methodElement.getAttribute(parameterTypesAttributeName);

        MethodKey methodKey = new MethodKey();
        methodKey.setMethod(method);
        methodKey.setParameterTypes(parameterTypes);
        if (methodMap.containsKey(methodKey)) {
            throw FrameworkExceptionFactory.createMethodDuplicatedException(methodElementName, methodKey);
        }

        methodMap.put(methodKey, parserContext.getDelegate().parseCustomElement(methodElement, builder.getRawBeanDefinition()));
    }

    return methodMap;
}
 
Example #25
Source File: CommunicationXmlParser.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/** 获取指令策略集合 */
private static ManagedMap<String, Object> getStrategies(Element configurationElement, ParserContext context) {
    // 设置每个执行策略配置
    ManagedMap<String, Object> strategies = new ManagedMap<>();
    String strategyName = configurationElement.getAttribute(AttributeDefinition.REFERENCE.getName());
    strategies.put(StringUtility.EMPTY, new RuntimeBeanReference(strategyName));
    List<Element> elements = XmlUtility.getChildElementsByTagName(configurationElement, ElementDefinition.STRATEGY.getName());
    for (Element element : elements) {
        String name = element.getAttribute(AttributeDefinition.NAME.getName());
        String reference = element.getAttribute(AttributeDefinition.REFERENCE.getName());
        strategies.put(name, new RuntimeBeanReference(reference));
    }
    return strategies;
}
 
Example #26
Source File: AbstractBeanDefinitionParser.java    From joyrpc with Apache License 2.0 5 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) {
        ManagedMap parameters = new ManagedMap();
        Node node;
        String key;
        String value;
        boolean hidden;
        for (int i = 0; i < nodes.getLength(); i++) {
            node = nodes.item(i);
            if (node instanceof Element && (PARAMETER.equals(node.getNodeName())
                    || PARAMETER.equals(node.getLocalName()))) {
                key = ((Element) node).getAttribute("key");
                if (!RequestContext.VALID_KEY.test(key)) {
                    throw new IllegalConfigureException("param.key", key, "key can not start with "
                            + Constants.HIDE_KEY_PREFIX + " and " + Constants.INTERNAL_KEY_PREFIX, ExceptionCode.COMMON_ABUSE_HIDE_KEY);
                }
                value = ((Element) node).getAttribute("value");
                hidden = Converts.getBoolean(((Element) node).getAttribute("hide"), Boolean.FALSE);
                if (hidden) {
                    key = Constants.HIDE_KEY_PREFIX + key;
                }
                parameters.put(key, new TypedStringValue(value, String.class));
            }
        }
        if (!parameters.isEmpty()) {
            definition.getPropertyValues().addPropertyValue(name, parameters);
        }
    }
}
 
Example #27
Source File: DataSourceBeanDefinitionParser.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
private Map<String, RuntimeBeanReference> parseInstances(final Element element) {
    List<String> instances = Splitter.on(",").trimResults().splitToList(element.getAttribute(DataSourceBeanDefinitionTag.INSTANCE_REF_TAG));
    Map<String, RuntimeBeanReference> result = new ManagedMap<>(instances.size());
    for (String each : instances) {
        result.put(each, new RuntimeBeanReference(each));
    }
    return result;
}
 
Example #28
Source File: UifBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Processes a top level (non nested) bean definition for expressions
 *
 * <p>
 * A bean that is non nested (or top of a collection) will hold all the expressions for the graph. A new
 * expression graph is initialized and expressions are collected as the bean and all its children are processed.
 * The expression graph is then set as a property on the top bean definition
 * </p>
 *
 * @param beanName name of the bean to process
 * @param beanDefinition bean definition to process
 * @param beanFactory factory holding all the bean definitions
 * @param processedBeanNames set of bean names that have already been processed
 */
protected void processBeanDefinition(String beanName, BeanDefinition beanDefinition,
        ConfigurableListableBeanFactory beanFactory, Set<String> processedBeanNames) {
    Class<?> beanClass = getBeanClass(beanDefinition, beanFactory);
    if ((beanClass == null) || !UifDictionaryBean.class.isAssignableFrom(beanClass) || processedBeanNames.contains(
            beanName)) {
        return;
    }

    // process bean definition and all nested definitions for expressions
    ManagedMap<String, String> expressionGraph = new ManagedMap<String, String>();
    MutablePropertyValues pvs = beanDefinition.getPropertyValues();
    if (pvs.contains(UifPropertyPaths.EXPRESSION_GRAPH)) {
        expressionGraph = (ManagedMap<String, String>) pvs.getPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH)
                .getValue();
        if (expressionGraph == null) {
            expressionGraph = new ManagedMap<String, String>();
        }
    }

    expressionGraph.setMergeEnabled(false);
    processNestedBeanDefinition(beanName, beanDefinition, "", expressionGraph, beanFactory, processedBeanNames);

    // add property for expression graph
    pvs = beanDefinition.getPropertyValues();
    pvs.addPropertyValue(UifPropertyPaths.EXPRESSION_GRAPH, expressionGraph);
}
 
Example #29
Source File: DefaultServletHandlerBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	String defaultServletName = element.getAttribute("default-servlet-name");
	RootBeanDefinition defaultServletHandlerDef = new RootBeanDefinition(DefaultServletHttpRequestHandler.class);
	defaultServletHandlerDef.setSource(source);
	defaultServletHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	if (StringUtils.hasText(defaultServletName)) {
		defaultServletHandlerDef.getPropertyValues().add("defaultServletName", defaultServletName);
	}
	String defaultServletHandlerName = parserContext.getReaderContext().generateBeanName(defaultServletHandlerDef);
	parserContext.getRegistry().registerBeanDefinition(defaultServletHandlerName, defaultServletHandlerDef);
	parserContext.registerComponent(new BeanComponentDefinition(defaultServletHandlerDef, defaultServletHandlerName));

	Map<String, String> urlMap = new ManagedMap<>();
	urlMap.put("/**", defaultServletHandlerName);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	String handlerMappingBeanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
	parserContext.getRegistry().registerBeanDefinition(handlerMappingBeanName, handlerMappingDef);
	parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingBeanName));

	// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
	MvcNamespaceUtils.registerDefaultComponents(parserContext, source);

	return null;
}
 
Example #30
Source File: DictionaryBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Iterates through the map values and calls helpers to process the value
 *
 * @param mapVal the set to process
 * @param propertyName name of the property which has the map value
 * @param nestedBeanStack stack of bean containers which contains the map property
 */
protected void visitMap(Map<?, ?> mapVal, String propertyName, Stack<BeanDefinitionHolder> nestedBeanStack) {
    boolean isMergeEnabled = false;
    if (mapVal instanceof ManagedMap) {
        isMergeEnabled = ((ManagedMap) mapVal).isMergeEnabled();
    }

    ManagedMap newMap = new ManagedMap();
    newMap.setMergeEnabled(isMergeEnabled);

    for (Map.Entry entry : mapVal.entrySet()) {
        Object key = entry.getKey();
        Object val = entry.getValue();

        if (isStringValue(val)) {
            val = processMapStringPropertyValue(propertyName, mapVal, getString(val), key, nestedBeanStack,
                    beanProcessors);
        } else {
            val = visitPropertyValue(propertyName, val, nestedBeanStack);
        }

        newMap.put(key, val);
    }

    mapVal.clear();
    mapVal.putAll(newMap);
}