BUG-47 : switched subobjects to generated source code.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / object / PCEPExplicitRouteObjectParser.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.EROSubobjectHandlerRegistry;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
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.path.definition.ExplicitRouteBuilder;
17
18 /**
19  * Parser for {@link ExplicitRouteObject}
20  */
21 public class PCEPExplicitRouteObjectParser extends AbstractEROWithSubobjectsParser {
22
23         public static final int CLASS = 7;
24
25         public static final int TYPE = 1;
26
27         public PCEPExplicitRouteObjectParser(final EROSubobjectHandlerRegistry subobjReg) {
28                 super(subobjReg);
29         }
30
31         @Override
32         public ExplicitRouteObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException,
33                         PCEPDocumentedException {
34                 if (bytes == null || bytes.length == 0) {
35                         throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
36                 }
37                 final ExplicitRouteBuilder builder = new ExplicitRouteBuilder();
38                 builder.setIgnore(header.isIgnore());
39                 builder.setProcessingRule(header.isProcessingRule());
40                 builder.setSubobjects(parseSubobjects(bytes));
41                 return builder.build();
42         }
43
44         @Override
45         public byte[] serializeObject(final Object object) {
46                 if (!(object instanceof ExplicitRouteObject)) {
47                         throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass()
48                                         + ". Needed ExplicitRouteObject.");
49                 }
50
51                 final ExplicitRouteObject ero = ((ExplicitRouteObject) object);
52
53                 assert !(ero.getSubobjects().isEmpty()) : "Empty Explicit Route Object.";
54
55                 return serializeSubobject(ero.getSubobjects());
56         }
57
58         @Override
59         public int getObjectType() {
60                 return TYPE;
61         }
62
63         @Override
64         public int getObjectClass() {
65                 return CLASS;
66         }
67 }