本文整理匯總了Java中java.beans.Beans.getInstanceOf方法的典型用法代碼示例。如果您正苦於以下問題:Java Beans.getInstanceOf方法的具體用法?Java Beans.getInstanceOf怎麽用?Java Beans.getInstanceOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.beans.Beans
的用法示例。
在下文中一共展示了Beans.getInstanceOf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setValue
import java.beans.Beans; //導入方法依賴的package包/類
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: setValue
import java.beans.Beans; //導入方法依賴的package包/類
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: getValue
import java.beans.Beans; //導入方法依賴的package包/類
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: destroy
import java.beans.Beans; //導入方法依賴的package包/類
/** 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: getValue
import java.beans.Beans; //導入方法依賴的package包/類
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: getIndexedValue
import java.beans.Beans; //導入方法依賴的package包/類
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: setIndexedValue
import java.beans.Beans; //導入方法依賴的package包/類
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: testGetInstanceOf
import java.beans.Beans; //導入方法依賴的package包/類
public void testGetInstanceOf() {
MockJavaBean bean = new MockJavaBean();
Class<Component> type = Component.class;
Object obj = Beans.getInstanceOf(bean, type);
assertSame(bean, obj);
}
示例9: getValue
import java.beans.Beans; //導入方法依賴的package包/類
public Object getValue () throws
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (getter == null) throw new IllegalAccessException ();
Object valideInstance = Beans.getInstanceOf (instance, getter.getDeclaringClass());
try {
return getter.invoke (valideInstance, new Object [0]);
} catch (IllegalAccessException ex) {
try {
getter.setAccessible(true);
return getter.invoke (valideInstance, new Object [0]);
} finally {
getter.setAccessible(false);
}
}
}
示例10: setValue
import java.beans.Beans; //導入方法依賴的package包/類
public void setValue (Object val) throws
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (setter == null) throw new IllegalAccessException ();
Object valideInstance = Beans.getInstanceOf (instance, setter.getDeclaringClass());
try {
setter.invoke (valideInstance, new Object [] {val});
} catch (IllegalAccessException ex) {
try {
setter.setAccessible(true);
setter.invoke (valideInstance, new Object [] {val});
} finally {
setter.setAccessible(false);
}
}
}
示例11: setValue
import java.beans.Beans; //導入方法依賴的package包/類
public void setValue (Object val) throws
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (!canWrite ()) throw new IllegalAccessException ();
Object validInstance = Beans.getInstanceOf (instance, setter.getDeclaringClass());
if ((val!=null)&&(setter.getParameterTypes()[0].getComponentType().isPrimitive())&&(!val.getClass().getComponentType().isPrimitive())) {
val = Utilities.toPrimitiveArray ((Object[])val);
}
setter.invoke (validInstance, new Object [] {val});
}
示例12: testGetInstanceOf_BeanNull
import java.beans.Beans; //導入方法依賴的package包/類
public void testGetInstanceOf_BeanNull() {
Class<Component> type = Component.class;
Object obj = Beans.getInstanceOf(null, type);
assertNull(obj);
}
示例13: testGetInstanceOf_TargetTypeNull
import java.beans.Beans; //導入方法依賴的package包/類
public void testGetInstanceOf_TargetTypeNull() {
MockJavaBean bean = new MockJavaBean();
Object obj = Beans.getInstanceOf(bean, null);
assertSame(bean, obj);
}
示例14: getValue
import java.beans.Beans; //導入方法依賴的package包/類
public Object getValue () throws
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (!canRead ()) throw new IllegalAccessException ();
Object validInstance = Beans.getInstanceOf (instance, getter.getDeclaringClass());
return getter.invoke (validInstance, new Object [0]);
}
示例15: getIndexedValue
import java.beans.Beans; //導入方法依賴的package包/類
public Object getIndexedValue (int index) throws
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (!canIndexedRead ()) throw new IllegalAccessException ();
Object validInstance = Beans.getInstanceOf (instance, indexedGetter.getDeclaringClass());
return indexedGetter.invoke (validInstance, new Object [] {new Integer (index)});
}