private IdleStrategy parseIdleStrategy(final String arg) throws ParseException { if (arg == null || arg.equalsIgnoreCase(NULL_VALUE)) { return null; } IdleStrategy strategy; if (arg.startsWith(BackoffIdleStrategy.class.getName())) { // this is a special case for BackoffIdleStrategy that allows us to pass in // the constructor parameters. At some point, we may want to add a generic way to // do this, but for now BackoffIdleStrategy gets special treatment. strategy = parseBackoffIdleStrategy(arg); } else { // Use reflection to create the new IdleStrategy with no parameters. try { final Class clazz = Class.forName(arg); strategy = (IdleStrategy) clazz.newInstance(); } catch (final ClassNotFoundException | IllegalAccessException | InstantiationException | ClassCastException ex) { throw new ParseException( "Error creating new instance of '" + arg + "': " + ex.getMessage()); } } return strategy; }
private LossGenerator parseLossGenerator(final String arg) throws ParseException { if (arg == null || arg.equalsIgnoreCase(NULL_VALUE)) { return null; } LossGenerator lossGenerator; try { final Class clazz = Class.forName(arg); lossGenerator = (LossGenerator) clazz.newInstance(); } catch (final ClassNotFoundException | IllegalAccessException | InstantiationException | ClassCastException ex) { throw new ParseException("Error creating new instance of '" + arg + "': " + ex.getMessage()); } return lossGenerator; }