swingjs/api, javajs/async
[jalview.git] / src / swingjs / 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 swingjs.api;
30
31 public class Interface {
32         
33         private static String instances=""; 
34
35         public static Object getInstanceWithParams(String name, Class<?>[] classes, Object... params) {
36                 try {
37                         Class<?> cl = Class.forName(name);
38                         return  cl.getConstructor(classes).newInstance(params);
39                 } catch (Exception e) {
40                         return null;
41                 }
42         }
43   public static Object getInstance(String name, boolean isQuiet) {
44         Object x = null;
45         /**
46          * @j2sNative
47          * 
48          * Clazz._isQuietLoad = isQuiet;
49          */
50         {}
51     try {
52         if (!isQuiet && instances.indexOf(name + ";") <= 0) {
53                 System.out.println("swingjs.api.Interface creating instance of " + name);
54                 instances += name + ";";
55         }
56         Class<?> y = Class.forName(name); 
57       if (y != null)
58         x = y.newInstance();
59     } catch (Throwable e) {
60       System.out.println("Swingjs.api.Interface Error creating instance for " + name + ": \n" + e);
61       /**
62        * @j2sNative
63        * 
64        * if (e.stack)System.out.println(e.stack);
65        */
66       {}
67     } finally {
68         /**
69          * @j2sNative
70          * 
71          * Clazz._isQuietLoad = false;
72          */
73         {}      
74     }
75     return x;           
76   }
77
78 }