本文整理汇总了Java中org.springframework.beans.PropertyAccessor类的典型用法代码示例。如果您正苦于以下问题:Java PropertyAccessor类的具体用法?Java PropertyAccessor怎么用?Java PropertyAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertyAccessor类属于org.springframework.beans包,在下文中一共展示了PropertyAccessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deepValue
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
/**
* This follows a path (like object.childobject.value), to its end value, so it can compare the values of two
* paths.
* This method follows the path recursively until it reaches the end value.
*
* @param object object to search
* @param path path of value
* @return result
*/
private Object deepValue(final Object object, final String path) {
final List<String> paths = new LinkedList<>(Arrays.asList(path.split("\\.")));
final String currentPath = paths.get(0);
final PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(object);
Object field = accessor.getPropertyValue(currentPath);
paths.remove(0);
if ((field != null) && (!paths.isEmpty())) {
field = deepValue(field, String.join(".", paths));
}
return field;
}
示例2: writeToEntity
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
/**
* Write the value to the existingEntity field with the name of key
*
* @param <T> Type of the entity
* @param existingEntity The entity we are changing
* @param key The key we are changing
* @param value The new value
*/
private <T extends BaseEntity> void writeToEntity(T existingEntity, String key, Object value) {
final PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(existingEntity);
if (accessor.getPropertyType(key) != null) {
try {
if (value.getClass().equals(JSONObject.class) &&
((JSONObject) value).has("_isMap") &&
((JSONObject) value).get("_isMap").equals(true)) {
writeArrayMapToEntity(accessor, key, (JSONObject) value);
} else if (value.getClass().equals(JSONObject.class)) {
writeObjectToEntity(accessor, key, (JSONObject) value);
} else if (value.getClass().equals(JSONArray.class)) {
writeArrayToEntity(accessor, key, (JSONArray) value);
} else if (isFieldValid(accessor, key, existingEntity.getClass())) {
writeValueToEntity(accessor, key, value);
}
} catch (JSONException e) {
logger.info("[FormParse] [writeToEntity] Unable To Process JSON", e);
}
}
}
示例3: hasRestrictionOnField
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
protected boolean hasRestrictionOnField(Query query, String fieldName) {
for (Restriction<PropertyAccessor> restriction : query.getRestrictions()) {
if (restriction instanceof FieldCondition) {
if (fieldName.equals(((FieldCondition) restriction).getFieldName())) {
return true;
}
} else if (restriction instanceof DisjunctionCondition) {
for (Query subQuery : ((DisjunctionCondition) restriction).getQueries()) {
if (hasRestrictionOnField(subQuery, fieldName)) {
return true;
}
}
}
}
return false;
}
示例4: getLastPropertySeparatorIndex
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
/**
* Returns the index of the last nested property separator in the given
* property path, ignoring dots in keys (like "map[my.key]").
*/
protected int getLastPropertySeparatorIndex(String propertyPath) {
boolean inKey = false;
for (int i = propertyPath.length() - 1; i >= 0; i--) {
switch (propertyPath.charAt(i)) {
case PropertyAccessor.PROPERTY_KEY_SUFFIX_CHAR:
inKey = true;
break;
case PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR:
return i;
case PropertyAccessor.NESTED_PROPERTY_SEPARATOR_CHAR:
if (!inKey) {
return i;
}
break;
}
}
return -1;
}
示例5: isReadableProperty
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
public boolean isReadableProperty(String propertyPath) {
if (PropertyAccessorUtils.isNestedProperty(propertyPath)) {
String baseProperty = getBasePropertyName(propertyPath);
String childPropertyPath = getChildPropertyPath(propertyPath);
if (!super.isReadableProperty(baseProperty)) {
return false;
}
else {
return ((PropertyAccessor) childPropertyAccessors.get(baseProperty))
.isReadableProperty(childPropertyPath);
}
}
else {
return super.isReadableProperty(propertyPath);
}
}
示例6: getNestingLevel
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
public static int getNestingLevel(String propertyName) {
propertyName = getPropertyName(propertyName);
int nestingLevel = 0;
boolean inKey = false;
for (int i = 0; i < propertyName.length(); i++) {
switch (propertyName.charAt(i)) {
case PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR:
if (!inKey) {
nestingLevel++;
}
case PropertyAccessor.PROPERTY_KEY_SUFFIX_CHAR:
inKey = !inKey;
}
}
return nestingLevel;
}
示例7: autobind
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
public void autobind(Object view) {
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(getModel());
PropertyAccessor viewPropertyAccessor = new DirectFieldAccessor(view);
// iterate on model properties
for (PropertyDescriptor pd : bw.getPropertyDescriptors()) {
String propertyName = pd.getName();
if ( !ignoredProperties.contains(propertyName) && viewPropertyAccessor.isReadableProperty(propertyName)) {
Object control = viewPropertyAccessor.getPropertyValue(propertyName);
if (control != null) {
if (log.isDebugEnabled())
log.debug("Found control: " + control.getClass().getSimpleName() +
" for property: " + propertyName);
bind(control, propertyName);
}
}
}
}
示例8: isValid
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
@Override
public boolean isValid(final WithId<?> value, final ConstraintValidatorContext context) {
if (value == null) {
return true;
}
final PropertyAccessor bean = new BeanWrapperImpl(value);
final String propertyValue = String.valueOf(bean.getPropertyValue(property));
@SuppressWarnings({"rawtypes", "unchecked"})
final Class<WithId> modelClass = (Class) value.getKind().modelClass;
@SuppressWarnings("unchecked")
final Set<String> ids = dataManager.fetchIdsByPropertyValue(modelClass, property, propertyValue);
final boolean isUnique = ids.isEmpty() || value.getId().map(id -> ids.contains(id)).orElse(false);
if (!isUnique) {
if (ids.stream().allMatch(id -> consideredValidByException(modelClass, id))) {
return true;
}
context.disableDefaultConstraintViolation();
context.unwrap(HibernateConstraintValidatorContext.class).addExpressionVariable("nonUnique", propertyValue)
.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
.addPropertyNode(property).addConstraintViolation();
}
return isUnique;
}
示例9: writeValueToEntity
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
/**
* Write normal value to entity.
*
* @param accessor The accessor for the existing entity
* @param key The fields name we are overwriting
* @param value The new value
*/
private void writeValueToEntity(final PropertyAccessor accessor,
final String key,
final Object value) {
final ResolvableType type = accessor.getPropertyTypeDescriptor(key).getResolvableType();
accessor.setPropertyValue(key, parseValue(value, type));
}
示例10: isFieldEditable
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
/**
* Is the field editable according to the SchemaView annotation
*
* @param accessor the accessor
* @param key the key
* @return boolean boolean
*/
private Boolean isFieldEditable(final PropertyAccessor accessor, final String key) {
final SchemaView schemaView = accessor.getPropertyTypeDescriptor(key).getAnnotation(SchemaView.class);
if (schemaView != null) {
final boolean isLocked = schemaView.locked() && accessor.getPropertyValue(key) != null;
final boolean isVisible = schemaView.visible();
return !isLocked && isVisible;
}
return false;
}
示例11: setPath
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
/**
* Set the path that this tag should apply.
* <p>E.g. "customer" to allow bind paths like "address.street"
* rather than "customer.address.street".
* @see BindTag#setPath
*/
public void setPath(String path) {
if (path == null) {
path = "";
}
if (path.length() > 0 && !path.endsWith(PropertyAccessor.NESTED_PROPERTY_SEPARATOR)) {
path += PropertyAccessor.NESTED_PROPERTY_SEPARATOR;
}
this.path = path;
}
示例12: getBindStatus
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
/**
* Get the {@link BindStatus} for this tag.
*/
protected BindStatus getBindStatus() throws JspException {
if (this.bindStatus == null) {
// HTML escaping in tags is performed by the ValueFormatter class.
String nestedPath = getNestedPath();
String pathToUse = (nestedPath != null ? nestedPath + getPath() : getPath());
if (pathToUse.endsWith(PropertyAccessor.NESTED_PROPERTY_SEPARATOR)) {
pathToUse = pathToUse.substring(0, pathToUse.length() - 1);
}
this.bindStatus = new BindStatus(getRequestContext(), pathToUse, false);
}
return this.bindStatus;
}
示例13: getDirectoryService
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
private Directory getDirectoryService() {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jacksonFactory = new JacksonFactory();
GoogleCredential credential = getGoogleCredential();
PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(credential);
accessor.setPropertyValue("serviceAccountUser", config.getAdminUsername());
accessor.setPropertyValue("serviceAccountScopes", SERVICE_ACCOUNT_SCOPES);
return new Directory.Builder(httpTransport, jacksonFactory, credential)
.setApplicationName("Spinnaker-Fiat")
.build();
}
示例14: overrideEnableFallback
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
@Test
public void overrideEnableFallback() throws Exception {
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor(
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.enableFallback:true");
assertThat(accessor.getPropertyValue("enableFallback")).isEqualTo(Boolean.TRUE);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:DeviceDelegatingViewResolverAutoConfigurationTests.java
示例15: overrideNormalPrefix
import org.springframework.beans.PropertyAccessor; //导入依赖的package包/类
@Test
public void overrideNormalPrefix() throws Exception {
PropertyAccessor accessor = getLiteDeviceDelegatingViewResolverAccessor(
"spring.mobile.devicedelegatingviewresolver.enabled:true",
"spring.mobile.devicedelegatingviewresolver.normalPrefix:normal/");
assertThat(accessor.getPropertyValue("normalPrefix")).isEqualTo("normal/");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:DeviceDelegatingViewResolverAutoConfigurationTests.java