11d9cab1b84e91f7d5906c292f913a0f1da09120
[controller.git] / opendaylight / md-sal / sal-dom-spi / src / main / java / org / opendaylight / controller / md / sal / dom / broker / spi / mount / SimpleDOMMountPoint.java
1 /*
2  * Copyright (c) 2014, 2015 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
9 package org.opendaylight.controller.md.sal.dom.broker.spi.mount;
10
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ClassToInstanceMap;
13 import com.google.common.collect.ImmutableClassToInstanceMap;
14 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
15 import org.opendaylight.controller.md.sal.dom.api.DOMService;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 public final class SimpleDOMMountPoint implements DOMMountPoint {
20
21     private final YangInstanceIdentifier identifier;
22     private final ClassToInstanceMap<DOMService> services;
23     private final SchemaContext schemaContext;
24
25     public static SimpleDOMMountPoint create(final YangInstanceIdentifier identifier,
26             final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
27         return new SimpleDOMMountPoint(identifier, services, ctx);
28     }
29
30     private SimpleDOMMountPoint(final YangInstanceIdentifier identifier,
31             final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
32         this.identifier = identifier;
33         this.services = ImmutableClassToInstanceMap.copyOf(services);
34         this.schemaContext = ctx;
35     }
36
37     @Override
38     public YangInstanceIdentifier getIdentifier() {
39         return identifier;
40     }
41
42     @Override
43     public SchemaContext getSchemaContext() {
44         return schemaContext;
45     }
46
47     @Override
48     public <T extends DOMService> Optional<T> getService(final Class<T> cls) {
49         return Optional.fromNullable(services.getInstance(cls));
50     }
51 }