use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.
the class RestStepsDefinitions method deserAndRegister.
@And("^I register path \"(.*?)\" with class \"(.*?)\" as \"(.*?)\"$")
public void deserAndRegister(String propertyPath, String className, String key) throws Throwable {
Class clazz = Class.forName(className);
RestResponse restResponse = JsonUtil.read(Context.getInstance().getRestResponse(), clazz);
Object value = restResponse;
if (!"null".equals(propertyPath)) {
BeanWrapper beanWrapper = new BeanWrapperImpl(restResponse);
value = beanWrapper.getPropertyValue(propertyPath);
}
REGISTRY.put(key, value);
}
use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.
the class ConstraintParser method parseConstraint.
private PropertyConstraint parseConstraint(String operator, Node keyNode, Node expressionNode, ParsingContextExecution context) {
ConstraintParsingInfo info = constraintBuildersMap.get(operator);
if (info == null) {
context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.UNKNOWN_CONSTRAINT, "Constraint parsing issue", keyNode.getStartMark(), "Unknown constraint operator, will be ignored.", keyNode.getEndMark(), operator));
return null;
}
PropertyConstraint constraint;
try {
constraint = info.constraintClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new ParsingTechnicalException("Unable to create constraint.", e);
}
BeanWrapper target = new BeanWrapperImpl(constraint);
parseAndSetValue(target, null, expressionNode, context, new MappingTarget(info.expressionPropertyName, info.expressionParser));
return constraint;
}
use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.
the class MapParser method doParse.
private Map<String, T> doParse(MappingNode node, ParsingContextExecution context) {
Map<String, T> map = Maps.newLinkedHashMap();
for (NodeTuple entry : node.getValue()) {
String key = scalarParser.parse(entry.getKeyNode(), context);
T value = null;
value = valueParser.parse(entry.getValueNode(), context);
if (value != null) {
if (keyPath != null) {
BeanWrapper valueWrapper = new BeanWrapperImpl(value);
valueWrapper.setPropertyValue(keyPath, key);
}
if (value == null) {
ParsingError err = new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Invalid format for the value.", node.getStartMark(), "The value cannot be parsed", node.getEndMark(), key);
context.getParsingErrors().add(err);
} else {
map.put(key, value);
}
}
}
return map;
}
use of org.springframework.beans.BeanWrapper in project alien4cloud by alien4cloud.
the class AbstractTypeNodeParser method findWrapperPropertyByPath.
/**
* For example:
* <ul>
* <li>.something : the value will be set to the property of root named 'something'
* <li>child1.child2.prop : the value will be mapped u getChild1().getChild2().setProp()
* </ul>
*/
private Entry<BeanWrapper, String> findWrapperPropertyByPath(BeanWrapper root, BeanWrapper current, String path) {
int dotIdx = path.indexOf(".");
if (dotIdx < 0) {
return new DefaultMapEntry<BeanWrapper, String>(current, path);
}
BeanWrapper base = current;
String nextPath = path;
if (path.startsWith("../")) {
base = new BeanWrapperImpl(ParsingContextExecution.getParent(current));
nextPath = path.substring(3);
} else if (path.startsWith(".")) {
base = root;
nextPath = path.substring(1);
} else {
String wrapperCandidateName = path.substring(0, path.indexOf("."));
Object wrapperCandidate = current.getPropertyValue(wrapperCandidateName);
base = new BeanWrapperImpl(wrapperCandidate);
nextPath = path.substring(path.indexOf(".") + 1);
}
return findWrapperPropertyByPath(root, base, nextPath);
}
use of org.springframework.beans.BeanWrapper in project molgenis by molgenis.
the class JobExecutor method writePropertyValues.
private void writePropertyValues(JobExecution jobExecution, MutablePropertyValues pvs) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(jobExecution);
bw.setPropertyValues(pvs, true);
}
Aggregations