Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[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 java.util.Map.Entry;
15 import java.util.Set;
16 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
17 import org.opendaylight.controller.md.sal.dom.api.DOMService;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20
21 public final class SimpleDOMMountPoint implements DOMMountPoint {
22
23     private final YangInstanceIdentifier identifier;
24     private final ClassToInstanceMap<DOMService> services;
25     private final SchemaContext schemaContext;
26
27     public static SimpleDOMMountPoint create(final YangInstanceIdentifier identifier,
28             final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
29         return new SimpleDOMMountPoint(identifier, services, ctx);
30     }
31
32     private SimpleDOMMountPoint(final YangInstanceIdentifier identifier,
33             final ClassToInstanceMap<DOMService> services, final SchemaContext ctx) {
34         this.identifier = identifier;
35         this.services = ImmutableClassToInstanceMap.copyOf(services);
36         this.schemaContext = ctx;
37     }
38
39     @Override
40     public YangInstanceIdentifier getIdentifier() {
41         return identifier;
42     }
43
44     @Override
45     public SchemaContext getSchemaContext() {
46         return schemaContext;
47     }
48
49     @Override
50     public <T extends DOMService> Optional<T> getService(final Class<T> cls) {
51         return Optional.fromNullable(services.getInstance(cls));
52     }
53
54     public Set<Entry<Class<? extends DOMService>, DOMService>> getAllServices() {
55         return services.entrySet();
56     }
57
58     public ClassToInstanceMap<DOMService> getServices() {
59         return services;
60     }
61
62     @Override
63     public int hashCode() {
64         return identifier.hashCode();
65     }
66
67     @Override
68     public boolean equals(final Object obj) {
69         return this == obj || obj instanceof DOMMountPoint && identifier.equals(((DOMMountPoint) obj).getIdentifier());
70     }
71 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.