Rework PCEPDeserializerException and move it into SPI
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / message / PCEPCloseMessageParser.java
index 5fd81073bbede711c36651600807dc5798391358..301a9c9d609d4a183d3f17b64cdc97b157adebf5 100644 (file)
@@ -11,10 +11,8 @@ import io.netty.buffer.ByteBuf;
 
 import java.util.List;
 
-import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
@@ -22,10 +20,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 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.close.message.CCloseMessage;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CClose;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
 
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPCloseMessage PCEPCloseMessage}
+ * Parser for {@link CloseMessage}
  */
 public class PCEPCloseMessageParser extends AbstractMessageParser {
 
@@ -50,32 +48,19 @@ public class PCEPCloseMessageParser extends AbstractMessageParser {
        }
 
        @Override
-       public CloseMessage parseMessage(final byte[] buffer) throws PCEPDeserializerException, PCEPDocumentedException {
-               if (buffer == null || buffer.length == 0) {
-                       throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
-               }
-               final List<Object> objs = parseObjects(buffer);
-
-               return validate(objs);
-       }
-
-       private Close validate(final List<Object> objects) throws PCEPDeserializerException {
+       protected Close validate(final List<Object> objects, final List<Message> errors) throws PCEPDeserializerException {
                if (objects == null) {
                        throw new IllegalArgumentException("Passed list can't be null.");
                }
-
                if (objects.isEmpty() || !(objects.get(0) instanceof CClose)) {
                        throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
                }
-
                final Object o = objects.get(0);
                final CCloseMessage msg = new CCloseMessageBuilder().setCClose((CClose) o).build();
                objects.remove(0);
-
                if (!objects.isEmpty()) {
                        throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
                }
-
                return new CloseBuilder().setCCloseMessage(msg).build();
        }