BUG-47 : PCEP migration to generated DTOs.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPIncludeRouteObjectParser.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.AbstractObjectParser;
13 import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.IncludeRouteBuilder;
19
20 /**
21  * Parser for {@link IncludeRouteObject}
22  */
23 public class PCEPIncludeRouteObjectParser extends AbstractObjectParser<IncludeRouteBuilder> {
24
25         public static final int CLASS = 10;
26
27         public static final int TYPE = 1;
28
29         public PCEPIncludeRouteObjectParser(final HandlerRegistry registry) {
30                 super(registry);
31         }
32
33         @Override
34         public IncludeRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
35                         PCEPDocumentedException {
36                 if (bytes == null || bytes.length == 0)
37                         throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
38
39                 final IncludeRouteBuilder builder = new IncludeRouteBuilder();
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 void addTlv(final IncludeRouteBuilder builder, final Tlv tlv) {
49                 // No tlvs defined
50         }
51
52         @Override
53         public byte[] serializeObject(final Object object) {
54                 if (!(object instanceof IncludeRouteObject))
55                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed IncludeRouteObject.");
56
57                 assert !(((IncludeRouteObject) object).getSubobjects().isEmpty()) : "Empty Include Route Object.";
58
59                 // return PCEPEROSubobjectParser.put(((PCEPIncludeRouteObject) object).getSubobjects());
60                 // FIXME add subobjects
61                 return null;
62         }
63
64         @Override
65         public int getObjectType() {
66                 return TYPE;
67         }
68
69         @Override
70         public int getObjectClass() {
71                 return CLASS;
72         }
73 }