BUG-47 : switched subobjects to generated source code.
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / SimpleRROSubobjectHandlerFactory.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.RROSubobjectHandlerRegistry;
12 import org.opendaylight.protocol.pcep.spi.RROSubobjectParser;
13 import org.opendaylight.protocol.pcep.spi.RROSubobjectSerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.Subobjects;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
16 import org.opendaylight.yangtools.yang.binding.DataContainer;
17
18 import com.google.common.base.Preconditions;
19
20 public final class SimpleRROSubobjectHandlerFactory implements RROSubobjectHandlerRegistry {
21         private final HandlerRegistry<DataContainer, RROSubobjectParser, RROSubobjectSerializer> handlers = new HandlerRegistry<>();
22
23         @Override
24         public AutoCloseable registerSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
25                 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
26                 return this.handlers.registerParser(subobjectType, parser);
27         }
28
29         @Override
30         public RROSubobjectParser getSubobjectParser(final int subobjectType) {
31                 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= 65535);
32                 return this.handlers.getParser(subobjectType);
33         }
34
35         @Override
36         public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
37                         final RROSubobjectSerializer serializer) {
38                 return this.handlers.registerSerializer(subobjectClass, serializer);
39         }
40
41         @Override
42         public RROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
43                 return this.handlers.getSerializer(subobject.getImplementedInterface());
44         }
45 }