View Javadoc

1   /*
2    * Copyright 2010 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may	obtain a copy of the License at
7    *
8    * 	http://www.osedu.org/licenses/ECL-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.student.contract.writer.service;
17  
18  import org.kuali.student.contract.model.MessageStructure;
19  import org.kuali.student.contract.model.ServiceContractModel;
20  import org.kuali.student.contract.writer.JavaClassWriter;
21  
22  /**
23   *
24   * @author nwright
25   */
26  public class GetterSetterNameCalculator {
27  
28      private MessageStructure ms;
29      private JavaClassWriter writer;
30      private ServiceContractModel model;
31  
32      public GetterSetterNameCalculator(MessageStructure ms,
33              JavaClassWriter writer,
34              ServiceContractModel model) {
35          this.ms = ms;
36          this.writer = writer;
37          this.model = model;
38      }
39  
40      public String calcGetter() {
41          if (calcFieldTypeToUse(ms.getType()).equals("Boolean")) {
42              if (ms.getShortName().toLowerCase().startsWith("is")) {
43                  return calcInitLower(ms.getShortName());
44              }
45              return "is" + calcInitUpper(ms.getShortName());
46          }
47          return "get" + calcInitUpper(ms.getShortName());
48      }
49  
50      public String calcSetter() {
51          if (calcFieldTypeToUse(ms.getType()).equals("Boolean")) {
52              if (ms.getShortName().toLowerCase().startsWith("is")) {
53                  return "set" + calcInitUpper(ms.getShortName().substring(2));
54              }
55          }
56          return "set" + calcInitUpper(ms.getShortName());
57      }
58  
59      public static String calcInitUpper(String name) {
60          return name.substring(0, 1).toUpperCase() + name.substring(1);
61      }
62  
63      public static String calcInitLower(String name) {
64          return name.substring(0, 1).toLowerCase() + name.substring(1);
65      }
66  
67      public String calcFieldTypeToUse(String type) {
68          return MessageStructureTypeCalculator.calculate(writer, model, type, type, null);
69      }
70  
71      public static String stripList(String str) {
72          if (str.endsWith("List")) {
73              return str.substring(0, str.length() - "List".length());
74          }
75          return str;
76      }
77  }