BUG-64 : initial rewrite, XROSubobjectRegistry.
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / SimpleObjectHandlerRegistry.java
index 2a3e704ac72f8fc25ddd14b5c30afacae1f8ab51..c93b9374c2c8faef763cee3108fc5c64b8872d1d 100644 (file)
@@ -11,8 +11,9 @@ import org.opendaylight.protocol.concepts.HandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
 import org.opendaylight.protocol.pcep.spi.ObjectParser;
 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
 import org.opendaylight.protocol.pcep.spi.UnknownObject;
-import org.opendaylight.protocol.util.Util;
+import org.opendaylight.protocol.util.Values;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
@@ -26,14 +27,14 @@ public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry
        private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
 
        private static int createKey(final int objectClass, final int objectType) {
-               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE);
                Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
                return (objectClass << 4) | objectType;
        }
 
        public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
-               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Util.UNSIGNED_BYTE_MAX_VALUE);
-               Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
+               Preconditions.checkArgument(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE, "Illagal object class %s", objectClass);
+               Preconditions.checkArgument(objectType >= 0 && objectType <= 15, "Illegal object type %s", objectType);
                return this.handlers.registerParser(createKey(objectClass, objectType), parser);
        }
 
@@ -48,26 +49,22 @@ public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry
                        return ret;
                }
 
-               boolean foundClass = false;
+               final boolean foundClass = false;
 
-               // FIXME: search the parsers, check classes
-               //e.getError() == PCEPErrors.UNRECOGNIZED_OBJ_CLASS || e.getError() == PCEPErrors.UNRECOGNIZED_OBJ_TYPE
+               // FIXME: BUG-187: search the parsers, check classes
 
                if (!foundClass) {
                        return new ObjectParser() {
                                @Override
                                public Object parseObject(final ObjectHeader header, final byte[] buffer) {
-                                       // FIXME: appropriate error (unrecognized object class)
-                                       return new UnknownObject(null);
+                                       return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
                                }
                        };
-
                } else {
                        return new ObjectParser() {
                                @Override
                                public Object parseObject(final ObjectHeader header, final byte[] buffer) {
-                                       // FIXME: appropriate error (unrecognized object type)
-                                       return new UnknownObject(null);
+                                       return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
                                }
                        };
                }