Fixed netconf monitoring.
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / model / Annotation.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.controller.config.yangjmxgenerator.plugin.ftl.model;
9
10 import java.util.List;
11
12 import org.opendaylight.controller.config.api.annotations.Description;
13 import org.opendaylight.controller.config.api.annotations.RequireInterface;
14 import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
15 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
16 import org.opendaylight.yangtools.yang.common.QName;
17
18 import com.google.common.base.Preconditions;
19 import com.google.common.collect.Lists;
20
21 public class Annotation {
22     final String name;
23     final List<Parameter> params;
24
25     public Annotation(String name, List<Parameter> params) {
26         this.name = name;
27         this.params = params;
28     }
29
30     public String getName() {
31         return name;
32     }
33
34     public List<Parameter> getParams() {
35         return params;
36     }
37
38     public static Annotation createDescriptionAnnotation(String description) {
39         Preconditions.checkNotNull(description,
40                 "Cannot create annotation from null description");
41         return new Annotation(Description.class.getCanonicalName(),
42                 Lists.newArrayList(new Parameter("value", q(description))));
43     }
44
45     public static Annotation createSieAnnotation(QName qname,
46             String exportedClassName) {
47         Preconditions.checkNotNull(qname,
48                 "Cannot create annotation from null qname");
49         Preconditions.checkNotNull(exportedClassName,
50                 "Cannot create annotation from null exportedClassName");
51
52         List<Parameter> params = Lists.newArrayList(new Parameter("value", q(qname.toString())));
53         params.add(new Parameter("osgiRegistrationType", exportedClassName + ".class"));
54
55         params.add(new Parameter("namespace", q(qname.getNamespace().toString())));
56         params.add(new Parameter("revision", q(qname.getFormattedRevision())));
57         params.add(new Parameter("localName", q(qname.getLocalName())));
58
59         return new Annotation(
60                 ServiceInterfaceAnnotation.class.getCanonicalName(), params);
61     }
62
63     public static Annotation createRequireIfcAnnotation(
64             ServiceInterfaceEntry sie) {
65         String reqIfc = sie.getFullyQualifiedName() + ".class";
66         return new Annotation(RequireInterface.class.getCanonicalName(),
67                 Lists.newArrayList(new Parameter("value", reqIfc)));
68     }
69
70     private static final String quote = "\"";
71
72     private static String q(String nullableDescription) {
73         return nullableDescription == null ? null : quote + nullableDescription
74                 + quote;
75     }
76
77     public static class Parameter {
78         private final String key, value;
79
80         public Parameter(String key, String value) {
81             this.key = key;
82             this.value = value;
83         }
84
85         public String getKey() {
86             return key;
87         }
88
89         public String getValue() {
90             return value;
91         }
92     }
93
94 }