Merge "BUG-2288: DOMNotification API"
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / ftl / model / ModuleField.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
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.List;
14 import org.opendaylight.controller.config.yangjmxgenerator.attribute.Dependency;
15
16 public class ModuleField extends Field {
17
18     private final String nullableDefault, attributeName;
19     private final boolean dependent, isListOfDependencies;
20     private final Dependency dependency;
21
22     private ModuleField(List<String> modifiers, String type, String name, String attributeName, String nullableDefault,
23             boolean isDependency, Dependency dependency, boolean isListOfDependencies, boolean needsDepResolver) {
24         super(modifiers, type, name, null, needsDepResolver);
25         this.dependent = isDependency;
26         this.dependency = dependency;
27         this.attributeName = attributeName;
28         if (type.startsWith(List.class.getName()) && nullableDefault == null) {
29             String generics = type.substring(List.class.getName().length());
30             nullableDefault = "new " + ArrayList.class.getName() + generics + "()";
31         }
32         this.nullableDefault = nullableDefault;
33         this.isListOfDependencies = isListOfDependencies;
34     }
35
36     public ModuleField(String type, String name, String attributeName, String nullableDefault, boolean isDependency,
37             Dependency dependency, boolean isListOfDependencies, boolean needsDepResolve) {
38         this(Collections.<String> emptyList(), type, name, attributeName, nullableDefault, isDependency, dependency,
39                 isListOfDependencies, needsDepResolve);
40     }
41
42     public boolean isIdentityRef() {
43         return false;
44     }
45
46     @Override
47     public String toString() {
48         return ModuleFieldSerializer.toString(this);
49     }
50
51     public Dependency getDependency() {
52         return dependency;
53     }
54
55     public String getNullableDefault() {
56         return nullableDefault;
57     }
58
59     public boolean isDependent() {
60         return dependent;
61     }
62
63     public boolean isListOfDependencies() {
64         return isListOfDependencies;
65     }
66
67     public String getAttributeName() {
68         return attributeName;
69     }
70
71
72     public boolean isList() {
73         return getType().startsWith("java.util.List");
74     }
75
76 }