2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.impl;
10 import java.util.ArrayList;
11 import java.util.List;
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;
19 import com.google.common.base.Preconditions;
22 * A PCEP message parser which also does validation.
24 public final class PCEPMessageFactory implements ProtocolMessageFactory<Message> {
25 private static final RawPCEPMessageFactory rawFactory = new RawPCEPMessageFactory();
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());
32 for (final Message msg : parsed) {
33 Preconditions.checkState(msg instanceof RawMessage);
34 final RawMessage raw = (RawMessage) msg;
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);
50 public byte[] put(final Message msg) {
51 return rawFactory.put(msg);