Package org.springframework.beans.factory.support

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


                }

                List list = retrieveList(oldValue);
                if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass))
                {
                    list.add(new ManagedMap());
                    retrieveMap(list.get(list.size() - 1)).put(
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(),
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue());
                }
                else if (beanClass.equals(ChildListEntryDefinitionParser.ListEntry.class.getName()))
                {
                    list.add(sourceProperties.getPropertyValue(ChildListEntryDefinitionParser.VALUE).getValue());
                }
                else
                {
                    list.add(bean.getBeanDefinition());
                }
            }
            else
            {
                // not a collection

                if (ChildMapEntryDefinitionParser.KeyValuePair.class.getName().equals(beanClass))
                {
                    if (null == pv || null == oldValue)
                    {
                        pv = new PropertyValue(newName, new ManagedMap());
                        targetProperties.addPropertyValue(pv);
                    }
                    retrieveMap(pv.getValue()).put(
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.KEY).getValue(),
                            sourceProperties.getPropertyValue(ChildMapEntryDefinitionParser.VALUE).getValue());
View Full Code Here


    }

    protected void insertDefinitionAsMap(String oldName)
    {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(MapCombiner.class);
        Map map = new ManagedMap();
        for (Iterator pvs = getBean().getBeanDefinition().getPropertyValues().getPropertyValueList().iterator();
             pvs.hasNext();)
        {
            PropertyValue pv = (PropertyValue) pvs.next();
            map.put(pv.getName(), pv.getValue());
        }
        List list = new ManagedList();
        list.add(map);
        builder.addPropertyValue(MapCombiner.LIST, list);
        setBean(builder);
View Full Code Here

        return MapFactoryBean.class;
    }

    protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
    {
        ManagedMap values = new ManagedMap();
        NamedNodeMap attributes = element.getAttributes();
        for (int x = 0; x < attributes.getLength(); x++)
        {
            Attr attribute = (Attr) attributes.item(x);
            String oldName = SpringXMLUtils.attributeName(attribute);
            //TODO How can I use bestGuessName
            String name = beanPropertyConfiguration.translateName(oldName);
            Object value = beanPropertyConfiguration.translateValue(oldName, attribute.getNodeValue());
            if (beanPropertyConfiguration.isReference(oldName))
            {
                values.put(name, new RuntimeBeanReference(attribute.getNodeValue()));
            }
            else
            {
                values.put(name, value);
            }
        }
        builder.addPropertyValue("sourceMap", values);
        builder.addPropertyValue("targetMapClass", super.getBeanClass(element));
        postProcess(parserContext, getBeanAssembler(element, builder), element);
View Full Code Here

  public Map parseMapElement(Element mapEle, BeanDefinition bd) {
    String defaultKeyTypeClassName = mapEle.getAttribute(KEY_TYPE_ATTRIBUTE);
    String defaultValueTypeClassName = mapEle.getAttribute(VALUE_TYPE_ATTRIBUTE);

    List entryEles = DomUtils.getChildElementsByTagName(mapEle, ENTRY_ELEMENT);
    ManagedMap map = new ManagedMap(entryEles.size());
    map.setMergeEnabled(parseMergeAttribute(mapEle));
    map.setSource(extractSource(mapEle));

    for (Iterator it = entryEles.iterator(); it.hasNext();) {
      Element entryEle = (Element) it.next();
      // Should only have one value child element: ref, value, list, etc.
      // Optionally, there might be a key child element.
      NodeList entrySubNodes = entryEle.getChildNodes();

      Element keyEle = null;
      Element valueEle = null;
      for (int j = 0; j < entrySubNodes.getLength(); j++) {
        if (entrySubNodes.item(j) instanceof Element) {
          Element candidateEle = (Element) entrySubNodes.item(j);
          if (DomUtils.nodeNameEquals(candidateEle, KEY_ELEMENT)) {
            if (keyEle != null) {
              error("<entry> element is only allowed to contain one <key> sub-element", entryEle);
            }
            else {
              keyEle = candidateEle;
            }
          }
          else {
            // Child element is what we're looking for.
            if (valueEle != null) {
              error("<entry> element must not contain more than one value sub-element", entryEle);
            }
            else {
              valueEle = candidateEle;
            }
          }
        }
      }

      // Extract key from attribute or sub-element.
      Object key = null;
      boolean hasKeyAttribute = entryEle.hasAttribute(KEY_ATTRIBUTE);
      boolean hasKeyRefAttribute = entryEle.hasAttribute(KEY_REF_ATTRIBUTE);
      if ((hasKeyAttribute && hasKeyRefAttribute) ||
          ((hasKeyAttribute || hasKeyRefAttribute)) && keyEle != null) {
        error("<entry> element is only allowed to contain either " +
                "a 'key' attribute OR a 'key-ref' attribute OR a <key> sub-element", entryEle);
      }
      if (hasKeyAttribute) {
        key = buildTypedStringValueForMap(
            entryEle.getAttribute(KEY_ATTRIBUTE), defaultKeyTypeClassName, entryEle);
      }
      else if (hasKeyRefAttribute) {
        String refName = entryEle.getAttribute(KEY_REF_ATTRIBUTE);
        if (!StringUtils.hasText(refName)) {
          error("<entry> element contains empty 'key-ref' attribute", entryEle);
        }
        RuntimeBeanReference ref = new RuntimeBeanReference(refName);
        ref.setSource(extractSource(entryEle));
        key = ref;
      }
      else if (keyEle != null) {
        key = parseKeyElement(keyEle, bd, defaultKeyTypeClassName);
      }
      else {
        error("<entry> element must specify a key", entryEle);
      }

      // Extract value from attribute or sub-element.
      Object value = null;
      boolean hasValueAttribute = entryEle.hasAttribute(VALUE_ATTRIBUTE);
      boolean hasValueRefAttribute = entryEle.hasAttribute(VALUE_REF_ATTRIBUTE);
      if ((hasValueAttribute && hasValueRefAttribute) ||
          ((hasValueAttribute || hasValueRefAttribute)) && valueEle != null) {
        error("<entry> element is only allowed to contain either " +
            "'value' attribute OR 'value-ref' attribute OR <value> sub-element", entryEle);
      }
      if (hasValueAttribute) {
        value = buildTypedStringValueForMap(
            entryEle.getAttribute(VALUE_ATTRIBUTE), defaultValueTypeClassName, entryEle);
      }
      else if (hasValueRefAttribute) {
        String refName = entryEle.getAttribute(VALUE_REF_ATTRIBUTE);
        if (!StringUtils.hasText(refName)) {
          error("<entry> element contains empty 'value-ref' attribute", entryEle);
        }
        RuntimeBeanReference ref = new RuntimeBeanReference(refName);
        ref.setSource(extractSource(entryEle));
        value = ref;
      }
      else if (valueEle != null) {
        value = parsePropertySubElement(valueEle, bd, defaultValueTypeClassName);
      }
      else {
        error("<entry> element must specify a value", entryEle);
      }

      // Add final key and value to the Map.
      map.put(key, value);
    }

    return map;
  }
View Full Code Here

    }
  }

  private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) {
    List methods = DomUtils.getChildElementsByTagName(attrEle, "method");
    ManagedMap transactionAttributeMap = new ManagedMap(methods.size());
    transactionAttributeMap.setSource(parserContext.extractSource(attrEle));

    for (int i = 0; i < methods.size(); i++) {
      Element methodEle = (Element) methods.get(i);

      String name = methodEle.getAttribute("name");
      TypedStringValue nameHolder = new TypedStringValue(name);
      nameHolder.setSource(parserContext.extractSource(methodEle));

      RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
      String propagation = methodEle.getAttribute(PROPAGATION);
      String isolation = methodEle.getAttribute(ISOLATION);
      String timeout = methodEle.getAttribute(TIMEOUT);
      String readOnly = methodEle.getAttribute(READ_ONLY);
      if (StringUtils.hasText(propagation)) {
        attribute.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation);
      }
      if (StringUtils.hasText(isolation)) {
        attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation);
      }
      if (StringUtils.hasText(timeout)) {
        try {
          attribute.setTimeout(Integer.parseInt(timeout));
        }
        catch (NumberFormatException ex) {
          parserContext.getReaderContext().error("Timeout must be an integer value: [" + timeout + "]", methodEle);
        }
      }
      if (StringUtils.hasText(readOnly)) {
        attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY)).booleanValue());
      }

      List rollbackRules = new LinkedList();
      if (methodEle.hasAttribute(ROLLBACK_FOR)) {
        String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR);
        addRollbackRuleAttributesTo(rollbackRules,rollbackForValue);
      }
      if (methodEle.hasAttribute(NO_ROLLBACK_FOR)) {
        String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR);
        addNoRollbackRuleAttributesTo(rollbackRules,noRollbackForValue);
      }
      attribute.setRollbackRules(rollbackRules);

      transactionAttributeMap.put(nameHolder, attribute);
    }

    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchTransactionAttributeSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(attrEle));
    attributeSourceDefinition.getPropertyValues().addPropertyValue(NAME_MAP, transactionAttributeMap);
View Full Code Here

  public Map parseMapElement(Element mapEle, BeanDefinition bd) {
    String defaultKeyTypeClassName = mapEle.getAttribute(KEY_TYPE_ATTRIBUTE);
    String defaultValueTypeClassName = mapEle.getAttribute(VALUE_TYPE_ATTRIBUTE);

    List entryEles = DomUtils.getChildElementsByTagName(mapEle, ENTRY_ELEMENT);
    ManagedMap map = new ManagedMap(entryEles.size());
    map.setMergeEnabled(parseMergeAttribute(mapEle));
    map.setSource(extractSource(mapEle));

    for (Iterator it = entryEles.iterator(); it.hasNext();) {
      Element entryEle = (Element) it.next();
      // Should only have one value child element: ref, value, list, etc.
      // Optionally, there might be a key child element.
      NodeList entrySubNodes = entryEle.getChildNodes();

      Element keyEle = null;
      Element valueEle = null;
      for (int j = 0; j < entrySubNodes.getLength(); j++) {
        if (entrySubNodes.item(j) instanceof Element) {
          Element candidateEle = (Element) entrySubNodes.item(j);
          if (DomUtils.nodeNameEquals(candidateEle, KEY_ELEMENT)) {
            if (keyEle != null) {
              error("<entry> element is only allowed to contain one <key> sub-element", entryEle);
            }
            else {
              keyEle = candidateEle;
            }
          }
          else {
            // Child element is what we're looking for.
            if (valueEle != null) {
              error("<entry> element must not contain more than one value sub-element", entryEle);
            }
            else {
              valueEle = candidateEle;
            }
          }
        }
      }

      // Extract key from attribute or sub-element.
      Object key = null;
      boolean hasKeyAttribute = entryEle.hasAttribute(KEY_ATTRIBUTE);
      boolean hasKeyRefAttribute = entryEle.hasAttribute(KEY_REF_ATTRIBUTE);
      if ((hasKeyAttribute && hasKeyRefAttribute) ||
          ((hasKeyAttribute || hasKeyRefAttribute)) && keyEle != null) {
        error("<entry> element is only allowed to contain either " +
                "a 'key' attribute OR a 'key-ref' attribute OR a <key> sub-element", entryEle);
      }
      if (hasKeyAttribute) {
        key = buildTypedStringValueForMap(
            entryEle.getAttribute(KEY_ATTRIBUTE), defaultKeyTypeClassName, entryEle);
      }
      else if (hasKeyRefAttribute) {
        String refName = entryEle.getAttribute(KEY_REF_ATTRIBUTE);
        if (!StringUtils.hasText(refName)) {
          error("<entry> element contains empty 'key-ref' attribute", entryEle);
        }
        RuntimeBeanReference ref = new RuntimeBeanReference(refName);
        ref.setSource(extractSource(entryEle));
        key = ref;
      }
      else if (keyEle != null) {
        key = parseKeyElement(keyEle, bd, defaultKeyTypeClassName);
      }
      else {
        error("<entry> element must specify a key", entryEle);
      }

      // Extract value from attribute or sub-element.
      Object value = null;
      boolean hasValueAttribute = entryEle.hasAttribute(VALUE_ATTRIBUTE);
      boolean hasValueRefAttribute = entryEle.hasAttribute(VALUE_REF_ATTRIBUTE);
      if ((hasValueAttribute && hasValueRefAttribute) ||
          ((hasValueAttribute || hasValueRefAttribute)) && valueEle != null) {
        error("<entry> element is only allowed to contain either " +
                "'value' attribute OR 'value-ref' attribute OR <value> sub-element", entryEle);
      }
      if (hasValueAttribute) {
        value = buildTypedStringValueForMap(
            entryEle.getAttribute(VALUE_ATTRIBUTE), defaultValueTypeClassName, entryEle);
      }
      else if (hasValueRefAttribute) {
        String refName = entryEle.getAttribute(VALUE_REF_ATTRIBUTE);
        if (!StringUtils.hasText(refName)) {
          error("<entry> element contains empty 'value-ref' attribute", entryEle);
        }
        RuntimeBeanReference ref = new RuntimeBeanReference(refName);
        ref.setSource(extractSource(entryEle));
        value = ref;
      }
      else if (valueEle != null) {
        value = parsePropertySubElement(valueEle, bd, defaultValueTypeClassName);
      }
      else {
        error("<entry> element must specify a value", entryEle);
      }

      // Add final key and value to the Map.
      map.put(key, value);
    }

    return map;
  }
View Full Code Here

 
  private void addZkEventListener(BeanDefinition bd, String eventname, String listenerid) {
    final MutablePropertyValues pvs = bd.getPropertyValues();
    PropertyValue pv = pvs.getPropertyValue("eventListeners");
    if (pv == null) {
      pvs.addPropertyValue("eventListeners", new ManagedMap());
      pv = pvs.getPropertyValue("eventListeners");
    }
    final Map eventListenersMap = (Map) pv.getValue(); //(comp.eventname, Set(listeners))
    Set listenersSet = (Set) eventListenersMap.get(new TypedStringValue(eventname));
    if (listenersSet == null) {
View Full Code Here

    pvs.addPropertyValue("sessionForm", "true");
    pvs.addPropertyValue("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();
View Full Code Here

    interceptors.add(userRoleInterceptor);
    interceptors.add(new MyHandlerInterceptor1());
    interceptors.add(new MyHandlerInterceptor2());

    MutablePropertyValues pvs = new MutablePropertyValues();
    Map portletModeMap = new ManagedMap();
    portletModeMap.put("view", new RuntimeBeanReference("viewController"));
    portletModeMap.put("edit", new RuntimeBeanReference("editController"));
    pvs.addPropertyValue("portletModeMap", portletModeMap);
    pvs.addPropertyValue("interceptors", interceptors);
    registerSingleton("handlerMapping3", PortletModeHandlerMapping.class, pvs);
   
    pvs = new MutablePropertyValues();
    Map parameterMap = new ManagedMap();
    parameterMap.put("test1", new RuntimeBeanReference("testController1"));
    parameterMap.put("test2", new RuntimeBeanReference("testController2"));
    parameterMap.put("requestLocaleChecker", new RuntimeBeanReference("requestLocaleCheckingController"));
    parameterMap.put("contextLocaleChecker", new RuntimeBeanReference("localeContextCheckingController"));
    parameterMap.put("exception1", new RuntimeBeanReference("exceptionThrowingHandler1"));
    parameterMap.put("exception2", new RuntimeBeanReference("exceptionThrowingHandler2"));
    parameterMap.put("myPortlet", new RuntimeBeanReference("myPortlet"));
    parameterMap.put("unknown", new RuntimeBeanReference("unknownHandler"));
    pvs.addPropertyValue("parameterMap", parameterMap);
    pvs.addPropertyValue("parameterName", "myParam");
    pvs.addPropertyValue("order", "2");
    registerSingleton("handlerMapping2", ParameterHandlerMapping.class, pvs);
   
    pvs = new MutablePropertyValues();
    Map innerMap = new ManagedMap();
    innerMap.put("help1", new RuntimeBeanReference("helpController1"));
    innerMap.put("help2", new RuntimeBeanReference("helpController2"));
    Map outerMap = new ManagedMap();
    outerMap.put("help", innerMap);
    pvs.addPropertyValue("portletModeParameterMap", outerMap);
    pvs.addPropertyValue("order", "1");
    registerSingleton("handlerMapping1", PortletModeParameterHandlerMapping.class, pvs);

    pvs = new MutablePropertyValues();
View Full Code Here

    Set someSet = new ManagedSet();
    someSet.add("na${age}me");
    someSet.add(new RuntimeBeanReference("${ref}"));
    pvs.addPropertyValue("someSet", someSet);

    Map someMap = new ManagedMap();
    someMap.put("key1", new RuntimeBeanReference("${ref}"));
    someMap.put("key2", "${age}name");
    MutablePropertyValues innerPvs = new MutablePropertyValues();
    innerPvs.addPropertyValue("touchy", "${os.name}");
    someMap.put("key3", new RootBeanDefinition(TestBean.class, innerPvs));
    MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs);
    someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child"));
    pvs.addPropertyValue("someMap", someMap);

    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, cas, pvs);
    wac.getDefaultListableBeanFactory().registerBeanDefinition("tb2", bd);
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.support.ManagedMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.