Update ObjectParser API
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / SimpleLabelRegistry.java
index a4cef53c988f59f32bbe42531eb6b5c04a71c0a3..0d75b08f630e29ed0f9a7c0eea6c90cec9d871b7 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.protocol.pcep.spi.pojo;
 
+import com.google.common.base.Preconditions;
+
 import io.netty.buffer.ByteBuf;
 
 import org.opendaylight.protocol.concepts.HandlerRegistry;
@@ -15,39 +17,36 @@ import org.opendaylight.protocol.pcep.spi.LabelRegistry;
 import org.opendaylight.protocol.pcep.spi.LabelSerializer;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.util.Values;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.label.subobject.LabelType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 
-import com.google.common.base.Preconditions;
-
 public class SimpleLabelRegistry implements LabelRegistry {
-       private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
-
-       public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
-               Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
-               return this.handlers.registerParser(cType, parser);
-       }
-
-       public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
-               return this.handlers.registerSerializer(labelClass, serializer);
-       }
-
-       @Override
-       public LabelType parseLabel(final int cType, final ByteBuf buffer) throws PCEPDeserializerException {
-               Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
-               final LabelParser parser = this.handlers.getParser(cType);
-               if (parser == null) {
-                       return null;
-               }
-               return parser.parseLabel(buffer);
-       }
-
-       @Override
-       public byte[] serializeLabel(final boolean unidirectional, final boolean global, final LabelType label) {
-               final LabelSerializer serializer = this.handlers.getSerializer(label.getImplementedInterface());
-               if (serializer == null) {
-                       return null;
-               }
-               return serializer.serializeLabel(unidirectional, global, label);
-       }
+    private final HandlerRegistry<DataContainer, LabelParser, LabelSerializer> handlers = new HandlerRegistry<>();
+
+    public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
+        Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
+        return this.handlers.registerParser(cType, parser);
+    }
+
+    public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
+        return this.handlers.registerSerializer(labelClass, serializer);
+    }
+
+    @Override
+    public LabelType parseLabel(final int cType, final ByteBuf buffer) throws PCEPDeserializerException {
+        Preconditions.checkArgument(cType >= 0 && cType <= Values.UNSIGNED_BYTE_MAX_VALUE);
+        final LabelParser parser = this.handlers.getParser(cType);
+        if (parser == null) {
+            return null;
+        }
+        return parser.parseLabel(buffer);
+    }
+
+    @Override
+    public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType label, final ByteBuf buffer) {
+        final LabelSerializer serializer = this.handlers.getSerializer(label.getImplementedInterface());
+        if (serializer != null) {
+            serializer.serializeLabel(unidirectional, global, label, buffer);
+        }
+    }
 }