sun.reflect.misc.MethodUtil Java Examples
The following examples show how to use
sun.reflect.misc.MethodUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BasicComboBoxEditor.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #2
Source File: DefaultMXBeanMappingFactory.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override final Object toNonNullOpenValue(Object value) throws OpenDataException { CompositeType ct = (CompositeType) getOpenType(); if (value instanceof CompositeDataView) return ((CompositeDataView) value).toCompositeData(ct); if (value == null) return null; Object[] values = new Object[getters.length]; for (int i = 0; i < getters.length; i++) { try { Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); values[i] = getterMappings[i].toOpenValue(got); } catch (Exception e) { throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e); } } return new CompositeDataSupport(ct, itemNames, values); }
Example #3
Source File: DefaultMXBeanMappingFactory.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override final Object toNonNullOpenValue(Object value) throws OpenDataException { CompositeType ct = (CompositeType) getOpenType(); if (value instanceof CompositeDataView) return ((CompositeDataView) value).toCompositeData(ct); if (value == null) return null; Object[] values = new Object[getters.length]; for (int i = 0; i < getters.length; i++) { try { Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); values[i] = getterMappings[i].toOpenValue(got); } catch (Exception e) { throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e); } } return new CompositeDataSupport(ct, itemNames, values); }
Example #4
Source File: DefaultMXBeanMappingFactory.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override final Object toNonNullOpenValue(Object value) throws OpenDataException { CompositeType ct = (CompositeType) getOpenType(); if (value instanceof CompositeDataView) return ((CompositeDataView) value).toCompositeData(ct); if (value == null) return null; Object[] values = new Object[getters.length]; for (int i = 0; i < getters.length; i++) { try { Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); values[i] = getterMappings[i].toOpenValue(got); } catch (Exception e) { throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e); } } return new CompositeDataSupport(ct, itemNames, values); }
Example #5
Source File: DefaultMXBeanMappingFactory.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) throws InvalidObjectException { Object o; try { final Class<?> targetClass = getTargetClass(); ReflectUtil.checkPackageAccess(targetClass); o = targetClass.newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
Example #6
Source File: BasicComboBoxEditor.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #7
Source File: MethodElementHandler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Returns the result of method execution. * * @param type the base class * @param args the array of arguments * @return the value of this element * @throws Exception if calculation is failed */ @Override protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception { Object bean = getContextBean(); Class<?>[] types = getArgumentTypes(args); Method method = (type != null) ? MethodFinder.findStaticMethod(type, this.name, types) : MethodFinder.findMethod(bean.getClass(), this.name, types); if (method.isVarArgs()) { args = getArguments(args, method.getParameterTypes()); } Object value = MethodUtil.invoke(method, bean, args); return method.getReturnType().equals(void.class) ? ValueObjectImpl.VOID : ValueObjectImpl.create(value); }
Example #8
Source File: DefaultMXBeanMappingFactory.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) throws InvalidObjectException { Object o; try { final Class<?> targetClass = getTargetClass(); ReflectUtil.checkPackageAccess(targetClass); o = targetClass.newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
Example #9
Source File: DefaultMXBeanMappingFactory.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@Override final Object toNonNullOpenValue(Object value) throws OpenDataException { CompositeType ct = (CompositeType) getOpenType(); if (value instanceof CompositeDataView) return ((CompositeDataView) value).toCompositeData(ct); if (value == null) return null; Object[] values = new Object[getters.length]; for (int i = 0; i < getters.length; i++) { try { Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); values[i] = getterMappings[i].toOpenValue(got); } catch (Exception e) { throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e); } } return new CompositeDataSupport(ct, itemNames, values); }
Example #10
Source File: BasicComboBoxEditor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #11
Source File: BasicComboBoxEditor.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #12
Source File: BasicComboBoxEditor.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #13
Source File: BasicComboBoxEditor.java From Bytecoder with Apache License 2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class<?>[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #14
Source File: MethodElementHandler.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Returns the result of method execution. * * @param type the base class * @param args the array of arguments * @return the value of this element * @throws Exception if calculation is failed */ @Override protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception { Object bean = getContextBean(); Class<?>[] types = getArgumentTypes(args); Method method = (type != null) ? MethodFinder.findStaticMethod(type, this.name, types) : MethodFinder.findMethod(bean.getClass(), this.name, types); if (method.isVarArgs()) { args = getArguments(args, method.getParameterTypes()); } Object value = MethodUtil.invoke(method, bean, args); return method.getReturnType().equals(void.class) ? ValueObjectImpl.VOID : ValueObjectImpl.create(value); }
Example #15
Source File: DefaultMXBeanMappingFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) throws InvalidObjectException { Object o; try { final Class<?> targetClass = getTargetClass(); ReflectUtil.checkPackageAccess(targetClass); o = targetClass.newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
Example #16
Source File: DefaultMXBeanMappingFactory.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) throws InvalidObjectException { Object o; try { final Class<?> targetClass = getTargetClass(); ReflectUtil.checkPackageAccess(targetClass); o = targetClass.newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
Example #17
Source File: MethodElementHandler.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Returns the result of method execution. * * @param type the base class * @param args the array of arguments * @return the value of this element * @throws Exception if calculation is failed */ @Override protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception { Object bean = getContextBean(); Class<?>[] types = getArgumentTypes(args); Method method = (type != null) ? MethodFinder.findStaticMethod(type, this.name, types) : MethodFinder.findMethod(bean.getClass(), this.name, types); if (method.isVarArgs()) { args = getArguments(args, method.getParameterTypes()); } Object value = MethodUtil.invoke(method, bean, args); return method.getReturnType().equals(void.class) ? ValueObjectImpl.VOID : ValueObjectImpl.create(value); }
Example #18
Source File: DefaultMXBeanMappingFactory.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override final Object toNonNullOpenValue(Object value) throws OpenDataException { CompositeType ct = (CompositeType) getOpenType(); if (value instanceof CompositeDataView) return ((CompositeDataView) value).toCompositeData(ct); if (value == null) return null; Object[] values = new Object[getters.length]; for (int i = 0; i < getters.length; i++) { try { Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); values[i] = getterMappings[i].toOpenValue(got); } catch (Exception e) { throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e); } } return new CompositeDataSupport(ct, itemNames, values); }
Example #19
Source File: BasicComboBoxEditor.java From JDKSourceCode1.8 with MIT License | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #20
Source File: BasicComboBoxEditor.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #21
Source File: DefaultMXBeanMappingFactory.java From JDKSourceCode1.8 with MIT License | 6 votes |
Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) throws InvalidObjectException { Object o; try { final Class<?> targetClass = getTargetClass(); ReflectUtil.checkPackageAccess(targetClass); o = targetClass.newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
Example #22
Source File: DefaultMXBeanMappingFactory.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override final Object toNonNullOpenValue(Object value) throws OpenDataException { CompositeType ct = (CompositeType) getOpenType(); if (value instanceof CompositeDataView) return ((CompositeDataView) value).toCompositeData(ct); if (value == null) return null; Object[] values = new Object[getters.length]; for (int i = 0; i < getters.length; i++) { try { Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); values[i] = getterMappings[i].toOpenValue(got); } catch (Exception e) { throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e); } } return new CompositeDataSupport(ct, itemNames, values); }
Example #23
Source File: BasicComboBoxEditor.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class<?>[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #24
Source File: DefaultMXBeanMappingFactory.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
Object fromCompositeData(CompositeData cd, String[] itemNames, MXBeanMapping[] converters) throws InvalidObjectException { Object o; try { final Class<?> targetClass = getTargetClass(); ReflectUtil.checkPackageAccess(targetClass); o = targetClass.newInstance(); for (int i = 0; i < itemNames.length; i++) { if (cd.containsKey(itemNames[i])) { Object openItem = cd.get(itemNames[i]); Object javaItem = converters[i].fromOpenValue(openItem); MethodUtil.invoke(setters[i], o, new Object[] {javaItem}); } } } catch (Exception e) { throw invalidObjectException(e); } return o; }
Example #25
Source File: MethodElementHandler.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Returns the result of method execution. * * @param type the base class * @param args the array of arguments * @return the value of this element * @throws Exception if calculation is failed */ @Override protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception { Object bean = getContextBean(); Class<?>[] types = getArgumentTypes(args); Method method = (type != null) ? MethodFinder.findStaticMethod(type, this.name, types) : MethodFinder.findMethod(bean.getClass(), this.name, types); if (method.isVarArgs()) { args = getArguments(args, method.getParameterTypes()); } Object value = MethodUtil.invoke(method, bean, args); return method.getReturnType().equals(void.class) ? ValueObjectImpl.VOID : ValueObjectImpl.create(value); }
Example #26
Source File: DefaultMXBeanMappingFactory.java From JDKSourceCode1.8 with MIT License | 6 votes |
@Override final Object toNonNullOpenValue(Object value) throws OpenDataException { CompositeType ct = (CompositeType) getOpenType(); if (value instanceof CompositeDataView) return ((CompositeDataView) value).toCompositeData(ct); if (value == null) return null; Object[] values = new Object[getters.length]; for (int i = 0; i < getters.length; i++) { try { Object got = MethodUtil.invoke(getters[i], value, (Object[]) null); values[i] = getterMappings[i].toOpenValue(got); } catch (Exception e) { throw openDataException("Error calling getter for " + itemNames[i] + ": " + e, e); } } return new CompositeDataSupport(ct, itemNames, values); }
Example #27
Source File: BasicComboBoxEditor.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public Object getItem() { Object newValue = editor.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class<?> cls = oldValue.getClass(); try { Method method = MethodUtil.getMethod(cls, "valueOf", new Class[]{String.class}); newValue = MethodUtil.invoke(method, oldValue, new Object[] { editor.getText()}); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }
Example #28
Source File: TransferHandler.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Causes a transfer to a component from a clipboard or a * DND drop operation. The <code>Transferable</code> represents * the data to be imported into the component. * <p> * Note: Swing now calls the newer version of <code>importData</code> * that takes a <code>TransferSupport</code>, which in turn calls this * method (if the component in the {@code TransferSupport} is a * {@code JComponent}). Developers are encouraged to call and override the * newer version as it provides more information (and is the only * version that supports use with a {@code TransferHandler} set directly * on a {@code JFrame} or other non-{@code JComponent}). * * @param comp the component to receive the transfer; * provided to enable sharing of <code>TransferHandler</code>s * @param t the data to import * @return true if the data was inserted into the component, false otherwise * @see #importData(TransferHandler.TransferSupport) */ public boolean importData(JComponent comp, Transferable t) { PropertyDescriptor prop = getPropertyDescriptor(comp); if (prop != null) { Method writer = prop.getWriteMethod(); if (writer == null) { // read-only property. ignore return false; } Class<?>[] params = writer.getParameterTypes(); if (params.length != 1) { // zero or more than one argument, ignore return false; } DataFlavor flavor = getPropertyDataFlavor(params[0], t.getTransferDataFlavors()); if (flavor != null) { try { Object value = t.getTransferData(flavor); Object[] args = { value }; MethodUtil.invoke(writer, comp, args); return true; } catch (Exception ex) { System.err.println("Invocation failed"); // invocation code } } } return false; }
Example #29
Source File: TransferHandler.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Returns an object which represents the data to be transferred. The class * of the object returned is defined by the representation class of the flavor. * * @param flavor the requested flavor for the data * @see DataFlavor#getRepresentationClass * @exception IOException if the data is no longer available * in the requested flavor. * @exception UnsupportedFlavorException if the requested data flavor is * not supported. */ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if (! isDataFlavorSupported(flavor)) { throw new UnsupportedFlavorException(flavor); } Method reader = property.getReadMethod(); Object value = null; try { value = MethodUtil.invoke(reader, component, (Object[])null); } catch (Exception ex) { throw new IOException("Property read failed: " + property.getName()); } return value; }
Example #30
Source File: EventHandler.java From Bytecoder with Apache License 2.0 | 5 votes |
private Object applyGetters(Object target, String getters) { if (getters == null || getters.isEmpty()) { return target; } int firstDot = getters.indexOf('.'); if (firstDot == -1) { firstDot = getters.length(); } String first = getters.substring(0, firstDot); String rest = getters.substring(Math.min(firstDot + 1, getters.length())); try { Method getter = null; if (target != null) { getter = Statement.getMethod(target.getClass(), "get" + NameGenerator.capitalize(first), new Class<?>[]{}); if (getter == null) { getter = Statement.getMethod(target.getClass(), "is" + NameGenerator.capitalize(first), new Class<?>[]{}); } if (getter == null) { getter = Statement.getMethod(target.getClass(), first, new Class<?>[]{}); } } if (getter == null) { throw new RuntimeException("No method called: " + first + " defined on " + target); } Object newTarget = MethodUtil.invoke(getter, target, new Object[]{}); return applyGetters(newTarget, rest); } catch (Exception e) { throw new RuntimeException("Failed to call method: " + first + " on " + target, e); } }