1 | /* |
2 | * Copyright 2013 the original author or authors. |
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 | |
17 | package org.springframework.data.elasticsearch.config; |
18 | |
19 | import org.springframework.beans.factory.support.AbstractBeanDefinition; |
20 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
21 | import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; |
22 | import org.springframework.beans.factory.xml.ParserContext; |
23 | import org.springframework.data.elasticsearch.client.NodeClientFactoryBean; |
24 | import org.w3c.dom.Element; |
25 | |
26 | /** |
27 | * NodeClientBeanDefinitionParser |
28 | * |
29 | * @author Rizwan Idrees |
30 | * @author Mohsin Husen |
31 | */ |
32 | |
33 | public class NodeClientBeanDefinitionParser extends AbstractBeanDefinitionParser { |
34 | |
35 | @Override |
36 | protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { |
37 | BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(NodeClientFactoryBean.class); |
38 | setLocalSettings(element,builder); |
39 | return getSourcedBeanDefinition(builder, element, parserContext); |
40 | } |
41 | |
42 | private void setLocalSettings(Element element, BeanDefinitionBuilder builder) { |
43 | builder.addPropertyValue("local", Boolean.valueOf(element.getAttribute("local"))); |
44 | } |
45 | |
46 | |
47 | private AbstractBeanDefinition getSourcedBeanDefinition(BeanDefinitionBuilder builder, Element source, |
48 | ParserContext context) { |
49 | AbstractBeanDefinition definition = builder.getBeanDefinition(); |
50 | definition.setSource(context.extractSource(source)); |
51 | return definition; |
52 | } |
53 | } |