2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.spi.pojo;
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.protocol.util.Values;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
16 import org.opendaylight.yangtools.yang.binding.DataContainer;
18 import com.google.common.base.Preconditions;
20 public class SimpleLabelHandlerRegistry implements LabelHandlerRegistry {
21 private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
23 public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
24 Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
25 return this.handlers.registerParser(cType, parser);
28 public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
29 return this.handlers.registerSerializer(labelClass, serializer);
33 public LabelParser getLabelParser(final int cType) {
34 Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
35 return this.handlers.getParser(cType);
39 public LabelSerializer getLabelSerializer(final LabelType label) {
40 return this.handlers.getSerializer(label.getImplementedInterface());