use of java.beans.IntrospectionException in project kotlin by JetBrains.
the class Args method usage.
/**
* Generate usage information based on the target annotations.
*
* @param errStream A {@link java.io.PrintStream} to print the usage information to.
* @param target An instance or class.
*/
public static void usage(PrintStream errStream, Object target) {
Class<?> clazz;
if (target instanceof Class) {
clazz = (Class) target;
} else {
clazz = target.getClass();
}
errStream.println("Usage: " + clazz.getName());
for (Class<?> currentClazz = clazz; currentClazz != null; currentClazz = currentClazz.getSuperclass()) {
for (Field field : currentClazz.getDeclaredFields()) {
fieldUsage(errStream, target, field);
}
}
try {
BeanInfo info = Introspector.getBeanInfo(clazz);
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
propertyUsage(errStream, target, pd);
}
} catch (IntrospectionException e) {
// If its not a JavaBean we ignore it
}
}
use of java.beans.IntrospectionException in project goci by EBISPOT.
the class EmbeddableDocument method embed.
public void embed(Document document) {
try {
Set<String> excludeNames = new HashSet<>();
BeanInfo objectInfo = Introspector.getBeanInfo(Document.class);
for (PropertyDescriptor descriptor : objectInfo.getPropertyDescriptors()) {
excludeNames.add(descriptor.getName());
}
try {
BeanInfo docInfo = Introspector.getBeanInfo(document.getClass());
for (PropertyDescriptor descriptor : docInfo.getPropertyDescriptors()) {
if (!excludeNames.contains(descriptor.getName())) {
boolean isExcluded = false;
Method readMethod = descriptor.getReadMethod();
readMethod.setAccessible(true);
if (readMethod.isAnnotationPresent(NonEmbeddableField.class)) {
isExcluded = true;
} else {
try {
Field field = document.getClass().getDeclaredField(descriptor.getName());
field.setAccessible(true);
if (field.isAnnotationPresent(NonEmbeddableField.class)) {
isExcluded = true;
}
} catch (NoSuchFieldException e) {
// no field with this name, skip
}
}
if (!isExcluded) {
try {
// determine method to update this document with doc being embedded
Method propertyAdderMethod = findPropertyAdder(descriptor);
// invoke read method on passed document
Object fieldToEmbed = descriptor.getReadMethod().invoke(document);
propertyAdderMethod.invoke(this, fieldToEmbed);
} catch (InvocationTargetException | IllegalAccessException e) {
throw new DocumentEmbeddingException("Failed to read property '" + descriptor.getName() + "'", e);
}
}
}
}
} catch (IntrospectionException e) {
throw new DocumentEmbeddingException("Failed to analyse document in preparation for embedding", e);
}
} catch (IntrospectionException e) {
throw new DocumentEmbeddingException("Failed to read Object.class when determining which properties to exclude", e);
}
}
use of java.beans.IntrospectionException in project goci by EBISPOT.
the class EmbeddableDocumentTest method testIntrospection.
@Test
public void testIntrospection() {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(studyDoc.getClass());
for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
System.out.println("Display name: " + pd.getDisplayName());
System.out.println("Name: " + pd.getName());
System.out.println("Read method: " + pd.getReadMethod());
System.out.println("\t" + pd);
}
} catch (IntrospectionException e) {
e.printStackTrace();
fail();
}
}
use of java.beans.IntrospectionException in project jdk8u_jdk by JetBrains.
the class Test4520754 method getBeanInfo.
private static BeanInfo getBeanInfo(Boolean mark, Class type) {
System.out.println("test=" + mark + " for " + type);
BeanInfo info;
try {
info = Introspector.getBeanInfo(type);
} catch (IntrospectionException exception) {
throw new Error("unexpected exception", exception);
}
if (info == null) {
throw new Error("could not find BeanInfo for " + type);
}
if (mark != info.getBeanDescriptor().getValue("test")) {
throw new Error("could not find marked BeanInfo for " + type);
}
return info;
}
use of java.beans.IntrospectionException in project jdk8u_jdk by JetBrains.
the class Test5102804 method getReference.
private static Reference getReference() {
try {
ClassLoader loader = new Loader();
Class type = Class.forName(BEAN_NAME, true, loader);
if (!type.getClassLoader().equals(loader)) {
throw new Error("Wrong class loader");
}
BeanInfo info = Introspector.getBeanInfo(type);
if (0 != info.getDefaultPropertyIndex()) {
throw new Error("Wrong bean info found");
}
return new WeakReference<Class>(type);
} catch (IntrospectionException exception) {
throw new Error("Introspection Error", exception);
} catch (ClassNotFoundException exception) {
throw new Error("Class Not Found", exception);
}
}
Aggregations