2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
10 import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
11 import org.opendaylight.controller.sal.binding.model.api.Constant;
12 import org.opendaylight.controller.sal.binding.model.api.Type;
13 import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
15 import java.util.ArrayList;
16 import java.util.List;
18 abstract class AbstractGeneratedTypeBuilder implements GeneratedTypeBuilder {
20 private final String packageName;
21 private String comment = "";
22 private final String name;
24 private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<>();
25 private final List<Type> implementsTypes = new ArrayList<>();
26 private final List<EnumBuilder> enumDefinitions = new ArrayList<>();
27 private final List<Constant> constants = new ArrayList<>();
28 private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<>();
29 private final List<GeneratedTypeBuilder> enclosedTypes = new ArrayList<>();
30 private final List<GeneratedTOBuilder> enclosingTransferObjects = new ArrayList<>();
31 private boolean isAbstract;
33 public AbstractGeneratedTypeBuilder(final String packageName, final String name) {
34 if (packageName == null) {
35 throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
38 throw new IllegalArgumentException("Name of Generated Type cannot be null!");
40 this.packageName = packageName;
45 public String getPackageName() {
50 public String getName() {
55 public String getFullyQualifiedName() {
56 return packageName + "." + name;
60 protected String getComment() {
64 protected List<AnnotationTypeBuilder> getAnnotations() {
65 return annotationBuilders;
68 protected boolean isAbstract() {
72 protected List<Type> getImplementsTypes() {
73 return implementsTypes;
76 protected List<EnumBuilder> getEnumerations() {
77 return enumDefinitions;
80 protected List<Constant> getConstants() {
84 protected List<MethodSignatureBuilder> getMethodDefinitions() {
85 return methodDefinitions;
88 protected List<GeneratedTypeBuilder> getEnclosedTypes() {
92 protected List<GeneratedTOBuilder> getEnclosedTransferObjects() {
93 return enclosingTransferObjects;
97 public GeneratedTypeBuilder addEnclosingType(String name) {
99 throw new IllegalArgumentException("Name for Enclosing Generated Type cannot be null!");
101 GeneratedTypeBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
102 enclosedTypes.add(builder);
107 public GeneratedTOBuilder addEnclosingTransferObject(String name) {
109 throw new IllegalArgumentException("Name for Enclosing Generated Transfer Object cannot be null!");
111 GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
112 enclosingTransferObjects.add(builder);
117 public void addComment(String comment) {
118 this.comment = comment;
122 public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
123 if (packageName == null) {
124 throw new IllegalArgumentException("Package Name for Annotation Type cannot be null!");
127 throw new IllegalArgumentException("Name of Annotation Type cannot be null!");
130 final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
131 annotationBuilders.add(builder);
136 public void setAbstract(boolean isAbstract) {
137 this.isAbstract = isAbstract;
141 public boolean addImplementsType(Type genType) {
142 if (genType == null) {
143 throw new IllegalArgumentException("Type cannot be null");
145 return implementsTypes.add(genType);
149 public Constant addConstant(Type type, String name, Object value) {
151 throw new IllegalArgumentException("Returning Type for Constant cannot be null!");
154 throw new IllegalArgumentException("Name of constant cannot be null!");
157 final Constant constant = new ConstantImpl(this, type, name, value);
158 constants.add(constant);
163 public EnumBuilder addEnumeration(String name) {
165 throw new IllegalArgumentException("Name of enumeration cannot be null!");
167 final EnumBuilder builder = new EnumerationBuilderImpl(
168 getFullyQualifiedName(), name);
169 enumDefinitions.add(builder);
174 public MethodSignatureBuilder addMethod(String name) {
176 throw new IllegalArgumentException("Name of method cannot be null!");
178 final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(name);
179 builder.setAccessModifier(AccessModifier.PUBLIC);
180 builder.setAbstract(true);
181 methodDefinitions.add(builder);
186 public int hashCode() {
187 final int prime = 31;
189 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
190 result = prime * result
191 + ((getPackageName() == null) ? 0 : getPackageName().hashCode());
196 public boolean equals(Object obj) {
203 if (getClass() != obj.getClass()) {
206 AbstractGeneratedTypeBuilder other = (AbstractGeneratedTypeBuilder) obj;
207 if (getName() == null) {
208 if (other.getName() != null) {
211 } else if (!getName().equals(other.getName())) {
214 if (getPackageName() == null) {
215 if (other.getPackageName() != null) {
218 } else if (!getPackageName().equals(other.getPackageName())) {