BUG-47 : unfinished PCEP migration to generated DTOs.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPMessageFactory.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;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.protocol.framework.DeserializerException;
14 import org.opendaylight.protocol.framework.DocumentedException;
15 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
16 import org.opendaylight.protocol.pcep.spi.RawMessage;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
18
19 import com.google.common.base.Preconditions;
20
21 /**
22  * A PCEP message parser which also does validation.
23  */
24 public final class PCEPMessageFactory implements ProtocolMessageFactory<Message> {
25         private static final RawPCEPMessageFactory rawFactory = new RawPCEPMessageFactory();
26
27         @Override
28         public List<Message> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
29                 final List<Message> parsed = rawFactory.parse(bytes);
30                 final List<Message> validated = new ArrayList<>(parsed.size());
31
32                 for (final Message msg : parsed) {
33                         Preconditions.checkState(msg instanceof RawMessage);
34                         final RawMessage raw = (RawMessage) msg;
35
36                         // try {
37                         // validated.addAll(PCEPMessageValidator.getValidator(raw.getMsgType()).validate(raw.getAllObjects()));
38                         // } catch (final PCEPDeserializerException e) {
39                         // // FIXME: at validation time we may want to terminate with:
40                         // // logger.error("Malformed message, terminating. ", e);
41                         // // this.terminate(Reason.MALFORMED_MSG);
42                         // throw e;
43                         // }
44                 }
45
46                 return validated;
47         }
48
49         @Override
50         public byte[] put(final Message msg) {
51                 return rawFactory.put(msg);
52         }
53 }