Coverage Report - org.apache.commons.contract.util.InteractiveMainWrapper
 
Classes in this File Line Coverage Branch Coverage Complexity
InteractiveMainWrapper
0%
0/33
0%
0/4
8
 
 1  
 /*
 2  
 *
 3  
 * ====================================================================
 4  
 *
 5  
 * Copyright 2004 The Apache Software Foundation 
 6  
 *
 7  
 * Licensed under the Apache License, Version 2.0 (the "License");
 8  
 * you may not use this file except in compliance with the License.
 9  
 * You may obtain a copy of the License at
 10  
 *
 11  
 *     http://www.apache.org/licenses/LICENSE-2.0
 12  
 *
 13  
 * Unless required by applicable law or agreed to in writing, software
 14  
 * distributed under the License is distributed on an "AS IS" BASIS,
 15  
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 16  
 * See the License for the specific language governing permissions and
 17  
 * limitations under the License.
 18  
 *
 19  
 */
 20  
 package org.apache.commons.contract.util;
 21  
 
 22  
 import java.io.BufferedReader;
 23  
 import java.io.IOException;
 24  
 import java.io.InputStreamReader;
 25  
 import java.util.HashMap;
 26  
 import java.util.Locale;
 27  
 import java.util.Map;
 28  
 
 29  
 import org.apache.commons.contract.Context;
 30  
 import org.apache.commons.contract.ContractViolationException;
 31  
 import org.apache.commons.contract.Executor;
 32  
 import org.apache.commons.contract.Processor;
 33  
 import org.apache.commons.contract.Result;
 34  
 import org.apache.commons.contract.context.VMContext;
 35  
 import org.apache.commons.contract.descriptor.ParameterDescriptor;
 36  
 import org.apache.commons.contract.i18n.ParameterBundle;
 37  
 
 38  0
 public class InteractiveMainWrapper extends MainWrapper {
 39  
     public static Result main(String []args, Processor processor) {
 40  0
         Executor.init();
 41  0
         printUsage(processor);
 42  0
         Context context = new VMContext();
 43  0
         ParameterDescriptor[] parameterDescriptors = processor.getParameterDescriptors();
 44  0
         Map parameters = new HashMap();
 45  0
         BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
 46  0
         for ( int i = 0; i < parameterDescriptors.length; i++ ) {
 47  0
             Object value = null;
 48  
             do {
 49  0
                 System.out.print(parameterDescriptors[i].getName()+" - ");
 50  0
             printParameterInfo(parameterDescriptors[i]);
 51  0
             System.out.print(((ParameterBundle)parameterDescriptors[i].getDescription()).getPrompt(Locale.getDefault()));
 52  
             try {
 53  0
                 String userInput = in.readLine();
 54  0
                 value = Executor.prepareValue(parameterDescriptors[i], userInput, context);
 55  0
             } catch (IOException e) {
 56  0
                 value = null;
 57  0
             } catch (ContractViolationException e) {
 58  0
                 printException(e);
 59  0
                 value = null;
 60  0
             }
 61  0
             } while ( value == null );
 62  0
             parameters.put(parameterDescriptors[i].getName(), value);
 63  
         }
 64  
         try {
 65  0
             Result result = Executor.process(processor, parameters, context);
 66  0
             printInformations(context.getInformations());
 67  0
             return result;
 68  0
         } catch ( ContractViolationException exception ) {
 69  0
             printException(exception);
 70  0
             System.out.println();
 71  0
             printUsage(processor);
 72  0
         } catch ( Exception exception ) {
 73  0
             exception.printStackTrace();
 74  0
         }
 75  0
         return null;
 76  
     }
 77  
 }