View Javadoc

1   /**
2    * Copyright 2004-2013 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.opensource.org/licenses/ecl2.php
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.command.run;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  import org.kuali.student.contract.model.ServiceContractModel;
22  import org.kuali.student.contract.model.impl.ServiceContractModelCache;
23  import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
24  import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
25  import org.kuali.student.contract.writer.service.EachMethodServiceWriter;
26  
27  /**
28   *
29   * @author nwright
30   */
31  public class EachMethodServiceWriterRun {
32  
33      public EachMethodServiceWriterRun() {
34      }
35      
36      public static final String DEFAULT_ROOT_PACKAGE = "org.kuali.student.enrollment";
37      private static final String CORE_DIRECTORY =
38              "C:/svn/student/ks-core/ks-core-api/src/main/java";
39      private static final String ENROLL_DIRECTORY =
40              "C:/svn/ks-1.3-services/ks-enroll/ks-enroll-api/src/main/java";
41  //                           "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
42      private static final String COMMON_DIRECTORY =
43              "C:/svn/student/ks-common/ks-common-api/src/main/java";
44      private static final String LUM_DIRECTORY =
45              "C:/svn/student/ks-lum/ks-lum-api/src/main/java";
46  
47      private static ServiceContractModel getModel() {
48          List<String> srcDirs = new ArrayList();
49          srcDirs.add(ENROLL_DIRECTORY);
50          ServiceContractModel instance = new ServiceContractModelQDoxLoader(srcDirs);
51          return new ServiceContractModelCache(instance);
52      }
53  
54      private static void validate(ServiceContractModel model) {
55          Collection<String> errors =
56                  new ServiceContractModelValidator(model).validate();
57          if (!errors.isEmpty()) {
58              StringBuilder buf = new StringBuilder();
59              buf.append(errors.size()).append(" errors found while validating the data.");
60              int cnt = 0;
61              for (String msg : errors) {
62                  cnt++;
63                  buf.append("\n");
64                  buf.append("*error*").append(cnt).append(":").append(msg);
65              }
66  
67              throw new IllegalArgumentException(buf.toString());
68          }
69      }
70  
71      public static void main(String[] args) {
72          ServiceContractModel model = getModel();
73          validate(model);
74  //   List<String> servicesToProcess = new ArrayList ();
75  //   servicesToProcess.add ("atp");
76  //   servicesToProcess.add ("lu");
77  //   servicesToProcess.add ("lo");
78  //   servicesToProcess.add ("organization");
79  //   servicesToProcess.add ("proposal");
80  ////   servicesToProcess.add ("comment");
81  //   servicesToProcess.add ("dictionary");
82  //   servicesToProcess.add ("document");
83  //   servicesToProcess.add ("enumerable");
84  //   servicesToProcess.add ("search");
85  //   ServicesFilter filter = new ServicesFilterByKeys (servicesToProcess);
86          String targetDir = "target/gen-src";
87  //  targetDir = "src/main/java";
88          EachMethodServiceWriter instance =
89                  new EachMethodServiceWriter(model,
90                  targetDir,
91                  DEFAULT_ROOT_PACKAGE,
92                  null);
93          instance.write();
94  
95      }
96  }