use of org.springframework.beans.factory.support.ManagedMap in project dubbo by alibaba.
the class DubboBeanDefinitionParser method parseParameters.
@SuppressWarnings("unchecked")
private static ManagedMap parseParameters(NodeList nodeList, RootBeanDefinition beanDefinition) {
if (nodeList != null && nodeList.getLength() > 0) {
ManagedMap parameters = null;
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
if (node instanceof Element) {
if ("parameter".equals(node.getNodeName()) || "parameter".equals(node.getLocalName())) {
if (parameters == null) {
parameters = new ManagedMap();
}
String key = ((Element) node).getAttribute("key");
String value = ((Element) node).getAttribute("value");
boolean hide = "true".equals(((Element) node).getAttribute("hide"));
if (hide) {
key = Constants.HIDE_KEY_PREFIX + key;
}
parameters.put(key, new TypedStringValue(value, String.class));
}
}
}
return parameters;
}
return null;
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-data-mongodb by spring-projects.
the class MongoParsingUtils method getWriteConcernPropertyEditorBuilder.
/**
* Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
* {@link WriteConcernPropertyEditor}.
*
* @return
*/
static BeanDefinitionBuilder getWriteConcernPropertyEditorBuilder() {
Map<String, Class<?>> customEditors = new ManagedMap<String, Class<?>>();
customEditors.put("com.mongodb.WriteConcern", WriteConcernPropertyEditor.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
builder.addPropertyValue("customEditors", customEditors);
return builder;
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-data-mongodb by spring-projects.
the class MongoParsingUtils method getServerAddressPropertyEditorBuilder.
/**
* One should only register one bean definition but want to have the convenience of using
* AbstractSingleBeanDefinitionParser but have the side effect of registering a 'default' property editor with the
* container.
*/
static BeanDefinitionBuilder getServerAddressPropertyEditorBuilder() {
Map<String, String> customEditors = new ManagedMap<String, String>();
customEditors.put("com.mongodb.ServerAddress[]", "org.springframework.data.mongodb.config.ServerAddressPropertyEditor");
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
builder.addPropertyValue("customEditors", customEditors);
return builder;
}
use of org.springframework.beans.factory.support.ManagedMap in project geronimo-xbean by apache.
the class XBeanNamespaceHandler method parseCustomMapElement.
protected Object parseCustomMapElement(MappingMetaData metadata, Element element, String name) {
Map map = new ManagedMap();
Element parent = (Element) element.getParentNode();
String entryName = metadata.getMapEntryName(getLocalName(parent), name);
String keyName = metadata.getMapKeyName(getLocalName(parent), name);
String dups = metadata.getMapDupsMode(getLocalName(parent), name);
boolean flat = metadata.isFlatMap(getLocalName(parent), name);
String defaultKey = metadata.getMapDefaultKey(getLocalName(parent), name);
if (entryName == null)
entryName = "property";
if (keyName == null)
keyName = "key";
if (dups == null)
dups = "replace";
// TODO : support further customizations
// String valueName = "value";
// boolean keyIsAttr = true;
// boolean valueIsAttr = false;
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element childElement = (Element) node;
String localName = childElement.getLocalName();
String uri = childElement.getNamespaceURI();
if (localName == null || localName.equals("xmlns") || localName.startsWith("xmlns:")) {
continue;
}
// attributes from namespace-specific attributes
if (!flat && !isEmpty(uri) && localName.equals(entryName)) {
String key = childElement.getAttribute(keyName);
if (key == null || key.length() == 0) {
key = defaultKey;
}
if (key == null) {
throw new RuntimeException("No key defined for map " + entryName);
}
Object keyValue = getValue(key, null);
Element valueElement = getFirstChildElement(childElement);
Object value;
if (valueElement != null) {
String valueElUri = valueElement.getNamespaceURI();
String valueElLocalName = valueElement.getLocalName();
if (valueElUri == null || valueElUri.equals(SPRING_SCHEMA) || valueElUri.equals(SPRING_SCHEMA_COMPAT) || valueElUri.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
if (BeanDefinitionParserDelegate.BEAN_ELEMENT.equals(valueElLocalName)) {
value = parserContext.getDelegate().parseBeanDefinitionElement(valueElement, null);
} else {
value = parserContext.getDelegate().parsePropertySubElement(valueElement, null);
}
} else {
value = parserContext.getDelegate().parseCustomElement(valueElement);
}
} else {
value = getElementText(childElement);
}
addValueToMap(map, keyValue, value, dups);
} else if (flat && !isEmpty(uri)) {
String key = childElement.getAttribute(keyName);
if (key == null || key.length() == 0) {
key = defaultKey;
}
if (key == null) {
throw new RuntimeException("No key defined for map entry " + entryName);
}
Object keyValue = getValue(key, null);
childElement.removeAttribute(keyName);
BeanDefinitionHolder bdh = parseBeanFromExtensionElement(childElement);
addValueToMap(map, keyValue, bdh, dups);
}
}
}
return map;
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-security-oauth by spring-projects.
the class ConfigUtils method createSecurityMetadataSource.
public static BeanDefinition createSecurityMetadataSource(Element element, ParserContext pc) {
List<Element> filterPatterns = DomUtils.getChildElementsByTagName(element, "url");
if (filterPatterns.isEmpty()) {
return null;
}
String patternType = element.getAttribute("path-type");
if (!StringUtils.hasText(patternType)) {
patternType = "ant";
}
MatcherType matcherType = MatcherType.valueOf(patternType);
ManagedMap<BeanDefinition, BeanDefinition> invocationDefinitionMap = new ManagedMap<BeanDefinition, BeanDefinition>();
for (Element filterPattern : filterPatterns) {
String path = filterPattern.getAttribute("pattern");
if (!StringUtils.hasText(path)) {
pc.getReaderContext().error("pattern attribute cannot be empty or null", filterPattern);
}
String method = filterPattern.getAttribute("httpMethod");
if (!StringUtils.hasText(method)) {
method = null;
}
String access = filterPattern.getAttribute("resources");
if (StringUtils.hasText(access)) {
BeanDefinition matcher;
if (createMatcherMethod4x != null) {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod4x, matcherType, pc, path, method);
} else {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod3x, matcherType, path, method);
}
if (access.equals("none")) {
invocationDefinitionMap.put(matcher, BeanDefinitionBuilder.rootBeanDefinition(Collections.class).setFactoryMethod("emptyList").getBeanDefinition());
} else {
BeanDefinitionBuilder attributeBuilder = BeanDefinitionBuilder.rootBeanDefinition(SecurityConfig.class);
attributeBuilder.addConstructorArgValue(access);
attributeBuilder.setFactoryMethod("createListFromCommaDelimitedString");
if (invocationDefinitionMap.containsKey(matcher)) {
pc.getReaderContext().warning("Duplicate URL defined: " + path + ". The original attribute values will be overwritten", pc.extractSource(filterPattern));
}
invocationDefinitionMap.put(matcher, attributeBuilder.getBeanDefinition());
}
}
}
BeanDefinitionBuilder fidsBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultFilterInvocationSecurityMetadataSource.class);
fidsBuilder.addConstructorArgValue(invocationDefinitionMap);
fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(element));
return fidsBuilder.getBeanDefinition();
}
Aggregations