本文整理汇总了Java中java.beans.BeanInfo.getEventSetDescriptors方法的典型用法代码示例。如果您正苦于以下问题:Java BeanInfo.getEventSetDescriptors方法的具体用法?Java BeanInfo.getEventSetDescriptors怎么用?Java BeanInfo.getEventSetDescriptors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.beans.BeanInfo
的用法示例。
在下文中一共展示了BeanInfo.getEventSetDescriptors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPList
import java.beans.BeanInfo; //导入方法依赖的package包/类
/** 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
}
}
示例2: setResourceListeners
import java.beans.BeanInfo; //导入方法依赖的package包/类
/**
* 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
}
示例3: removeResourceListeners
import java.beans.BeanInfo; //导入方法依赖的package包/类
/**
* 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
}