Jian Li | b54d14b | 2017-03-28 21:34:34 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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.onosproject.mapping.web.codec; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.onosproject.codec.CodecContext; |
| 20 | import org.onosproject.codec.JsonCodec; |
| 21 | import org.onosproject.mapping.instructions.MappingInstruction; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Mapping instruction codec. |
| 29 | */ |
| 30 | public final class MappingInstructionCodec extends JsonCodec<MappingInstruction> { |
| 31 | |
| 32 | protected static final Logger log = LoggerFactory.getLogger(MappingInstruction.class); |
| 33 | |
| 34 | protected static final String TYPE = "type"; |
| 35 | protected static final String SUBTYPE = "subtype"; |
| 36 | protected static final String UNICAST_WEIGHT = "unicastWeight"; |
| 37 | protected static final String UNICAST_PRIORITY = "unicastPriority"; |
| 38 | protected static final String MULTICAST_WEIGHT = "multicastWeight"; |
| 39 | protected static final String MULTICAST_PRIORITY = "multicastPriority"; |
| 40 | |
| 41 | protected static final String MISSING_MEMBER_MESSAGE = |
| 42 | " member is required in Instruction"; |
| 43 | protected static final String ERROR_MESSAGE = |
| 44 | " not specified in Instruction"; |
| 45 | |
| 46 | @Override |
| 47 | public ObjectNode encode(MappingInstruction instruction, CodecContext context) { |
| 48 | checkNotNull(instruction, "Mapping instruction cannot be null"); |
| 49 | |
| 50 | return new EncodeMappingInstructionCodecHelper(instruction, context).encode(); |
| 51 | } |
| 52 | } |