1 | /* |
2 | * Copyright 2012 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 | package org.springframework.data.elasticsearch.repository.config; |
17 | |
18 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
19 | import org.springframework.core.annotation.AnnotationAttributes; |
20 | import org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean; |
21 | import org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource; |
22 | import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; |
23 | import org.springframework.data.repository.config.XmlRepositoryConfigurationSource; |
24 | import org.w3c.dom.Element; |
25 | |
26 | |
27 | |
28 | /** |
29 | * {@link org.springframework.data.repository.config.RepositoryConfigurationExtension} implementation to configure Elasticsearch repository configuration support, |
30 | * evaluating the {@link EnableElasticsearchRepositories} annotation or the equivalent XML element. |
31 | * |
32 | */ |
33 | public class ElasticsearchRepositoryConfigExtension extends RepositoryConfigurationExtensionSupport { |
34 | |
35 | /* |
36 | * (non-Javadoc) |
37 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryClassName() |
38 | */ |
39 | @Override |
40 | public String getRepositoryFactoryClassName() { |
41 | return ElasticsearchRepositoryFactoryBean.class.getName(); |
42 | } |
43 | |
44 | /* |
45 | * (non-Javadoc) |
46 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix() |
47 | */ |
48 | @Override |
49 | protected String getModulePrefix() { |
50 | return "elasticsearch"; |
51 | } |
52 | |
53 | /* |
54 | * (non-Javadoc) |
55 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource) |
56 | */ |
57 | @Override |
58 | public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) { |
59 | |
60 | AnnotationAttributes attributes = config.getAttributes(); |
61 | builder.addPropertyReference("elasticsearchOperations", attributes.getString("elasticsearchTemplateRef")); |
62 | } |
63 | |
64 | /* |
65 | * (non-Javadoc) |
66 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.XmlRepositoryConfigurationSource) |
67 | */ |
68 | @Override |
69 | public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) { |
70 | |
71 | Element element = config.getElement(); |
72 | builder.addPropertyReference("elasticsearchOperations", element.getAttribute("elasticsearch-template-ref")); |
73 | } |
74 | } |