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.object;
10 import java.util.List;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.PCEPObject;
14 import org.opendaylight.protocol.pcep.impl.PCEPEROSubobjectParser;
15 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
16 import org.opendaylight.protocol.pcep.object.PCEPSecondaryExplicitRouteObject;
17 import org.opendaylight.protocol.pcep.subobject.ExplicitRouteSubobject;
19 public class PCEPSecondaryExplicitRouteObjectParser implements PCEPObjectParser {
22 public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException {
23 if (bytes == null || bytes.length == 0)
24 throw new IllegalArgumentException("Byte array is mandatory. Can't be null or empty.");
26 final List<ExplicitRouteSubobject> subobjects = PCEPEROSubobjectParser.parse(bytes);
27 if (subobjects.isEmpty())
28 throw new PCEPDeserializerException("Empty Secondary Explicit Route Object.");
30 return new PCEPSecondaryExplicitRouteObject(subobjects, processed, ignored);
34 public byte[] put(PCEPObject obj) {
35 if (!(obj instanceof PCEPSecondaryExplicitRouteObject))
36 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPSecondaryExplicitRouteObject.");
38 assert !(((PCEPSecondaryExplicitRouteObject) obj).getSubobjects().isEmpty()) : "Empty Secondary Explicit Route Object.";
40 return PCEPEROSubobjectParser.put(((PCEPSecondaryExplicitRouteObject) obj).getSubobjects());