Make it so mapping files are used and then reapplied.
[SquirrelJME.git] / modules / cldc-compact / src / main / java / cc / squirreljme / jvm / suite / EntryPoints.java
blob1bd1849c6b138911e2e2078821dde008a83123fc
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 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;
20 /**
21 * This parses the entry points which are available for usage.
23 * @since 2017/08/20
25 @Exported
26 public class EntryPoints
27 extends AbstractList<EntryPoint>
29 /** Available entry points. */
30 private final EntryPoint[] _entrypoints;
32 /**
33 * Initializes the entry points the hosted launcher can find.
35 * @param __man The manifest to parse.
36 * @throws NullPointerException On null arguments.
37 * @since 2018/03/24
39 @Exported
40 public EntryPoints(JavaManifest __man)
41 throws NullPointerException
43 this(__man.getMainAttributes());
46 /**
47 * Initializes the entry points the hosted launcher can find.
49 * @param __attr The attributes to parse.
50 * @throws NullPointerException On null arguments.
51 * @since 2017/08/20
53 @Exported
54 public EntryPoints(JavaManifestAttributes __attr)
55 throws NullPointerException
57 // Check
58 if (__attr == null)
59 throw new NullPointerException("NARG");
61 // Target list
62 List<EntryPoint> target = new ArrayList<>();
64 // Parse main class first
65 String oldClass = __attr.get(new JavaManifestKey("Main-Class"));
66 if (oldClass != null)
67 target.add(new EntryPoint("Command Line", oldClass,
68 null, false));
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)
77 break;
79 // The MIDlet field is in 3 fields: name, icon, class
80 // {@squirreljme.error DG03 Expected two commas in the MIDlet
81 // field.}
82 int pc = midletval.indexOf(','),
83 sc = midletval.indexOf(',', Math.max(pc + 1, 0));
84 if (pc < 0 || sc < 0)
85 throw new RuntimeException("DG03");
87 // Split fields
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));
94 // Finalize
95 this._entrypoints = target.<EntryPoint>toArray(
96 new EntryPoint[target.size()]);
99 /**
100 * {@inheritDoc}
101 * @since 2017/08/20
103 @Override
104 public EntryPoint get(int __i)
106 return this._entrypoints[__i];
110 * {@inheritDoc}
111 * @since 2017/08/20
113 @Override
114 public int size()
116 return this._entrypoints.length;