030adfcb64d1c8607d40060ffcaa3f3b94209af5
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / SimpleXROSubobjectHandlerRegistry.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.spi.pojo;
9
10 import org.opendaylight.protocol.concepts.HandlerRegistry;
11 import org.opendaylight.protocol.pcep.spi.XROSubobjectHandlerRegistry;
12 import org.opendaylight.protocol.pcep.spi.XROSubobjectParser;
13 import org.opendaylight.protocol.pcep.spi.XROSubobjectSerializer;
14 import org.opendaylight.protocol.util.Util;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.CSubobject;
17 import org.opendaylight.yangtools.yang.binding.DataContainer;
18
19 import com.google.common.base.Preconditions;
20
21 public final class SimpleXROSubobjectHandlerRegistry implements XROSubobjectHandlerRegistry {
22         private final HandlerRegistry<DataContainer, XROSubobjectParser, XROSubobjectSerializer> handlers = new HandlerRegistry<>();
23
24         public AutoCloseable registerSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
25                 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
26                 return this.handlers.registerParser(subobjectType, parser);
27         }
28
29         public AutoCloseable registerSubobjectSerializer(final Class<? extends CSubobject> subobjectClass,
30                         final XROSubobjectSerializer serializer) {
31                 return this.handlers.registerSerializer(subobjectClass, serializer);
32         }
33
34         @Override
35         public XROSubobjectParser getSubobjectParser(final int subobjectType) {
36                 Preconditions.checkArgument(subobjectType >= 0 && subobjectType <= Util.UNSIGNED_SHORT_MAX_VALUE);
37                 return this.handlers.getParser(subobjectType);
38         }
39
40         @Override
41         public XROSubobjectSerializer getSubobjectSerializer(final Subobjects subobject) {
42                 return this.handlers.getSerializer(subobject.getImplementedInterface());
43         }
44 }