Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPSecondaryRecordRouteObjectParser.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.pcep.impl.object;
9
10 import java.util.List;
11
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.PCEPObject;
14 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
15 import org.opendaylight.protocol.pcep.impl.PCEPRROSubobjectParser;
16 import org.opendaylight.protocol.pcep.object.PCEPSecondaryRecordRouteObject;
17 import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject;
18
19 public class PCEPSecondaryRecordRouteObjectParser implements PCEPObjectParser {
20
21     @Override
22     public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException {
23         if (bytes == null || bytes.length == 0)
24             throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
25
26         final List<ReportedRouteSubobject> subobjects = PCEPRROSubobjectParser.parse(bytes);
27         if (subobjects.isEmpty())
28             throw new PCEPDeserializerException("Empty Secondary Recorded Route Object.");
29
30         return new PCEPSecondaryRecordRouteObject(subobjects, processed, ignored);
31     }
32
33     @Override
34     public byte[] put(PCEPObject obj) {
35
36         if (!(obj instanceof PCEPSecondaryRecordRouteObject))
37             throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPSecondaryRecordRouteObject.");
38
39         assert !(((PCEPSecondaryRecordRouteObject) obj).getSubobjects().isEmpty()) : "Empty Secondary Record Route Object.";
40
41         return PCEPRROSubobjectParser.put(((PCEPSecondaryRecordRouteObject) obj).getSubobjects());
42     }
43
44 }