Fix junit dependencies in poms. Reuse existing from parent,
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / SimpleLabelHandlerRegistry.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
10 import org.opendaylight.protocol.concepts.HandlerRegistry;
11 import org.opendaylight.protocol.pcep.spi.LabelHandlerRegistry;
12 import org.opendaylight.protocol.pcep.spi.LabelParser;
13 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CLabel;
15 import org.opendaylight.yangtools.yang.binding.DataContainer;
16
17 import com.google.common.base.Preconditions;
18
19 public class SimpleLabelHandlerRegistry implements LabelHandlerRegistry {
20         private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
21
22         @Override
23         public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
24                 Preconditions.checkArgument(cType >= 0 && cType <= 255);
25                 return handlers.registerParser(cType, parser);
26         }
27
28         @Override
29         public LabelParser getLabelParser(final int cType) {
30                 Preconditions.checkArgument(cType >= 0 && cType <= 255);
31                 return handlers.getParser(cType);
32         }
33
34         @Override
35         public AutoCloseable registerLabelSerializer(final Class<? extends CLabel> labelClass, final LabelSerializer serializer) {
36                 return handlers.registerSerializer(labelClass, serializer);
37         }
38
39         @Override
40         public LabelSerializer getLabelSerializer(final CLabel label) {
41                 return handlers.getSerializer(label.getImplementedInterface());
42         }
43 }