Search in sources :

Example 21 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project intellij-community by JetBrains.

the class CreateListenerAction method prepareActionGroup.

private DefaultActionGroup prepareActionGroup(final List<RadComponent> selection) {
    final DefaultActionGroup actionGroup = new DefaultActionGroup();
    final EventSetDescriptor[] eventSetDescriptors;
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(selection.get(0).getComponentClass());
        eventSetDescriptors = beanInfo.getEventSetDescriptors();
    } catch (IntrospectionException e) {
        LOG.error(e);
        return null;
    }
    EventSetDescriptor[] sortedDescriptors = new EventSetDescriptor[eventSetDescriptors.length];
    System.arraycopy(eventSetDescriptors, 0, sortedDescriptors, 0, eventSetDescriptors.length);
    Arrays.sort(sortedDescriptors, (o1, o2) -> o1.getListenerType().getName().compareTo(o2.getListenerType().getName()));
    for (EventSetDescriptor descriptor : sortedDescriptors) {
        actionGroup.add(new MyCreateListenerAction(selection, descriptor));
    }
    return actionGroup;
}
Also used : BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) EventSetDescriptor(java.beans.EventSetDescriptor)

Example 22 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project ACS by ACS-Community.

the class IntrospectionBasedNodeUpdater method findPropertyChangeListenerMethods.

//
// -- PRIVATE METHODS -----------------------------------------------
//
private void findPropertyChangeListenerMethods() {
    // add propertyChangeListener
    EventSetDescriptor[] eventSetDescriptors = _beanInfo.getEventSetDescriptors();
    for (int i = 0; i < eventSetDescriptors.length; i++) {
        Method method = eventSetDescriptors[i].getAddListenerMethod();
        if (method != null && method.getName().equals("addPropertyChangeListener") && Modifier.isPublic(method.getModifiers())) {
            // set descriptor. In such a case, do not try to add a listener.
            try {
                _propertyChangeListener = new PropertyChangeListenerImpl();
                method.invoke(_bean, new Object[] { _propertyChangeListener });
                _hasRegisteredListener = true;
            } catch (Exception e) {
                // Warning, not info: likely to call e.g. getters or other things used
                // during startup of the bean, so it is not good to swallow errors here
                // (e.g. SharedClassObject.initialize throws RuntimeException -> it is
                // caught here and probably someone wants to know).
                GPManager.notify(GPManager.ERROR, e);
            // [PENDING] deal with the error to notify
            }
            _removePropertyChangeListenerMethod = eventSetDescriptors[i].getRemoveListenerMethod();
            break;
        }
    }
}
Also used : Method(java.lang.reflect.Method) EventSetDescriptor(java.beans.EventSetDescriptor) IntrospectionException(java.beans.IntrospectionException)

Example 23 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project jdk8u_jdk by JetBrains.

the class Test6311051 method main.

public static void main(String[] args) throws IntrospectionException, NoSuchMethodException {
    EventSetDescriptor esd = new EventSetDescriptor("foo", FooListener.class, new Method[] { FooListener.class.getMethod("fooHappened", EventObject.class), FooListener.class.getMethod("moreFooHappened", EventObject.class, Object.class), FooListener.class.getMethod("lessFooHappened") }, Bean.class.getMethod("addFooListener", FooListener.class), Bean.class.getMethod("removeFooListener", FooListener.class));
    System.gc();
    for (Method method : esd.getListenerMethods()) {
        System.out.println(method);
    }
}
Also used : EventObject(java.util.EventObject) Method(java.lang.reflect.Method) EventSetDescriptor(java.beans.EventSetDescriptor) EventObject(java.util.EventObject)

Example 24 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project yamcs-studio by yamcs.

the class DefaultWidgetIntrospector method getBeanInfo.

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);
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) MethodDescriptor(java.beans.MethodDescriptor) EventSetDescriptor(java.beans.EventSetDescriptor) BeanDescriptor(java.beans.BeanDescriptor)

Example 25 with EventSetDescriptor

use of java.beans.EventSetDescriptor in project opennms by OpenNMS.

the class BeanInfoManager method initialize.

// -------------------------------------
/**
 * Initializes by mapping property names to BeanInfoProperties
 */
void initialize(Logger pLogger) throws ELException {
    try {
        mBeanInfo = Introspector.getBeanInfo(mBeanClass);
        mPropertyByName = new HashMap();
        mIndexedPropertyByName = new HashMap();
        PropertyDescriptor[] pds = mBeanInfo.getPropertyDescriptors();
        for (int i = 0; pds != null && i < pds.length; i++) {
            // Treat as both an indexed property and a normal property
            PropertyDescriptor pd = pds[i];
            if (pd instanceof IndexedPropertyDescriptor) {
                IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
                Method readMethod = getPublicMethod(ipd.getIndexedReadMethod());
                Method writeMethod = getPublicMethod(ipd.getIndexedWriteMethod());
                BeanInfoIndexedProperty property = new BeanInfoIndexedProperty(readMethod, writeMethod, ipd);
                mIndexedPropertyByName.put(ipd.getName(), property);
            }
            Method readMethod = getPublicMethod(pd.getReadMethod());
            Method writeMethod = getPublicMethod(pd.getWriteMethod());
            BeanInfoProperty property = new BeanInfoProperty(readMethod, writeMethod, pd);
            mPropertyByName.put(pd.getName(), property);
        }
        mEventSetByName = new HashMap();
        EventSetDescriptor[] esds = mBeanInfo.getEventSetDescriptors();
        for (int i = 0; esds != null && i < esds.length; i++) {
            EventSetDescriptor esd = esds[i];
            mEventSetByName.put(esd.getName(), esd);
        }
    } catch (IntrospectionException exc) {
        if (pLogger.isLoggingWarning()) {
            pLogger.logWarning(Constants.EXCEPTION_GETTING_BEANINFO, exc, mBeanClass.getName());
        }
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) HashMap(java.util.HashMap) IntrospectionException(java.beans.IntrospectionException) IndexedPropertyDescriptor(java.beans.IndexedPropertyDescriptor) Method(java.lang.reflect.Method) EventSetDescriptor(java.beans.EventSetDescriptor)

Aggregations

EventSetDescriptor (java.beans.EventSetDescriptor)55 Method (java.lang.reflect.Method)34 MockPropertyChangeListener (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeListener)31 BeanInfo (java.beans.BeanInfo)10 MethodDescriptor (java.beans.MethodDescriptor)10 IntrospectionException (java.beans.IntrospectionException)9 PropertyDescriptor (java.beans.PropertyDescriptor)6 MockPropertyChangeEvent (org.apache.harmony.beans.tests.support.mock.MockPropertyChangeEvent)6 SimpleBeanInfo (java.beans.SimpleBeanInfo)5 FakeFox01BeanInfo (org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo)5 IndexedPropertyDescriptor (java.beans.IndexedPropertyDescriptor)3 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 BeanDescriptor (java.beans.BeanDescriptor)2 PrivilegedActionException (java.security.PrivilegedActionException)2 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)2 CachedMethod (org.codehaus.groovy.reflection.CachedMethod)2 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)2 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)2 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)2 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)2