| 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 | 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 | * @author Rizwan Idrees |
| 33 | * @author Mohsin Husen |
| 34 | */ |
| 35 | public class ElasticsearchRepositoryConfigExtension extends RepositoryConfigurationExtensionSupport { |
| 36 | |
| 37 | /* |
| 38 | * (non-Javadoc) |
| 39 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryClassName() |
| 40 | */ |
| 41 | @Override |
| 42 | public String getRepositoryFactoryClassName() { |
| 43 | return ElasticsearchRepositoryFactoryBean.class.getName(); |
| 44 | } |
| 45 | |
| 46 | /* |
| 47 | * (non-Javadoc) |
| 48 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix() |
| 49 | */ |
| 50 | @Override |
| 51 | protected String getModulePrefix() { |
| 52 | return "elasticsearch"; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * (non-Javadoc) |
| 57 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource) |
| 58 | */ |
| 59 | @Override |
| 60 | public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) { |
| 61 | |
| 62 | AnnotationAttributes attributes = config.getAttributes(); |
| 63 | builder.addPropertyReference("elasticsearchOperations", attributes.getString("elasticsearchTemplateRef")); |
| 64 | } |
| 65 | |
| 66 | /* |
| 67 | * (non-Javadoc) |
| 68 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.XmlRepositoryConfigurationSource) |
| 69 | */ |
| 70 | @Override |
| 71 | public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) { |
| 72 | |
| 73 | Element element = config.getElement(); |
| 74 | builder.addPropertyReference("elasticsearchOperations", element.getAttribute("elasticsearch-template-ref")); |
| 75 | } |
| 76 | } |