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    
022    import org.kuali.student.contract.model.ServiceContractModel;
023    import org.kuali.student.contract.model.impl.ServiceContractModelCache;
024    import org.kuali.student.contract.model.impl.ServiceContractModelQDoxLoader;
025    import org.kuali.student.contract.model.validation.ServiceContractModelValidator;
026    import org.kuali.student.contract.writer.service.PureJavaInfcWriter;
027    
028    /**
029     *
030     * @author nwright
031     */
032    public class PureJavaInterfaceWriterRun {
033    
034        public PureJavaInterfaceWriterRun() {
035        }
036        private static final String CORE_DIRECTORY =
037                "C:/svn/student/ks-core/ks-core-api/src/main/java";
038        private static final String ENROLL_DIRECTORY =
039                "C:/svn/ks-1.3-services/ks-enroll/ks-enroll-api/src/main/java";
040    //                           "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
041        private static final String COMMON_DIRECTORY =
042                "C:/svn/student/ks-common/ks-common-api/src/main/java";
043        private static final String LUM_DIRECTORY =
044                "C:/svn/student/ks-lum/ks-lum-api/src/main/java";
045    
046        private static ServiceContractModel getModel() {
047            List<String> srcDirs = new ArrayList();
048            srcDirs.add(ENROLL_DIRECTORY);
049            ServiceContractModel instance = new ServiceContractModelQDoxLoader(srcDirs);
050            return new ServiceContractModelCache(instance);
051        }
052    
053        private static void validate(ServiceContractModel model) {
054            Collection<String> errors =
055                    new ServiceContractModelValidator(model).validate();
056            if (errors.size() > 0) {
057                StringBuffer buf = new StringBuffer();
058                buf.append(errors.size() + " errors found while validating the data.");
059                int cnt = 0;
060                for (String msg : errors) {
061                    cnt++;
062                    buf.append("\n");
063                    buf.append("*error*" + cnt + ":" + msg);
064                }
065    
066                throw new IllegalArgumentException(buf.toString());
067            }
068        }
069    
070        public static void main(String[] args) {
071            ServiceContractModel model = getModel();
072            validate(model);
073    //   List<String> servicesToProcess = new ArrayList ();
074    //   servicesToProcess.add ("atp");
075    //   servicesToProcess.add ("lu");
076    //   servicesToProcess.add ("lo");
077    //   servicesToProcess.add ("organization");
078    //   servicesToProcess.add ("proposal");
079    ////   servicesToProcess.add ("comment");
080    //   servicesToProcess.add ("dictionary");
081    //   servicesToProcess.add ("document");
082    //   servicesToProcess.add ("enumerable");
083    //   servicesToProcess.add ("search");
084    //   ServicesFilter filter = new ServicesFilterByKeys (servicesToProcess);
085            String targetDir = "target/gen-src";
086    //  targetDir = "src/main/java";
087            PureJavaInfcWriter instance =
088                    new PureJavaInfcWriter(model,
089                    targetDir,
090                    PureJavaInfcWriter.DEFAULT_ROOT_PACKAGE,
091                    null);
092            instance.write();
093    
094        }
095    }