*/
package org.opendaylight.protocol.pcep.impl.object;
+import java.util.List;
+
import org.opendaylight.protocol.pcep.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.PCEPDocumentedException;
-import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
-import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
-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.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.IncludeRouteBuilder;
+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.PCEPIncludeRouteObject;
+import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
/**
- * Parser for {@link IncludeRouteObject}
+ * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPIncludeRouteObject
+ * PCEPIncludeRouteObject}
*/
-public class PCEPIncludeRouteObjectParser extends AbstractObjectParser<IncludeRouteBuilder> {
-
- public static final int CLASS = 10;
-
- public static final int TYPE = 1;
-
- public PCEPIncludeRouteObjectParser(final HandlerRegistry registry) {
- super(registry);
- }
+public class PCEPIncludeRouteObjectParser implements PCEPObjectParser {
@Override
- public IncludeRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
- PCEPDocumentedException {
+ 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.");
- final IncludeRouteBuilder builder = new IncludeRouteBuilder();
+ final List<ExplicitRouteSubobject> subobjects = PCEPEROSubobjectParser.parse(bytes);
+ if (subobjects.isEmpty())
+ throw new PCEPDeserializerException("Empty Include Route Object.");
- builder.setIgnore(header.isIgnore());
- builder.setProcessingRule(header.isProcessingRule());
- // FIXME: add subobjects
- return builder.build();
+ return new PCEPIncludeRouteObject(subobjects, processed, ignored);
}
@Override
- public void addTlv(final IncludeRouteBuilder builder, final Tlv tlv) {
- // No tlvs defined
- }
+ public byte[] put(PCEPObject obj) {
+ if (!(obj instanceof PCEPIncludeRouteObject))
+ throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPIncludeRouteObject.");
- @Override
- public byte[] serializeObject(final Object object) {
- if (!(object instanceof IncludeRouteObject))
- throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed IncludeRouteObject.");
+ assert !(((PCEPIncludeRouteObject) obj).getSubobjects().isEmpty()) : "Empty Include Route Object.";
- assert !(((IncludeRouteObject) object).getSubobjects().isEmpty()) : "Empty Include Route Object.";
-
- // return PCEPEROSubobjectParser.put(((PCEPIncludeRouteObject) object).getSubobjects());
- // FIXME add subobjects
- return null;
- }
-
- @Override
- public int getObjectType() {
- return TYPE;
+ return PCEPEROSubobjectParser.put(((PCEPIncludeRouteObject) obj).getSubobjects());
}
- @Override
- public int getObjectClass() {
- return CLASS;
- }
}