Package org.springframework.beans.factory.support

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


                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 (!StringUtils.hasText(forClass)) {
                            throw new RuntimeException("persister element must have valid for-class attribute");
                        }
                        if (!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 && StringUtils.hasText(e.getAttribute("enabled"))) {
                rbaseConfBuilder.addPropertyValue("keepReference",
                        Boolean.parseBoolean(e.getAttribute("enabled")));
            }

            e = DomUtils.getChildElementByTagName(ksessionConf,
                    CLOCK_TYPE);
            if (e != null && 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);
                }
            }
        }

        Element batch = DomUtils.getChildElementByTagName(element,
                "batch");
        if (batch == null) {
            // just temporary legacy suppport
            batch = DomUtils.getChildElementByTagName(element,
                    "script");
        }
        if (batch != null) {
            // we know there can only ever be one
            ManagedList children = new ManagedList();

            for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
                Node n = batch.getChildNodes().item(i);
                if (n instanceof Element) {
                    Element e = (Element) n;

                    BeanDefinitionBuilder beanBuilder = null;
                    if ("insert-object".equals(e.getLocalName())) {
                        String ref = e.getAttribute("ref");
                        Element nestedElm = getFirstElement(e.getChildNodes());
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(InsertObjectCommand.class);
                        if (StringUtils.hasText(ref)) {
                            beanBuilder.addConstructorArgReference(ref);
                        } else if (nestedElm != null) {
                            beanBuilder.addConstructorArgValue(parserContext.getDelegate().parsePropertySubElement(nestedElm,
                                    null,
                                    null));
                        } else {
                            throw new IllegalArgumentException("insert-object must either specify a 'ref' attribute or have a nested bean");
                        }
                    } else if ("set-global".equals(e.getLocalName())) {
                        String ref = e.getAttribute("ref");
                        Element nestedElm = getFirstElement(e.getChildNodes());
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SetGlobalCommand.class);
                        beanBuilder.addConstructorArgValue(e.getAttribute("identifier"));
                        if (StringUtils.hasText(ref)) {
                            beanBuilder.addConstructorArgReference(ref);
                        } else if (nestedElm != null) {
                            beanBuilder.addConstructorArgValue(parserContext.getDelegate().parsePropertySubElement(nestedElm,
                                    null,
                                    null));
                        } else {
                            throw new IllegalArgumentException("set-global must either specify a 'ref' attribute or have a nested bean");
                        }
                    } else if ("fire-until-halt".equals(e.getLocalName())) {
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireUntilHaltCommand.class);
                    } else if ("fire-all-rules".equals(e.getLocalName())) {
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireAllRulesCommand.class);
                        String max = e.getAttribute("max");
                        if (StringUtils.hasText(max)) {
                            beanBuilder.addPropertyValue("max",
                                    max);
                        }
                    } else if ("start-process".equals(e.getLocalName())) {

                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(StartProcessCommand.class);
                        String processId = e.getAttribute("process-id");
                        if (!StringUtils.hasText(processId)) {
                            throw new IllegalArgumentException("start-process must specify a process-id");
                        }
                        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 (!StringUtils.hasText(identifier)) {
                                    throw new IllegalArgumentException("start-process paramaters must specify an identifier");
                                }

                                String ref = param.getAttribute("ref");
                                Element nestedElm = getFirstElement(param.getChildNodes());
                                if (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


    }

    /** 创建<code>ManagedMap</code>,避免type safety警告。 */
    @SuppressWarnings("unchecked")
    public static Map<Object, Object> createManagedMap(Element element, ParserContext parserContext) {
        ManagedMap map = new ManagedMap();

        map.setSource(parserContext.getReaderContext().extractSource(element));

        return map;
    }
View Full Code Here

    }

    /** 创建<code>ManagedMap</code>,避免type safety警告。 */
    @SuppressWarnings("unchecked")
    public static Map<Object, Object> createManagedMap(Element element, ParserContext parserContext) {
        ManagedMap map = new ManagedMap();

        map.setSource(parserContext.getReaderContext().extractSource(element));

        return map;
    }
View Full Code Here

    /**
     * ����<code>ManagedMap</code>������type safety���档
     */
    @SuppressWarnings("unchecked")
    public static Map<Object, Object> createManagedMap(Element element, ParserContext parserContext) {
        ManagedMap map = new ManagedMap();

        map.setSource(parserContext.getReaderContext().extractSource(element));

        return map;
    }
View Full Code Here

            parseNested(element, parserContext, ServiceBean.class, true, "service", "provider", id, beanDefinition);
        } else if (ProviderConfig.class.equals(beanClass)) {
            parseNested(element, parserContext, ReferenceBean.class, false, "reference", "consumer", id, beanDefinition);
        }
        Set<String> props = new HashSet<String>();
        ManagedMap parameters = null;
        for (Method setter : beanClass.getMethods()) {
            String name = setter.getName();
            if (name.length() > 3 && name.startsWith("set")
                    && Modifier.isPublic(setter.getModifiers())
                    && setter.getParameterTypes().length == 1) {
                Class<?> type = setter.getParameterTypes()[0];
                String property = StringUtils.camelToSplitName(name.substring(3, 4).toLowerCase() + name.substring(4), "-");
                props.add(property);
                Method getter = null;
                try {
                    getter = beanClass.getMethod("get" + name.substring(3), new Class<?>[0]);
                } catch (NoSuchMethodException e) {
                    try {
                        getter = beanClass.getMethod("is" + name.substring(3), new Class<?>[0]);
                    } catch (NoSuchMethodException e2) {
                    }
                }
                if (getter == null
                        || ! Modifier.isPublic(getter.getModifiers())
                        || ! type.equals(getter.getReturnType())) {
                    continue;
                }
                if ("parameters".equals(property)) {
                    parameters = parseParameters(element.getChildNodes(), beanDefinition);
                } else if ("methods".equals(property)) {
                    parseMethods(id, element.getChildNodes(), beanDefinition, parserContext);
                } else if ("arguments".equals(property)) {
                    parseArguments(id, element.getChildNodes(), beanDefinition, parserContext);
                } else {
                    String value = element.getAttribute(property);
                    if (value != null) {
                      value = value.trim();
                      if (value.length() > 0) {
                        if ("registry".equals(property) && RegistryConfig.NO_AVAILABLE.equalsIgnoreCase(value)) {
                              RegistryConfig registryConfig = new RegistryConfig();
                              registryConfig.setAddress(RegistryConfig.NO_AVAILABLE);
                              beanDefinition.getPropertyValues().addPropertyValue(property, registryConfig);
                            } else if ("registry".equals(property) && value.indexOf(',') != -1) {
                          parseMultiRef("registries", value, beanDefinition, parserContext);
                            } else if ("provider".equals(property) && value.indexOf(',') != -1) {
                              parseMultiRef("providers", value, beanDefinition, parserContext);
                            } else if ("protocol".equals(property) && value.indexOf(',') != -1) {
                                parseMultiRef("protocols", value, beanDefinition, parserContext);
                            } else {
                                Object reference;
                                if (isPrimitive(type)) {
                                    if ("async".equals(property) && "false".equals(value)
                                            || "timeout".equals(property) && "0".equals(value)
                                            || "delay".equals(property) && "0".equals(value)
                                            || "version".equals(property) && "0.0.0".equals(value)
                                            || "stat".equals(property) && "-1".equals(value)
                                            || "reliable".equals(property) && "false".equals(value)) {
                                        // 兼容旧版本xsd中的default值
                                        value = null;
                                    }
                                    reference = value;
                                } else if ("protocol".equals(property)
                                        && ExtensionLoader.getExtensionLoader(Protocol.class).hasExtension(value)
                                        && (! parserContext.getRegistry().containsBeanDefinition(value)
                                                || ! ProtocolConfig.class.getName().equals(parserContext.getRegistry().getBeanDefinition(value).getBeanClassName()))) {
                                    if ("dubbo:provider".equals(element.getTagName())) {
                                        logger.warn("Recommended replace <dubbo:provider protocol=\"" + value + "\" ... /> to <dubbo:protocol name=\"" + value + "\" ... />");
                                    }
                                    // 兼容旧版本配置
                                    ProtocolConfig protocol = new ProtocolConfig();
                                    protocol.setName(value);
                                    reference = protocol;
                                } else if ("monitor".equals(property)
                                        && (! parserContext.getRegistry().containsBeanDefinition(value)
                                                || ! MonitorConfig.class.getName().equals(parserContext.getRegistry().getBeanDefinition(value).getBeanClassName()))) {
                                    // 兼容旧版本配置
                                    reference = convertMonitor(value);
                                } else if ("onreturn".equals(property)) {
                                    int index = value.lastIndexOf(".");
                                    String returnRef = value.substring(0, index);
                                    String returnMethod = value.substring(index + 1);
                                    reference = new RuntimeBeanReference(returnRef);
                                    beanDefinition.getPropertyValues().addPropertyValue("onreturnMethod", returnMethod);
                                } else if ("onthrow".equals(property)) {
                                    int index = value.lastIndexOf(".");
                                    String throwRef = value.substring(0, index);
                                    String throwMethod = value.substring(index + 1);
                                    reference = new RuntimeBeanReference(throwRef);
                                    beanDefinition.getPropertyValues().addPropertyValue("onthrowMethod", throwMethod);
                                } else {
                                    if ("ref".equals(property) && parserContext.getRegistry().containsBeanDefinition(value)) {
                                        BeanDefinition refBean = parserContext.getRegistry().getBeanDefinition(value);
                                        if (! refBean.isSingleton()) {
                                            throw new IllegalStateException("The exported service ref " + value + " must be singleton! Please set the " + value + " bean scope to singleton, eg: <bean id=\"" + value+ "\" scope=\"singleton\" ...>");
                                        }
                                    }
                                    reference = new RuntimeBeanReference(value);
                                }
                            beanDefinition.getPropertyValues().addPropertyValue(property, reference);
                            }
                      }
                    }
                }
            }
        }
        NamedNodeMap attributes = element.getAttributes();
        int len = attributes.getLength();
        for (int i = 0; i < len; i++) {
            Node node = attributes.item(i);
            String name = node.getLocalName();
            if (! props.contains(name)) {
                if (parameters == null) {
                    parameters = new ManagedMap();
                }
                String value = node.getNodeValue();
                parameters.put(name, new TypedStringValue(value, String.class));
            }
        }
        if (parameters != null) {
            beanDefinition.getPropertyValues().addPropertyValue("parameters", parameters);
        }
View Full Code Here

    }

    @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;
        }
View Full Code Here

           
            e = DomUtils.getChildElementByTagName(kbaseConf, ACCUMULATE_FUNCTIONS);
            if ( e != null ) {
                List<Element> children = DomUtils.getChildElementsByTagName( e, ACCUMULATE_FUNCTION );
                if ( children != null && !children.isEmpty() ) {
                    ManagedMap functions = new ManagedMap();
                    for ( Element child : children ) {
                        functions.putchild.getAttribute( "name" ),
                                        new RuntimeBeanReference( child.getAttribute( "ref" ) ) );
                    }
                    factory.addPropertyValue( "accumulateFunctions", functions );                   
                }
            }
           
            e = DomUtils.getChildElementByTagName(kbaseConf, EVALUATORS);
            if ( e != null ) {
                List<Element> children = DomUtils.getChildElementsByTagName( e, EVALUATOR );
                if ( children != null && !children.isEmpty() ) {
                    ManagedMap evaluators = new ManagedMap();
                    for ( Element child : children ) {
                        evaluators.putchild.getAttribute( "name" ),
                                        new RuntimeBeanReference( child.getAttribute( "ref" ) ) );
                    }
                    factory.addPropertyValue( "evaluators", evaluators );                   
                }
            }           
View Full Code Here

                beanBuilder.addPropertyReference( "entityManagerFactory", ref );
               
                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 ( !StringUtils.hasText( forClass ) ) {                       
                            throw new RuntimeException( "persister element must have valid for-class attribute" );
                        }
                        if ( !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 && StringUtils.hasText( e.getAttribute( "enabled" ) )) {
                rbaseConfBuilder.addPropertyValue( "keepReference", Boolean.parseBoolean( e.getAttribute( "enabled" ) ) );
            }  
           
            e = DomUtils.getChildElementByTagName(ksessionConf, CLOCK_TYPE);
            if ( e != null && 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.putchild.getAttribute( "name" ),
                                       new RuntimeBeanReference( child.getAttribute( "ref" ) ) );
                    }
                    factory.addPropertyValue( "workItems", workDefs );                   
                }
            }           
        }
       
        Element batch = DomUtils.getChildElementByTagName(element, "batch");
        if ( batch == null ) {
            // just temporary legacy suppport
            batch = DomUtils.getChildElementByTagName(element, "script");
        }
        if ( batch != null) {
            // we know there can only ever be one
            ManagedList children = new ManagedList();

            for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
                Node n = batch.getChildNodes().item( i );
                if ( n instanceof Element ) {
                    Element e = ( Element ) n;
                   
                    BeanDefinitionBuilder beanBuilder = null;
                    if ( "insert-object".equals( e.getLocalName() ) ) {
                        String ref = e.getAttribute( "ref" );
                        Element nestedElm = getFirstElement( e.getChildNodes() );                  
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition( InsertObjectCommand.class );                       
                        if ( StringUtils.hasText( ref ) ) {
                            beanBuilder.addConstructorArgReference( ref );
                        } else if ( nestedElm != null  ) {
                            beanBuilder.addConstructorArgValue( parserContext.getDelegate().parseBeanDefinitionElement( nestedElm ) );                        
                        } else {
                            throw new IllegalArgumentException( "insert-object must either specify a 'ref' attribute or have a nested bean" );
                        }
                    } else if ( "set-global".equals( e.getLocalName() ) ) {
                        String ref = e.getAttribute( "ref" );
                        Element nestedElm = getFirstElement( e.getChildNodes() );                  
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition( SetGlobalCommand.class );
                        beanBuilder.addConstructorArgValue( e.getAttribute( "identifier" ) );
                        if ( StringUtils.hasText( ref ) ) {
                            beanBuilder.addConstructorArgReference( ref );
                        } else if ( nestedElm != null  ) {
                            beanBuilder.addConstructorArgValue( parserContext.getDelegate().parseBeanDefinitionElement( nestedElm ) );                        
                        } else {
                            throw new IllegalArgumentException( "set-global must either specify a 'ref' attribute or have a nested bean" );
                        }
                    }  else if ( "fire-until-halt".equals( e.getLocalName() ) ) {
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition( FireUntilHaltCommand.class );
                    else if ( "fire-all-rules".equals( e.getLocalName() ) ) {
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition( FireAllRulesCommand.class );
                        String max = e.getAttribute( "max" );
                        if ( StringUtils.hasText( max ) ) {
                            beanBuilder.addPropertyValue( "max", max );
                        }
                    }  else if ( "start-process".equals( e.getLocalName() ) ) {
                       
                        beanBuilder = BeanDefinitionBuilder.genericBeanDefinition( StartProcessCommand.class );
                        String processId = e.getAttribute( "process-id" );
                        if ( !StringUtils.hasText( processId ) ) {
                            throw new IllegalArgumentException( "start-process must specify a process-id" );
                        }
                        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 ( !StringUtils.hasText( identifier ) ) {
                                    throw new IllegalArgumentException( "start-process paramaters must specify an identifier" );
                                }
                               
                                String ref = param.getAttribute( "ref" );
                                Element nestedElm = getFirstElement( param.getChildNodes() )
                                if ( StringUtils.hasText( ref ) ) {
                                    map.put( identifier,  new RuntimeBeanReference( ref) );
                                } else if ( nestedElm != null  ) {
                                    map.put( identifier,  parserContext.getDelegate().parseBeanDefinitionElement( nestedElm ) );
                                } else {
                                    throw new IllegalArgumentException( "start-process paramaters must either specify a 'ref' attribute or have a nested bean" );
                                }                                   
                            }  
                            beanBuilder.addPropertyValue( "parameters", map );
View Full Code Here

     * Parse the "ftplets" element
     */
    private Map parseFtplets(final Element childElm,
            final ParserContext parserContext,
            final BeanDefinitionBuilder builder) {
        ManagedMap ftplets = new ManagedMap();

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

        for (Element ftpletElm : childs) {
            ftplets
                    .put(ftpletElm.getAttribute("name"), SpringUtil
                            .parseSpringChildElement(ftpletElm, parserContext,
                                    builder));
        }

View Full Code Here

     */
    @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

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.