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 GNU General Public License v3+, or later.
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 cc
.squirreljme
.runtime
.cldc
.annotation
.Exported
;
16 import java
.util
.AbstractList
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
21 * This parses the entry points which are available for usage.
26 public class EntryPoints
27 extends AbstractList
<EntryPoint
>
29 /** Available entry points. */
30 private final EntryPoint
[] _entrypoints
;
33 * Initializes the entry points the hosted launcher can find.
35 * @param __man The manifest to parse.
36 * @throws NullPointerException On null arguments.
40 public EntryPoints(JavaManifest __man
)
41 throws NullPointerException
43 this(__man
.getMainAttributes());
47 * Initializes the entry points the hosted launcher can find.
49 * @param __attr The attributes to parse.
50 * @throws NullPointerException On null arguments.
54 public EntryPoints(JavaManifestAttributes __attr
)
55 throws NullPointerException
59 throw new NullPointerException("NARG");
62 List
<EntryPoint
> target
= new ArrayList
<>();
64 // Parse main class first
65 String oldClass
= __attr
.get(new JavaManifestKey("Main-Class"));
67 target
.add(new EntryPoint("Command Line", oldClass
,
70 // Parse MIDlet identifiers next
71 for (int i
= 1; i
>= 1; i
++)
73 // These are always in sequence
74 String midletval
= __attr
.get(new JavaManifestKey(
75 String
.format("MIDlet-%d", i
)));
76 if (midletval
== null)
79 // The MIDlet field is in 3 fields: name, icon, class
80 // {@squirreljme.error DG03 Expected two commas in the MIDlet
82 int pc
= midletval
.indexOf(','),
83 sc
= midletval
.indexOf(',', Math
.max(pc
+ 1, 0));
85 throw new RuntimeException("DG03");
88 String iconRc
= midletval
.substring(pc
+ 1, sc
).trim();
89 target
.add(new EntryPoint(midletval
.substring(0, pc
).trim(),
90 midletval
.substring(sc
+ 1).trim(),
91 (iconRc
.isEmpty() ?
null : iconRc
), true));
95 this._entrypoints
= target
.<EntryPoint
>toArray(
96 new EntryPoint
[target
.size()]);
104 public EntryPoint
get(int __i
)
106 return this._entrypoints
[__i
];
116 return this._entrypoints
.length
;