java.beans.Beans#getInstanceOf ( )源码实例Demo

下面列出了java.beans.Beans#getInstanceOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: PropertySupport.java
public void setValue(T val)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (setter == null) {
        throw new IllegalAccessException();
    }

    Object valideInstance = Beans.getInstanceOf(instance, setter.getDeclaringClass());

    try {
        setter.invoke(valideInstance, val);
    } catch (IllegalAccessException ex) {
        try {
            setter.setAccessible(true);
            setter.invoke(valideInstance, val);
        } finally {
            setter.setAccessible(false);
        }
    }
}
 
源代码2 项目: netbeans   文件: IndexedPropertySupport.java
public void setValue(T val) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (!canWrite()) {
        throw new IllegalAccessException();
    }

    Object validInstance = Beans.getInstanceOf(instance, setter.getDeclaringClass());

    Object value = val;
    if (
        (val != null) && (setter.getParameterTypes()[0].getComponentType().isPrimitive()) &&
            (!val.getClass().getComponentType().isPrimitive())
    ) {
        value = Utilities.toPrimitiveArray((Object[]) val);
    }

    setter.invoke(validInstance, value);
}
 
源代码3 项目: netbeans   文件: PropertySupport.java
public T getValue() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (getter == null) {
        throw new IllegalAccessException();
    }

    Object valideInstance = Beans.getInstanceOf(instance, getter.getDeclaringClass());

    try {
        try {
            return cast(getValueType(), getter.invoke(valideInstance));
        } catch (IllegalAccessException ex) {
            try {
                getter.setAccessible(true);

                return cast(getValueType(), getter.invoke(valideInstance));
            } finally {
                getter.setAccessible(false);
            }
        }
    } catch (IllegalArgumentException iae) {
        //Provide a better message for debugging
        StringBuffer sb = new StringBuffer("Attempted to invoke method ");
        sb.append(getter.getName());
        sb.append(" from class ");
        sb.append(getter.getDeclaringClass().getName());
        sb.append(" on an instance of ");
        sb.append(valideInstance.getClass().getName());
        sb.append(" Problem:");
        sb.append(iae.getMessage());
        throw (IllegalArgumentException) new IllegalArgumentException(sb.toString()).initCause(iae);
    }
}
 
源代码4 项目: netbeans   文件: BeanNode.java
/** Detaches all listeners from the bean and destroys it.
* @throws IOException if there was a problem
*/
@Override
public void destroy() throws IOException {
    if (removePCLMethod != null) {
        try {
            Object o = Beans.getInstanceOf(bean, removePCLMethod.getDeclaringClass());
            removePCLMethod.invoke(o, new Object[] { propertyChangeListener });
        } catch (Exception e) {
            NodeOp.exception(e);
        }
    }

    super.destroy();
}
 
源代码5 项目: netbeans   文件: IndexedPropertySupport.java
public T getValue() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (!canRead()) {
        throw new IllegalAccessException();
    }

    Object validInstance = Beans.getInstanceOf(instance, getter.getDeclaringClass());

    return PropertySupport.cast(getValueType(), getter.invoke(validInstance));
}
 
源代码6 项目: netbeans   文件: IndexedPropertySupport.java
public E getIndexedValue(int index)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (!canIndexedRead()) {
        throw new IllegalAccessException();
    }

    Object validInstance = Beans.getInstanceOf(instance, indexedGetter.getDeclaringClass());

    return PropertySupport.cast(getElementType(), indexedGetter.invoke(validInstance, index));
}
 
源代码7 项目: netbeans   文件: IndexedPropertySupport.java
public void setIndexedValue(int index, E val)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (!canIndexedWrite()) {
        throw new IllegalAccessException();
    }

    Object validInstance = Beans.getInstanceOf(instance, indexedSetter.getDeclaringClass());
    indexedSetter.invoke(validInstance, new Object[] { new Integer(index), val });
}
 
源代码8 项目: netbeans   文件: BeanNode.java
/** Performs initialization of the node
*/
private void initialization(boolean hasLookup) throws IntrospectionException {
    setIconBaseWithExtension(ICON_BASE);

    setSynchronizeName(true);

    // Find the first public superclass of the actual class.
    // Should not introspect on a private class, because then the method objects
    // used for the property descriptors will not be callable without an
    // IllegalAccessException, even if overriding a public method from a public superclass.
    Class<?> clazz = bean.getClass();

    while (!Modifier.isPublic(clazz.getModifiers()) && !hasExplicitBeanInfo(clazz)) {
        clazz = clazz.getSuperclass();

        if (clazz == null) {
            clazz = Object.class; // in case it was an interface
        }
    }

    beanInfo = Utilities.getBeanInfo(clazz);

    // resolving the name of this bean
    registerName();
    setNameSilently(getNameForBean());

    BeanDescriptor descriptor = beanInfo.getBeanDescriptor();
    String sd = descriptor.getShortDescription();

    if (!Utilities.compareObjects(sd, descriptor.getDisplayName())) {
        setShortDescription(sd);
    }

    // add propertyChangeListener
    EventSetDescriptor[] eventSetDescriptors = beanInfo.getEventSetDescriptors();
    int i;
    int k = eventSetDescriptors.length;
    Method method = null;

    for (i = 0; i < k; i++) {
        method = eventSetDescriptors[i].getAddListenerMethod();

        if (
            (method != null) && method.getName().equals("addPropertyChangeListener") && // NOI18N
                Modifier.isPublic(method.getModifiers())
        ) {
            break;
        }
    }

    if (i != k) {
        try {
            Object o = Beans.getInstanceOf(bean, method.getDeclaringClass());
            propertyChangeListener = new PropL();
            method.invoke(o, new Object[] { WeakListeners.propertyChange(propertyChangeListener, o) });
            removePCLMethod = eventSetDescriptors[i].getRemoveListenerMethod();
        } 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).
            Exceptions.attachMessage(e,
                                     "Trying to invoke " + method +
                                     " where introspected class is " +
                                     clazz.getName()); // NOI18N
            NodeOp.warning(e);
        }
    }

    createProperties(bean, beanInfo);

    for (Enumeration e = beanInfo.getBeanDescriptor().attributeNames(); e.hasMoreElements();) {
        String aname = (String) e.nextElement();
        setValue(aname, beanInfo.getBeanDescriptor().getValue(aname));
    }

    if (!hasLookup) {
        Node.Cookie instanceCookie = TMUtil.createInstanceCookie(bean);

        if (instanceCookie != null) {
            getCookieSet().add(instanceCookie);
        }
    }
}