BUG-50 : adjusted ERO object.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPExplicitRouteObjectParser.java
index aad0c00c3b7e86f624cfc75fb79cfa61a3e4fb8a..33ca3f94ab9a3d9652515db531645c11efa8f90f 100644 (file)
@@ -7,41 +7,59 @@
  */
 package org.opendaylight.protocol.pcep.impl.object;
 
-import java.util.List;
-
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.PCEPObject;
-import org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParser;
-import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
-import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
-import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
+import org.opendaylight.protocol.pcep.PCEPDocumentedException;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectHandlerRegistry;
+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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Ero;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder;
 
 /**
- * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject
- * PCEPExplicitRouteObject}
+ * Parser for {@link Ero}
  */
-public class PCEPExplicitRouteObjectParser implements PCEPObjectParser {
+public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsParser {
 
-       @Override
-       public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException {
-               if (bytes == null || bytes.length == 0)
-                       throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
+       public static final int CLASS = 7;
 
-               final List<ExplicitRouteSubobject> subobjects = PCEPEROSubobjectParser.parse(bytes);
-               if (subobjects.isEmpty())
-                       throw new PCEPDeserializerException("Empty Explicit Route Object.");
+       public static final int TYPE = 1;
 
-               return new PCEPExplicitRouteObject(subobjects, ignored);
+       public PCEPExplicitRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
+               super(subobjReg);
+       }
+
+       @Override
+       public Ero parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
+               if (bytes == null || bytes.length == 0) {
+                       throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
+               }
+               final EroBuilder builder = new EroBuilder();
+               builder.setIgnore(header.isIgnore());
+               builder.setProcessingRule(header.isProcessingRule());
+               builder.setSubobjects(parseSubobjects(bytes));
+               return builder.build();
        }
 
        @Override
-       public byte[] put(PCEPObject obj) {
-               if (!(obj instanceof PCEPExplicitRouteObject))
-                       throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPExplicitRouteObject.");
+       public byte[] serializeObject(final Object object) {
+               if (!(object instanceof Ero)) {
+                       throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
+                                       + ". Needed ExplicitRouteObject.");
+               }
+               final Ero ero = ((Ero) object);
+
+               assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
 
-               assert !(((PCEPExplicitRouteObject) obj).getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
+               return serializeSubobject(ero.getSubobjects());
+       }
 
-               return PCEPEROSubobjectParser.put(((PCEPExplicitRouteObject) obj).getSubobjects());
+       @Override
+       public int getObjectType() {
+               return TYPE;
        }
 
+       @Override
+       public int getObjectClass() {
+               return CLASS;
+       }
 }