2 * Copyright (c) 2014 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.pcep.spi.pojo;
11 import com.google.common.primitives.Ints;
13 import io.netty.buffer.ByteBuf;
15 import java.util.Optional;
16 import org.opendaylight.protocol.concepts.HandlerRegistry;
17 import org.opendaylight.protocol.pcep.spi.ObjectParser;
18 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
19 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
20 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
21 import org.opendaylight.protocol.pcep.spi.UnknownObject;
22 import org.opendaylight.protocol.pcep.spi.VendorInformationObjectRegistry;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
28 import org.opendaylight.yangtools.yang.binding.DataContainer;
30 public class SimpleVendorInformationObjectRegistry implements VendorInformationObjectRegistry {
32 private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
34 public AutoCloseable registerVendorInformationObjectParser(final EnterpriseNumber enterpriseNumber, final ObjectParser parser) {
35 return this.handlers.registerParser(Ints.checkedCast(enterpriseNumber.getValue()), parser);
38 public AutoCloseable registerVendorInformationObjectSerializer(final Class<? extends EnterpriseSpecificInformation> esInformationClass, final ObjectSerializer serializer) {
39 return this.handlers.registerSerializer(esInformationClass, serializer);
43 public Optional<? extends Object> parseVendorInformationObject(final EnterpriseNumber enterpriseNumber, final ObjectHeader header, final ByteBuf buffer)
44 throws PCEPDeserializerException {
45 final ObjectParser parser = this.handlers.getParser(Ints.checkedCast(enterpriseNumber.getValue()));
47 if (!header.isProcessingRule()) {
48 return Optional.empty();
50 return Optional.of(new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS));
52 return Optional.of(parser.parseObject(header, buffer));
56 public void serializeVendorInformationObject(final VendorInformationObject viObject, final ByteBuf buffer) {
57 final ObjectSerializer serializer = this.handlers.getSerializer(viObject.getEnterpriseSpecificInformation().getImplementedInterface());
58 if (serializer == null) {
61 serializer.serializeObject(viObject, buffer);