View Javadoc
1   package at.rseiler.spbee.core.pojo;
2   
3   import at.rseiler.spbee.core.util.StringUtil;
4   
5   import java.io.Serializable;
6   import java.util.LinkedList;
7   import java.util.List;
8   
9   /**
10   * Holds the information to generate the DTO class.
11   *
12   * @author Reinhard Seiler {@literal <rseiler.developer@gmail.com>}
13   */
14  public class DtoClass implements Serializable {
15  
16      private static final long serialVersionUID = -7146790314269625019L;
17  
18      private final String superQualifiedClassName;
19      private final boolean anInterface;
20      private final boolean hasDataSourceConstructor;
21      private final List<StoredProcedureMethod> storedProcedureMethods = new LinkedList<>();
22  
23      /**
24       * Constructs a new DtoClass.
25       *
26       * @param superQualifiedClassName  the qualified class name of the interface or the abstract class.
27       * @param anInterface              specifies if it's an interface. Otherwise it's handled as an abstract class.
28       * @param hasDataSourceConstructor specifies if the class has an constructor with a DataSource as parameter.
29       */
30      public DtoClass(String superQualifiedClassName, boolean anInterface, boolean hasDataSourceConstructor) {
31          this.superQualifiedClassName = superQualifiedClassName;
32          this.anInterface = anInterface;
33          this.hasDataSourceConstructor = hasDataSourceConstructor;
34      }
35  
36      /**
37       * Adds stored procedure method to the DTO class.
38       *
39       * @param method the method which should be added
40       */
41      public void add(StoredProcedureMethod method) {
42          storedProcedureMethods.add(method);
43      }
44  
45      /**
46       * Returns the qualified class name of the interface or the abstract class of which this DTO class is derived.
47       *
48       * @return the qualified class name
49       */
50      public String getSuperQualifiedClassName() {
51          return superQualifiedClassName;
52      }
53  
54      /**
55       * Returns the qualified class name of the DTO class.
56       *
57       * @return the qualified class name
58       */
59      public String getQualifiedClassName() {
60          return StringUtil.getQualifiedDtoClassName(superQualifiedClassName);
61      }
62  
63      /**
64       * Returns the package of the DTO class.
65       *
66       * @return the package
67       */
68      public String getPackage() {
69          return StringUtil.getPackage(getQualifiedClassName());
70      }
71  
72      /**
73       * Returns the simple class name of the DTO class.
74       *
75       * @return the simple class name
76       */
77      public String getSimpleClassName() {
78          return StringUtil.getSimpleClassName(getQualifiedClassName());
79      }
80  
81      /**
82       * Returns true if the DTO class is derived from an interface or an abstract class.
83       *
84       * @return true if the DTO class is derived from an interface
85       */
86      public boolean isAnInterface() {
87          return anInterface;
88      }
89  
90      /**
91       * Returns true if the DTO class has a constructor with a DataSource as parameter.
92       *
93       * @return tru if the DTO class has a constructor with a DataSource as parameter
94       */
95      public boolean hasDataSourceConstructor() {
96          return hasDataSourceConstructor;
97      }
98  
99      /**
100      * Returns all stored procedure methods from the DTO class.
101      *
102      * @return the stored procedure method.
103      */
104     public List<StoredProcedureMethod> getStoredProcedureMethods() {
105         return storedProcedureMethods;
106     }
107 
108     @Override
109     public String toString() {
110         return "DtoClass{" +
111                 "superQualifiedClassName='" + superQualifiedClassName + '\'' +
112                 ", anInterface=" + anInterface +
113                 ", hasDataSourceConstructor=" + hasDataSourceConstructor +
114                 ", storedProcedureMethods=" + storedProcedureMethods +
115                 '}';
116     }
117 
118 }