Package org.springframework.beans.factory.support

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


    }

    @Override
    protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
    {
        ManagedMap values = new ManagedMap();

        values.put(processHeaderName(element.getLocalName()), element.getAttribute("value"));

        builder.addPropertyValue("sourceMap", values);
        builder.addPropertyValue("targetMapClass", super.getBeanClass(element));
        postProcess(parserContext, getBeanAssembler(element, builder), element);
    }
View Full Code Here


                containsRuntimeRefs = true;
                break;
            }
        }
        if (containsRuntimeRefs) {
            Map managedMap = new ManagedMap();
            managedMap.putAll(map);
            return managedMap;
        }
        return value;
    }
View Full Code Here

                filterChainMap.put(path, filterChain);
            }
        }

        ManagedMap map = new ManagedMap(filterChainMap.size());
        map.putAll(filterChainMap);

        filterChainProxy.getPropertyValues().addPropertyValue("filterChainMap", map);

        return holder;
    }
View Full Code Here

    public static final String ELEMENT_AGENDA_EVENT_LISTENER = "agendaEventListener";
    public static final String ELEMENT_PROCESS_EVENT_LISTENER = "processEventListener";
    public static final String ELEMENT_WORKING_MEMORY_EVENT_LISTENER = "workingMemoryEventListener";

    public static void parseEventListeners(ParserContext parserContext, BeanDefinitionBuilder factory, Element element) {
        ManagedMap completeListenersMap = new ManagedMap();

        List<Element> eventListeners = DomUtils.getChildElementsByTagName(element, ELEMENT_AGENDA_EVENT_LISTENER);
        if (eventListeners != null) {
            ManagedMap listeners = parseEventListenersByType(parserContext, eventListeners, TYPE_AGENDA_EVENT_LISTENER);
            completeListenersMap.putAll(listeners);
        }

        eventListeners = DomUtils.getChildElementsByTagName(element, ELEMENT_PROCESS_EVENT_LISTENER);
        if (eventListeners != null) {
            ManagedMap listeners = parseEventListenersByType(parserContext, eventListeners, TYPE_PROCESS_EVENT_LISTENER);
            completeListenersMap.putAll(listeners);
        }

        eventListeners = DomUtils.getChildElementsByTagName(element, ELEMENT_WORKING_MEMORY_EVENT_LISTENER);
        if (eventListeners != null) {
            ManagedMap listeners = parseEventListenersByType(parserContext, eventListeners, TYPE_WORKING_MEMORY_EVENT_LISTENER);
            completeListenersMap.putAll(listeners);
        }

        factory.addPropertyValue("eventListeners", completeListenersMap);
    }
View Full Code Here

        factory.addPropertyValue("eventListeners", completeListenersMap);
    }

    private static ManagedMap parseEventListenersByType(ParserContext parserContext, List<Element> eventListeners, String listenerType) {
        ManagedMap listeners = new ManagedMap();
        for (Element listener : eventListeners) {
            String ref = listener.getAttribute("ref");
            // if this a bean ref
            if (StringUtils.hasText(ref)) {
                if (TYPE_AGENDA_EVENT_LISTENER.equalsIgnoreCase(listenerType) || TYPE_PROCESS_EVENT_LISTENER.equalsIgnoreCase(listenerType) || TYPE_WORKING_MEMORY_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                    ManagedList subList = (ManagedList) listeners.get(listenerType);
                    if (subList == null) {
                        subList = new ManagedList();
                        listeners.put(listenerType, subList);
                    }
                    subList.add(new RuntimeBeanReference(ref));
                } else {
                    throw new IllegalArgumentException("eventListener must be of type 'agenda-event-listener or 'process-event-listener' or 'working-memory-event-listener'.");
                }
            } else {
                //not a ref check if it is a nested bean
                Element nestedBean = DomUtils.getChildElementByTagName(listener, "bean");
                if (nestedBean == null) {
                    //no 'ref' and no nested beans, add the default debug listeners part of the core libs.
                    Object obj = null;
                    if (TYPE_AGENDA_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                        obj = new DebugAgendaEventListener();
                    } else if (TYPE_PROCESS_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                        obj = new DebugProcessEventListener();
                    } else if (TYPE_WORKING_MEMORY_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                        obj = new DebugRuleRuntimeEventListener();
                    } else {
                        throw new IllegalArgumentException("eventListener must be of type 'agenda-event-listener or 'process-event-listener' or 'working-memory-event-listener'.");
                    }
                    ManagedList subList = (ManagedList) listeners.get(listenerType);
                    if (subList == null) {
                        subList = new ManagedList();
                        listeners.put(listenerType, subList);
                    }
                    subList.add(obj);
                } else {
                    //String type = StringUtils.hasText(listenerType) ? listenerType: "infer";
                    Object obj = parserContext.getDelegate().parsePropertySubElement(nestedBean, null, null);
                    ManagedList subList = (ManagedList) listeners.get(listenerType);
                    if (subList == null) {
                        subList = new ManagedList();
                        listeners.put(listenerType, subList);
                    }
                    subList.add(obj);
                }
            }
        }
View Full Code Here

    }
  }

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

    for (Element methodEle : methods) {
      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)));
      }

      List<RollbackRuleAttribute> rollbackRules = new LinkedList<RollbackRuleAttribute>();
      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().add(NAME_MAP, transactionAttributeMap);
View Full Code Here

    protected ManagedMap parseMap(Element element,
                                  String childElementName,
                                  AbstractDevkitBasedDefinitionParser.ParseDelegate parserDelegate)
    {
        ManagedMap managedMap = new ManagedMap();
        List<Element> childDomElements = DomUtils.getChildElementsByTagName(element, childElementName);
        if (childDomElements.size() == 0)
        {
            childDomElements = DomUtils.getChildElements(element);
        }
        for (Element childDomElement : childDomElements)
        {
            Object key = null;
            if (hasAttribute(childDomElement, "key-ref"))
            {
                key = new RuntimeBeanReference(childDomElement.getAttribute("key-ref"));
            }
            else
            {
                if (hasAttribute(childDomElement, "key"))
                {
                    key = childDomElement.getAttribute("key");
                }
                else
                {
                    key = childDomElement.getTagName();
                }
            }
            if (hasAttribute(childDomElement, "value-ref"))
            {
                if (!isMuleExpression(childDomElement.getAttribute("value-ref")))
                {
                    managedMap.put(key, new RuntimeBeanReference(childDomElement.getAttribute("value-ref")));
                }
                else
                {
                    managedMap.put(key, childDomElement.getAttribute("value-ref"));
                }
            }
            else
            {
                managedMap.put(key, parserDelegate.parse(childDomElement));
            }
        }
        return managedMap;
    }
View Full Code Here

            {
                setRef(builder, fieldName, domElement.getAttribute("ref"));
            }
            else
            {
                ManagedMap managedMap = parseMap(domElement, childElementName, parserDelegate);
                builder.addPropertyValue(fieldName, managedMap);
            }
        }
    }
View Full Code Here

            {
                setRef(builder, fieldName, domElement.getAttribute("ref"));
            }
            else
            {
                ManagedMap managedMap = parseMap(domElement, childElementName, parserDelegate);
                builder.addPropertyValue(fieldName, managedMap);
            }
        }
        else
        {
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

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.