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.binding.generator.util.AbstractBaseType;
11 import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
12 import org.opendaylight.controller.sal.binding.model.api.Constant;
13 import org.opendaylight.controller.sal.binding.model.api.Type;
14 import org.opendaylight.controller.sal.binding.model.api.type.builder.*;
16 import java.util.ArrayList;
17 import java.util.List;
19 abstract class AbstractGeneratedTypeBuilder extends AbstractBaseType implements GeneratedTypeBuilder {
21 private final String packageName;
22 private String comment = "";
23 private final String name;
25 private final List<AnnotationTypeBuilder> annotationBuilders = new ArrayList<>();
26 private final List<Type> implementsTypes = new ArrayList<>();
27 private final List<EnumBuilder> enumDefinitions = new ArrayList<>();
28 private final List<Constant> constants = new ArrayList<>();
29 private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<>();
30 private final List<GeneratedTypeBuilder> enclosedTypes = new ArrayList<>();
31 private final List<GeneratedTOBuilder> enclosingTransferObjects = new ArrayList<>();
32 private boolean isAbstract;
34 public AbstractGeneratedTypeBuilder(final String packageName, final String name) {
35 super(packageName, name);
36 if (packageName == null) {
37 throw new IllegalArgumentException("Package Name for Generated Type cannot be null!");
40 throw new IllegalArgumentException("Name of Generated Type cannot be null!");
42 this.packageName = packageName;
46 protected String getComment() {
50 protected List<AnnotationTypeBuilder> getAnnotations() {
51 return annotationBuilders;
54 protected boolean isAbstract() {
58 protected List<Type> getImplementsTypes() {
59 return implementsTypes;
62 protected List<EnumBuilder> getEnumerations() {
63 return enumDefinitions;
66 protected List<Constant> getConstants() {
70 protected List<MethodSignatureBuilder> getMethodDefinitions() {
71 return methodDefinitions;
74 protected List<GeneratedTypeBuilder> getEnclosedTypes() {
78 protected List<GeneratedTOBuilder> getEnclosedTransferObjects() {
79 return enclosingTransferObjects;
83 public GeneratedTypeBuilder addEnclosingType(String name) {
85 throw new IllegalArgumentException("Name for Enclosing Generated Type cannot be null!");
87 GeneratedTypeBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
88 enclosedTypes.add(builder);
93 public GeneratedTOBuilder addEnclosingTransferObject(String name) {
95 throw new IllegalArgumentException("Name for Enclosing Generated Transfer Object cannot be null!");
97 GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
98 enclosingTransferObjects.add(builder);
103 public void addComment(String comment) {
104 this.comment = comment;
108 public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) {
109 if (packageName == null) {
110 throw new IllegalArgumentException("Package Name for Annotation Type cannot be null!");
113 throw new IllegalArgumentException("Name of Annotation Type cannot be null!");
116 final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
117 annotationBuilders.add(builder);
122 public void setAbstract(boolean isAbstract) {
123 this.isAbstract = isAbstract;
127 public boolean addImplementsType(Type genType) {
128 if (genType == null) {
129 throw new IllegalArgumentException("Type cannot be null");
131 return implementsTypes.add(genType);
135 public Constant addConstant(Type type, String name, Object value) {
137 throw new IllegalArgumentException("Returning Type for Constant cannot be null!");
140 throw new IllegalArgumentException("Name of constant cannot be null!");
143 final Constant constant = new ConstantImpl(this, type, name, value);
144 constants.add(constant);
149 public EnumBuilder addEnumeration(String name) {
151 throw new IllegalArgumentException("Name of enumeration cannot be null!");
153 final EnumBuilder builder = new EnumerationBuilderImpl(
154 getFullyQualifiedName(), name);
155 enumDefinitions.add(builder);
160 public MethodSignatureBuilder addMethod(String name) {
162 throw new IllegalArgumentException("Name of method cannot be null!");
164 final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(name);
165 builder.setAccessModifier(AccessModifier.PUBLIC);
166 builder.setAbstract(true);
167 methodDefinitions.add(builder);
172 public int hashCode() {
173 final int prime = 31;
175 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
176 result = prime * result
177 + ((getPackageName() == null) ? 0 : getPackageName().hashCode());
182 public boolean equals(Object obj) {
189 if (getClass() != obj.getClass()) {
192 AbstractGeneratedTypeBuilder other = (AbstractGeneratedTypeBuilder) obj;
193 if (getName() == null) {
194 if (other.getName() != null) {
197 } else if (!getName().equals(other.getName())) {
200 if (getPackageName() == null) {
201 if (other.getPackageName() != null) {
204 } else if (!getPackageName().equals(other.getPackageName())) {