8ac45d83361252536fcb3e21d446f5eb024b6a04
[jalviewjs.git] / src / javajs / api / Interface.java
1 /* $RCSfile$\r
2  * $Author$\r
3  * $Date$\r
4  * $Revision$\r
5  *\r
6  * Copyright (C) 2006  The Jmol Development Team\r
7  *\r
8  * Contact: jmol-developers@lists.sf.net\r
9  *\r
10  *  This library is free software; you can redistribute it and/or\r
11  *  modify it under the terms of the GNU Lesser General Public\r
12  *  License as published by the Free Software Foundation; either\r
13  *  version 2.1 of the License, or (at your option) any later version.\r
14  *\r
15  *  This library is distributed in the hope that it will be useful,\r
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
18  *  Lesser General Public License for more details.\r
19  *\r
20  *  You should have received a copy of the GNU Lesser General Public\r
21  *  License along with this library; if not, write to the Free Software\r
22  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
23  *  02110-1301, USA.\r
24  */\r
25 \r
26 package javajs.api;\r
27 \r
28 public class Interface {\r
29 \r
30   public static Object getInterface(String name) {\r
31     try {\r
32       Class<?> x = Class.forName(name);\r
33       return (x == null ? null : x.newInstance());\r
34     } catch (Exception e) {\r
35       System.out.println("Interface.getInterface Error creating instance for " + name + ": \n" + e);\r
36       return null;\r
37     }\r
38   }\r
39   \r
40         public static Object getInstanceWithParams(String name, Class[] classes, Object... params) {\r
41                 try {\r
42                         Class<?> cl = Class.forName(name);\r
43                         return  cl.getConstructor(classes).newInstance(params);\r
44                 } catch (Exception e) {\r
45       System.out.println("Interface.getInterfaceWithParams Error creating instance for " + name + ": \n" + e);\r
46                         return null;\r
47                 }\r
48         }\r
49 \r
50 \r
51 }\r