Merge changes Ic12888cc,I669cc282,Iad2d6119
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / SimpleTlvHandlerRegistry.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.spi.pojo;
9
10 import org.opendaylight.protocol.concepts.HandlerRegistry;
11 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
12 import org.opendaylight.protocol.pcep.spi.TlvParser;
13 import org.opendaylight.protocol.pcep.spi.TlvSerializer;
14 import org.opendaylight.protocol.util.Values;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
16 import org.opendaylight.yangtools.yang.binding.DataContainer;
17
18 import com.google.common.base.Preconditions;
19
20 /**
21  *
22  */
23 public final class SimpleTlvHandlerRegistry implements TlvHandlerRegistry {
24         private final HandlerRegistry<DataContainer, TlvParser, TlvSerializer> handlers = new HandlerRegistry<>();
25
26         public AutoCloseable registerTlvParser(final int tlvType, final TlvParser parser) {
27                 Preconditions.checkArgument(tlvType >= 0 && tlvType < Values.UNSIGNED_SHORT_MAX_VALUE);
28                 return this.handlers.registerParser(tlvType, parser);
29         }
30
31         public AutoCloseable registerTlvSerializer(final Class<? extends Tlv> tlvClass, final TlvSerializer serializer) {
32                 return this.handlers.registerSerializer(tlvClass, serializer);
33         }
34
35         @Override
36         public TlvParser getTlvParser(final int tlvType) {
37                 return this.handlers.getParser(tlvType);
38         }
39
40         @Override
41         public TlvSerializer getTlvSerializer(final Tlv tlv) {
42                 return this.handlers.getSerializer(tlv.getImplementedInterface());
43         }
44 }