BUG-47: more subobject models
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / SimpleSubobjectHandlerFactory.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 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;
16
17 import com.google.common.base.Preconditions;
18
19 public final class SimpleSubobjectHandlerFactory implements SubobjectHandlerRegistry {
20         private final HandlerRegistry<DataContainer, SubobjectParser, SubobjectSerializer> handlers = new HandlerRegistry<>();
21
22         @Override
23         public AutoCloseable registerSubobjectParser(final int subobjectType, final SubobjectParser parser) {
24                 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
25                 return handlers.registerParser(subobjectType, parser);
26         }
27
28         @Override
29         public SubobjectParser getSubobjectParser(final int subobjectType) {
30                 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
31                 return handlers.getParser(subobjectType);
32         }
33
34         @Override
35         public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass, final SubobjectSerializer serializer) {
36                 return handlers.registerSerializer(subobjectClass, serializer);
37         }
38
39         @Override
40         public SubobjectSerializer getSubobjectSerializer(final CSubobject subobject) {
41                 return handlers.getSerializer(subobject.getImplementedInterface());
42         }
43 }