src/share/classes/sun/nio/ch/Reflect.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  58             Constructor<?> c = cl.getDeclaredConstructor(paramTypes);
  59             setAccessible(c);
  60             return c;
  61         } catch (ClassNotFoundException | NoSuchMethodException x) {
  62             throw new ReflectionError(x);
  63         }
  64     }
  65 
  66     static Object invoke(Constructor<?> c, Object[] args) {
  67         try {
  68             return c.newInstance(args);
  69         } catch (InstantiationException |
  70                  IllegalAccessException |
  71                  InvocationTargetException x) {
  72             throw new ReflectionError(x);
  73         }
  74     }
  75 
  76     static Method lookupMethod(String className,
  77                                String methodName,
  78                                Class... paramTypes)
  79     {
  80         try {
  81             Class<?> cl = Class.forName(className);
  82             Method m = cl.getDeclaredMethod(methodName, paramTypes);
  83             setAccessible(m);
  84             return m;
  85         } catch (ClassNotFoundException | NoSuchMethodException x) {
  86             throw new ReflectionError(x);
  87         }
  88     }
  89 
  90     static Object invoke(Method m, Object ob, Object[] args) {
  91         try {
  92             return m.invoke(ob, args);
  93         } catch (IllegalAccessException | InvocationTargetException x) {
  94             throw new ReflectionError(x);
  95         }
  96     }
  97 
  98     static Object invokeIO(Method m, Object ob, Object[] args)


   1 /*
   2  * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  58             Constructor<?> c = cl.getDeclaredConstructor(paramTypes);
  59             setAccessible(c);
  60             return c;
  61         } catch (ClassNotFoundException | NoSuchMethodException x) {
  62             throw new ReflectionError(x);
  63         }
  64     }
  65 
  66     static Object invoke(Constructor<?> c, Object[] args) {
  67         try {
  68             return c.newInstance(args);
  69         } catch (InstantiationException |
  70                  IllegalAccessException |
  71                  InvocationTargetException x) {
  72             throw new ReflectionError(x);
  73         }
  74     }
  75 
  76     static Method lookupMethod(String className,
  77                                String methodName,
  78                                Class<?>... paramTypes)
  79     {
  80         try {
  81             Class<?> cl = Class.forName(className);
  82             Method m = cl.getDeclaredMethod(methodName, paramTypes);
  83             setAccessible(m);
  84             return m;
  85         } catch (ClassNotFoundException | NoSuchMethodException x) {
  86             throw new ReflectionError(x);
  87         }
  88     }
  89 
  90     static Object invoke(Method m, Object ob, Object[] args) {
  91         try {
  92             return m.invoke(ob, args);
  93         } catch (IllegalAccessException | InvocationTargetException x) {
  94             throw new ReflectionError(x);
  95         }
  96     }
  97 
  98     static Object invokeIO(Method m, Object ob, Object[] args)