BUG-731 : removed critical sonar warnings
[bgpcep.git] / pcep / segment-routing / src / main / java / org / opendaylight / protocol / pcep / lsp / setup / type01 / CInitiated00SrpObjectWithPstTlvParser.java
1 /*
2  * Copyright (c) 2014 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.lsp.setup.type01;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.protocol.pcep.ietf.initiated00.CInitiated00SrpObjectParser;
12 import org.opendaylight.protocol.pcep.spi.TlvRegistry;
13 import org.opendaylight.protocol.pcep.spi.VendorInformationTlvRegistry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.Tlvs;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev131222.srp.object.srp.TlvsBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.PathSetupTypeTlv;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs5;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs6;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs7;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs7Builder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.Tlvs8;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.lsp.setup.type._01.rev140507.path.setup.type.tlv.PathSetupType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
24
25 public class CInitiated00SrpObjectWithPstTlvParser extends CInitiated00SrpObjectParser {
26
27     public CInitiated00SrpObjectWithPstTlvParser(final TlvRegistry tlvReg, final VendorInformationTlvRegistry viTlvReg) {
28         super(tlvReg, viTlvReg);
29     }
30
31     @Override
32     public void addTlv(final TlvsBuilder builder, final Tlv tlv) {
33         super.addTlv(builder, tlv);
34         final Tlvs7Builder tlvBuilder = new Tlvs7Builder();
35         final Tlvs7 tlvs = builder.getAugmentation(Tlvs7.class);
36         if (tlvs != null && tlvs.getPathSetupType() != null) {
37             tlvBuilder.setPathSetupType(tlvs.getPathSetupType());
38         }
39         if (tlv instanceof PathSetupType) {
40             tlvBuilder.setPathSetupType((PathSetupType) tlv);
41         }
42         builder.addAugmentation(Tlvs7.class, tlvBuilder.build());
43     }
44
45     @Override
46     public void serializeTlvs(final Tlvs tlvs, final ByteBuf body) {
47         if (tlvs == null) {
48             return;
49         }
50         super.serializeTlvs(tlvs, body);
51         if (tlvs.getAugmentation(Tlvs5.class) != null) {
52             serializePathSetupType(tlvs.getAugmentation(Tlvs5.class), body);
53         } else if (tlvs.getAugmentation(Tlvs6.class) != null) {
54             serializePathSetupType(tlvs.getAugmentation(Tlvs6.class), body);
55         } else if (tlvs.getAugmentation(Tlvs7.class) != null) {
56             serializePathSetupType(tlvs.getAugmentation(Tlvs7.class), body);
57         } else if (tlvs.getAugmentation(Tlvs8.class) != null) {
58             serializePathSetupType(tlvs.getAugmentation(Tlvs8.class), body);
59         }
60     }
61
62     private void serializePathSetupType(final PathSetupTypeTlv pstTlv, final ByteBuf body) {
63         if (pstTlv.getPathSetupType() != null) {
64             serializeTlv(pstTlv.getPathSetupType(), body);
65         }
66     }
67 }