Package org.springframework.beans.factory.support

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


     */
    @SuppressWarnings("unchecked")
    private Map parseListeners(final Element listenersElm,
            final ParserContext parserContext,
            final BeanDefinitionBuilder builder) {
        ManagedMap listeners = new ManagedMap();

        List<Element> childs = SpringUtil.getChildElements(listenersElm);

        for (Element listenerElm : childs) {
            Object listener = null;
            String ln = listenerElm.getLocalName();
            if ("nio-listener".equals(ln)) {
                listener = parserContext.getDelegate().parseCustomElement(
                        listenerElm, builder.getBeanDefinition());
            } else if ("listener".equals(ln)) {
                listener = SpringUtil.parseSpringChildElement(listenerElm,
                        parserContext, builder);
            } else {
                throw new FtpServerConfigurationException(
                        "Unknown listener element " + ln);
            }

            String name = listenerElm.getAttribute("name");

            listeners.put(name, listener);
        }

        return listeners;
    }
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++) {
        Node node = entrySubNodes.item(j);
        if (node instanceof Element) {
          Element candidateEle = (Element) node;
          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

                Element variablePersisters = DomUtils.getChildElementByTagName(persistenceElm, "variable-persisters");
                if (variablePersisters != null && variablePersisters.hasChildNodes()) {
                    List<Element> childPersisterElems = DomUtils.getChildElementsByTagName(variablePersisters,
                            "persister");
                    ManagedMap persistors = new ManagedMap(childPersisterElems.size());
                    for (Element persisterElem : childPersisterElems) {
                        String forClass = persisterElem.getAttribute(FORCLASS_ATTRIBUTE);
                        String implementation = persisterElem.getAttribute(IMPLEMENTATION_ATTRIBUTE);
                        if (!org.springframework.util.StringUtils.hasText(forClass)) {
                            throw new RuntimeException("persister element must have valid for-class attribute");
                        }
                        if (!org.springframework.util.StringUtils.hasText(implementation)) {
                            throw new RuntimeException("persister element must have valid implementation attribute");
                        }
                        persistors.put(forClass, implementation);
                    }
                    beanBuilder.addPropertyValue("variablePersisters", persistors);
                }
                factory.addPropertyValue("jpaConfiguration", beanBuilder.getBeanDefinition());
            }
            BeanDefinitionBuilder rbaseConfBuilder = BeanDefinitionBuilder.rootBeanDefinition(SessionConfiguration.class);
            Element e = DomUtils.getChildElementByTagName(ksessionConf, KEEP_REFERENCE);
            if (e != null && org.springframework.util.StringUtils.hasText(e.getAttribute("enabled"))) {
                rbaseConfBuilder.addPropertyValue("keepReference", Boolean.parseBoolean(e.getAttribute("enabled")));
            }

            e = DomUtils.getChildElementByTagName(ksessionConf, CLOCK_TYPE);
            if (e != null && org.springframework.util.StringUtils.hasText(e.getAttribute("type"))) {
                rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
            }
            factory.addPropertyValue("conf", rbaseConfBuilder.getBeanDefinition());

            e = DomUtils.getChildElementByTagName(ksessionConf, WORK_ITEMS);
            if (e != null) {
                List<Element> children = DomUtils.getChildElementsByTagName(e, WORK_ITEM);
                if (children != null && !children.isEmpty()) {
                    ManagedMap workDefs = new ManagedMap();
                    for (Element child : children) {
                        workDefs.put(child.getAttribute("name"), new RuntimeBeanReference(child.getAttribute("ref")));
                    }
                    factory.addPropertyValue("workItems", workDefs);
                }
            }
        }
View Full Code Here

                        }
                        beanBuilder.addConstructorArgValue(processId);

                        List<Element> params = DomUtils.getChildElementsByTagName(e, "parameter");
                        if (!params.isEmpty()) {
                            ManagedMap map = new ManagedMap();
                            for (Element param : params) {
                                String identifier = param.getAttribute("identifier");
                                if (!org.springframework.util.StringUtils.hasText(identifier)) {
                                    throw new IllegalArgumentException("start-process paramaters must specify an identifier");
                                }

                                String ref = param.getAttribute("ref");
                                Element nestedElm = getFirstElement(param.getChildNodes());
                                if (org.springframework.util.StringUtils.hasText(ref)) {
                                    map.put(identifier, new RuntimeBeanReference(ref));
                                } else if (nestedElm != null) {
                                    map.put(identifier, parserContext.getDelegate().parsePropertySubElement(nestedElm,
                                            null,
                                            null));
                                } else {
                                    throw new IllegalArgumentException("start-process parameters must either specify a 'ref' attribute or have a nested bean");
                                }
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_RULE_RUNTIME_EVENT_LISTENER = "ruleRuntimeEventListener";

    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_RULE_RUNTIME_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


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

        NodeList properties = element.getChildNodes();
        for(int index = 0; index < properties.getLength(); index ++)
        {
            Node property = properties.item(index);
            if(property instanceof Element)
            {
                String localName = property.getLocalName();
                String ref = ((Element)property).getAttribute("ref");
                String key = "";

                if("username-token-validator".equals(localName))
                {
                    key = SecurityConstants.USERNAME_TOKEN_VALIDATOR;
                }
                else if("saml1-token-validator".equals(localName))
                {
                    key = SecurityConstants.SAML1_TOKEN_VALIDATOR;
                }
                else if("saml2-token-validator".equals(localName))
                {
                    key = SecurityConstants.SAML2_TOKEN_VALIDATOR;
                }
                else if("timestamp-token-validator".equals(localName))
                {
                    key = SecurityConstants.TIMESTAMP_TOKEN_VALIDATOR;
                }
                else if("signature-token-validator".equals(localName))
                {
                    key = SecurityConstants.SIGNATURE_TOKEN_VALIDATOR;
                }
                else if("bst-token-validator".equals(localName))
                {
                    key = SecurityConstants.BST_TOKEN_VALIDATOR;
                }
                else
                {
                    throw new IllegalArgumentException("Illegal custom validator: " + localName);
                }

                values.put(key, new RuntimeBeanReference(ref));
            }
        }

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

                }

                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

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.