JAL-3253 jalview.bin.Instance for AppCache and FeatureAttribute
[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.ws.jws1.Discoverer;
42 import jalview.ws.jws2.Jws2Discoverer;
43 import jalview.ws.jws2.jabaws2.Jws2InstanceFactory;
44 import jalview.ws.rest.RestClient;
45 import jalview.ws.sifts.SiftsSettings;
46
47 import java.util.IdentityHashMap;
48
49 /**
50  * A class to hold singleton instances so that they are not shared among
51  * multiple JavaScript apps on a page. Fields are all formerly static class or
52  * object references are preserved in this singleton as "pseudo" static
53  * references that will be unique for each JavaScript applet or Java
54  * application.
55  * 
56  * There are three kinds of references:
57  * 
58  * Class references for classes with public getInstance() calls and a private
59  * constructor.
60  * 
61  * Class references for classes with private getInstance() calls and a private
62  * constructor.
63  * 
64  * Object references held here for a class as "pseudo" static field and
65  * referenced by Instance.getInstance().fieldName. These classes
66  * 
67  * @author hansonr
68  *
69  */
70 public class Instance
71 {
72
73   private Instance()
74   {
75     // singleton -- use getInstance();
76   }
77
78   private static Instance instance;
79
80   /**
81    * 
82    * Creates a static reference to this class, either as a static field (Java)
83    * or as an element in the applet's ThreadGroup object.
84    * 
85    * @return new Instance()
86    */
87   public static Instance getInstance()
88   {
89     Instance i;
90     @SuppressWarnings("unused")
91     ThreadGroup g = Thread.currentThread().getThreadGroup();
92     /**
93      * @j2sNative i = g._jalviewInstance;
94      */
95     {
96       i = instance;
97     }
98     if (i == null)
99     {
100       i = instance = new Instance();
101       /**
102        * @j2sNative g._jalviewInstance = i;
103        */
104     }
105     return i;
106   }
107
108   public Jalview jalview;
109
110   public Desktop desktop;
111
112
113
114   // The following are PUBLIC singletons; their class has a private constructor
115   // that is assigned by the class as part of a public static getInstance()
116   // call.
117
118   public AppCache appCache;
119
120   public ColourSchemes colourSchemes;
121
122   public Discoverer discoverer;
123
124   public FileFormats fileFormats;
125
126   public HttpServer httpServer;
127
128   public RestClient restClient;
129
130   public RestHandler restHandler;
131
132   public ScoreModels scoreModels;
133
134   public jalview.ws.SequenceFetcher sequenceFetcher;
135
136   public SiftsSettings siftsSettings;
137
138
139   // The following are PRIVATE singletons; their class has only static public
140   // methods and a private constructor that is assigned by the class as part of
141   // a private static getInstance() call.
142
143   public AlignmentSorter alignmentSorter;
144
145   public Cache cache;
146
147   public EnsemblInfo ensemblInfo;
148
149   public FeatureAttributes featureAttributes;
150
151   public FeatureSources featureSources;
152
153   public IdOrgSettings idOrgSettings;
154
155   public Jws2Discoverer j2s2discoverer;
156
157   public Jws2InstanceFactory jws2InstanceFactory;
158
159   public PDBFTSRestClient pdbFTSRestClient;
160
161   public SequenceOntologyFactory sequenceOntologyFactory;
162
163   public StructureImportSettings structureImportSettings;
164
165   public UniProtFTSRestClient uniprotFTSRestClient;
166
167   // The following formerly static Object references are
168   // preserved in this singleton as "pseudo" static references
169   // that will be unique for each JavaScript applet or Java application.
170
171   /**
172    * StructureSelectionManager "static"
173    */
174   public IdentityHashMap<StructureSelectionManagerProvider, StructureSelectionManager> structureSelections;
175
176
177 }