use of java.beans.BeanInfo 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.BeanInfo 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.BeanInfo 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;
}
use of java.beans.BeanInfo in project jbosstools-hibernate by jbosstools.
the class GenericPropertySource method buildPropertyDescriptors.
private IPropertyDescriptor[] buildPropertyDescriptors() {
if (real == null)
return new IPropertyDescriptor[0];
try {
BeanInfo beanInfo = Introspector.getBeanInfo(real.getClass(), Object.class);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
IPropertyDescriptor[] result = new IPropertyDescriptor[propertyDescriptors.length];
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
result[i] = new BeanPropertyDescriptor(descriptor);
}
return result;
} catch (IntrospectionException e) {
return new IPropertyDescriptor[0];
}
}
use of java.beans.BeanInfo in project synergic-developing by zeemood.
the class JSONWriter method bean.
private void bean(Object object) {
add("{");
BeanInfo info;
boolean addedSomething = false;
try {
info = Introspector.getBeanInfo(object.getClass());
PropertyDescriptor[] props = info.getPropertyDescriptors();
for (int i = 0; i < props.length; ++i) {
PropertyDescriptor prop = props[i];
String name = prop.getName();
Method accessor = prop.getReadMethod();
if ((emitClassName || !"class".equals(name)) && accessor != null) {
if (!accessor.isAccessible())
accessor.setAccessible(true);
Object value = accessor.invoke(object, (Object[]) null);
if (value == null)
continue;
if (addedSomething)
add(',');
add(name, value);
addedSomething = true;
}
}
Field[] ff = object.getClass().getFields();
for (int i = 0; i < ff.length; ++i) {
Field field = ff[i];
Object value = field.get(object);
if (value == null)
continue;
if (addedSomething)
add(',');
add(field.getName(), value);
addedSomething = true;
}
} catch (IllegalAccessException iae) {
iae.printStackTrace();
} catch (InvocationTargetException ite) {
ite.getCause().printStackTrace();
ite.printStackTrace();
} catch (IntrospectionException ie) {
ie.printStackTrace();
}
add("}");
}
Aggregations