📄 midletsuiteimpl.java
字号:
protected int countMIDlets() { int i; for (i = 1; getProperty("MIDlet-" + i) != null; i++); return i - 1; } /** * Retrieves the classname for a given MIDlet name. * <p> * * @param midletName the name of the MIDlet to find * @return the classname of the MIDlet. <code>null</code> if the * MIDlet cannot be found */ protected String getMIDletClassName(String midletName) { String midlet; MIDletInfo midletInfo; for (int i = 1; ; i++) { midlet = getProperty("MIDlet-" + i); if (midlet == null) { /* * If the name was a class name use it. * (Temporary implemention - overloading the * name as MIDlet name or class name could be in * conflict. Longer term solution would expand * Installer.execute() semantics to allow a class * name to run, rather than just the indirection * via MIDlet info.) */ try { Class.forName(midletName); return midletName; } catch (Exception e) {} return null; // We went past the last MIDlet } midletInfo = new MIDletInfo(midlet); if (midletInfo.name.equals(midletName)) { return midletInfo.classname; } } } /** * Gets properites from a symbolically named installed package. * The properties are the attributes in the application descriptor * and JAR Manifest. */ private void getPropertiesFromStorage() { RandomAccessStream myStorage; int size; byte[] buffer; InputStream is; DataInputStream dis; String jadEncoding = null; myStorage = new RandomAccessStream(classSecurityToken); // Get the JAD encoding, if the server provided one try { myStorage.connect(storageRoot + Installer.JAD_ENCODING_FILENAME, Connector.READ); try { // convert the JAD encoding to UTF8 and write it to storage dis = myStorage.openDataInputStream(); try { jadEncoding = dis.readUTF(); } finally { dis.close(); } } finally { myStorage.disconnect(); } } catch (IOException e) { // servers can choose the default encoding by not providing one } // Load .jad file bufferedJadProps = new JadProperties(); try { myStorage.connect(storageRoot + Installer.JAD_FILENAME, Connector.READ); try { size = myStorage.getSizeOf(); buffer = new byte[size]; dis = myStorage.openDataInputStream(); try { dis.readFully(buffer); is = new ByteArrayInputStream(buffer); bufferedJadProps.load(is, jadEncoding); buffer = null; is = null; } finally { dis.close(); } } finally { myStorage.disconnect(); } } catch (IOException e) { // Jar only install } try { // Get Manifest file so we can buffer it myStorage.connect(storageRoot + Installer.MANIFEST_FILENAME, Connector.READ); try { size = myStorage.getSizeOf(); buffer = new byte[size]; dis = myStorage.openDataInputStream(); try { dis.readFully(buffer); is = new ByteArrayInputStream(buffer); bufferedJarProps = new ManifestProperties(); bufferedJarProps.load(is); buffer = null; is = null; } finally { dis.close(); } } finally { myStorage.disconnect(); } } catch (IOException e) { // ignore } } /** * Gets push setting for interrupting other MIDlets. * Reuses the Permissions. * * @return push setting for interrupting MIDlets the value * will be permission level from {@link Permissions} */ public int getPushInterruptSetting() { return pushInterruptSetting; } /** * Gets list of permissions for this suite. * * @return array of permissions from {@link Permissions} */ public byte[][] getPermissions() { return copyPermissions(permissions); } /** * Makes a copy of a list of permissions. * * @param permissions source copy * @return array of permissions from {@link Permissions} */ protected byte[][] copyPermissions(byte[][] permissions) { if (permissions == null) { return null; } byte[][] copy = new byte[2][]; for (int i = 0; i < 2; i++) { copy[i] = new byte[permissions[i].length]; System.arraycopy(permissions[i], 0, copy[i], 0, permissions[i].length); } return copy; } /** * Saves any the settings (security or others) that the user may have * changed. Normally called by the scheduler after * the last running MIDlet in the suite is destoryed. * However it could be called during a suspend of the VM so * that persisent settings of the suite can be perserved or * by the graphical manager application settings MIDlet. */ public void saveSettings() { try { Installer.saveSuiteSettings(classSecurityToken, storageRoot, (byte)pushInterruptSetting, permissions, trusted); } catch (IOException e) { // ignore } } /** * Reads the suite settings from storage. */ private void readSettings() { byte[] maximums = Permissions.getEmptySet(); byte[] currentLevels = Permissions.getEmptySet(); RandomAccessStream storage = new RandomAccessStream(classSecurityToken); DataInputStream storageStream; int version; int count; permissions = new byte[2][]; permissions[Permissions.MAX_LEVELS] = maximums; permissions[Permissions.CUR_LEVELS] = currentLevels; try { storage.connect(getStorageRoot() + Installer.SETTINGS_FILENAME, Connector.READ); try { storageStream = storage.openDataInputStream(); version = storageStream.readByte(); /* * only version 1 are handled by the method * 0 means that this is a beta version that are not handled * by the method. Note that version number only has to * increase if data has been removed, not if new data has been * added to the end of the file. */ if (version != 1) { System.out.println("Corrupt application settings file."); return; } trusted = storageStream.readBoolean(); pushInterruptSetting = storageStream.readByte(); count = storageStream.readByte(); storageStream.readFully(currentLevels, 0, count); count = storageStream.readByte(); storageStream.readFully(maximums, 0, count); } finally { storage.disconnect(); } } catch (IOException e) { // ignore, old settings files are shorter } } /** * Asks the user want to interrupt the current MIDlet with * a new MIDlet that has received network data. * * @param connection connection to place in the permission question or * null for alarm * * @return true if the use wants interrupt the current MIDlet, else false */ public boolean permissionToInterrupt(String connection) { String name; MIDletSuite current; String question; String currentName; if (pushInterruptSetting == Permissions.USER_DENIED || pushInterruptSetting == Permissions.NEVER) { return false; } // treat SESSION level the same as ONE_SHOT switch (pushInterruptSetting) { case Permissions.ALLOW: case Permissions.BLANKET_GRANTED: return true; } name = getSuiteNameForInterrupt(); // The currently running suite controls what question to ask. current = Scheduler.getScheduler().getMIDletSuite(); if (current instanceof MIDletSuiteImpl) { MIDletSuiteImpl temp = (MIDletSuiteImpl)current; if (connection == null) { question = temp.getAlarmInterruptQuestion(); } else { question = temp.getPushInterruptQuestion(); } currentName = temp.getSuiteNameForInterrupt(); } else { // use the questions of this suite if (connection == null) { question = getAlarmInterruptQuestion(); } else { question = getPushInterruptQuestion(); } currentName = Resource.getString("The current application"); } try { switch (SecurityToken.askUserForPermission(classSecurityToken, "Can %1 Interrupt?", question, name, currentName, null, Permissions.BLANKET, pushInterruptSetting)) { case Permissions.BLANKET: pushInterruptSetting = Permissions.BLANKET_GRANTED; return true; case Permissions.SESSION: case Permissions.ONE_SHOT: // treat one shot as session pushInterruptSetting = Permissions.SESSION; return true; case Permissions.DENY: pushInterruptSetting = Permissions.USER_DENIED; return false; } } catch (InterruptedException ie) { return false; } // default, is cancel, ask again next time pushInterruptSetting = Permissions.DENY_SESSION; return false; } /** * Indicates if this suite is trusted. * (not to be confused with a domain named "trusted", * this is used to determine if a trusted symbol should be displayed * to the user and not used for permissions) * * @return true if the suite is trusted false if not */ public boolean isTrusted() { return trusted; } /** * Indicates if the named MIDlet is registered in the suite * with MIDlet-<n> record in the manifest or * application descriptor. * @param midletName class name of the MIDlet to be checked * * @return true if the MIDlet is registered */ public boolean isRegistered(String midletName) { String midlet; MIDletInfo midletInfo; for (int i = 1; ; i++) { midlet = getProperty("MIDlet-" + i); if (midlet == null) { return false; // We went past the last MIDlet } /* Check if the names match. */ midletInfo = new MIDletInfo(midlet); if (midletInfo.classname.equals(midletName)) { return true; } } } /** * Gets the Push interrupt question the should be used when * interrupting this suite. * <p> * The question will have %2 where this suite name should be and * a %1 where the current suite name should be. * * @return push interrupt question */ protected String getPushInterruptQuestion() { return PUSH_INTERRUPT_QUESTION; } /** * Gets the Alarm interrupt question the should be used when * interrupting this suite. * <p> * The question will have %2 where this suite name should be and * a %1 where the current suite name should be. * * @return alarm interrupt question */ protected String getAlarmInterruptQuestion() { return ALARM_INTERRUPT_QUESTION; } /** * Gets the suite name for interruption purposes. * * @return name for interrupt question */ protected String getSuiteNameForInterrupt() { return getProperty(Installer.SUITE_NAME_PROP); } /** * Gets the JAD URL of the suite. This is only for the installer. * * @return URL of the JAD can be null */ public String getJadUrl() { RandomAccessStream storage = new RandomAccessStream(classSecurityToken); DataInputStream storageStream; try { storage.connect(getStorageRoot() + Installer.JAD_URL_FILENAME, Connector.READ); // convert the JAD URL to UTF8 and write it to storage storageStream = storage.openDataInputStream(); return storageStream.readUTF(); } catch (Exception e) { // ignore, not all suite have JAD URLs return null; } finally { try { storage.disconnect(); } catch (IOException e) { // ignore } } } /** * Gets the JAR URL of the suite. This is only for the installer. * * @return URL of the JAR, never null, even in development environments */ public String getJarUrl() { RandomAccessStream storage = new RandomAccessStream(classSecurityToken); DataInputStream storageStream; try { storage.connect(getStorageRoot() + Installer.JAR_URL_FILENAME, Connector.READ); // convert the JAR URL to UTF8 and write it to storage storageStream = storage.openDataInputStream(); return storageStream.readUTF(); } catch (Exception e) { // old installations did not have JAR URL's return "unknown"; } finally { try { storage.disconnect(); } catch (IOException e) { // ignore } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -