Resolve Bug:445 Remove freemarker from config code generator.
[controller.git] / opendaylight / config / yang-jmx-generator-plugin / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / plugin / java / JavaFileInputBuilder.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
9 package org.opendaylight.controller.config.yangjmxgenerator.plugin.java;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.yangjmxgenerator.plugin.ftl.model.Annotation;
13
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
17
18 import static com.google.common.base.Preconditions.checkNotNull;
19
20 public class JavaFileInputBuilder {
21
22     private Optional<String> copyright = Optional.absent(), header = Optional.absent(), classJavaDoc = Optional.absent();
23
24     private TypeName typeName = TypeName.classType;
25
26     private FullyQualifiedName fqn;
27
28     private final List<String> classAnnotations = new ArrayList<>();
29
30     private final List<FullyQualifiedName> extendsFQNs = new ArrayList<>();
31
32     private final List<FullyQualifiedName> implementsFQNs = new ArrayList<>();
33
34     private final List<String> bodyElements = new ArrayList<>();
35
36     public void addToBody(String element) {
37         bodyElements.add(element + "\n");
38     }
39
40     public void addClassAnnotation(Annotation annotation) {
41         addClassAnnotation(annotation.toString());
42     }
43
44     public void addClassAnnotation(String annotation) {
45         classAnnotations.add(checkNotNull(annotation));
46     }
47
48     public void addExtendsFQN(FullyQualifiedName fqn) {
49         extendsFQNs.add(fqn);
50     }
51
52     public void addImplementsFQN(FullyQualifiedName fqn) {
53         implementsFQNs.add(fqn);
54     }
55
56     public Optional<String> getCopyright() {
57         return copyright;
58     }
59
60     public void setCopyright(Optional<String> copyright) {
61         this.copyright = checkNotNull(copyright);
62     }
63
64     public Optional<String> getHeader() {
65         return header;
66     }
67
68     public void setHeader(Optional<String> header) {
69         this.header = checkNotNull(header);
70     }
71
72
73     public Optional<String> getClassJavaDoc() {
74         return classJavaDoc;
75     }
76
77     public void setClassJavaDoc(Optional<String> classJavaDoc) {
78         this.classJavaDoc = checkNotNull(classJavaDoc);
79     }
80
81
82     public FullyQualifiedName getFqn() {
83         return fqn;
84     }
85
86     public void setFqn(FullyQualifiedName fqn) {
87         this.fqn = fqn;
88     }
89
90     public List<FullyQualifiedName> getExtendsFQNs() {
91         return extendsFQNs;
92     }
93
94
95     public List<FullyQualifiedName> getImplementsFQNs() {
96         return implementsFQNs;
97     }
98
99
100     public TypeName getTypeName() {
101         return typeName;
102     }
103
104     public void setTypeName(TypeName typeName) {
105         this.typeName = typeName;
106     }
107
108
109     public JavaFileInput build() {
110         checkNotNull(copyright);
111         checkNotNull(header);
112         checkNotNull(classJavaDoc);
113         checkNotNull(typeName);
114         checkNotNull(fqn);
115
116         return new JavaFileInput() {
117
118             @Override
119             public FullyQualifiedName getFQN() {
120                 return fqn;
121             }
122
123             @Override
124             public Optional<String> getCopyright() {
125                 return copyright;
126             }
127
128             @Override
129             public Optional<String> getHeader() {
130                 return header;
131             }
132
133             @Override
134             public Optional<String> getClassJavaDoc() {
135                 return classJavaDoc;
136             }
137
138             @Override
139             public TypeName getType() {
140                 return typeName;
141             }
142
143             @Override
144             public List<FullyQualifiedName> getExtends() {
145                 return Collections.unmodifiableList(extendsFQNs);
146             }
147
148             @Override
149             public List<FullyQualifiedName> getImplements() {
150                 return Collections.unmodifiableList(implementsFQNs);
151             }
152
153             @Override
154             public List<String> getClassAnnotations() {
155                 return Collections.unmodifiableList(classAnnotations);
156             }
157
158             @Override
159             public List<String> getBodyElements() {
160                 return Collections.unmodifiableList(bodyElements);
161             }
162         };
163     }
164 }