1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.jvm
.suite
;
12 import cc
.squirreljme
.jvm
.manifest
.JavaManifest
;
13 import cc
.squirreljme
.jvm
.manifest
.JavaManifestAttributes
;
14 import cc
.squirreljme
.jvm
.manifest
.JavaManifestKey
;
15 import java
.util
.AbstractList
;
16 import java
.util
.ArrayList
;
17 import java
.util
.List
;
20 * This parses the entry points which are available for usage.
24 public class EntryPoints
25 extends AbstractList
<EntryPoint
>
27 /** Available entry points. */
28 private final EntryPoint
[] _entrypoints
;
31 * Initializes the entry points the hosted launcher can find.
33 * @param __man The manifest to parse.
34 * @throws NullPointerException On null arguments.
37 public EntryPoints(JavaManifest __man
)
38 throws NullPointerException
40 this(__man
.getMainAttributes());
44 * Initializes the entry points the hosted launcher can find.
46 * @param __attr The attributes to parse.
47 * @throws NullPointerException On null arguments.
50 public EntryPoints(JavaManifestAttributes __attr
)
51 throws NullPointerException
55 throw new NullPointerException("NARG");
58 List
<EntryPoint
> target
= new ArrayList
<>();
60 // Parse main class first
61 String oldClass
= __attr
.get(new JavaManifestKey("Main-Class"));
63 target
.add(new EntryPoint("Command Line", oldClass
,
66 // Parse MIDlet identifiers next
67 for (int i
= 1; i
>= 1; i
++)
69 // These are always in sequence
70 String midletval
= __attr
.get(new JavaManifestKey(
71 String
.format("MIDlet-%d", i
)));
72 if (midletval
== null)
75 // The MIDlet field is in 3 fields: name, icon, class
76 /* {@squirreljme.error DG03 Expected two commas in the MIDlet
78 int pc
= midletval
.indexOf(','),
79 sc
= midletval
.indexOf(',', Math
.max(pc
+ 1, 0));
81 throw new RuntimeException("DG03");
84 String iconRc
= midletval
.substring(pc
+ 1, sc
).trim();
85 target
.add(new EntryPoint(midletval
.substring(0, pc
).trim(),
86 midletval
.substring(sc
+ 1).trim(),
87 (iconRc
.isEmpty() ?
null : iconRc
), true));
91 this._entrypoints
= target
.<EntryPoint
>toArray(
92 new EntryPoint
[target
.size()]);
100 public EntryPoint
get(int __i
)
102 return this._entrypoints
[__i
];
112 return this._entrypoints
.length
;