Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPExplicitRouteObjectParser.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.PCEPEROSubobjectParser;
15 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
16 import org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject;
17 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
18
19 /**
20  * Parser for {@link org.opendaylight.protocol.pcep.object.PCEPExplicitRouteObject
21  * PCEPExplicitRouteObject}
22  */
23 public class PCEPExplicitRouteObjectParser implements PCEPObjectParser {
24
25         @Override
26         public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException {
27                 if (bytes == null || bytes.length == 0)
28                         throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
29
30                 final List<ExplicitRouteSubobject> subobjects = PCEPEROSubobjectParser.parse(bytes);
31                 if (subobjects.isEmpty())
32                         throw new PCEPDeserializerException("Empty Explicit Route Object.");
33
34                 return new PCEPExplicitRouteObject(subobjects, ignored);
35         }
36
37         @Override
38         public byte[] put(PCEPObject obj) {
39                 if (!(obj instanceof PCEPExplicitRouteObject))
40                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPExplicitRouteObject.");
41
42                 assert !(((PCEPExplicitRouteObject) obj).getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
43
44                 return PCEPEROSubobjectParser.put(((PCEPExplicitRouteObject) obj).getSubobjects());
45         }
46
47 }