BUG-64 : reformat TlvRegistry, to skip using getType method.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPOpenObjectParser.java
index e78b61c54ba3f28de6d091d16c45b57f031fced8..d27b341391d3effd88517bb69df5e3a63e83fc08 100644 (file)
@@ -8,23 +8,22 @@
 
 package org.opendaylight.protocol.pcep.impl.object;
 
+import org.opendaylight.protocol.pcep.spi.AbstractObjectWithTlvsParser;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
-import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.TlvRegistry;
 import org.opendaylight.protocol.pcep.spi.UnknownObject;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.db.version.tlv.LspDbVersion;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.predundancy.group.id.tlv.PredundancyGroupId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,7 +68,7 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
 
        private static final int PCEP_VERSION = 1;
 
-       public PCEPOpenObjectParser(final TlvHandlerRegistry tlvReg) {
+       public PCEPOpenObjectParser(final TlvRegistry tlvReg) {
                super(tlvReg);
        }
 
@@ -106,12 +105,6 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
        public void addTlv(final TlvsBuilder tbuilder, final Tlv tlv) {
                if (tlv instanceof OfList) {
                        tbuilder.setOfList((OfList) tlv);
-               } else if (tlv instanceof Stateful) {
-                       tbuilder.setStateful((Stateful) tlv);
-               } else if (tlv instanceof PredundancyGroupId) {
-                       tbuilder.setPredundancyGroupId((PredundancyGroupId) tlv);
-               } else if (tlv instanceof LspDbVersion) {
-                       tbuilder.setLspDbVersion((LspDbVersion) tlv);
                }
        }
 
@@ -142,55 +135,25 @@ public class PCEPOpenObjectParser extends AbstractObjectWithTlvsParser<TlvsBuild
                if (tlvs == null) {
                        return new byte[0];
                }
-               int finalLength = 0;
                byte[] ofListBytes = null;
-               byte[] statefulBytes = null;
-               byte[] predundancyBytes = null;
-               byte[] lspDbBytes = null;
                if (tlvs.getOfList() != null) {
                        ofListBytes = serializeTlv(tlvs.getOfList());
-                       finalLength += ofListBytes.length;
                }
-               if (tlvs.getStateful() != null) {
-                       statefulBytes = serializeTlv(tlvs.getStateful());
-                       finalLength += statefulBytes.length;
-               }
-               if (tlvs.getPredundancyGroupId() != null) {
-                       predundancyBytes = serializeTlv(tlvs.getPredundancyGroupId());
-                       finalLength += predundancyBytes.length;
-               }
-               if (tlvs.getLspDbVersion() != null) {
-                       lspDbBytes = serializeTlv(tlvs.getLspDbVersion());
-                       finalLength += lspDbBytes.length;
-               }
-               int offset = 0;
-               final byte[] result = new byte[finalLength];
+               byte[] result = new byte[0];
                if (ofListBytes != null) {
-                       ByteArray.copyWhole(ofListBytes, result, offset);
-                       offset += ofListBytes.length;
-               }
-               if (statefulBytes != null) {
-                       ByteArray.copyWhole(statefulBytes, result, offset);
-                       offset += statefulBytes.length;
-               }
-               if (lspDbBytes != null) {
-                       ByteArray.copyWhole(lspDbBytes, result, offset);
-                       offset += lspDbBytes.length;
-               }
-               if (predundancyBytes != null) {
-                       ByteArray.copyWhole(predundancyBytes, result, offset);
-                       offset += predundancyBytes.length;
+                       result = new byte[ofListBytes.length];
+                       ByteArray.copyWhole(ofListBytes, result, 0);
                }
                return result;
        }
 
        @Override
-       public int getObjectType() {
+       public final int getObjectType() {
                return TYPE;
        }
 
        @Override
-       public int getObjectClass() {
+       public final int getObjectClass() {
                return CLASS;
        }
 }