View Javadoc

1   /*
2    * Copyright 2009 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.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.MockImplWriter;
26  
27  /**
28   *
29   * @author nwright
30   */
31  public class MockImplWriterRun {
32  
33      public MockImplWriterRun() {
34      }
35      private static final String CORE_DIRECTORY =
36              "C:/svn/student/ks-core/ks-core-api/src/main/java";
37      private static final String ENROLL13_DIRECTORY =
38              "C:/svn/ks-1.3/ks-enroll/ks-enroll-api/src/main/java";
39      private static final String ENROLL13_SERVICES_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(ENROLL13_SERVICES_DIRECTORY);
50  //        srcDirs.add(ENROLL13_DIRECTORY);
51  //        srcDirs.add(LUM_DIRECTORY);
52  //        srcDirs.add(CORE_DIRECTORY);
53  //        srcDirs.add(COMMON_DIRECTORY);
54          ServiceContractModel instance = new ServiceContractModelQDoxLoader(srcDirs);
55          return new ServiceContractModelCache(instance);
56      }
57  
58      private static void validate(ServiceContractModel model) {
59          Collection<String> errors =
60                  new ServiceContractModelValidator(model).validate();
61          if (!errors.isEmpty()) {
62              StringBuilder buf = new StringBuilder();
63              buf.append(errors.size()).append(" errors found while validating the data.");
64              int cnt = 0;
65              for (String msg : errors) {
66                  cnt++;
67                  buf.append("\n");
68                  buf.append("*error*").append(cnt).append(":").append(msg);
69              }
70  
71              throw new IllegalArgumentException(buf.toString());
72          }
73      }
74  
75      public static void main(String[] args) {
76          ServiceContractModel model = getModel();
77          validate(model);
78  //   List<String> servicesToProcess = new ArrayList ();
79  //   servicesToProcess.add ("atp");
80  //   servicesToProcess.add ("lu");
81  //   servicesToProcess.add ("lo");
82  //   servicesToProcess.add ("organization");
83  //   servicesToProcess.add ("proposal");
84  ////   servicesToProcess.add ("comment");
85  //   servicesToProcess.add ("dictionary");
86  //   servicesToProcess.add ("document");
87  //   servicesToProcess.add ("enumerable");
88  //   servicesToProcess.add ("search");
89  //   ServicesFilter filter = new ServicesFilterByKeys (servicesToProcess);
90          String targetDir = "target/gen-src";
91  //  targetDir = "src/main/java";
92          boolean isR1 = false;
93          MockImplWriter instance =
94                  new MockImplWriter(model,
95                  targetDir,
96                  MockImplWriter.ROOT_PACKAGE,
97  //                MockImplWriter.ENROLLMENT_ROOT_PACKAGE,
98                  null,
99                  isR1);
100         instance.write();
101 
102     }
103 }