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