本文整理汇总了Java中jodd.bean.BeanUtil类的典型用法代码示例。如果您正苦于以下问题:Java BeanUtil类的具体用法?Java BeanUtil怎么用?Java BeanUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanUtil类属于jodd.bean包,在下文中一共展示了BeanUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import jodd.bean.BeanUtil; //导入依赖的package包/类
@Override
public Object get(Object bean) {
PropertyNode currentNode = this;
Object currentBean = bean;
while (!currentNode.isLeafNode() && currentNode.next() != null) {
currentBean = BeanUtil.getProperty(currentBean, currentNode.name());
currentNode = currentNode.next();
}
if (currentNode.isLeafNode() && currentBean != null) {
return BeanUtil.getProperty(currentBean, currentNode.name());
} else {
return null;
}
}
示例2: validate
import jodd.bean.BeanUtil; //导入依赖的package包/类
/**
* Performs validation of provided validation context and appends violations.
*/
public List<Violation> validate(ValidationContext ctx, Object target, String targetName) {
for (Map.Entry<String, List<Check>> entry : ctx.map.entrySet()) {
String name = entry.getKey();
Object value = BeanUtil.declaredSilent.getProperty(target, name);
String valueName = targetName != null ? (targetName + '.' + name) : name; // move up
ValidationConstraintContext vcc = new ValidationConstraintContext(this, target, valueName);
for (Check check : entry.getValue()) {
String[] checkProfiles = check.getProfiles();
if (!matchProfiles(checkProfiles)) {
continue;
}
if (check.getSeverity() < severity) {
continue;
}
ValidationConstraint constraint = check.getConstraint();
if (!constraint.isValid(vcc, value)) {
addViolation(new Violation(valueName, target, value, check));
}
}
}
return getViolations();
}
示例3: instanceFirstInit
import jodd.bean.BeanUtil; //导入依赖的package包/类
public static <T extends Object> T instanceFirstInit(final Class<T> klass) {
try {
T _xblockexpression = null;
{
final T instance = klass.newInstance();
Field[] _declaredFields = klass.getDeclaredFields();
final Consumer<Field> _function = (Field field) -> {
String _name = field.getName();
String _name_1 = field.getName();
Object _firstInitFrom = MockHelper.firstInitFrom(_name_1);
BeanUtil.setDeclaredProperty(instance, _name, _firstInitFrom);
};
((List<Field>)Conversions.doWrapArray(_declaredFields)).forEach(_function);
_xblockexpression = instance;
}
return _xblockexpression;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例4: instanceSecondInit
import jodd.bean.BeanUtil; //导入依赖的package包/类
public static <T extends Object> T instanceSecondInit(final T instance) {
T _xblockexpression = null;
{
Class<?> _class = instance.getClass();
Field[] _declaredFields = _class.getDeclaredFields();
final Consumer<Field> _function = (Field field) -> {
String _name = field.getName();
String _name_1 = field.getName();
Object _secondInitFrom = MockHelper.secondInitFrom(_name_1, instance);
BeanUtil.setDeclaredProperty(instance, _name, _secondInitFrom);
};
((List<Field>)Conversions.doWrapArray(_declaredFields)).forEach(_function);
_xblockexpression = instance;
}
return _xblockexpression;
}
示例5: testKeyword
import jodd.bean.BeanUtil; //导入依赖的package包/类
/**
This method tests, if the test-value for keyword is copied into the xml document.
*/
@Test
public void testKeyword() {
BeanUtil.setProperty(smlKeyword, "keyword","testkeyword");
multiSmlKeyword.getItems().add(smlKeyword);
Document doc = beanTransformerService.mergeToISO(multiSmlKeyword,mRefDatasetDocument);
multiSmlKeyword.getItems().remove(smlKeyword);
Source beanSource = new DOMSource(doc);
try {
assertThat(
beanSource,
hasXPath(
"/*/sml:keywords/sml:KeywordList/sml:keyword[text()='testkeyword']",
usingNamespaces));
} catch (NoSuchMethodError e) {
LOG.error("Possibly XPath is invalid with compared source", e);
throw e;
}
}
示例6: testIdentifer
import jodd.bean.BeanUtil; //导入依赖的package包/类
/**
This method tests, if the test-value for uniqueId is copied into the xml document.
*/
@Test
public void testIdentifer() {
BeanUtil.setProperty(smlIdentifier, "id", "testIdentifier");
Document doc = beanTransformerService.mergeToISO(smlIdentifier,
mRefDatasetDocument);
Source beanSource = new DOMSource(doc);
try {
assertThat(
beanSource,
hasXPath(
"/sml:PhysicalSystem/gml:identifier[text()='testIdentifier']",
usingNamespaces));
} catch (NoSuchMethodError e) {
LOG.error("Possibly XPath is invalid with compared source", e);
throw e;
}
}
示例7: set
import jodd.bean.BeanUtil; //导入依赖的package包/类
@Override
public void set(Object bean, Object value) {
if (!isLeaf) {
Object nodeBean = BeanUtil.getProperty(bean, name);
if (nodeBean == null) {
nodeBean = injector.getInstance(type);
BeanUtil.setProperty(bean, name, nodeBean);
}
next.set(nodeBean, value);
} else {
BeanUtil.setProperty(bean, name, validValue(value, type));
}
}
示例8: getClassPK
import jodd.bean.BeanUtil; //导入依赖的package包/类
/**
* If 'entry' is null it should return default parent value.
*
* @param entry
* @return
*/
protected Object getClassPK(Object entry) {
if (Validator.isNull(entry)) {
return 0L;
}
return BeanUtil.getDeclaredProperty(entry, getClassPKName());
}
示例9: getClassPK
import jodd.bean.BeanUtil; //导入依赖的package包/类
@Override
protected Object getClassPK(Object entry) {
if (Validator.isNull(entry)) {
return StringPool.BLANK;
}
return BeanUtil.getDeclaredProperty(entry, getClassPKName());
}
示例10: getHystrixThreadPoolPropertiesSetter
import jodd.bean.BeanUtil; //导入依赖的package包/类
private HystrixThreadPoolProperties.Setter getHystrixThreadPoolPropertiesSetter(
com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand hystrixCommand) {
HystrixThreadPoolProperties.Setter commandPropertiesDefaults = HystrixThreadPoolProperties.defaultSetter();
if (hystrixCommand.threadPoolProperties() == null || hystrixCommand.threadPoolProperties().length == 0) {
return commandPropertiesDefaults;
}
Map<String, Object> commandProperties = new HashMap<String, Object>();
for (HystrixProperty commandProperty : hystrixCommand.threadPoolProperties()) {
commandProperties.put(commandProperty.name(), commandProperty.value());
BeanUtil.setDeclaredProperty(commandPropertiesDefaults, commandProperty.name(),
commandProperty.value());
}
return commandPropertiesDefaults;
}
示例11: validate
import jodd.bean.BeanUtil; //导入依赖的package包/类
public static boolean validate(Object target, Object value, String fieldName) {
if (value == null) {
return true;
}
Object valueToCompare;
try {
valueToCompare = BeanUtil.declared.getProperty(target, fieldName);
} catch (BeanException bex) {
throw new VtorException("Invalid value: " + fieldName, bex);
}
if (valueToCompare == null) {
return false;
}
return value.equals(valueToCompare);
}
示例12: validate
import jodd.bean.BeanUtil; //导入依赖的package包/类
public static boolean validate(Object target, Object value, String fieldName) {
if (value == null) {
return true;
}
Object valueToCompare;
try {
valueToCompare = BeanUtil.pojo.getProperty(target, fieldName);
} catch (BeanException bex) {
throw new VtorException("Invalid value: " + fieldName, bex);
}
if (valueToCompare == null) {
return false;
}
return value.equals(valueToCompare);
}
示例13: secondInitFrom
import jodd.bean.BeanUtil; //导入依赖的package包/类
public static Object secondInitFrom(final String fieldName, final Object instance) {
Object _switchResult = null;
String _trim = fieldName.trim();
switch (_trim) {
case "email":
Object _declaredProperty = BeanUtil.getDeclaredProperty(instance, "realname");
_switchResult = Randoms.email(((String) _declaredProperty));
break;
case "username":
Object _declaredProperty_1 = BeanUtil.getDeclaredProperty(instance, "realname");
_switchResult = Randoms.username(((String) _declaredProperty_1));
break;
case "nickname":
Object _declaredProperty_2 = BeanUtil.getDeclaredProperty(instance, "realname");
_switchResult = Randoms.nickname(((String) _declaredProperty_2));
break;
case "age":
Object _declaredProperty_3 = BeanUtil.getDeclaredProperty(instance, "birthday");
_switchResult = Integer.valueOf(Randoms.age(((DateTime) _declaredProperty_3)));
break;
case "endTime":
Object _declaredProperty_4 = BeanUtil.getDeclaredProperty(instance, "startTime");
int _nextInt = RandomUtils.nextInt(0, 10000);
_switchResult = ((DateTime) _declaredProperty_4).plusHours(_nextInt);
break;
default:
_switchResult = BeanUtil.getDeclaredProperty(instance, fieldName);
break;
}
return _switchResult;
}
示例14: testSmlIdentification
import jodd.bean.BeanUtil; //导入依赖的package包/类
/**
This method tests, if the test-value for smlIdentification is copied into the xml document.
*/
@Test
public void testSmlIdentification() {
BeanUtil.setProperty(smlIdentification, "definition","testdefinition");
BeanUtil.setProperty(smlIdentification, "label","testname");
BeanUtil.setProperty(smlIdentification, "codeSpace","http://testIdentifierCodeSpace");
BeanUtil.setProperty(smlIdentification, "value","testvalue");
multiSmlIdentification.getItems().add(smlIdentification);
Document doc = beanTransformerService.mergeToISO(multiSmlIdentification,mRefDatasetDocument);
multiSmlIdentification.getItems().remove(smlIdentification);
Source beanSource = new DOMSource(doc);
try {
assertThat(
beanSource,
hasXPath(
"/*/sml:identification/sml:IdentifierList/sml:identifier/sml:Term[@definition='testdefinition']/sml:value[text()='testvalue']",
usingNamespaces));
assertThat(
beanSource,
hasXPath(
"/*/sml:identification/sml:IdentifierList/sml:identifier/sml:Term[@definition='testdefinition']/sml:label[text()='testname']",
usingNamespaces));
assertThat(
beanSource,
hasXPath(
"/*/sml:identification/sml:IdentifierList/sml:identifier/sml:Term[@definition='testdefinition']/sml:codeSpace[@xlink:href='http://testIdentifierCodeSpace']",
usingNamespaces));
} catch (NoSuchMethodError e) {
LOG.error("Possibly XPath is invalid with compared source", e);
throw e;
}
}
示例15: testSmlClassification
import jodd.bean.BeanUtil; //导入依赖的package包/类
/**
This method tests, if the test-value for smlClassification is copied into the xml document.
*/
@Test
public void testSmlClassification() {
BeanUtil.setProperty(smlClassification, "definition","testdefinition");
BeanUtil.setProperty(smlClassification, "label","testname");
BeanUtil.setProperty(smlClassification, "codeSpace","http://testClassifierCodeSpace");
BeanUtil.setProperty(smlClassification, "value","testvalue");
multiSmlClassification.getItems().add(smlClassification);
Document doc = beanTransformerService.mergeToISO(multiSmlClassification,mRefDatasetDocument);
multiSmlClassification.getItems().remove(smlClassification);
Source beanSource = new DOMSource(doc);
try {
assertThat(
beanSource,
hasXPath(
"/*/sml:classification/sml:ClassifierList/sml:classifier/sml:Term[@definition='testdefinition']/sml:value[text()='testvalue']",
usingNamespaces));
assertThat(
beanSource,
hasXPath(
"/*/sml:classification/sml:ClassifierList/sml:classifier/sml:Term[@definition='testdefinition']/sml:label[text()='testname']",
usingNamespaces));
assertThat(
beanSource,
hasXPath(
"/*/sml:classification/sml:ClassifierList/sml:classifier/sml:Term[@definition='testdefinition']/sml:codeSpace[@xlink:href='http://testClassifierCodeSpace']",
usingNamespaces));
} catch (NoSuchMethodError e) {
LOG.error("Possibly XPath is invalid with compared source", e);
throw e;
}
}