use of java.beans.PropertyDescriptor in project qiuyj-code by qiuyuanjun.
the class BeanWrapperImpl method doGetPropertyValue.
@Override
protected Object doGetPropertyValue(String property) {
PropertyDescriptor pd = getPropertyDescriptor(property);
Object getterValue = null;
if (Objects.isNull(pd)) {
throw new ReflectionException("Can not found property: " + property + " in class: " + wrappedClass);
} else if (pd instanceof NoGetterSetterPropertyDescriptor) {
Field propertyField = ((NoGetterSetterPropertyDescriptor) pd).getPropertyField();
ReflectionUtils.makeAccessible(propertyField);
try {
getterValue = propertyField.get(wrappedInstance);
} catch (IllegalAccessException e) {
// ignore
}
} else {
Method readMethod = pd.getReadMethod();
if (Objects.isNull(readMethod)) {
if (fieldOperationSupport) {
Field propertyField = ReflectionUtils.getDeclaredField(wrappedClass, property);
ReflectionUtils.makeAccessible(propertyField);
try {
getterValue = propertyField.get(wrappedInstance);
} catch (IllegalAccessException e) {
// ignore
}
} else {
throw new ReflectionException("Property '" + property + "' is an reading invisible property.");
}
} else {
ReflectionUtils.makeAccessible(readMethod);
getterValue = ReflectionUtils.invokeMethod(wrappedInstance, readMethod);
}
}
return getterValue;
}
use of java.beans.PropertyDescriptor in project liferay-ide by liferay.
the class NameFragment method getMethodCompletionProposals.
public ICompletionProposal[] getMethodCompletionProposals(int subOffset, int offset, Class parentClass, IResource file) {
if (instanceOf(parentClass, String.class) || instanceOf(parentClass, Number.class) || instanceOf(parentClass, Date.class) || instanceOf(parentClass, Collection.class) || instanceOf(parentClass, List.class) || instanceOf(parentClass, Map.class))
return null;
String prefix = getContent().substring(1, subOffset);
List proposals = new ArrayList();
String pUpper = prefix.toUpperCase();
try {
BeanInfo bi = Introspector.getBeanInfo(parentClass);
PropertyDescriptor[] pds = bi.getPropertyDescriptors();
for (int i = 0; i < pds.length; i++) {
PropertyDescriptor pd = pds[i];
String propertyName = pd.getName();
if (!propertyName.equals("class") && propertyName.toUpperCase().startsWith(pUpper)) {
// $NON-NLS-1$
proposals.add(new CompletionProposal(propertyName, offset - subOffset + 1, getContent().length() - 1, propertyName.length(), null, propertyName + " - " + pd.getReadMethod().getReturnType().getName(), null, // $NON-NLS-1$
null));
}
}
for (int i = 0; i < parentClass.getMethods().length; i++) {
Method m = parentClass.getMethods()[i];
String mName = m.getName();
if (m.getParameterTypes().length > 0 && mName.startsWith("get") && mName.toUpperCase().startsWith(pUpper)) {
// $NON-NLS-1$
StringBuffer display = new StringBuffer();
display.append(mName);
// $NON-NLS-1$
display.append("(");
for (int j = 0; j < m.getParameterTypes().length; j++) {
// $NON-NLS-1$
if (j > 0)
display.append(", ");
display.append(m.getParameterTypes()[j].getName());
}
// $NON-NLS-1$
display.append(")");
// $NON-NLS-1$
String actual = mName + "()";
int tLength = actual.length();
if (m.getParameterTypes().length > 0)
tLength--;
proposals.add(new CompletionProposal(actual, offset - subOffset + 1, getContent().length() - 1, tLength, null, display.toString() + " - " + m.getReturnType().getName(), null, // $NON-NLS-1$
null));
}
}
return completionProposals(proposals);
} catch (IntrospectionException e) {
return null;
}
}
use of java.beans.PropertyDescriptor in project cu-kfs by CU-CommunityApps.
the class AssetSeparatePaymentDistributor method applyRatioToPaymentAmounts.
/**
* Utility method which can take one payment and distribute its amount by ratio to the target payments
*
* @param source Source Payment
* @param targets Target Payment
* @param ratios Ratio to be applied for each target
*/
private void applyRatioToPaymentAmounts(AssetPayment source, AssetPayment[] targets, double[] ratios) {
try {
for (PropertyDescriptor propertyDescriptor : assetPaymentProperties) {
Method readMethod = propertyDescriptor.getReadMethod();
if (readMethod != null && propertyDescriptor.getPropertyType() != null && KualiDecimal.class.isAssignableFrom(propertyDescriptor.getPropertyType())) {
KualiDecimal amount = (KualiDecimal) readMethod.invoke(source);
if (amount != null && amount.isNonZero()) {
KualiDecimal[] ratioAmounts = KualiDecimalUtils.allocateByRatio(amount, ratios);
Method writeMethod = propertyDescriptor.getWriteMethod();
if (writeMethod != null) {
for (int i = 0; i < ratioAmounts.length; i++) {
writeMethod.invoke(targets[i], ratioAmounts[i]);
}
}
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of java.beans.PropertyDescriptor in project knox by apache.
the class XmlUrlRewriteRulesExporter method createElement.
private Element createElement(Document document, String name, Object bean) throws IntrospectionException, InvocationTargetException, NoSuchMethodException, IllegalAccessException {
Element element = document.createElement(name);
BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass(), Object.class);
for (PropertyDescriptor propInfo : beanInfo.getPropertyDescriptors()) {
String propName = propInfo.getName();
if (propInfo.getReadMethod() != null && String.class.isAssignableFrom(propInfo.getPropertyType())) {
String propValue = BeanUtils.getProperty(bean, propName);
if (propValue != null && !propValue.isEmpty()) {
// Doing it the hard way to avoid having the &'s in the query string escaped at &
Attr attr = document.createAttribute(propName);
attr.setValue(propValue);
element.setAttributeNode(attr);
// element.setAttribute( propName, propValue );
}
}
}
return element;
}
use of java.beans.PropertyDescriptor in project fabric8 by jboss-fuse.
the class JolokiaFabricController method getPropertyDescriptors.
public static Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?> aClass) throws IntrospectionException {
Map<String, PropertyDescriptor> answer = new HashMap<>();
if (aClass != null) {
BeanInfo beanInfo = java.beans.Introspector.getBeanInfo(aClass);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
// ignore the class property
String name = propertyDescriptor.getName();
if (name.equals("class")) {
continue;
}
answer.put(name, propertyDescriptor);
}
}
return answer;
}
Aggregations