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 com.google.common.collect.HashBasedTable;
13 import com.google.common.collect.Table;
14 import io.netty.buffer.ByteBuf;
15 import java.util.HashMap;
17 import org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException;
18 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectParser;
19 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectRegistry;
20 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
21 import org.opendaylight.protocol.util.Values;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
24 public final class SimpleRSVPObjectRegistry implements RSVPTeObjectRegistry {
26 private final Table<Integer, Integer, RSVPTeObjectParser> parserHandler = HashBasedTable.create();
27 private final Map<Class<? extends RsvpTeObject>, RSVPTeObjectSerializer> serializerHandler = new HashMap<>();
29 public void registerRsvpObjectParser(final int classNum, final int ctype, final RSVPTeObjectParser parser) {
30 Preconditions.checkArgument(classNum >= 0 && classNum <= Values.UNSIGNED_BYTE_MAX_VALUE);
31 Preconditions.checkArgument(ctype >= 0 && ctype <= Values.UNSIGNED_BYTE_MAX_VALUE);
32 this.parserHandler.put(classNum, ctype, parser);
35 public void registerRsvpObjectSerializer(final Class<? extends RsvpTeObject> objectClass,
36 final RSVPTeObjectSerializer serializer) {
37 this.serializerHandler.put(objectClass, serializer);
41 public RsvpTeObject parseRSPVTe(final int classNum, final int ctype, final ByteBuf buffer)
42 throws RSVPParsingException {
43 final RSVPTeObjectParser parser = this.parserHandler.get(classNum, ctype);
47 return parser.parseObject(buffer);
51 public void serializeRSPVTe(final RsvpTeObject parameter, final ByteBuf bytes) {
52 if (parameter == null) {
55 final RSVPTeObjectSerializer serializer = this.serializerHandler.get(parameter.implementedInterface());
56 if (serializer == null) {
59 serializer.serializeObject(parameter, bytes);