2 * Copyright (c) 2015 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
9 package org.opendaylight.protocol.rsvp.parser.spi.pojo;
11 import com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.concepts.HandlerRegistry;
14 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
15 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
16 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectRegistry;
17 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
18 import org.opendaylight.protocol.util.Values;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainer;
21 import org.opendaylight.yangtools.yang.binding.DataContainer;
23 public class SimpleXROSubobjectRegistry implements XROSubobjectRegistry {
24 private final HandlerRegistry<DataContainer, XROSubobjectParser, XROSubobjectSerializer> handlers =
25 new HandlerRegistry<>();
27 public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
28 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Values.UNSIGNED_SHORT_MAX_VALUE);
29 return this.handlers.registerParser(subobjectType, parser);
32 public AutoCloseable registerSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass,
33 final XROSubobjectSerializer serializer) {
34 return this.handlers.registerSerializer(subobjectClass, serializer);
38 public SubobjectContainer parseSubobject(final int type, final ByteBuf buffer, final boolean mandatory)
39 throws RSVPParsingException {
40 Preconditions.checkArgument(type >= 0 && type <= Values.UNSIGNED_SHORT_MAX_VALUE);
41 final XROSubobjectParser parser = this.handlers.getParser(type);
45 return parser.parseSubobject(buffer, mandatory);
49 public void serializeSubobject(final SubobjectContainer subobject, final ByteBuf buffer) {
50 final XROSubobjectSerializer serializer = this.handlers.getSerializer(subobject.getSubobjectType()
51 .getImplementedInterface());
52 if (serializer == null) {
55 serializer.serializeSubobject(subobject, buffer);