本文整理匯總了Java中org.springframework.beans.PropertyAccessorFactory.forDirectFieldAccess方法的典型用法代碼示例。如果您正苦於以下問題:Java PropertyAccessorFactory.forDirectFieldAccess方法的具體用法?Java PropertyAccessorFactory.forDirectFieldAccess怎麽用?Java PropertyAccessorFactory.forDirectFieldAccess使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.beans.PropertyAccessorFactory
的用法示例。
在下文中一共展示了PropertyAccessorFactory.forDirectFieldAccess方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deepValue
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的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.PropertyAccessorFactory; //導入方法依賴的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: getDirectoryService
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的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();
}
示例4: handleModification
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
private List<PropertyChange<?>> handleModification(DescriptorEvent event)
{
final Class<?> objectClass = event.getSource().getClass();
final WriteObjectQuery writeObjectQuery = (WriteObjectQuery)event.getQuery();
final ObjectChangeSet changeset = writeObjectQuery.getObjectChangeSet();
final ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(event.getObject());
final List<ChangeRecord> changes = changeset != null ? changeset.getChanges() : extractManually(writeObjectQuery, fieldFilter);
final List<PropertyChange<?>> propChanges = new ArrayList<PropertyChange<?>>();
for (ChangeRecord change : changes)
{
final String attrName = change.getAttribute();
final Object newValue = accessor.getPropertyValue(attrName);
final Object oldValue = change.getOldValue();
final Class<?> attrType = accessor.getPropertyType(attrName);
final Field field = ReflectionUtils.findField(objectClass, change.getAttribute());
if (fieldFilter != null && !fieldFilter.test(field))
{
continue;
}
entityUtil.extractSingle(field, attrName, attrType, oldValue, newValue, propChanges);
}
return propChanges;
}
示例5: deserializeNonTemplate
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
private CompositionElement deserializeNonTemplate(JsonNode node, Map<String, Object> valueMap)
throws JsonProcessingException {
CompositionElement result = new CompositionElement();
PropertyAccessor beanAccessor = PropertyAccessorFactory.forDirectFieldAccess(result);
for (Iterator<Entry<String, JsonNode>> iter = node.fields(); iter.hasNext();) {
Entry<String, JsonNode> subNode = iter.next();
if (consumedListProperties.contains(subNode.getKey())) {
result.getProperties().put(subNode.getKey(), mapper.treeToValue(subNode.getValue(), List.class));
} else if (consumedMapProperties.contains(subNode.getKey())) {
processMapProperty(result, subNode, valueMap);
} else if (consumedIntProperties.contains(subNode.getKey())) {
result.getProperties().put(subNode.getKey(), mapper.treeToValue(subNode.getValue(), Integer.class));
} else if (consumedProperties.contains(subNode.getKey())) {
processConsumedProperty(result, subNode, valueMap);
} else if (supportedTextProperties.contains(subNode.getKey())) {
beanAccessor.setPropertyValue(subNode.getKey(), subNode.getValue().asText());
} else if (supportedIntProperties.contains(subNode.getKey())) {
beanAccessor.setPropertyValue(subNode.getKey(), subNode.getValue().asInt());
} else {
throw new IllegalArgumentException("Unknown property: " + subNode.getKey());
// result.getProperties().put(subNode.getKey(),
// subNode.getValue().asText());
}
}
return result;
}
示例6: getBean
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
protected Object getBean(String beanName, Map<String, Object> model) {
Object bean;
if (model != null) {
bean = model.get(beanName);
} else {
ConfigurablePropertyAccessor bw = PropertyAccessorFactory.forDirectFieldAccess(getRequestContext());
HttpServletRequest request = (HttpServletRequest) bw.getPropertyValue("request");
bean = request.getAttribute(beanName);
}
return bean;
}
示例7: intializeCollection
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
* Initialize collection
* @param em
* @param entity
* @param a
* @param i
*/
@SuppressWarnings("rawtypes")
private static void intializeCollection(EntityManager em, Object entity, Object attached,
Attribute a, int depth) {
PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(attached);
Collection c = (Collection) accessor.getPropertyValue(a.getName());
for (Object o : c)
initialize(em, o, depth -1);
PropertyAccessorFactory.forDirectFieldAccess(entity).setPropertyValue(a.getName(), c);
}
示例8: isNew
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
* Test if entity is New
* @param entity
* @return true if entity is new, ie not detached
*/
@SuppressWarnings("unchecked")
protected boolean isNew(T entity) {
SingularAttribute<?, ?> id = getIdAttribute(entity.getClass());
// try field
PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(entity);
PK key = (PK) pa.getPropertyValue(id.getName());
if (key == null)
key = (PK) PropertyAccessorFactory.forBeanPropertyAccess(entity).getPropertyValue(id.getName());
return key == null || !exists(key, entity.getClass());
}
示例9: createDirectFieldAccessor
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
/**
* Create a new DirectFieldAccessor for the underlying target object.
* @see #getTarget()
*/
protected ConfigurablePropertyAccessor createDirectFieldAccessor() {
Assert.state(this.target != null, "Cannot access fields on null target instance '" + getObjectName() + "'!");
return PropertyAccessorFactory.forDirectFieldAccess(this.target);
}
示例10: extractManually
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
private List<ChangeRecord> extractManually(WriteObjectQuery writeObjectQuery, Predicate<Field> filter)
{
final Object oldObj = writeObjectQuery.getBackupClone();
final Object newObj = writeObjectQuery.getObject();
final ConfigurablePropertyAccessor accessorOld = PropertyAccessorFactory.forDirectFieldAccess(oldObj);
final ConfigurablePropertyAccessor accessorNew = PropertyAccessorFactory.forDirectFieldAccess(newObj);
final BeanWrapper beanAccessor = PropertyAccessorFactory.forBeanPropertyAccess(newObj);
final List<ChangeRecord> retVal = new LinkedList<>();
for (PropertyDescriptor desc : beanAccessor.getPropertyDescriptors())
{
final String propName = desc.getName();
if (accessorNew.isReadableProperty(propName))
{
final Field field = ReflectionUtils.findField(oldObj.getClass(), propName);
if (filter == null || filter.test(field))
{
final Object newPropValue = accessorNew.getPropertyValue(propName);
final Object oldPropValue = accessorOld.getPropertyValue(propName);
if (! Objects.equals(newPropValue, oldPropValue))
{
final ChangeRecord c = new ChangeRecord()
{
@Override
public ObjectChangeSet getOwner()
{
return null;
}
@Override
public Object getOldValue()
{
return oldPropValue;
}
@Override
public String getAttribute()
{
return propName;
}
};
retVal.add(c);
}
}
}
}
return retVal;
}
示例11: createAccessor
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
@Override
public ConfigurablePropertyAccessor createAccessor(Object obj) {
ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(obj);
accessor.setAutoGrowNestedPaths(true);
return accessor;
}
示例12: newPropertyAccessor
import org.springframework.beans.PropertyAccessorFactory; //導入方法依賴的package包/類
public static ConfigurablePropertyAccessor newPropertyAccessor(Object obj, boolean directFieldAccess){
ConfigurablePropertyAccessor bw = directFieldAccess?PropertyAccessorFactory.forDirectFieldAccess(obj):PropertyAccessorFactory.forBeanPropertyAccess(obj);
bw.setAutoGrowNestedPaths(true);
return bw;
}