/** * Get this EventSet's event listener interface type */ public Class getListenerType() { return descriptor.getListenerType(); }
private boolean isAssignable(EventSetDescriptor set, Class consumerClass) { return set.getListenerType().isAssignableFrom(consumerClass); }
boolean supportsPropertyChangeListener = false; BeanInfo info = Introspector.getBeanInfo(Bean.class); EventSetDescriptor[] descriptors = info.getEventSetDescriptors(); for (EventSetDescriptor descriptor : descriptors) { if (descriptor.getListenerType().equals(PropertyChangeListener.class)) { supportsPropertyChangeListener = true; } } System.out.println(supportsPropertyChangeListener);
/** * Return a list of input beans capable of receiving the supplied event * * @param esd the event in question * @return a vector of beans capable of handling the event */ public Vector<BeanInstance> getSuitableTargets(EventSetDescriptor esd) { Class<?> listenerClass = esd.getListenerType(); // class of the listener Vector<BeanInstance> targets = new Vector<BeanInstance>(); for (int i = 0; i < m_inputs.size(); i++) { BeanInstance input = (BeanInstance) m_inputs.elementAt(i); if (listenerClass.isInstance(input.getBean())) { targets.add(input); } } return targets; }
/** * Return a list of input beans capable of receiving the supplied event * * @param esd the event in question * @return a vector of beans capable of handling the event */ public Vector<BeanInstance> getSuitableTargets(EventSetDescriptor esd) { Class<?> listenerClass = esd.getListenerType(); // class of the listener Vector<BeanInstance> targets = new Vector<BeanInstance>(); for (int i = 0; i < m_inputs.size(); i++) { BeanInstance input = (BeanInstance) m_inputs.elementAt(i); if (listenerClass.isInstance(input.getBean())) { targets.add(input); } } return targets; }
static String notCompatibleWithEvent(Object consumer, EventSetDescriptor set, Object producer) { return _formatter.format("not-compatible-with-event", new Object[] { consumer, set.getListenerType().getName(), set.getName(), producer }); }
private static EventSetDescriptor getEventSetDescriptor(Object object) { assert object != null; EventSetDescriptor[] eds = getBeanInfo(object).getEventSetDescriptors(); for (EventSetDescriptor ed : eds) { if (ed.getListenerType() == PropertyChangeListener.class) { return ed; } } return null; }
private static EventSetDescriptor getEventSetDescriptor(Object object) { assert object != null; EventSetDescriptor[] eds = getBeanInfo(object).getEventSetDescriptors(); for (EventSetDescriptor ed : eds) { if (ed.getListenerType() == PropertyChangeListener.class) { return ed; } } return null; }
/** * Start listening to the source object */ private void listenToSource() { try { if (source != null) { BeanInfo info = getBeanInfo(source.getClass(), source); EventSetDescriptor[] events = info.getEventSetDescriptors(); for (int i = 0; i < events.length; ++i) { EventSetDescriptor event = events[i]; Class listenerType = event.getListenerType(); Object listenerObj = this; if (listenerType.isInstance(listenerObj)) { Method method = event.getAddListenerMethod(); method.invoke(source, new Object[] { listenerObj }); } } } } catch (Exception err) { PropertyValueControl.theLogger.error("An error occurred", err); } }
/** * Stop listening to the source object */ private void stopListeningToSource() { try { if (source != null) { BeanInfo info = getBeanInfo(source.getClass(), source); EventSetDescriptor[] events = info.getEventSetDescriptors(); Object listenerObj = this; for (int i = 0; i < events.length; ++i) { EventSetDescriptor event = events[i]; Class listenerType = event.getListenerType(); if (listenerType.isInstance(listenerObj)) { Method method = event.getRemoveListenerMethod(); method.invoke(source, new Object[] { this }); } } } } catch (Exception err) { PropertyValueControl.theLogger.error("An error occurred", err); } }
public BeanActionBinding(Component component, String actionExpression) { super(actionExpression); this.view = component; boolean foundActionEvents = false; try { BeanInfo info = Introspector.getBeanInfo(component.getClass()); EventSetDescriptor[] events = info.getEventSetDescriptors(); if (events != null && events.length > 0) { for (EventSetDescriptor event : events) { if (ActionListener.class .isAssignableFrom(event.getListenerType())) { event.getAddListenerMethod().invoke(component, new ActionListener() { public void actionPerformed(ActionEvent e) { fireAction(); } }); foundActionEvents = true; break; } } } } catch (Exception e) { throw new CayenneRuntimeException("Error binding to component", e); } if (!foundActionEvents) { throw new CayenneRuntimeException("Component does not define action events: %s", component); } }
Class<?> listenerClass = esd.getListenerType(); if (listenerClass.isInstance(targetBean)) { try {
Class<?> listenerClass = esd.getListenerType(); if (listenerClass.isInstance(targetBean)) { try {
private int encodeEventSetDescriptor(EventSetDescriptor eventSet, Class<?> beanClass) { BeanInfo info = BeanUtils.getBeanInfo(beanClass); EventSetDescriptor[] eventSets = info.getEventSetDescriptors(); int eventSetId = encodeObject(eventSets, eventSet, FeatureDescriptorComparator.INSTANCE); if (eventSetId == -1) { return -1; } Method[] methods = eventSet.getListenerType().getMethods(); Method method = eventSet.getListenerMethods()[0]; int methodId = encodeObject(methods, method, MethodComparator.INSTANCE); if (methodId == -1) { return -1; } // TODO: allow customisation of number of bits return (eventSetId << 4) | methodId; }
Class<?> listenerClass = esd.getListenerType(); // class of the listener JComponent source = (JComponent) bi.getBean();
Class<?> listenerClass = esd.getListenerType(); // class of the listener JComponent source = (JComponent) bi.getBean();
public static EventSetDescriptor getDescriptor(BeanInfo beanInfo, String eventSetName, String listenerMethodName) { checkNotNull(beanInfo, "beanInfo"); checkNotNull(eventSetName, "eventSetName"); checkNotNull(listenerMethodName, "listenerMethodName"); EventSetDescriptor descriptor = getDescriptor(beanInfo, eventSetName); MethodDescriptor listenerMethodDescriptor = BeanUtils.getListenerMethodDescriptor(descriptor, listenerMethodName); Method[] listenerMethods = new Method[] {listenerMethodDescriptor.getMethod()}; try { return new EventSetDescriptor(descriptor.getName(), descriptor.getListenerType(), listenerMethods, descriptor.getAddListenerMethod(), descriptor.getRemoveListenerMethod(), descriptor.getGetListenerMethod()); } catch (IntrospectionException exception) { throw new BeanException("Cannot construct event set descriptor", exception); } }
return new EventSetDescriptor(eventSet.getName(), eventSet.getListenerType(), new Method[] {method}, eventSet.getAddListenerMethod(), eventSet.getRemoveListenerMethod(), eventSet.getGetListenerMethod());