Java Code Examples for java.beans.BeanInfo#getEventSetDescriptors()
The following examples show how to use
java.beans.BeanInfo#getEventSetDescriptors() .
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: DefaultWidgetIntrospector.java From nebula with Eclipse Public License 2.0 | 6 votes |
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException { Introspector.flushFromCaches(beanClass); BeanInfo bi = Introspector.getBeanInfo(beanClass); BeanDescriptor bd = bi.getBeanDescriptor(); MethodDescriptor mds[] = bi.getMethodDescriptors(); EventSetDescriptor esds[] = bi.getEventSetDescriptors(); PropertyDescriptor pds[] = bi.getPropertyDescriptors(); List<PropertyDescriptor> filteredPDList = new ArrayList<PropertyDescriptor>(); List<String> nonPropList = Arrays.asList(getNonProperties()); for(PropertyDescriptor pd : pds){ if(!nonPropList.contains(pd.getName()) && pd.getWriteMethod() != null && pd.getReadMethod() != null) filteredPDList.add(pd); } int defaultEvent = bi.getDefaultEventIndex(); int defaultProperty = bi.getDefaultPropertyIndex(); return new GenericBeanInfo(bd, esds, defaultEvent, filteredPDList.toArray(new PropertyDescriptor[filteredPDList.size()]), defaultProperty, mds, null); }
Example 2
Source File: SerialDataNode.java From netbeans with Apache License 2.0 | 6 votes |
/** try to register PropertyChangeListener to instance to fire its changes. * @param bean */ private void initPList (Object bean, BeanInfo bInfo, BeanNode.Descriptor descr) { EventSetDescriptor[] descs = bInfo.getEventSetDescriptors(); try { Method setter = null; for (int i = 0; descs != null && i < descs.length; i++) { setter = descs[i].getAddListenerMethod(); if (setter != null && setter.getName().equals("addPropertyChangeListener")) { // NOI18N propertyChangeListener = new PropL(createSupportedPropertyNames(descr)); setter.invoke(bean, new Object[] {WeakListeners.propertyChange(propertyChangeListener, bean)}); setSettingsInstance(bean); } } } catch (Exception ex) { // ignore } }
Example 3
Source File: AbstractResource.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Adds listeners to a resource. * @param listeners The listeners to be registered with the resource. A * {@link java.util.Map} that maps from fully qualified class name (as a * string) to listener (of the type declared by the key). * @param resource the resource that listeners will be registered to. */ public static void setResourceListeners(Resource resource, Map<String, ? extends Object> listeners) throws IntrospectionException, InvocationTargetException, IllegalAccessException, GateException { // get the beaninfo for the resource bean, excluding data about Object BeanInfo resBeanInfo = getBeanInfo(resource.getClass()); // get all the events the bean can fire EventSetDescriptor[] events = resBeanInfo.getEventSetDescriptors(); // add the listeners if (events != null) { EventSetDescriptor event; for(int i = 0; i < events.length; i++) { event = events[i]; // did we get such a listener? Object listener = listeners.get(event.getListenerType().getName()); if(listener != null) { Method addListener = event.getAddListenerMethod(); // call the set method with the parameter value Object[] args = new Object[1]; args[0] = listener; addListener.invoke(resource, args); } } // for each event } // if events != null }
Example 4
Source File: AbstractResource.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Removes listeners from a resource. * @param listeners The listeners to be removed from the resource. A * {@link java.util.Map} that maps from fully qualified class name * (as a string) to listener (of the type declared by the key). * @param resource the resource that listeners will be removed from. */ public static void removeResourceListeners(Resource resource, Map<String, ? extends Object> listeners) throws IntrospectionException, InvocationTargetException, IllegalAccessException, GateException{ // get the beaninfo for the resource bean, excluding data about Object BeanInfo resBeanInfo = getBeanInfo(resource.getClass()); // get all the events the bean can fire EventSetDescriptor[] events = resBeanInfo.getEventSetDescriptors(); //remove the listeners if(events != null) { EventSetDescriptor event; for(int i = 0; i < events.length; i++) { event = events[i]; // did we get such a listener? Object listener = listeners.get(event.getListenerType().getName()); if(listener != null) { Method removeListener = event.getRemoveListenerMethod(); // call the set method with the parameter value Object[] args = new Object[1]; args[0] = listener; removeListener.invoke(resource, args); } } // for each event } // if events != null }
Example 5
Source File: IntrospectorTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * The test checks the getEventSetDescriptors method * * @throws IntrospectionException */ public void testUnicastEventSetDescriptor() throws IntrospectionException { BeanInfo info = Introspector.getBeanInfo(SampleBean.class); assertNotNull(info); EventSetDescriptor[] descriptors = info.getEventSetDescriptors(); assertNotNull(descriptors); for (EventSetDescriptor descriptor : descriptors) { Method m = descriptor.getAddListenerMethod(); if (m != null) { Class<?>[] exceptionTypes = m.getExceptionTypes(); boolean found = false; for (Class<?> et : exceptionTypes) { if (et .equals(TooManyListenersException.class)) { assertTrue(descriptor.isUnicast()); found = true; break; } } if (!found) { assertFalse(descriptor.isUnicast()); } } } }
Example 6
Source File: IntrospectorTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * The test checks the getEventSetDescriptors method * * @throws IntrospectionException */ public void testEventSetDescriptorWithoutAddListenerMethod() throws IntrospectionException { BeanInfo info = Introspector.getBeanInfo(OtherBean.class); EventSetDescriptor[] descriptors; assertNotNull(info); descriptors = info.getEventSetDescriptors(); assertNotNull(descriptors); assertEquals(1, descriptors.length); assertTrue(contains("sample", descriptors)); }
Example 7
Source File: IntrospectorTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * The test checks the getEventSetDescriptors method * * @throws IntrospectionException */ public void testIllegalEventSetDescriptor() throws IntrospectionException { BeanInfo info = Introspector.getBeanInfo(MisprintBean.class); assertNotNull(info); EventSetDescriptor[] descriptors = info.getEventSetDescriptors(); assertNotNull(descriptors); assertEquals(0, descriptors.length); }
Example 8
Source File: IntrospectorTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testGetBeanInfoClassint_IGNORE_ALL_Event() throws IntrospectionException { BeanInfo info = Introspector.getBeanInfo(MockFooSub.class, Introspector.IGNORE_ALL_BEANINFO); EventSetDescriptor[] esds = info.getEventSetDescriptors(); assertEquals(1, esds.length); assertTrue(contains("mockPropertyChange", esds)); }
Example 9
Source File: IntrospectorTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testDefaultEvent() throws IntrospectionException { Class<?> beanClass = MockClassForDefaultEvent.class; BeanInfo info = Introspector.getBeanInfo(beanClass); assertEquals(-1, info.getDefaultEventIndex()); assertEquals(-1, info.getDefaultPropertyIndex()); EventSetDescriptor[] events = info.getEventSetDescriptors(); for (EventSetDescriptor event : events) { assertFalse(event.isUnicast()); assertTrue(event.isInDefaultEventSet()); assertFalse(event.isExpert()); assertFalse(event.isHidden()); assertFalse(event.isPreferred()); } }
Example 10
Source File: IntrospectorTest.java From j2objc with Apache License 2.0 | 4 votes |
private static void assertBeanInfoEquals(BeanInfo beanInfo, BeanInfo info) { // compare BeanDescriptor assertEquals(beanInfo.getBeanDescriptor().getDisplayName(), info .getBeanDescriptor().getDisplayName()); // compare MethodDescriptor MethodDescriptor[] methodDesc1 = beanInfo.getMethodDescriptors(); MethodDescriptor[] methodDesc2 = info.getMethodDescriptors(); assertEquals(methodDesc1.length, methodDesc2.length); for (int i = 0; i < methodDesc1.length; i++) { assertEquals(methodDesc1[i].getMethod(), methodDesc2[i].getMethod()); assertEquals(methodDesc1[i].getDisplayName(), methodDesc2[i] .getDisplayName()); } // compare PropertyDescriptor PropertyDescriptor[] propertyDesc1 = beanInfo.getPropertyDescriptors(); PropertyDescriptor[] propertyDesc2 = info.getPropertyDescriptors(); assertEquals(propertyDesc1.length, propertyDesc2.length); for (int i = 0; i < propertyDesc1.length; i++) { assertEquals(propertyDesc1[i], propertyDesc2[i]); } // compare EventSetDescriptor EventSetDescriptor[] eventDesc1 = beanInfo.getEventSetDescriptors(); EventSetDescriptor[] eventDesc2 = beanInfo.getEventSetDescriptors(); if (eventDesc1 == null) { assertNull(eventDesc2); } if (eventDesc2 == null) { assertNull(eventDesc1); } if ((eventDesc1 != null) && (eventDesc1 != null)) { assertEquals(eventDesc1.length, eventDesc2.length); for (int i = 0; i < eventDesc1.length; i++) { assertEquals(eventDesc1[i].getAddListenerMethod(), eventDesc2[i].getAddListenerMethod()); assertEquals(eventDesc1[i].getRemoveListenerMethod(), eventDesc2[i].getRemoveListenerMethod()); assertEquals(eventDesc1[i].getGetListenerMethod(), eventDesc2[i].getGetListenerMethod()); assertEquals(eventDesc1[i].getListenerMethods().length, eventDesc2[i].getListenerMethods().length); } } }