Merge branch 'Jalview-JS/JAL-3253-applet' of https://source.jalview.org/git/jalview...
[jalview.git] / src / jalview / bin / Instance.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.bin;
22
23 import jalview.analysis.AlignmentSorter;
24 import jalview.analysis.scoremodels.ScoreModels;
25 import jalview.api.StructureSelectionManagerProvider;
26 import jalview.datamodel.features.FeatureAttributes;
27 import jalview.datamodel.features.FeatureSources;
28 import jalview.ext.ensembl.EnsemblInfo;
29 import jalview.fts.service.pdb.PDBFTSRestClient;
30 import jalview.fts.service.uniprot.UniProtFTSRestClient;
31 import jalview.gui.Desktop;
32 import jalview.httpserver.HttpServer;
33 import jalview.io.FileFormats;
34 import jalview.io.cache.AppCache;
35 import jalview.io.gff.SequenceOntologyFactory;
36 import jalview.rest.RestHandler;
37 import jalview.schemes.ColourSchemes;
38 import jalview.structure.StructureImportSettings;
39 import jalview.structure.StructureSelectionManager;
40 import jalview.urls.IdOrgSettings;
41 import jalview.util.Platform;
42 import jalview.ws.jws1.Discoverer;
43 import jalview.ws.jws2.Jws2Discoverer;
44 import jalview.ws.jws2.jabaws2.Jws2InstanceFactory;
45 import jalview.ws.rest.RestClient;
46 import jalview.ws.sifts.SiftsSettings;
47
48 import java.util.IdentityHashMap;
49
50 /**
51  * A class to hold singleton instances so that they are not shared among
52  * multiple JavaScript apps on a page. Fields are all formerly static class or
53  * object references are preserved in this singleton as "pseudo" static
54  * references that will be unique for each JavaScript applet or Java
55  * application.
56  * 
57  * There are three kinds of references:
58  * 
59  * Class references for classes with public getInstance() calls and a private
60  * constructor.
61  * 
62  * Class references for classes with private getInstance() calls and a private
63  * constructor.
64  * 
65  * Object references held here for a class as "pseudo" static field and
66  * referenced by Instance.getInstance().fieldName. These classes
67  * 
68  * @author hansonr
69  *
70  */
71 public class Instance
72 {
73
74   private Instance()
75   {
76     // singleton -- use getInstance();
77   }
78
79   private static Instance instance;
80
81   /**
82    * 
83    * Creates a static reference to this class, either as a static field (Java)
84    * or as an element in the applet's ThreadGroup object.
85    * 
86    * @return new Instance()
87    */
88   public static Instance getInstance()
89   {
90
91     // assign g only if JavaScript and instance only if Java
92
93     @SuppressWarnings("unused")
94     ThreadGroup g = (Platform.isJS()
95             ? Thread.currentThread().getThreadGroup()
96             : null);
97     Instance i = /** @j2sNative g._jalviewInstance || */
98             instance;
99     if (i == null)
100     {
101       i = /**
102            * @j2sNative g._jalviewInstance =
103            */
104               new Instance();
105       instance = /** @j2sNative null && */
106               i;
107     }
108     return i;
109   }
110
111   public Jalview jalview;
112
113   public Desktop desktop;
114
115
116
117   // The following are PUBLIC singletons; their class has a private constructor
118   // that is assigned by the class as part of a public static getInstance()
119   // call.
120
121   public AppCache appCache;
122
123   public ColourSchemes colourSchemes;
124
125   public Discoverer discoverer;
126
127   public FileFormats fileFormats;
128
129   public HttpServer httpServer;
130
131   public RestClient restClient;
132
133   public RestHandler restHandler;
134
135   public ScoreModels scoreModels;
136
137   public jalview.ws.SequenceFetcher sequenceFetcher;
138
139   public SiftsSettings siftsSettings;
140
141
142   // The following are PRIVATE singletons; their class has only static public
143   // methods and a private constructor that is assigned by the class as part of
144   // a private static getInstance() call.
145
146   public AlignmentSorter alignmentSorter;
147
148   public Cache cache;
149
150   public EnsemblInfo ensemblInfo;
151
152   public FeatureAttributes featureAttributes;
153
154   public FeatureSources featureSources;
155
156   public IdOrgSettings idOrgSettings;
157
158   public Jws2Discoverer j2s2discoverer;
159
160   public Jws2InstanceFactory jws2InstanceFactory;
161
162   public PDBFTSRestClient pdbFTSRestClient;
163
164   public SequenceOntologyFactory sequenceOntologyFactory;
165
166   public StructureImportSettings structureImportSettings;
167
168   public UniProtFTSRestClient uniprotFTSRestClient;
169
170   // The following formerly static Object references are
171   // preserved in this singleton as "pseudo" static references
172   // that will be unique for each JavaScript applet or Java application.
173
174   /**
175    * StructureSelectionManager "static"
176    */
177   public IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> structureSelections;
178
179
180 }