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.core.convert; |
17 | |
18 | import org.springframework.beans.BeansException; |
19 | import org.springframework.context.ApplicationContext; |
20 | import org.springframework.context.ApplicationContextAware; |
21 | import org.springframework.core.convert.ConversionService; |
22 | import org.springframework.core.convert.support.DefaultConversionService; |
23 | import org.springframework.core.convert.support.GenericConversionService; |
24 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; |
25 | import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; |
26 | import org.springframework.data.mapping.context.MappingContext; |
27 | import org.springframework.util.Assert; |
28 | |
29 | /** |
30 | * MappingElasticsearchConverter |
31 | * |
32 | * @author Rizwan Idrees |
33 | * @author Mohsin Husen |
34 | */ |
35 | |
36 | public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware{ |
37 | |
38 | private final MappingContext<? extends ElasticsearchPersistentEntity<?>,ElasticsearchPersistentProperty> mappingContext; |
39 | private final GenericConversionService conversionService; |
40 | |
41 | @SuppressWarnings("unused") |
42 | private ApplicationContext applicationContext; |
43 | |
44 | public MappingElasticsearchConverter(MappingContext<? extends ElasticsearchPersistentEntity<?>,ElasticsearchPersistentProperty> mappingContext) { |
45 | Assert.notNull(mappingContext); |
46 | this.mappingContext = mappingContext; |
47 | this.conversionService = new DefaultConversionService(); |
48 | } |
49 | |
50 | @Override |
51 | public MappingContext<? extends ElasticsearchPersistentEntity<?>,ElasticsearchPersistentProperty> getMappingContext() { |
52 | return mappingContext; |
53 | } |
54 | |
55 | @Override |
56 | public ConversionService getConversionService() { |
57 | return this.conversionService; |
58 | } |
59 | |
60 | @Override |
61 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
62 | this.applicationContext = applicationContext; |
63 | } |
64 | |
65 | } |