
com.codetaco.cli.variables.VariablePuller Maven / Gradle / Ivy
package com.codetaco.cli.variables;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.codetaco.cli.ICmdLine;
import com.codetaco.cli.type.CmdLineCLA;
import com.codetaco.cli.type.ICmdLineArg;
/**
*
* VariablePuller class.
*
*
* @author Chris DeGreef [email protected]
*/
public class VariablePuller {
private final static Logger logger = LoggerFactory.getLogger(VariablePuller.class.getName());
static private VariablePuller instance;
/**
*
* Getter for the field instance
.
*
*
* @return a {@link com.codetaco.cli.variables.VariablePuller} object.
*/
public static VariablePuller getInstance() {
if (instance == null)
instance = new VariablePuller();
return instance;
}
/**
*
* pull.
*
*
* @param arg a {@link com.codetaco.cli.type.ICmdLineArg} object.
* @param variableSource a {@link java.lang.Object} object.
* @throws java.text.ParseException if any.
* @throws java.lang.IllegalArgumentException if any.
* @throws java.lang.IllegalAccessException if any.
*/
@SuppressWarnings("unchecked")
public void pull(final ICmdLineArg> arg, final Object variableSource)
throws ParseException, IllegalArgumentException, IllegalAccessException {
arg.reset();
if (arg.isSystemGenerated())
return;
final String errMsg = "pulling "
+ arg.getVariable()
+ " from "
+ variableSource.getClass().getName();
final Field field = VariableAssigner.findFieldInAnyParentOrMyself(arg, variableSource.getClass(), errMsg);
if (field == null)
return;
final boolean wasAccessible = field.isAccessible();
try {
field.setAccessible(true);
if (field.getType() == List.class) {
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy