private void setupBuilderConfiguration(PropertyLoader propertyLoader) { if (configClass.isAnnotationPresent(LoadingOrder.class)) { builderConfiguration.setAnnotationOrder( configClass.getAnnotation(LoadingOrder.class).value()); } if (configClass.isAnnotationPresent(PropertyNamePrefix.class)) { builderConfiguration.setPropertyNamePrefixes( configClass.getAnnotation(PropertyNamePrefix.class).value()); } final Properties properties = propertyLoader.load(); properties.putAll(additionalProperties); builderConfiguration.setProperties(properties); builderConfiguration.setCommandLine( commandLineHelper.getCommandLine(configClass, commandLineArgs)); }
protected ConfigBuilder(Class<T> configClass, ConfigBuilderFactory configBuilderFactory) { configBuilderFactory.<T>initialize(); this.configClass = configClass; this.builderConfiguration = configBuilderFactory.getInstance(BuilderConfiguration.class); this.commandLineHelper = configBuilderFactory.getInstance(CommandLineHelper.class); this.configValidator = configBuilderFactory.getInstance(ConfigValidator.class); this.fieldSetter = configBuilderFactory.getInstance(FieldSetter.class); this.errorMessageSetup = configBuilderFactory.getInstance(ErrorMessageSetup.class); this.constructionHelper = configBuilderFactory.getInstance(ConstructionHelper.class); this.additionalProperties = configBuilderFactory.createInstance(Properties.class); propertyLoader = configBuilderFactory .getInstance(PropertyLoaderConfigurator.class) .configurePropertyLoader(configClass); commandLineOptions = commandLineHelper.getOptions(configClass); }
public static String doMain(String[] args, int run) { String modelName = null; if (args.length == 1) { // test for "-h" or "--help" if (args[0].equals("-h") || args[0].equals("--help")) { printHelp(); } else { System.out.println("ERROR: Wrong usage."); printHelp(); // exit program System.exit(1); } } else { if ((args.length == 8) || (args[8].equals("-h"))) { // test for "normal" parameters String modelFileName = null; String initFilename = null; try { modelFileName = getModelFileName(args); SystemDynamicsCommandLine.numberRounds = getNumberRounds(args); exportCSV(args); initFilename = getExportFileName(args); SystemDynamicsCommandLine.exportFileName = getExportFileName(args); SystemDynamicsCommandLine.exportFileName = SystemDynamicsCommandLine.exportFileName + "_" + run; } catch (IllegalArgumentException e) { // wrong parameters -> show help System.out.println("ERROR: " + e.getMessage()); printHelp(); // exit program System.exit(1); } /* Modification*/ /*@Author: Pradeep Jawahar*/ /*Date: 04/23/2011*/ /*Adding pre - processing step*/ if (args.length > 8) { try { PreProcess preProcess = new PreProcess(); HashMap<String, String> initMap = new HashMap<String, String>(); HashMap<String, String> clist = CommandLineHelper.convertCl(args[9]); HashMap<String, String> preList = new HashMap<String, String>(); int flag = 0; if (args[12].equals("2") && args[11].equals("0")) { initMap = preProcess.phase2PreProcess("phase2/" + initFilename + "_-1"); preList.putAll(initMap); flag = 1; } modelName = preProcess.preprocess(modelFileName, clist, preList, run, flag); } catch (Exception e) { e.printStackTrace(); } } } else { // wrong parameters -> show help System.out.println("ERROR: Wrong usage."); printHelp(); // exit program System.exit(1); } } return modelName; }