private Optional<Map<String, String>> parseProperties(Element el) { List<Element> propEls = subElements(el, "properties", "prop"); if (!propEls.isEmpty()) { Map<String, String> props = new ManagedMap<>(); for (Element propEl : propEls) { String name = propEl.getAttribute("name").trim(); String value = getTextValue(propEl).trim(); props.put(name, value); } return Optional.of(props); } return Optional.empty(); }
/** * 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; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void postProcessBeanFactory( ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { String[] igniteConfigNames = configurableListableBeanFactory.getBeanNamesForType(IgniteConfiguration.class); if (igniteConfigNames.length != 1) { throw new IllegalArgumentException("Spring config must contain exactly one ignite configuration!"); } String[] activeStoreConfigNames = configurableListableBeanFactory.getBeanNamesForType(BaseActiveStoreConfiguration.class); if (activeStoreConfigNames.length != 1) { throw new IllegalArgumentException("Spring config must contain exactly one active store configuration!"); } BeanDefinition igniteConfigDef = configurableListableBeanFactory.getBeanDefinition(igniteConfigNames[0]); MutablePropertyValues propertyValues = igniteConfigDef.getPropertyValues(); if (!propertyValues.contains(USER_ATTRS_PROP_NAME)) { propertyValues.add(USER_ATTRS_PROP_NAME, new ManagedMap()); } PropertyValue propertyValue = propertyValues.getPropertyValue(USER_ATTRS_PROP_NAME); Map userAttrs = (Map)propertyValue.getValue(); TypedStringValue key = new TypedStringValue(CONFIG_USER_ATTR); RuntimeBeanReference value = new RuntimeBeanReference(beanName); userAttrs.put(key, value); }
/** * 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; }
@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); } }
@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); } }
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; }
protected void doParse(Element element, BeanDefinitionBuilder bean) { final Map<Object, Object> configuration = new ManagedMap<>(); final Node keywordValueNode = element .getElementsByTagNameNS("http://xdcrafts.github.com/schema/flower", "keyword-value") .item(0); final Node predicateNode = element .getElementsByTagNameNS("http://xdcrafts.github.com/schema/flower", "predicate") .item(0); if (keywordValueNode != null) { configuration.put("keyword-value", keywordValueNode.getTextContent()); } if (predicateNode != null) { configuration.put("predicate", new RuntimeBeanReference(predicateNode.getTextContent())); } bean .addPropertyReference("action", element.getAttribute("action")) .addPropertyValue("configuration", configuration); }
protected void doParse(Element element, BeanDefinitionBuilder bean) { final ManagedMap<Object, Object> extensions = new ManagedMap<>(); final NodeList bindingNodes = element .getElementsByTagNameNS("http://xdcrafts.github.com/schema/flower", "binding"); if (bindingNodes != null && bindingNodes.getLength() != 0) { for (int i = 0; i < bindingNodes.getLength(); i++) { final Node bindingNode = bindingNodes.item(i); final String extension = bindingNode .getAttributes() .getNamedItem("extension") .getNodeValue(); final String selector = bindingNode .getAttributes() .getNamedItem("selector") .getNodeValue(); extensions.put(new RuntimeBeanReference(extension), new RuntimeBeanReference(selector)); } } bean.addPropertyValue("extensions", extensions); }
/** * 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; }
/** * 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; }
private BeanDefinition createGroupRegistryDefinition(String name, Element element) { ManagedMap<String, BeanDefinition> ptpGroupsMap = new ManagedMap<String, BeanDefinition>(); String currentGroupName = ParticipantsGroupRegistry.GROUPS_REGISTRY__ROOT_GROUPNAME; ManagedList<BeanDefinition> rootGrpParticipants = registerGroup( ptpGroupsMap, currentGroupName); processGroup(ptpGroupsMap, element, currentGroupName, rootGrpParticipants); RootBeanDefinition grpRegistryDef = new RootBeanDefinition( ParticipantsGroupRegistry.class); ConstructorArgumentValues cav = grpRegistryDef .getConstructorArgumentValues(); cav.addGenericArgumentValue(ptpGroupsMap); return grpRegistryDef; }
public void parseFields(Element element, RootBeanDefinition beandef, ParserContext parserContext) { Element fieldsele = DomUtils.getChildElementByTagName(element, FIELDS); if (fieldsele == null) { return; } List<Element> fieldlist = DomUtils.getChildElementsByTagName(fieldsele, FIELD); if (fieldlist.size() == 0) { return; } Map<String, RuntimeBeanReference> fields = new ManagedMap<String, RuntimeBeanReference>(); String fieldname = null; for (Element field : fieldlist) { fieldname = field.getAttribute(NAME); if (!(StringUtils.hasLength(fieldname))) { System.out.println("Tag 'field' must have a 'name' attribute"); return; } if("".equals(DomUtils.getTextValue(field))){ fields.put(fieldname, null); } else { fields.put(fieldname, new RuntimeBeanReference(DomUtils.getTextValue(field))); } } beandef.getPropertyValues().addPropertyValue(FIELDS, fields); }
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; }
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(); } }
/** * 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. */ private ManagedMap parseMap(ArrayList<Element> grandChildren, Element child, BeanDefinitionBuilder parent, ParserContext parserContext) { ManagedMap map = new ManagedMap(); String merge = child.getAttribute("merge"); for (int j = 0; j < grandChildren.size(); j++) { Object key = findKey(grandChildren.get(j)); Object value = findValue(grandChildren.get(j)); map.put(key, value); } if (merge != null) { map.setMergeEnabled(Boolean.valueOf(merge)); } return map; }
/** * @param graph Graph * @param beanId String * @param v PropertyValue */ private static void addGraphEdge(final Graph graph, final String beanId, final PropertyValue v) { if (v.getValue() instanceof RuntimeBeanReference) { graph.addEdge(beanId, ((RuntimeBeanReference) v.getValue()).getBeanName()); } else if (v.getValue() instanceof ManagedList) { ManagedList list = (ManagedList) v.getValue(); for (Object o : list) { if (o instanceof RuntimeBeanReference) { graph.addEdge(beanId, ((RuntimeBeanReference) o).getBeanName()); } } } else if (v.getValue() instanceof ManagedMap) { ManagedMap map = (ManagedMap) v.getValue(); for (Object value : map.values()) { if (value instanceof RuntimeBeanReference) { graph.addEdge(beanId, ((RuntimeBeanReference) value).getBeanName()); } } } }
/** * @param graph Graph * @param beanId String * @param v ConstructorArgumentValues.ValueHolder v */ private static void addGraphEdge(final Graph graph, final String beanId, final ConstructorArgumentValues.ValueHolder v) { if (v.getValue() instanceof BeanDefinition) { //In most cases this should be a field instead of an edge (?) // graph.addEdge(beanId, ((BeanDefinition) v.getValue()).getBeanClassName()); } else if (v.getValue() instanceof RuntimeBeanReference) { graph.addEdge(beanId, ((RuntimeBeanReference) v.getValue()).getBeanName()); } else if (v.getValue() instanceof ManagedList) { ManagedList list = (ManagedList) v.getValue(); for (Object o : list) { if (o instanceof RuntimeBeanReference) { graph.addEdge(beanId, ((RuntimeBeanReference) o).getBeanName()); } } } else if (v.getValue() instanceof ManagedMap) { ManagedMap map = (ManagedMap) v.getValue(); for (Object value : map.values()) { if (value instanceof RuntimeBeanReference) { graph.addEdge(beanId, ((RuntimeBeanReference) value).getBeanName()); } } } else { System.out.println("Unhandled constructor argument type"); } }
/** * @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; }
/** * Parse the "ftplets" element */ private Map<?, ?> parseFtplets(final Element childElm, final ParserContext parserContext, final BeanDefinitionBuilder builder) { List<Element> childs = SpringUtil.getChildElements(childElm); if(childs.size() > 0 && childs.get(0).getLocalName().equals("map")) { // using a beans:map element return parserContext.getDelegate().parseMapElement( childs.get(0), builder.getBeanDefinition()); } else { ManagedMap ftplets = new ManagedMap(); for (Element ftpletElm : childs) { ftplets .put(ftpletElm.getAttribute("name"), SpringUtil .parseSpringChildElement(ftpletElm, parserContext, builder)); } return ftplets; } }
protected BeanDefinition registerSpringConfiguratorIfNecessary(BeanDefinitionRegistry registry) { if (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID)) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class); builder.addPropertyValue("creators", new ManagedMap()); builder.addPropertyValue("converters", new ManagedMap()); registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID, builder.getBeanDefinition()); } return registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID); }
private ManagedMap buildParameters(String[] keyValues) { if (keyValues.length == 0 || keyValues.length % 2 != 0) { return null; } ManagedMap managedMap = new ManagedMap(); for (int i = 0; i < keyValues.length; i+=2) { managedMap.put(keyValues[i], new TypedStringValue(keyValues[i + 1], String.class)); } return managedMap; }
/** * Checks if a configuration object (usually from a <code><dwr:configuration></code> tag) has already * been processed. If not it registers one automatically. * * @param registry a non null instance * @return the configuration bean definition currently in the context (cannot be null) */ public static BeanDefinition registerConfigurationIfNecessary(BeanDefinitionRegistry registry) { if (!registry.containsBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID)) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringConfigurator.class); builder.addPropertyValue("creators", new ManagedMap()); builder.addPropertyValue("converters", new ManagedMap()); builder.addPropertyValue("filters", new ManagedList()); registry.registerBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID, builder.getBeanDefinition()); } return registry.getBeanDefinition(DEFAULT_SPRING_CONFIGURATOR_ID); }
private BeanDefinitionBuilder getWriteConcernPropertyEditorBuilder() { Map<String, Class<?>> customEditors = new ManagedMap<>(); customEditors.put("com.mongodb.WriteConcern", WriteConcernPropertyEditor.class); BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class); builder.addPropertyValue("customEditors", customEditors); return builder; }
@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; }
protected void shallowCloneManagedCollections(final AbstractBeanDefinition cloneBeanDefinition) { // clone is not a deep clone - managed lists / maps are by-reference which is problematic for placeholder resolution final MutablePropertyValues propertyValues = cloneBeanDefinition.getPropertyValues(); for (final PropertyValue pv : propertyValues.getPropertyValues()) { final Object value = pv.getValue(); if (value instanceof ManagedList<?>) { final ManagedList<Object> newList = new ManagedList<>(); newList.setSource(((ManagedList<?>) value).getSource()); newList.setElementTypeName(((ManagedList<?>) value).getElementTypeName()); newList.addAll((ManagedList<?>) value); propertyValues.add(pv.getName(), newList); } else if (value instanceof ManagedSet<?>) { final ManagedSet<Object> newSet = new ManagedSet<>(); newSet.setSource(((ManagedSet<?>) value).getSource()); newSet.setElementTypeName(((ManagedSet<?>) value).getElementTypeName()); newSet.addAll((ManagedSet<?>) value); propertyValues.add(pv.getName(), newSet); } else if (value instanceof ManagedMap<?, ?>) { final ManagedMap<Object, Object> newMap = new ManagedMap<>(); newMap.setSource(((ManagedMap<?, ?>) value).getSource()); newMap.setKeyTypeName(((ManagedMap<?, ?>) value).getKeyTypeName()); newMap.setValueTypeName(((ManagedMap<?, ?>) value).getValueTypeName()); newMap.putAll((ManagedMap<?, ?>) value); propertyValues.add(pv.getName(), newMap); } } }
/** * 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); }
/** * 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); }
protected ManagedList<BeanDefinition> registerGroup( ManagedMap<String, BeanDefinition> ptpGroupsMap, String groupName) { ManagedList<BeanDefinition> grpParticipants = new ManagedList<BeanDefinition>(); BeanDefinitionBuilder rootGrpDefBuilder = BeanDefinitionBuilder .rootBeanDefinition(ParticipantsGroup.class); ConstructorArgumentValues constructorArgumentValues = rootGrpDefBuilder .getBeanDefinition().getConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(groupName); constructorArgumentValues.addGenericArgumentValue(grpParticipants); ptpGroupsMap.put(groupName, rootGrpDefBuilder.getBeanDefinition()); return grpParticipants; }
protected void processGroup( ManagedMap<String, BeanDefinition> ptpGroupsMap, Element groupElt, String groupName, ManagedList<BeanDefinition> grpParticipants) { NodeList childNodes = groupElt.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String localName = node.getLocalName(); if (PARTICIPANT_ELEMENT.equals(localName)) { BeanDefinition ptpBeanDef = parseParticipant((Element) node); grpParticipants.add(ptpBeanDef); } else if (GROUP_ELEMENT.equals(localName)) { Element childGrpElt = (Element) node; String childGroupName = childGrpElt .getAttribute(NAME_ATTRIBUTE); grpParticipants = registerGroup(ptpGroupsMap, childGroupName); processGroup(ptpGroupsMap, childGrpElt, childGroupName, grpParticipants); } else if (SUBFLOW_ELEMENT.equals(localName)) { Element childSubflowElt = (Element) node; processGroup(ptpGroupsMap, childSubflowElt, null, null); } } } }
@Override public void refresh() throws BeansException { MutablePropertyValues pvs = new MutablePropertyValues(); registerSingleton("controller1", TestFormController.class, pvs); pvs = new MutablePropertyValues(); pvs.add("bindOnNewForm", "true"); registerSingleton("controller2", TestFormController.class, pvs); pvs = new MutablePropertyValues(); pvs.add("requireSession", "true"); pvs.add("sessionForm", "true"); pvs.add("bindOnNewForm", "true"); registerSingleton("controller3", TestFormController.class, pvs); pvs = new MutablePropertyValues(); pvs.add("requireSession", "true"); pvs.add("sessionForm", "true"); pvs.add("bindOnNewForm", "false"); registerSingleton("controller4", TestFormController.class, pvs); pvs = new MutablePropertyValues(); Map parameterMap = new ManagedMap(); parameterMap.put("form", new RuntimeBeanReference("controller1")); parameterMap.put("form-bind", new RuntimeBeanReference("controller2")); parameterMap.put("form-session-bind", new RuntimeBeanReference("controller3")); parameterMap.put("form-session-nobind", new RuntimeBeanReference("controller4")); pvs.addPropertyValue(new PropertyValue("parameterMap", parameterMap)); registerSingleton("handlerMapping", ParameterHandlerMapping.class, pvs); super.refresh(); TestFormController controller1 = (TestFormController) getBean("controller1"); this.renderCommandSessionAttributeName = controller1.getRenderCommandName(); this.formSessionAttributeName = controller1.getFormSessionName(); }
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; }
public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register SimpleUrlHandlerMapping for view controllers BeanDefinition handlerMappingDef = registerHandlerMapping(parserContext, source); // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off" MvcNamespaceUtils.registerDefaultComponents(parserContext, source); // Create view controller bean definition RootBeanDefinition viewControllerDef = new RootBeanDefinition(ParameterizableViewController.class); viewControllerDef.setSource(source); if (element.hasAttribute("view-name")) { viewControllerDef.getPropertyValues().add("viewName", element.getAttribute("view-name")); } Map<String, BeanDefinition> urlMap; if (handlerMappingDef.getPropertyValues().contains("urlMap")) { urlMap = (Map<String, BeanDefinition>) handlerMappingDef.getPropertyValues().getPropertyValue("urlMap").getValue(); } else { urlMap = new ManagedMap<String, BeanDefinition>(); handlerMappingDef.getPropertyValues().add("urlMap", urlMap); } urlMap.put(element.getAttribute("path"), viewControllerDef); return null; }
public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); String resourceHandlerName = registerResourceHandler(parserContext, element, source); if (resourceHandlerName == null) { return null; } Map<String, String> urlMap = new ManagedMap<String, String>(); String resourceRequestPath = element.getAttribute("mapping"); if (!StringUtils.hasText(resourceRequestPath)) { parserContext.getReaderContext().error("The 'mapping' attribute is required.", parserContext.extractSource(element)); return null; } urlMap.put(resourceRequestPath, resourceHandlerName); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class); handlerMappingDef.setSource(source); handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); handlerMappingDef.getPropertyValues().add("urlMap", urlMap); String order = element.getAttribute("order"); // use a default of near-lowest precedence, still allowing for even lower precedence in other mappings handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1); String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef); parserContext.getRegistry().registerBeanDefinition(beanName, handlerMappingDef); parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, beanName)); // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off" // Register HttpRequestHandlerAdapter MvcNamespaceUtils.registerDefaultComponents(parserContext, source); return null; }