Assigned bugs to FIXMEs.
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / SimpleObjectHandlerRegistry.java
index 7452e375783dc9402778d6222c54a8afd7a9d8e1..5fbb0e8262567bbb474fa500e7b1406470095592 100644 (file)
@@ -11,8 +11,11 @@ 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.util.Util;
+import org.opendaylight.protocol.pcep.spi.PCEPErrors;
+import org.opendaylight.protocol.pcep.spi.UnknownObject;
+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;
 
 import com.google.common.base.Preconditions;
@@ -24,13 +27,13 @@ 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(objectClass >= 0 && objectClass <= Values.UNSIGNED_BYTE_MAX_VALUE);
                Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
                return this.handlers.registerParser(createKey(objectClass, objectType), parser);
        }
@@ -41,7 +44,30 @@ public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry
 
        @Override
        public ObjectParser getObjectParser(final int objectClass, final int objectType) {
-               return this.handlers.getParser(createKey(objectClass, objectType));
+               final ObjectParser ret = this.handlers.getParser(createKey(objectClass, objectType));
+               if (ret != null) {
+                       return ret;
+               }
+
+               final boolean foundClass = false;
+
+               // FIXME: BUG-187: search the parsers, check classes
+
+               if (!foundClass) {
+                       return new ObjectParser() {
+                               @Override
+                               public Object parseObject(final ObjectHeader header, final byte[] buffer) {
+                                       return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_CLASS);
+                               }
+                       };
+               } else {
+                       return new ObjectParser() {
+                               @Override
+                               public Object parseObject(final ObjectHeader header, final byte[] buffer) {
+                                       return new UnknownObject(PCEPErrors.UNRECOGNIZED_OBJ_TYPE);
+                               }
+                       };
+               }
        }
 
        @Override