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.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 | public class MappingElasticsearchConverter implements ElasticsearchConverter, ApplicationContextAware{ |
31 | |
32 | private final MappingContext<? extends ElasticsearchPersistentEntity<?>,ElasticsearchPersistentProperty> mappingContext; |
33 | private final GenericConversionService conversionService; |
34 | |
35 | @SuppressWarnings("unused") |
36 | private ApplicationContext applicationContext; |
37 | |
38 | public MappingElasticsearchConverter(MappingContext<? extends ElasticsearchPersistentEntity<?>,ElasticsearchPersistentProperty> mappingContext) { |
39 | Assert.notNull(mappingContext); |
40 | this.mappingContext = mappingContext; |
41 | this.conversionService = new DefaultConversionService(); |
42 | } |
43 | |
44 | @Override |
45 | public MappingContext<? extends ElasticsearchPersistentEntity<?>,ElasticsearchPersistentProperty> getMappingContext() { |
46 | return mappingContext; |
47 | } |
48 | |
49 | @Override |
50 | public ConversionService getConversionService() { |
51 | return this.conversionService; |
52 | } |
53 | |
54 | @Override |
55 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
56 | this.applicationContext = applicationContext; |
57 | } |
58 | |
59 | } |