001 /** 002 * Copyright 2004-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.student.contract.command.run; 017 018 import java.util.ArrayList; 019 import java.util.Collection; 020 import java.util.List; 021 import org.kuali.student.contract.model.ServiceContractModel; 022 import org.kuali.student.contract.model.impl.ServiceContractModelCache; 023 import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader; 024 import org.kuali.student.contract.model.validation.ServiceContractModelValidator; 025 import org.kuali.student.contract.writer.service.EachMethodServiceWriter; 026 027 /** 028 * 029 * @author nwright 030 */ 031 public class EachMethodServiceWriterRun { 032 033 public EachMethodServiceWriterRun() { 034 } 035 036 public static final String DEFAULT_ROOT_PACKAGE = "org.kuali.student.enrollment"; 037 private static final String CORE_DIRECTORY = 038 "C:/svn/student/ks-core/ks-core-api/src/main/java"; 039 private static final String ENROLL_DIRECTORY = 040 "C:/svn/ks-1.3-services/ks-enroll/ks-enroll-api/src/main/java"; 041 // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core"; 042 private static final String COMMON_DIRECTORY = 043 "C:/svn/student/ks-common/ks-common-api/src/main/java"; 044 private static final String LUM_DIRECTORY = 045 "C:/svn/student/ks-lum/ks-lum-api/src/main/java"; 046 047 private static ServiceContractModel getModel() { 048 List<String> srcDirs = new ArrayList(); 049 srcDirs.add(ENROLL_DIRECTORY); 050 ServiceContractModel instance = new ServiceContractModelQDoxLoader(srcDirs); 051 return new ServiceContractModelCache(instance); 052 } 053 054 private static void validate(ServiceContractModel model) { 055 Collection<String> errors = 056 new ServiceContractModelValidator(model).validate(); 057 if (!errors.isEmpty()) { 058 StringBuilder buf = new StringBuilder(); 059 buf.append(errors.size()).append(" errors found while validating the data."); 060 int cnt = 0; 061 for (String msg : errors) { 062 cnt++; 063 buf.append("\n"); 064 buf.append("*error*").append(cnt).append(":").append(msg); 065 } 066 067 throw new IllegalArgumentException(buf.toString()); 068 } 069 } 070 071 public static void main(String[] args) { 072 ServiceContractModel model = getModel(); 073 validate(model); 074 // List<String> servicesToProcess = new ArrayList (); 075 // servicesToProcess.add ("atp"); 076 // servicesToProcess.add ("lu"); 077 // servicesToProcess.add ("lo"); 078 // servicesToProcess.add ("organization"); 079 // servicesToProcess.add ("proposal"); 080 //// servicesToProcess.add ("comment"); 081 // servicesToProcess.add ("dictionary"); 082 // servicesToProcess.add ("document"); 083 // servicesToProcess.add ("enumerable"); 084 // servicesToProcess.add ("search"); 085 // ServicesFilter filter = new ServicesFilterByKeys (servicesToProcess); 086 String targetDir = "target/gen-src"; 087 // targetDir = "src/main/java"; 088 EachMethodServiceWriter instance = 089 new EachMethodServiceWriter(model, 090 targetDir, 091 DEFAULT_ROOT_PACKAGE, 092 null); 093 instance.write(); 094 095 } 096 }