本文整理汇总了Java中org.apache.commons.beanutils.NestedNullException类的典型用法代码示例。如果您正苦于以下问题:Java NestedNullException类的具体用法?Java NestedNullException怎么用?Java NestedNullException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NestedNullException类属于org.apache.commons.beanutils包,在下文中一共展示了NestedNullException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compare
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
@Override
public int compare(T o1, T o2) {
Comparable obj1 = null;
Comparable obj2 = null;
try {
obj1 = (Comparable) PropertyUtils.getProperty(o1, this.propertyPath);
obj2 = (Comparable) PropertyUtils.getProperty(o2, this.propertyPath);
} catch (NestedNullException ignored) {
// Ignored, als het property NULL is, dan vergelijken met NULL
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalArgumentException("Could not retrieve property " + this.propertyPath, e);
}
Comparator<Comparable<Object>> objectComparator = null;
if ((obj1 != null && obj2 != null) && obj1 instanceof String) {
obj1 = ((String) obj1).toLowerCase().trim();
obj2 = ((String) obj2).toLowerCase().trim();
if (!StringUtils.isEmpty((String) obj1) && !StringUtils.isEmpty((String) obj2)) {
if (StringUtils.isNumeric((String) obj1) && StringUtils.isNumeric((String) obj2)) {
objectComparator = Comparator.comparingDouble(o -> new Double(String.valueOf(o)));
}
}
}
if (objectComparator == null) {
objectComparator = Comparator.naturalOrder();
}
//noinspection unchecked
return Comparator.nullsLast(objectComparator).compare(obj1, obj2);
}
示例2: isWriteable
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
/**
* Return whether or not an attribute is writeable. This method is aware that that Collections may be involved and
* handles them
* consistently with the way in which OJB handles specifying the attributes of elements of a Collection.
*
* @param object
* @param property
* @return
* @throws IllegalArgumentException
*/
public static boolean isWriteable(Object object, String property,
PersistenceStructureService persistenceStructureService) throws IllegalArgumentException {
if (null == object || null == property) {
throw new IllegalArgumentException("Cannot check writeable status with null arguments.");
}
// Try the easy way.
try {
if (!(PropertyUtils.isWriteable(object, property))) {
// If that fails lets try to be a bit smarter, understanding that Collections may be involved.
return isWriteableHelper(object, property, persistenceStructureService);
} else {
return true;
}
} catch (NestedNullException nestedNullException) {
// If a NestedNullException is thrown then the property has a null
// value. Call the helper to find the class of the property and
// get a newInstance of it.
return isWriteableHelper(object, property, persistenceStructureService);
}
}
示例3: getNestedProperty
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
public static Object getNestedProperty(Object data, String name) {
try {
if (!name.contains(".")) {
return PropertyUtils.getProperty(data, name);
}
if (name.contains("[")) {
String[] names = name.split("\\.", 2);
Object obj = null;
try {
obj = PropertyUtils.getIndexedProperty(data, names[0]);
} catch (NullPointerException npe) {
// アクセスする配列オブジェクトがnullの場合
obj = null;
}
if (obj == null) {
return null;
}
return getNestedProperty(obj, names[1]);
}
try {
return PropertyUtils.getNestedProperty(data, name);
} catch (NestedNullException nne) {
// ネストしたプロパティの途中がnullの場合はエラーとせず
// nullを返す
return null;
}
} catch (Exception e) {
throw new ApplicationFatalRuntimeException("invalid property : " + name, e);
}
}
示例4: isPropertyReadable
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
private static boolean isPropertyReadable(Object bean, String name) {
try {
return PropertyUtils.isReadable(bean, name);
} catch (NestedNullException e) {
return false;
}
}
示例5: isPropertyWritable
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
private static boolean isPropertyWritable(Object bean, String name) {
try {
return PropertyUtils.isWriteable(bean, name);
} catch (NestedNullException e) {
return false;
}
}
示例6: getValue
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
@Override
public Object getValue() {
try {
final int propIndex = propertyProvider.getNestedIndex(propertyName);
if (propIndex >= 0 && propIndex < nestedProps.size())
return nestedProps.get(propIndex);
else
return PropertyUtils.getNestedProperty(bean, propertyName);
} catch (final NestedNullException ne) {
return null;
} catch (final Throwable e) {
propagate(e);
}
return null;
}
示例7: getPropertyFromMap
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
/**
* Tries to get a property from map using the provided
* key. If the Map contains the key, the associated property value
* is obtained from the Map and returned. Otherwise, checks to see if
* the Map contains a key matching the remainder of the keypath. If so,
* the property value stored under the alternate key is returned.
*/
public Object getPropertyFromMap(Map map, String key, Keypath keypath) {
String alternateKey = keypath.remainingKeypath();
if (!(map.containsKey(key) || map.containsKey(alternateKey)))
throw new NestedNullException("No property named " + key +
" or " + alternateKey);
if (map.containsKey(key))
return map.get(key);
if (map.containsKey(alternateKey))
keypath.invalidate();
return map.get(alternateKey);
}
示例8: testPopulateBusinessObjectFromMap
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
@Test
public void testPopulateBusinessObjectFromMap() {
PojoPlugin.initBeanUtils();
NestedBo nestedBo = new NestedBo();
Map<String, Object> values = new HashMap<String, Object>();
values.put("nestedImpl.value", "value");
FieldUtils.populateBusinessObjectFromMap(nestedBo, values);
assertNotNull(nestedBo.nested);
nestedBo.nested = null;
values.clear();
values.put("nestedIntf.value", "value");
try {
FieldUtils.populateBusinessObjectFromMap(nestedBo, values);
fail("Expected to throw NestedNullException due to attempt to instantiate interface");
} catch (NestedNullException nne) {
// expected
}
BOContainingPerson bo = new BOContainingPerson();
values.clear();
values.put("person.name", "value");
FieldUtils.populateBusinessObjectFromMap(bo, values);
assertNotNull(bo.getPerson());
assertEquals("value", bo.getPerson().getName());
}
示例9: getCollection
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
public Collection getCollection() {
throw new NestedNullException();
}
示例10: searchAttributesParam
import org.apache.commons.beanutils.NestedNullException; //导入依赖的package包/类
@Test(dependsOnMethods="createComplex", groups = "searchComplex")
public void searchAttributesParam() throws Exception{
int count=3;
List<String> attrList=Arrays.asList("name.familyName", "active");
logger.debug("Searching at most {} users using POST verb", count);
logger.debug("Sorted by family name descending");
logger.debug("Retrieving only the attributes {}", attrList);
SearchRequest sr=new SearchRequest();
sr.setFilter("name.familyName pr");
sr.setSortBy("name.familyName");
sr.setSortOrder("descending");
//Generate a string with the attributes desired to be returned separated by comma
sr.setAttributes(attrList.toString().replaceFirst("\\[","").replaceFirst("]",""));
sr.setCount(count);
Response response=client.searchUsersPost(sr);
assertEquals(response.getStatus(), OK.getStatusCode());
ListResponse listResponse=response.readEntity(ListResponse.class);
if (listResponse.getResources().size()<count)
logger.warn("Less than {} users satisfying the criteria. TESTER please check manually", count);
else{
//Obtain an array of results
UserResource users[]=listResponse.getResources().stream().map(usrClass::cast)
.collect(Collectors.toList()).toArray(new UserResource[]{});
assertEquals(users.length, count);
//Build a set of all attributes that should not appear in the response
Set<String> check=new HashSet<>();
check.addAll(IntrospectUtil.allAttrs.get(usrClass));
//Remove from the ALL list, those requested plus its "parents"
for (String attr : attrList){
String part=attr;
for (int i=part.length(); i>0; i = part.lastIndexOf(".")){
part=part.substring(0, i);
check.remove(part);
}
}
//Remove those that are ALWAYS present (per spec)
check.removeAll(IntrospectUtil.alwaysCoreAttrs.get(usrClass).keySet());
//Confirm for every user, those attributes are not there
for (UserResource user : users)
for (String path : check){
String val=null;
try {
val=BeanUtils.getProperty(user, path);
}
catch (NestedNullException nne){
//Intentionally left empty
}
finally {
assertNull(val);
}
}
for (int i=1;i<users.length;i++) {
String familyName=users[i-1].getName().getFamilyName().toLowerCase();
String familyName2=users[i].getName().getFamilyName().toLowerCase();
//Check if first string is greater or equal than second
assertFalse(familyName.compareTo(familyName2)<0);
}
}
}