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 org.opendaylight.protocol.concepts.HandlerRegistry;
11 import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry;
12 import org.opendaylight.protocol.pcep.spi.SubobjectParser;
13 import org.opendaylight.protocol.pcep.spi.SubobjectSerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
15 import org.opendaylight.yangtools.yang.binding.DataContainer;
17 import com.google.common.base.Preconditions;
19 public final class SimpleSubobjectHandlerFactory implements SubobjectHandlerRegistry {
20 private final HandlerRegistry<DataContainer, SubobjectParser, SubobjectSerializer> handlers = new HandlerRegistry<>();
23 public AutoCloseable registerSubobjectParser(final int subobjectType, final SubobjectParser parser) {
24 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
25 return handlers.registerParser(subobjectType, parser);
29 public SubobjectParser getSubobjectParser(final int subobjectType) {
30 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
31 return handlers.getParser(subobjectType);
35 public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass, final SubobjectSerializer serializer) {
36 return handlers.registerSerializer(subobjectClass, serializer);
40 public SubobjectSerializer getSubobjectSerializer(final CSubobject subobject) {
41 return handlers.getSerializer(subobject.getImplementedInterface());