Revert StaticDisplayState; For hosted only allow debug to be used.
[SquirrelJME.git] / modules / meep-swm / src / main / java / javax / microedition / swm / __SystemSuiteManager__.java
blob83b9b61c77886f5fc3725f75915f31b645d73ebd
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package javax.microedition.swm;
12 import cc.squirreljme.jvm.suite.DependencyInfo;
13 import cc.squirreljme.jvm.suite.InvalidSuiteException;
14 import cc.squirreljme.jvm.suite.MatchResult;
15 import cc.squirreljme.runtime.cldc.debug.Debugging;
16 import cc.squirreljme.runtime.swm.ByteArrayJarStreamSupplier;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.LinkedHashSet;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
24 /**
25 * This class manages the bridge for the suite manager to the native program
26 * manager.
28 * @since 2017/12/08
30 @Deprecated
31 final class __SystemSuiteManager__
32 implements SuiteManager
34 /** Cache of suites which are available. */
35 private static final Map<String, Suite> _SUITES =
36 new HashMap<>();
38 /** Internal lock for suite management. */
39 protected final Object lock =
40 new Object();
42 /**
43 * {@inheritDoc}
44 * @since 2017/12/08
46 @Override
47 public void addSuiteListener(SuiteListener __sl)
49 throw Debugging.todo();
52 /**
53 * {@inheritDoc}
54 * @since 2017/12/08
56 @Override
57 public Suite getSuite(String __vendor, String __name)
59 throw Debugging.todo();
62 /**
63 * {@inheritDoc}
64 * @since 2017/12/08
66 @Override
67 public SuiteInstaller getSuiteInstaller(byte[] __b, int __o,
68 int __l, boolean __ignuplock)
69 throws IllegalArgumentException, SecurityException
71 return new SuiteInstaller(
72 new ByteArrayJarStreamSupplier(__b, __o, __l));
75 /**
76 * {@inheritDoc}
77 * @since 2017/12/08
79 @Override
80 public SuiteInstaller getSuiteInstaller(String __url,
81 boolean __ignuplock)
82 throws IllegalArgumentException, SecurityException
84 throw Debugging.todo();
87 /**
88 * {@inheritDoc}
89 * @since 2017/12/08
91 @Override
92 public List<Suite> getSuites(SuiteType __t)
93 throws IllegalArgumentException, NullPointerException
95 if (__t == null)
96 throw new NullPointerException("NARG");
98 // Go through suites and find suites to return
99 List<Suite> rv = new ArrayList<>();
100 for (Suite s : __SystemSuiteManager__.__allSuites())
101 if (s.getSuiteType() == __t)
102 rv.add(s);
104 return rv;
108 * {@inheritDoc}
109 * @since 2017/12/08
111 @Override
112 public void removeSuite(Suite __s, boolean __ignuplock)
113 throws IllegalArgumentException, SuiteLockedException
115 throw Debugging.todo();
119 * {@inheritDoc}
120 * @since 2017/12/08
122 @Override
123 public void removeSuiteListener(SuiteListener __sl)
125 throw Debugging.todo();
129 * Returns all the suites which are available.
131 * @return All the available suites.
132 * @since 2018/10/30
134 static List<Suite> __allSuites()
136 throw Debugging.todo();
138 // Just get every suite
139 List<Suite> rv = new ArrayList<>();
140 for (String as : SuiteAccess.availableSuites())
142 // It is possible they might not load
143 Suite s = __SystemSuiteManager__.__getSuite(as);
144 if (s != null)
145 rv.add(s);
148 return rv;*/
152 * Gets the specified suite.
154 * @param __s The suite to get.
155 * @return The suite for the given name.
156 * @throws NullPointerException On null arguments.
157 * @since 2018/10/26
159 static Suite __getSuite(String __s)
160 throws NullPointerException
162 if (__s == null)
163 throw new NullPointerException("NARG");
165 Map<String, Suite> suites = __SystemSuiteManager__._SUITES;
166 synchronized (suites)
168 // Preloaded?
169 Suite rv = suites.get(__s);
170 if (rv != null)
171 return rv;
173 // Previously did not exist or failed to load
174 if (suites.containsKey(__s))
175 return null;
179 // Cache the suite
180 suites.put(__s, (rv = new Suite(__s)));
181 return rv;
183 catch (InvalidSuiteException e)
185 // Debug it
186 e.printStackTrace();
188 // Just cache it as invalid
189 suites.put(__s, null);
190 return null;
196 * Returns the suites which match the given dependency set.
198 * @param __set The set of dependencies to get.
199 * @param __opt If {@code true} include optional dependencies.
200 * @return Suites which satisfy the given dependencies.
201 * @throws NullPointerException On null arguments.
202 * @since 2018/11/02
204 @Deprecated
205 static Suite[] __matchDependencies(DependencyInfo __set, boolean __opt)
206 throws NullPointerException
208 if (__set == null)
209 throw new NullPointerException("NARG");
211 // Clear all optionals if they are not included
212 if (!__opt)
213 __set = __set.noOptionals();
215 // No dependencies to search for
216 if (__set.isEmpty())
217 return new Suite[0];
219 // Remember the original set for recursive dependency checks
220 DependencyInfo original = __set;
222 // The returning set
223 Set<Suite> rv = new LinkedHashSet<>();
225 // Go through all binaries and attempt to match
226 for (Suite bin : __SystemSuiteManager__.__allSuites())
228 // Only consider matches
229 MatchResult result = bin.__matchedDependencies(__set);
230 if (!result.hasMatches())
231 continue;
233 // Use this as a dependency
234 rv.add(bin);
236 // Recursively go down
237 for (Suite sub : __SystemSuiteManager__.__matchDependencies(
238 bin.__suiteInfo().dependencies(), false))
239 rv.add(sub);
241 // Use remaining unmatched set
242 __set = result.unmatched();
244 // If the set was emptied then it will never have any more matches
245 if (__set.isEmpty())
246 break;
249 // {@squirreljme.error DG0u Could not locate the suite which
250 // statifies the given dependency. (The dependency to look for)}
251 if (rv.isEmpty())
252 throw new RuntimeException(
253 String.format("DG0u %s", __set));
255 return rv.<Suite>toArray(new Suite[rv.size()]);