JAL-4152 Remove redundant casts from getInstance usages.
[jalview.git] / src / jalview / ws / jws2 / jabaws2 / Jws2InstanceFactory.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.ws.jws2.jabaws2;
22
23 import jalview.bin.ApplicationSingletonProvider;
24 import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
25
26 import jalview.ws.uimodel.AlignAnalysisUIText;
27
28 import java.util.HashMap;
29 import java.util.HashSet;
30
31 import compbio.data.msa.JABAService;
32
33 public class Jws2InstanceFactory implements ApplicationSingletonI
34 {
35
36   private Jws2InstanceFactory()
37   {
38     // private singleton
39   }
40
41   private static Jws2InstanceFactory getInstance()
42   {
43     return ApplicationSingletonProvider.getInstance(Jws2InstanceFactory.class);
44   }
45
46   private HashMap<String, AlignAnalysisUIText> aaConGUI;
47
48   private HashSet<String> ignoreGUI;
49
50   private static String category_rewrite(String cat_name)
51   {
52     return (cat_name != null && cat_name.equals("Prediction"))
53             ? "Secondary Structure Prediction"
54             : cat_name;
55   }
56
57   private void init()
58   {
59     if (aaConGUI == null)
60     {
61       aaConGUI = new HashMap<>();
62       aaConGUI.put(compbio.ws.client.Services.AAConWS.toString(),
63               AAConClient.getAlignAnalysisUIText());
64       aaConGUI.put(compbio.ws.client.Services.RNAalifoldWS.toString(),
65               RNAalifoldClient.getAlignAnalysisUIText());
66       // ignore list for JABAWS services not supported in jalview ...
67       ignoreGUI = new HashSet<>();
68     }
69   }
70
71   /**
72    * exclusion list to avoid creating GUI elements for services we don't fully
73    * support
74    * 
75    * @param serviceType
76    * @return
77    */
78   public static boolean ignoreService(String serviceType)
79   {
80     getInstance().init();
81     return (getInstance().ignoreGUI.contains(serviceType.toString()));
82   }
83
84   /**
85    * construct a service instance and configure it with any additional
86    * properties needed so Jalview can access it correctly
87    * 
88    * @param jwsservers
89    * @param serviceType
90    * @param name
91    * @param description
92    * @param service
93    * @return
94    */
95   public static Jws2Instance newJws2Instance(String jwsservers,
96           String serviceType, String name, String description,
97           JABAService service)
98   {
99     getInstance().init();
100     Jws2Instance svc = new Jws2Instance(jwsservers, serviceType,
101             category_rewrite(name), description, service);
102     svc.setAlignAnalysisUI(getInstance().aaConGUI.get(serviceType.toString()));
103     return svc;
104   }
105
106 }