BUG-47 : switched subobjects to generated source code.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPReportedRouteObjectParser.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 org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
12 import org.opendaylight.protocol.pcep.spi.RROSubobjectHandlerRegistry;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.pcreq.message.pcreq.message.requests.segment.computation.p2p.ReportedRouteBuilder;
17
18 /**
19  * Parser for {@link ReportedRouteObject}
20  */
21 public class PCEPReportedRouteObjectParser extends AbstractRROWithSubobjectsParser {
22
23         public static final int CLASS = 8;
24
25         public static final int TYPE = 1;
26
27         public PCEPReportedRouteObjectParser(final RROSubobjectHandlerRegistry subobjReg) {
28                 super(subobjReg);
29         }
30
31         @Override
32         public ReportedRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
33                         PCEPDocumentedException {
34                 if (bytes == null || bytes.length == 0) {
35                         throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
36                 }
37                 final ReportedRouteBuilder builder = new ReportedRouteBuilder();
38
39                 builder.setIgnore(header.isIgnore());
40                 builder.setProcessingRule(header.isProcessingRule());
41                 builder.setSubobjects(parseSubobjects(bytes));
42                 return builder.build();
43         }
44
45         @Override
46         public byte[] serializeObject(final Object object) {
47                 if (!(object instanceof ReportedRouteObject)) {
48                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
49                                         + ". Needed ReportedRouteObject.");
50                 }
51
52                 final ReportedRouteObject obj = (ReportedRouteObject) object;
53                 assert !(obj.getSubobjects().isEmpty()) : "Empty Reported Route Object.";
54                 return serializeSubobject(obj.getSubobjects());
55         }
56
57         @Override
58         public int getObjectType() {
59                 return TYPE;
60         }
61
62         @Override
63         public int getObjectClass() {
64                 return CLASS;
65         }
66 }