PageRenderTime 19ms CodeModel.GetById 1ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

/hazelcast-spring/src/main/java/com/hazelcast/spring/AbstractHazelcastBeanDefinitionParser.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 62 lines | 37 code | 7 blank | 18 comment | 12 complexity | deb3cfe30488e6a375cbecd952cadfe8 MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.spring;
18
19import com.hazelcast.config.AbstractXmlConfigHelper;
20import org.springframework.beans.factory.support.BeanDefinitionBuilder;
21import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
22import org.springframework.beans.factory.xml.ParserContext;
23import org.w3c.dom.NamedNodeMap;
24import org.w3c.dom.Node;
25
26/**
27 * @mdogan 4/10/12
28 */
29public abstract class AbstractHazelcastBeanDefinitionParser extends AbstractBeanDefinitionParser {
30
31    public abstract class SpringXmlBuilderHelper extends AbstractXmlConfigHelper {
32
33        protected void handleCommonBeanAttributes(Node node, BeanDefinitionBuilder builder, ParserContext parserContext) {
34            final NamedNodeMap attributes = node.getAttributes();
35            if (attributes != null) {
36                Node lazyInitAttr = attributes.getNamedItem("lazy-init");
37                if (lazyInitAttr != null) {
38                    builder.setLazyInit(Boolean.valueOf(getValue(lazyInitAttr)));
39                } else {
40                    builder.setLazyInit(parserContext.isDefaultLazyInit());
41                }
42
43                if (parserContext.isNested()) {
44                    builder.setScope(parserContext.getContainingBeanDefinition().getScope());
45                } else {
46                    Node scopeNode = attributes.getNamedItem("scope");
47                    if (scopeNode != null) {
48                        builder.setScope(getValue(scopeNode));
49                    }
50                }
51
52                Node dependsOnNode = attributes.getNamedItem("depends-on");
53                if (dependsOnNode != null) {
54                    String[] dependsOn = getValue(dependsOnNode).split("[,;]");
55                    for (String dep : dependsOn) {
56                        builder.addDependsOn(dep.trim());
57                    }
58                }
59            }
60        }
61    }
62}