Ejemplo n.º 1
0
  /**
   * Adds a property to the suite.
   *
   * @param key the name of the property
   * @param value the value of the property
   * @exception SecurityException if the calling suite does not have internal API permission
   */
  public void addProperty(String key, String value) {
    MIDletSuite current = Scheduler.getScheduler().getMIDletSuite();

    if (current != null) {
      current.checkIfPermissionAllowed(Permissions.MIDP);
    }

    if (bufferedJadProps != null) {
      bufferedJadProps.addProperty(key, value);
      return;
    }

    bufferedJarProps.addProperty(key, value);
  }
Ejemplo n.º 2
0
  /**
   * Gets a property of the suite. A property is an attribute from either the application descriptor
   * or JAR Manifest.
   *
   * @param key the name of the property
   * @return A string with the value of the property. <code>null</code> is returned if no value is
   *     available for the key.
   */
  public String getProperty(String key) {
    String prop;

    if (bufferedJadProps == null) {
      getPropertiesFromStorage();
      if (bufferedJadProps == null) {
        return null;
      }
    }

    // check the JAD first
    prop = bufferedJadProps.getProperty(key);
    if (prop != null) {
      return prop;
    }

    if (bufferedJarProps == null) {
      return null;
    }

    return bufferedJarProps.getProperty(key);
  }
Ejemplo n.º 3
0
  /**
   * 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
    }
  }