blob: 7bebe4311abf3fd10b27036601754a8e780fa4bf [file] [log] [blame]
Jian Li45083522017-03-20 18:46:07 +09001/*
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 */
16package org.onosproject.mapping.web;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.onosproject.codec.CodecService;
Jian Licb42c312017-03-30 16:20:33 +090024import org.onosproject.mapping.MappingTreatment;
Jian Liee65a232017-03-29 14:15:30 +090025import org.onosproject.mapping.actions.MappingAction;
Jian Li45083522017-03-20 18:46:07 +090026import org.onosproject.mapping.addresses.MappingAddress;
Jian Lib54d14b2017-03-28 21:34:34 +090027import org.onosproject.mapping.instructions.MappingInstruction;
Jian Liee65a232017-03-29 14:15:30 +090028import org.onosproject.mapping.web.codec.MappingActionCodec;
Jian Li45083522017-03-20 18:46:07 +090029import org.onosproject.mapping.web.codec.MappingAddressCodec;
Jian Lib54d14b2017-03-28 21:34:34 +090030import org.onosproject.mapping.web.codec.MappingInstructionCodec;
Jian Licb42c312017-03-30 16:20:33 +090031import org.onosproject.mapping.web.codec.MappingTreatmentCodec;
Jian Li45083522017-03-20 18:46:07 +090032import org.slf4j.Logger;
33
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Implementation of the JSON codec brokering service for mapping primitives.
38 */
39@Component(immediate = true)
40public class MappingCodecRegistrator {
41
42 private final Logger log = getLogger(getClass());
43
44 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
45 public CodecService codecService;
46
47 @Activate
48 public void activate() {
49 codecService.registerCodec(MappingAddress.class, new MappingAddressCodec());
Jian Lib54d14b2017-03-28 21:34:34 +090050 codecService.registerCodec(MappingInstruction.class, new MappingInstructionCodec());
Jian Liee65a232017-03-29 14:15:30 +090051 codecService.registerCodec(MappingAction.class, new MappingActionCodec());
Jian Licb42c312017-03-30 16:20:33 +090052 codecService.registerCodec(MappingTreatment.class, new MappingTreatmentCodec());
Jian Li45083522017-03-20 18:46:07 +090053
54 log.info("Started");
55 }
56
57 @Deactivate
58 public void deactivate() {
59 codecService.unregisterCodec(MappingAddress.class);
Jian Lib54d14b2017-03-28 21:34:34 +090060 codecService.unregisterCodec(MappingInstruction.class);
Jian Liee65a232017-03-29 14:15:30 +090061 codecService.unregisterCodec(MappingAction.class);
Jian Licb42c312017-03-30 16:20:33 +090062 codecService.unregisterCodec(MappingTreatment.class);
Jian Li45083522017-03-20 18:46:07 +090063
64 log.info("Stopped");
65 }
66}