Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / message / PCEPOpenMessageValidator.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.message;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
14 import org.opendaylight.protocol.pcep.PCEPObject;
15 import org.opendaylight.protocol.pcep.impl.PCEPMessageValidator;
16 import org.opendaylight.protocol.pcep.message.PCEPOpenMessage;
17 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
19
20 /**
21  * PCEPOpenMessage validator. Validates message integrity.
22  */
23 public class PCEPOpenMessageValidator extends PCEPMessageValidator {
24
25         @Override
26         public List<Message> validate(final List<PCEPObject> objects) throws PCEPDeserializerException {
27                 if (objects == null)
28                         throw new IllegalArgumentException("Passed list can't be null.");
29
30                 if (objects.isEmpty() || !(objects.get(0) instanceof PCEPOpenObject))
31                         throw new PCEPDeserializerException("Open message doesn't contain OPEN object.");
32
33                 final PCEPOpenMessage msg = new PCEPOpenMessage((PCEPOpenObject) objects.get(0));
34                 objects.remove(0);
35
36                 if (!objects.isEmpty())
37                         throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
38
39                 return new ArrayList<Message>() {
40                         private static final long serialVersionUID = 1L;
41                         {
42                                 this.add(msg);
43                         }
44                 };
45         }
46 }