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