Jian Li | fa69be6 | 2017-04-05 16:00:10 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jian Li | fa69be6 | 2017-04-05 16:00:10 +0900 | [diff] [blame] | 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 | */ |
Jian Li | 2e818b0 | 2017-04-12 19:28:30 +0900 | [diff] [blame] | 16 | package org.onosproject.mapping.codec; |
Jian Li | fa69be6 | 2017-04-05 16:00:10 +0900 | [diff] [blame] | 17 | |
| 18 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 19 | import org.onosproject.codec.CodecContext; |
| 20 | import org.onosproject.codec.CodecService; |
| 21 | import org.onosproject.codec.JsonCodec; |
| 22 | |
| 23 | /** |
| 24 | * An adapter that provides mapping codec context. |
| 25 | */ |
| 26 | public class MappingCodecContextAdapter implements CodecContext { |
| 27 | |
| 28 | private final ObjectMapper mapper = new ObjectMapper(); |
| 29 | private final CodecService manager; |
| 30 | |
| 31 | /** |
| 32 | * Constructs a new mock codec context. |
| 33 | * |
| 34 | * @param manager codec manager |
| 35 | */ |
| 36 | public MappingCodecContextAdapter(CodecService manager) { |
| 37 | this.manager = manager; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public ObjectMapper mapper() { |
| 42 | return mapper; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public <T> JsonCodec<T> codec(Class<T> entityClass) { |
| 47 | return manager.getCodec(entityClass); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public <T> T getService(Class<T> serviceClass) { |
| 52 | return null; |
| 53 | } |
| 54 | } |