BUG-47 : switched subobjects to generated source code.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPEndPointsObjectParser.java
index 434e7dfa64408e60aa81f1a8c6de4e7b65280746..72a957fc7d51e55869bae5d3a14c534a9e9b19a7 100644 (file)
@@ -12,8 +12,8 @@ import org.opendaylight.protocol.concepts.Ipv6Util;
 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
 import org.opendaylight.protocol.pcep.PCEPErrors;
-import org.opendaylight.protocol.pcep.spi.AbstractObjectParser;
-import org.opendaylight.protocol.pcep.spi.HandlerRegistry;
+import org.opendaylight.protocol.pcep.impl.message.AbstractObjectWithTlvsParser;
+import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
@@ -29,7 +29,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ
 /**
  * Parser for IPv4 {@link EndpointsObject}
  */
-public class PCEPEndPointsObjectParser extends AbstractObjectParser<EndpointsBuilder> {
+public class PCEPEndPointsObjectParser extends AbstractObjectWithTlvsParser<EndpointsBuilder> {
 
        public static final int CLASS = 4;
 
@@ -43,7 +43,7 @@ public class PCEPEndPointsObjectParser extends AbstractObjectParser<EndpointsBui
 
        public static final int SRC4_F_OFFSET = 0;
        public static final int DEST4_F_OFFSET = SRC4_F_OFFSET + SRC4_F_LENGTH;
-       
+
        public static final int CLASS_6 = 4;
 
        public static final int TYPE_6 = 2;
@@ -54,23 +54,25 @@ public class PCEPEndPointsObjectParser extends AbstractObjectParser<EndpointsBui
        public static final int SRC6_F_OFFSET = 0;
        public static final int DEST6_F_OFFSET = SRC6_F_OFFSET + SRC6_F_LENGTH;
 
-       public PCEPEndPointsObjectParser(final HandlerRegistry registry) {
-               super(registry);
+       public PCEPEndPointsObjectParser(final TlvHandlerRegistry tlvReg) {
+               super(tlvReg);
        }
 
        @Override
        public EndpointsObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
-                       PCEPDocumentedException {
-               if (bytes == null)
+       PCEPDocumentedException {
+               if (bytes == null) {
                        throw new IllegalArgumentException("Array of bytes is mandatory");
-               
-               if (!header.isProcessingRule())
+               }
+
+               if (!header.isProcessingRule()) {
                        throw new PCEPDocumentedException("Processed flag not set", PCEPErrors.P_FLAG_NOT_SET);
-               
+               }
+
                final EndpointsBuilder builder = new EndpointsBuilder();
                builder.setIgnore(header.isIgnore());
                builder.setProcessingRule(header.isProcessingRule());
-               
+
                if (bytes.length == SRC4_F_LENGTH + DEST4_F_LENGTH) {
                        final Ipv4Builder b = new Ipv4Builder();
                        b.setSourceIpv4Address(Ipv4Util.addressForBytes(ByteArray.subByte(bytes, SRC4_F_OFFSET, SRC4_F_LENGTH)));
@@ -81,8 +83,9 @@ public class PCEPEndPointsObjectParser extends AbstractObjectParser<EndpointsBui
                        b.setSourceIpv6Address(Ipv6Util.addressForBytes(ByteArray.subByte(bytes, SRC6_F_OFFSET, SRC6_F_LENGTH)));
                        b.setDestinationIpv6Address((Ipv6Util.addressForBytes(ByteArray.subByte(bytes, DEST6_F_OFFSET, DEST6_F_LENGTH))));
                        builder.setAddressFamily(b.build());
-               } else
+               } else {
                        throw new PCEPDeserializerException("Wrong length of array of bytes.");
+               }
                return builder.build();
        }
 
@@ -93,8 +96,9 @@ public class PCEPEndPointsObjectParser extends AbstractObjectParser<EndpointsBui
 
        @Override
        public byte[] serializeObject(final Object object) {
-               if (!(object instanceof EndpointsObject))
+               if (!(object instanceof EndpointsObject)) {
                        throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed EndpointsObject.");
+               }
 
                final EndpointsObject ePObj = (EndpointsObject) object;
 
@@ -110,8 +114,9 @@ public class PCEPEndPointsObjectParser extends AbstractObjectParser<EndpointsBui
                        ByteArray.copyWhole(Ipv6Util.bytesForAddress(((Ipv6) afi).getSourceIpv6Address()), retBytes, SRC6_F_OFFSET);
                        ByteArray.copyWhole(Ipv6Util.bytesForAddress(((Ipv6) afi).getDestinationIpv6Address()), retBytes, DEST6_F_OFFSET);
                        return retBytes;
-               } else
+               } else {
                        throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + afi.getClass() + ". Needed IPv4");
+               }
        }
 
        @Override
@@ -123,7 +128,7 @@ public class PCEPEndPointsObjectParser extends AbstractObjectParser<EndpointsBui
        public int getObjectClass() {
                return CLASS;
        }
-       
+
        public int get6ObjectType() {
                return TYPE_6;
        }