Fixed testool performance bottleneck due to testtool using NetconfMonitoring from...
[controller.git] / opendaylight / netconf / netconf-testtool / src / main / java / org / opendaylight / controller / netconf / test / tool / ModuleBuilderCapability.java
1 /*
2  * Copyright (c) 2014 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.netconf.test.tool;
10
11 import com.google.common.base.Optional;
12 import java.util.Collections;
13 import java.util.Date;
14 import java.util.List;
15 import org.opendaylight.controller.netconf.api.Capability;
16 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
19
20 final class ModuleBuilderCapability implements Capability {
21     private static final Date NO_REVISION = new Date(0);
22     private static final List<String> NETCONF = Collections.singletonList("NETCONF");
23     private final ModuleBuilder input;
24     private final Optional<String> content;
25
26     public ModuleBuilderCapability(final ModuleBuilder input, final String inputStream) {
27         this.input = input;
28         this.content = Optional.of(inputStream);
29     }
30
31     @Override
32     public String getCapabilityUri() {
33         // FIXME capabilities in Netconf-impl need to check for NO REVISION
34         final String withoutRevision = getModuleNamespace().get() + "?module=" + getModuleName().get();
35         return hasRevision() ? withoutRevision + "&revision=" + Util.writeDate(input.getRevision()) : withoutRevision;
36     }
37
38     @Override
39     public Optional<String> getModuleNamespace() {
40         return Optional.of(input.getNamespace().toString());
41     }
42
43     @Override
44     public Optional<String> getModuleName() {
45         return Optional.of(input.getName());
46     }
47
48     @Override
49     public Optional<String> getRevision() {
50         return Optional.of(hasRevision() ? QName.formattedRevision(input.getRevision()) : "");
51     }
52
53     private boolean hasRevision() {
54         return !input.getRevision().equals(NO_REVISION);
55     }
56
57     @Override
58     public Optional<String> getCapabilitySchema() {
59         return content;
60     }
61
62     @Override
63     public List<String> getLocation() {
64         return NETCONF;
65     }
66 }

©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.