java.beans.IntrospectionException Java Examples
The following examples show how to use
java.beans.IntrospectionException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtendedBeanInfoTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void nonStandardReadMethodAndStandardWriteMethod() throws IntrospectionException { @SuppressWarnings("unused") class C { public void getFoo() { } public void setFoo(String foo) { } } BeanInfo bi = Introspector.getBeanInfo(C.class); BeanInfo ebi = new ExtendedBeanInfo(bi); assertThat(hasReadMethodForProperty(bi, "foo"), is(false)); assertThat(hasWriteMethodForProperty(bi, "foo"), is(true)); assertThat(hasReadMethodForProperty(ebi, "foo"), is(false)); assertThat(hasWriteMethodForProperty(ebi, "foo"), is(true)); }
Example #2
Source File: TestIntrospector.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static void test(StringBuilder sb) throws IntrospectionException { long time = 0L; if (sb != null) { sb.append("Time\t#Props\t#Events\t#Methods\tClass\n"); sb.append("----------------------------------------"); time = -System.currentTimeMillis(); } for (Class type : TYPES) { test(sb, type); } if (sb != null) { time += System.currentTimeMillis(); sb.append("\nTime: ").append(time).append(" ms\n"); System.out.println(sb); sb.setLength(0); } }
Example #3
Source File: CatalogNode.java From netbeans with Apache License 2.0 | 6 votes |
/** Creates new CatalogNode */ public CatalogNode(CatalogReader catalog) throws IntrospectionException { super(catalog, new CatalogChildren(catalog)); this.catalog=catalog; getCookieSet().add(this); if (catalog instanceof CatalogDescriptorBase) { // set node properties acording to descriptor CatalogDescriptorBase desc = (CatalogDescriptorBase) catalog; setSynchronizeName(false); setName(desc.getDisplayName()); String bundleString = catalog instanceof CatalogWriter ?"LBL_catalogReadWrite":"LBL_catalogReadOnly"; //NOI18N setDisplayName(NbBundle.getMessage(CatalogNode.class, bundleString, desc.getDisplayName())); setShortDescription(desc.getShortDescription()); fireIconChange(); // listen on it desc.addPropertyChangeListener(WeakListeners.propertyChange(this, desc)); } }
Example #4
Source File: IndexedPropertyDescriptorTest.java From j2objc with Apache License 2.0 | 6 votes |
public void testIndexedPropertyDescriptorStringMethodMethodMethodMethod_RWNull() throws SecurityException, NoSuchMethodException, IntrospectionException { String propertyName = "PropertyFour"; Class<MockJavaBean> beanClass = MockJavaBean.class; Method indexedReadMethod = beanClass.getMethod("get" + propertyName, new Class[] { Integer.TYPE }); Method indexedWriteMethod = beanClass.getMethod("set" + propertyName, new Class[] { Integer.TYPE, String.class }); IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor( propertyName, null, null, indexedReadMethod, indexedWriteMethod); assertNull(ipd.getPropertyType()); assertEquals(String.class, ipd.getIndexedPropertyType()); }
Example #5
Source File: FieldColumn.java From DataFrame with MIT License | 6 votes |
/** * Converts the value object and inserts it in the field of an object. * The field name is defined as the field name in this object * * @param value value that is converted and inserted * @param object object that gets the value inserted */ public void set(Object value, Object object) { Object convertedVal; if (field.getType().isInstance(value)) { convertedVal = value; } else { convertedVal = ParserUtil.parseOrNull(field.getType(), value.toString()); } try { if (Modifier.isPublic(field.getModifiers())) { field.set(object, convertedVal); } else { PropertyDescriptor objPropertyDescriptor = new PropertyDescriptor(field.getName(), object.getClass()); objPropertyDescriptor.getWriteMethod().invoke(object, convertedVal); } } catch (IllegalAccessException | InvocationTargetException | IntrospectionException e) { e.printStackTrace(); } }
Example #6
Source File: BundleCacher.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
@Override protected Set<Property> getProperties(Class<? extends Object> type) throws IntrospectionException { if (type.equals(Ruby.class) || type.equals(KCode.class) || type.equals(RubyProc.class)) { return Collections.emptySet(); } Set<Property> set = super.getProperties(type); if (CommandElement.class.isAssignableFrom(type) || type.equals(EnvironmentElement.class)) { // drop runtime, invoke, and invoke block properties Set<Property> toRemove = new HashSet<Property>(); for (Property prop : set) { if ("invokeBlock".equals(prop.getName()) || "runtime".equals(prop.getName()) //$NON-NLS-1$ //$NON-NLS-2$ || "invoke".equals(prop.getName())) //$NON-NLS-1$ { toRemove.add(prop); } } set.removeAll(toRemove); } return set; }
Example #7
Source File: JiveBeanInfo.java From Openfire with Apache License 2.0 | 6 votes |
@Override public PropertyDescriptor[] getPropertyDescriptors() { Class beanClass = getBeanClass(); String[] properties = getPropertyNames(); PropertyDescriptor[] descriptors = new PropertyDescriptor[properties.length]; try { // For each property, create a property descriptor and set the // name and description using the localized data. for (int i = 0; i < descriptors.length; i++) { PropertyDescriptor newDescriptor = new PropertyDescriptor(properties[i], beanClass); if (bundle != null) { newDescriptor.setDisplayName(bundle.getString(properties[i] + ".displayName")); newDescriptor.setShortDescription(bundle.getString(properties[i] + ".shortDescription")); } descriptors[i] = newDescriptor; } return descriptors; } catch (IntrospectionException ie) { Log.error(ie.getMessage(), ie); throw new Error(ie.toString()); } }
Example #8
Source File: JOutlookBarBeanInfo.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
/** Constructor for the JOutlookBarBeanInfo object */ public JOutlookBarBeanInfo() throws java.beans.IntrospectionException { // setup bean descriptor in constructor. bd.setName("JOutlookBar"); bd.setShortDescription("JOutlookBar brings the famous Outlook component to Swing"); BeanInfo info = Introspector.getBeanInfo(getBeanDescriptor().getBeanClass().getSuperclass()); String order = info.getBeanDescriptor().getValue("propertyorder") == null ? "" : (String) info.getBeanDescriptor().getValue("propertyorder"); PropertyDescriptor[] pd = getPropertyDescriptors(); for (int i = 0; i != pd.length; i++) { if (order.indexOf(pd[i].getName()) == -1) { order = order + (order.length() == 0 ? "" : ":") + pd[i].getName(); } } getBeanDescriptor().setValue("propertyorder", order); }
Example #9
Source File: HelpCtx.java From netbeans with Apache License 2.0 | 6 votes |
/** Finds help context for a generic object. Right now checks * for HelpCtx.Provider and handles java.awt.Component in a * special way compatible with JavaHelp. * Also {@link BeanDescriptor}'s are checked for a string-valued attribute * <code>helpID</code>, as per the JavaHelp specification (but no help sets * will be loaded). * * @param instance to search help for * @return the help for the object or <code>HelpCtx.DEFAULT_HELP</code> if HelpCtx cannot be found * * @since 4.3 */ public static HelpCtx findHelp(Object instance) { if (instance instanceof java.awt.Component) { return findHelp((java.awt.Component) instance); } if (instance instanceof HelpCtx.Provider) { return ((HelpCtx.Provider) instance).getHelpCtx(); } try { BeanDescriptor d = Introspector.getBeanInfo(instance.getClass()).getBeanDescriptor(); String v = (String) d.getValue("helpID"); // NOI18N if (v != null) { return new HelpCtx(v); } } catch (IntrospectionException e) { err.log(Level.FINE, "findHelp on {0}: {1}", new Object[]{instance, e}); } return HelpCtx.DEFAULT_HELP; }
Example #10
Source File: MBeanProxyInvocationHandler.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * * @param member * member to which this MBean belongs * @param monitoringRegion * corresponding MonitoringRegion * @param objectName * ObjectName of the MBean * @param interfaceClass * on which interface the proxy to be exposed * @return Object * @throws ClassNotFoundException * @throws IntrospectionException */ public static Object newProxyInstance(DistributedMember member, Region<String, Object> monitoringRegion, ObjectName objectName, Class interfaceClass) throws ClassNotFoundException, IntrospectionException { boolean isMXBean = JMX.isMXBeanInterface(interfaceClass); boolean notificationBroadcaster = ((FederationComponent) monitoringRegion .get(objectName.toString())).isNotificationEmitter(); InvocationHandler handler = new MBeanProxyInvocationHandler(member, objectName, monitoringRegion, isMXBean); Class[] interfaces; if (notificationBroadcaster) { interfaces = new Class[] { interfaceClass, ProxyInterface.class, NotificationBroadCasterProxy.class }; } else { interfaces = new Class[] { interfaceClass, ProxyInterface.class }; } Object proxy = Proxy.newProxyInstance(MBeanProxyInvocationHandler.class .getClassLoader(), interfaces, handler); return interfaceClass.cast(proxy); }
Example #11
Source File: Annotations.java From boon with Apache License 2.0 | 6 votes |
/** * Find annotation given a particular property name and clazz. This figures * out the writeMethod for the property, and uses the write method * to look up the annotation. * * @param clazz The class that holds the property. * @param propertyName The name of the property. * @return * @throws java.beans.IntrospectionException * */ private static Annotation[] findPropertyAnnotations( Class<?> clazz, String propertyName, boolean useRead ) throws IntrospectionException { PropertyDescriptor propertyDescriptor = getPropertyDescriptor( clazz, propertyName ); if ( propertyDescriptor == null ) { return new Annotation[]{ }; } Method accessMethod = null; if ( useRead ) { accessMethod = propertyDescriptor.getReadMethod(); } else { accessMethod = propertyDescriptor.getWriteMethod(); } if ( accessMethod != null ) { Annotation[] annotations = accessMethod.getAnnotations(); return annotations; } else { return new Annotation[]{ }; } }
Example #12
Source File: EventSetDescriptorTest.java From j2objc with Apache License 2.0 | 6 votes |
public void testEventSetDescriptorClassStringClassStringArrayStringString_sourceClassNull() throws IntrospectionException { Class<?> sourceClass = null; String eventSetName = "MockPropertyChange"; Class<?> listenerType = MockPropertyChangeListener.class; String[] listenerMethodNames = { "mockPropertyChange", "mockPropertyChange2", }; String addMethod = "addMockPropertyChangeListener"; String removeMethod = "removeMockPropertyChangeListener"; try { new EventSetDescriptor(sourceClass, eventSetName, listenerType, listenerMethodNames, addMethod, removeMethod); fail("Should throw NullPointerException."); } catch (NullPointerException e) { } }
Example #13
Source File: Test6447751.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
private static void test(Class<?> type, Class<?> expected) { Class<?> actual; try { actual = Introspector.getBeanInfo(type).getBeanDescriptor().getCustomizerClass(); } catch (IntrospectionException exception) { throw new Error("unexpected error", exception); } if (actual != expected) { StringBuilder sb = new StringBuilder(); sb.append("bean ").append(type).append(": "); if (expected != null) { sb.append("expected ").append(expected); if (actual != null) { sb.append(", but "); } } if (actual != null) { sb.append("found ").append(actual); } throw new Error(sb.toString()); } }
Example #14
Source File: CachedIntrospectionResults.java From java-technology-stack with MIT License | 6 votes |
private void introspectInterfaces(Class<?> beanClass, Class<?> currClass) throws IntrospectionException { for (Class<?> ifc : currClass.getInterfaces()) { if (!ClassUtils.isJavaLanguageInterface(ifc)) { for (PropertyDescriptor pd : getBeanInfo(ifc).getPropertyDescriptors()) { PropertyDescriptor existingPd = this.propertyDescriptorCache.get(pd.getName()); if (existingPd == null || (existingPd.getReadMethod() == null && pd.getReadMethod() != null)) { // GenericTypeAwarePropertyDescriptor leniently resolves a set* write method // against a declared read method, so we prefer read method descriptors here. pd = buildGenericTypeAwarePropertyDescriptor(beanClass, pd); this.propertyDescriptorCache.put(pd.getName(), pd); } } introspectInterfaces(ifc, ifc); } } }
Example #15
Source File: FieldHelper.java From genericdao with Artistic License 2.0 | 6 votes |
/** * 通过方法获取属性 * @param entityClass * @return */ public List<EntityField> getProperties(Class<?> entityClass) { List<EntityField> entityFields = new ArrayList<EntityField>(); BeanInfo beanInfo = null; try { beanInfo = Introspector.getBeanInfo(entityClass); } catch (IntrospectionException e) { throw new RuntimeException(e); } PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor desc : descriptors) { if (!desc.getName().equals("class")) { entityFields.add(new EntityField(desc)); } } return entityFields; }
Example #16
Source File: Test4634390.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
private static PropertyDescriptor create(PropertyDescriptor pd) { try { if (pd instanceof IndexedPropertyDescriptor) { IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; return new IndexedPropertyDescriptor( ipd.getName(), ipd.getReadMethod(), ipd.getWriteMethod(), ipd.getIndexedReadMethod(), ipd.getIndexedWriteMethod()); } else { return new PropertyDescriptor( pd.getName(), pd.getReadMethod(), pd.getWriteMethod()); } } catch (IntrospectionException exception) { exception.printStackTrace(); return null; } }
Example #17
Source File: ExtendedBeanInfoTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void indexedWriteMethodOnly() throws IntrospectionException { @SuppressWarnings("unused") class C { // indexed write method public void setFoos(int i, String foo) { } } BeanInfo bi = Introspector.getBeanInfo(C.class); BeanInfo ebi = new ExtendedBeanInfo(Introspector.getBeanInfo(C.class)); assertThat(hasWriteMethodForProperty(bi, "foos"), is(false)); assertThat(hasIndexedWriteMethodForProperty(bi, "foos"), is(true)); assertThat(hasWriteMethodForProperty(ebi, "foos"), is(false)); assertThat(hasIndexedWriteMethodForProperty(ebi, "foos"), is(true)); }
Example #18
Source File: TestIntrospector.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static void test(StringBuilder sb) throws IntrospectionException { long time = 0L; if (sb != null) { sb.append("Time\t#Props\t#Events\t#Methods\tClass\n"); sb.append("----------------------------------------"); time = -System.currentTimeMillis(); } for (Class type : TYPES) { test(sb, type); } if (sb != null) { time += System.currentTimeMillis(); sb.append("\nTime: ").append(time).append(" ms\n"); System.out.println(sb); sb.setLength(0); } }
Example #19
Source File: Test4274639.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public PropertyDescriptor[] getPropertyDescriptors() { PropertyDescriptor[] pds = new PropertyDescriptor[2]; try { pds[0] = new PropertyDescriptor(STRING_PROPERTY, TestBean.class); pds[0].setPropertyEditorClass(StringEditor.class); pds[1] = new PropertyDescriptor(INTEGER_PROPERTY, TestBean.class); pds[1].setPropertyEditorClass(IntegerEditor.class); } catch (IntrospectionException exception) { throw new Error("unexpected error", exception); } return pds; }
Example #20
Source File: BeanUtils.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Returns an array of property descriptors for specified class. * * @param type the class to introspect * @return an array of property descriptors */ public static PropertyDescriptor[] getPropertyDescriptors(Class type) { try { return Introspector.getBeanInfo(type).getPropertyDescriptors(); } catch (IntrospectionException exception) { throw new Error("unexpected exception", exception); } }
Example #21
Source File: ReflectionUtils.java From easy-random with MIT License | 5 votes |
/** * Set a value in a field of a target object. If the target object provides * a setter for the field, this setter will be used. Otherwise, the field * will be set using reflection. * * @param object instance to set the property on * @param field field to set the property on * @param value value to set * @throws IllegalAccessException if the property cannot be set */ public static void setProperty(final Object object, final Field field, final Object value) throws IllegalAccessException, InvocationTargetException { try { PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), object.getClass()); Method setter = propertyDescriptor.getWriteMethod(); if (setter != null) { setter.invoke(object, value); } else { setFieldValue(object, field, value); } } catch (IntrospectionException | IllegalAccessException e) { setFieldValue(object, field, value); } }
Example #22
Source File: PropertyDescriptorTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testPropertyDescriptorStringMethodMethod() throws SecurityException, NoSuchMethodException, IntrospectionException { String propertyName = "PropertyOne"; Class<MockJavaBean> beanClass = MockJavaBean.class; Method readMethod = beanClass.getMethod("get" + propertyName, (Class[]) null); Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String.class }); PropertyDescriptor pd = new PropertyDescriptor(propertyName, readMethod, writeMethod); assertEquals(String.class, pd.getPropertyType()); assertEquals("get" + propertyName, pd.getReadMethod().getName()); assertEquals("set" + propertyName, pd.getWriteMethod().getName()); assertFalse(pd.isBound()); assertFalse(pd.isConstrained()); assertEquals(propertyName, pd.getDisplayName()); assertEquals(propertyName, pd.getName()); assertEquals(propertyName, pd.getShortDescription()); assertNotNull(pd.attributeNames()); assertFalse(pd.isExpert()); assertFalse(pd.isHidden()); assertFalse(pd.isPreferred()); }
Example #23
Source File: ReflectionInfoTest.java From netbeans with Apache License 2.0 | 5 votes |
@Test public void testMixedRowArray() throws IntrospectionException { List<ReflectionInfo> ri = ReflectionInfo.prepare(Collections.singletonList(new Object[]{1, new DemoObject()})); assertEquals(4, ri.size()); assertEquals(0, ri.get(0).getIndex().intValue()); assertNull(ri.get(0).getPropertyName()); assertEquals(1, ri.get(1).getIndex().intValue()); assertEquals("demoBool", ri.get(1).getPropertyName()); assertEquals(1, ri.get(2).getIndex().intValue()); assertEquals("id", ri.get(2).getPropertyName()); assertEquals(1, ri.get(3).getIndex().intValue()); assertEquals("title", ri.get(3).getPropertyName()); }
Example #24
Source File: WhereUsedDataLoaderBeanInfo.java From netbeans with Apache License 2.0 | 5 votes |
public BeanInfo[] getAdditionalBeanInfo() { try { return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)}; } catch (IntrospectionException e) { throw new AssertionError(e); } }
Example #25
Source File: Test6660539.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static PropertyDescriptor[] getPropertyDescriptors() { try { BeanInfo info = Introspector.getBeanInfo(Test6660539.class); return info.getPropertyDescriptors(); } catch (IntrospectionException exception) { throw new Error("unexpected", exception); } }
Example #26
Source File: ExtendedBeanInfo.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Class<?> getIndexedPropertyType() { if (this.indexedPropertyType == null) { try { this.indexedPropertyType = PropertyDescriptorUtils.findIndexedPropertyType( getName(), getPropertyType(), this.indexedReadMethod, this.indexedWriteMethod); } catch (IntrospectionException ex) { // Ignore, as does IndexedPropertyDescriptor#getIndexedPropertyType } } return this.indexedPropertyType; }
Example #27
Source File: ExtendedBeanInfoTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void cornerSpr8949() throws IntrospectionException { class A { @SuppressWarnings("unused") public boolean isTargetMethod() { return false; } } class B extends A { @Override public boolean isTargetMethod() { return false; } } BeanInfo bi = Introspector.getBeanInfo(B.class); // java.beans.Introspector returns the "wrong" declaring class for overridden read // methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding // method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)} // helps out here, and is now put into use in ExtendedBeanInfo as well. BeanInfo ebi = new ExtendedBeanInfo(bi); assertThat(hasReadMethodForProperty(bi, "targetMethod"), is(true)); assertThat(hasWriteMethodForProperty(bi, "targetMethod"), is(false)); assertThat(hasReadMethodForProperty(ebi, "targetMethod"), is(true)); assertThat(hasWriteMethodForProperty(ebi, "targetMethod"), is(false)); }
Example #28
Source File: Utility.java From birt with Eclipse Public License 1.0 | 5 votes |
public static void setProperty(Object obj, String propertyName, Object value) throws IntrospectionException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { PropertyDescriptor descriptor = getPropertyDescriptor(obj, propertyName); if(descriptor != null) { Method method = descriptor.getWriteMethod(); if(method != null) { method.invoke(obj, new Object[]{value}); } } }
Example #29
Source File: LoadingStandardIcons.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(final String[] args) { final Object bi; try { bi = Introspector.getBeanInfo(JButton.class); } catch (IntrospectionException e) { throw new RuntimeException(e); } final Image m16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_16x16); final Image m32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_32x32); final Image c16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_16x16); final Image c32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_32x32); if (m16 == null || m32 == null || c16 == null || c32 == null) { throw new RuntimeException("Image should not be null"); } }
Example #30
Source File: PersisterFactoryGenerator.java From copper-engine with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws UnsupportedEncodingException, IOException, IntrospectionException { GenerationDescription impl = new GenerationDescription("TEMPLATE", "org.copperengine.core.persistent.alpha.generator", "org.copperengine.core.persistent.alpha.generator"); for (PropertyDescriptor desc : Introspector.getBeanInfo(TEMPLATE.class).getPropertyDescriptors()) { if ("entityId".equals(desc.getName())) continue; if (desc.getWriteMethod() != null && desc.getReadMethod() != null) { impl.getPersistentMembers().add(PersistentMember.fromProperty(desc)); } } new PersisterFactoryGenerator().generatePersisterFactory(impl, new OutputStreamWriter(System.out)); new PersisterFactoryGenerator().generateSqlCreateTable(impl, new OutputStreamWriter(System.out)); }