use of org.pentaho.di.trans.steps.loadsave.setter.Setter in project pentaho-kettle by pentaho.
the class LoadSaveTester method createValidatorMapAndInvokeSetters.
@Override
@SuppressWarnings("unchecked")
protected Map<String, FieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
Map<String, FieldLoadSaveValidator<?>> validatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
for (String attribute : attributes) {
Getter<?> getter = manipulator.getGetter(attribute);
@SuppressWarnings("rawtypes") Setter setter = manipulator.getSetter(attribute);
FieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
try {
Object testValue = validator.getTestObject();
setter.set(metaToSave, testValue);
if (validator instanceof DatabaseMetaLoadSaveValidator) {
addDatabase((DatabaseMeta) testValue);
validateStepUsesDatabaseMeta(metaToSave, (DatabaseMeta) testValue);
}
} catch (Exception e) {
throw new RuntimeException("Unable to invoke setter for " + attribute, e);
}
validatorMap.put(attribute, validator);
}
return validatorMap;
}
use of org.pentaho.di.trans.steps.loadsave.setter.Setter in project pentaho-kettle by pentaho.
the class LoadSaveBase method createValidatorMapAndInvokeSetters.
@SuppressWarnings({ "unchecked" })
protected Map<String, FieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
Map<String, FieldLoadSaveValidator<?>> validatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
databases.clear();
for (String attribute : attributes) {
Getter<?> getter = manipulator.getGetter(attribute);
@SuppressWarnings("rawtypes") Setter setter = manipulator.getSetter(attribute);
FieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
try {
Object testValue = validator.getTestObject();
// no-inspection unchecked
setter.set(metaToSave, testValue);
if (testValue instanceof DatabaseMeta) {
addDatabase((DatabaseMeta) testValue);
} else if (testValue instanceof DatabaseMeta[]) {
addDatabase((DatabaseMeta[]) testValue);
}
} catch (Exception e) {
throw new RuntimeException("Unable to invoke setter for " + attribute, e);
}
validatorMap.put(attribute, validator);
}
return validatorMap;
}
use of org.pentaho.di.trans.steps.loadsave.setter.Setter in project pentaho-kettle by pentaho.
the class ObjectValidator method getTestObject.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public T getTestObject() {
try {
T object = clazz.newInstance();
for (String attribute : fieldNames) {
Setter setter = manipulator.getSetter(attribute);
setter.set(object, fieldLoadSaveValidatorFactory.createValidator(manipulator.getGetter(attribute)).getTestObject());
}
return object;
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate " + clazz, e);
}
}
Aggregations