⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jad.java

📁 MoMEUnit是一个单元测试的J2ME的应用程序xUnit架构实例。这是来自JUnit框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  /**   * Returns <code>MIDlet-Delete-Confirm</code> attribute value.   *    * @return the <code>MIDlet-Delete-Confirm</code> attribute value.   * @since 1.1   */  public String getDeleteConfirm()  {    return this.props.getProperty(DELETE_CONFIRM);  }  /**   * Sets <code>MIDlet-Delete-Confirm</code> attribute value.   *    * @param prop   *          <code>MIDlet-Delete-Confirm</code> attribute value to set.   * @since 1.1   */  public void setDeleteConfirm(String prop)  {    this.props.setProperty(DELETE_CONFIRM, checkValue(prop));  }  /**   * Returns value of attribute specified by name.   *    * @param name   *          name of attribute.   * @return the value of attribute.   * @since 1.1   */  public String getAppProperty(String name)  {    return this.props.getProperty(name);  }  /**   * Returns all attributes of this JAD except midlet and push ones. Use   * {@link #getMIDletProperties()} and {@link #getPushInfoProperties()} for   * accessing midlet and push attributes respectively.   *    * @return the attributes of this JAD as {@link Properties} instance.   * @since 1.1   */  public Properties getProperties()  {    return (Properties) this.props.clone();  }  /**   * Sets JAD attribute with given name and value.   *    * @param name   *          name of attribute.   * @param value   *          value of attribute.   * @since 1.1   */  public void setProperty(String name, String value)  {    name = checkName(name);    value = checkValue(value);    if (!setPushProperty(name, value) && !setMIDletProperty(name, value)) this.props        .setProperty(name, value);  }  /**   * @param name   * @param value   * @return   * @since 1.1   */  private boolean setMIDletProperty(String name, String value)  {    boolean res = false;    Matcher matcher = midletPattern.matcher(name);    if (res = matcher.matches()) setMIDlet(Integer.parseInt(matcher.group(1)),        new MIDletInfo(value));    return res;  }  private boolean setPushProperty(String name, String value)  {    boolean res = false;    Matcher matcher = pushPattern.matcher(name);    if (res = matcher.matches()) setPush(Integer.parseInt(matcher.group(1)),        new PushInfo(value));    return res;  }  /**   * Returns all attributes names except midlet and push ones.   *    * @return the {@link Enumeration} of attributes names.   * @since 1.1   */  public Enumeration getPropertyNames()  {    return this.props.propertyNames();  }  /**   * Checks {@link MIDletInfo} object for required fields.   *    * @param midlet   *          the {@link MIDletInfo} object to check.   * @return checked {@link MIDletInfo} object.   * @throws IllegalArgumentException   *           if some required fields are not set.   * @since 1.1   */  public static MIDletInfo checkMIDlet(MIDletInfo midlet)  {    if (midlet == null) throw new NullPointerException("Unspecified midlet");    if (midlet.getName() == null) throw new NullPointerException(        "Unspecified midlet's name");    if (midlet.getClassName() == null) throw new NullPointerException(        "Unspecified midlet's class");    return midlet;  }  /**   * Checks {@link PushInfo} object for required fields.   *    * @param pushInfo   *          the {@link PushInfo} object to check.   * @return checked {@link PushInfo} object.   * @throws IllegalArgumentException   *           if some required fields are not set.   * @since 1.1   */  public static PushInfo checkPush(PushInfo pushInfo)  {    if (pushInfo == null) throw new NullPointerException("Unspecified push");    if (pushInfo.getConURL() == null) throw new NullPointerException(        "Unspecified push's conurl");    if (pushInfo.getClassName() == null) throw new NullPointerException(        "Unspecified push's classname");    if (pushInfo.getAllowedSender() == null) throw new NullPointerException(        "Unspecified push's allowedsender");    return pushInfo;  }  /**   * Adds midlet to this JAD.   *    * @param midlet   *          midlet to add.   * @since 1.1   */  public void addMIDlet(MIDletInfo midlet)  {    checkMIDlet(midlet);    boolean set = false;    for (int i = 1; i <= this.maxMIDletNumber && !set; i++)      if (getMIDlet(i) == null)      {        setMIDlet(i, midlet);        set = true;      }    if (!set) this.midlets.put(new Integer(++this.maxMIDletNumber), midlet);  }  /**   * Adds push record to this JAD.   *    * @param pushInfo   *          push record to add.   * @since 1.1   */  public void addPush(PushInfo pushInfo)  {    checkPush(pushInfo);    boolean set = false;    for (int i = 1; i <= this.maxPushNumber && !set; i++)      if (getPush(i) == null)      {        setPush(i, pushInfo);        set = true;      }    if (!set) this.pushs.put(new Integer(++this.maxPushNumber), pushInfo);  }  /**   * Adds given midlet with given number.   *    * @param pos   *          number of midlet to add.   * @param midlet   *          midlet to add.   * @return the midlet that was assigned to the given number. or   *         <code>null</code> if none.   * @since 1.1   */  public MIDletInfo setMIDlet(int pos, MIDletInfo midlet)  {    checkMIDlet(midlet);    if (pos > this.maxMIDletNumber) this.maxMIDletNumber = pos;    return (MIDletInfo) this.midlets.put(new Integer(pos), midlet);  }  /**   * Adds given push record with the given midlet.   *    * @param pos   *          number of push record.   * @param pushInfo   *          push record to add.   * @return the push record that was assigned to the given number, or   *         <code>null</code> if none.   * @since 1.1   */  public PushInfo setPush(int pos, PushInfo pushInfo)  {    checkPush(pushInfo);    if (pos > this.maxPushNumber) this.maxPushNumber = pos;    return (PushInfo) this.pushs.put(new Integer(pos), pushInfo);  }  /**   * Returns the least number assigned to the given midlet or <code>-1</code>   * if not found.   *    * @param midlet   *          midlet to look for.   * @return the least number assigned to given midlet, or <code>-1</code> if   *         no found.   * @since 1.1   */  public int indexOfMIDlet(MIDletInfo midlet)  {    int res = -1;    if (this.midlets.containsValue(midlet))    {      for (Iterator i = this.midlets.entrySet().iterator(); i.hasNext();)      {        Map.Entry entry = (Map.Entry) i.next();        if (entry.getValue().equals(midlet)) res = ((Integer) entry.getKey())            .intValue();      }    }    return res;  }  /**   * Returns the least number assigned to the given push record or   * <code>-1</code> if not found.   *    * @param pushInfo   *          push record to look for.   * @return the least number assigned to given push record, or <code>-1</code>   *         if no found.   * @since 1.1   */  public int indexOfPush(PushInfo pushInfo)  {    int res = -1;    if (this.pushs.containsValue(pushInfo))    {      for (Iterator i = this.pushs.entrySet().iterator(); i.hasNext();)      {        Map.Entry entry = (Map.Entry) i.next();        if (entry.getValue().equals(pushInfo)) res = ((Integer) entry.getKey())            .intValue();      }    }    return res;  }  /**   * Returns midlet with the given number or <code>null</code> if not found.   *    * @param pos   *          number of midlet to look for.   * @return the midlet with the given number or <code>null</code> if not   *         found.   * @since 1.1   */  public MIDletInfo getMIDlet(int pos)  {    return (MIDletInfo) this.midlets.get(new Integer(pos));  }  /**   * Returns push record with the given number or <code>null</code> if not   * found.   *    * @param pos   *          number of push record to look for.   * @return the push record with the given number or <code>null</code> if not   *         found.   * @since 1.1   */  public PushInfo getPush(int pos)  {    return (PushInfo) this.pushs.get(new Integer(pos));  }  /**   * Removes given midlet. Shifts others.   *    * @param midlet   *          midlet to remove.   * @since 1.1   */  public void removeMIDlet(MIDletInfo midlet)  {    this.midlets.remove(new Integer(indexOfMIDlet(midlet)));  }  /**   * Removes given push record. Shifts others.   *    * @param pushInfo   *          push record to remove.   * @since 1.1   */  public void removePush(PushInfo pushInfo)  {    this.pushs.remove(new Integer(indexOfPush(pushInfo)));  }  /**   * Removes midlet with the given number. Shifts others.   *    * @param pos   *          number of midlet to remove.   * @since 1.1   */  public void removeMIDletAt(int pos)  {    this.midlets.remove(new Integer(pos));  }  /**   * Removes push record with the given number. Shifts others.   *    * @param pos   *          number of push record to remove.   * @since 1.1   */  public void removePushAt(int pos)  {    this.pushs.remove(new Integer(pos));  }  /**   * Returns collection of midlets.   *    * @return the collection of midlets.   * @since 1.1   */  public Collection getMIDlets()  {    return this.midlets.values();  }  /**   * Returns collection of push records.   *    * @return collection of push records.   * @since 1.1   */  public Collection getPushs()  {    return this.pushs.values();  }  /**   * Returns maximum number assigned to a midlet in this JAD.   *    * @return the maximum number assigned to a midlet in this JAD.   * @since 1.1   */  public int getMaxMIDletNumber()  {    return this.maxMIDletNumber;  }  /**   * Returns maximum number assigned to a push record in this JAD.   *    * @return the maximum number assigned to a push record in this JAD.   * @since 1.1   */  public int getMaxPushNumber()  {    return this.maxPushNumber;  }  /**   * Saves JAD to given file with given encoding.   *    * @param out   *          file to write JAD descriptor to.   * @param encoding   *          encoding to use.   * @throws IOException   *           if write error occurred.   * @since 1.1   */  public void save(File out, String encoding) throws IOException  {    save(new FileOutputStream(out), encoding);  }  /**   * Saves JAD to given {@link OutputStream} with given encoding.   *    * @param out   *          OutputStream to write JAD descriptor to.   * @param encoding   *          encoding to use.   * @throws IOException   *           if write error occurred.   * @since 1.1   */  public void save(OutputStream out, String encoding) throws IOException  {    save(new OutputStreamWriter(out, encoding));  }  /**   * Saves JAD to given {@link Writer}.   *    * @param writer   *          Writer to write JAD descriptor to.   * @throws IOException   *           if write error occurred.   * @since 1.1   */  public void save(Writer writer) throws IOException  {    BufferedWriter bufWriter = new BufferedWriter(writer);    checkJAD();    writeProperties(this.props, bufWriter);    writeProperties(getMIDletProperties(), bufWriter);    writeProperties(getPushInfoProperties(), bufWriter);    bufWriter.close();  }  private static void writeProperties(Properties props, BufferedWriter writer)      throws IOException  {    for (Enumeration e = props.propertyNames(); e.hasMoreElements();)    {      String name = (String) e.nextElement();      writer.write(name + ":" + props.getProperty(name));      writer.newLine();    }  }  private static Pattern attributePattern = Pattern.compile("([^:]+):(.*)");  private static Pattern midletPattern = Pattern.compile(MIDLET_PREFIX      + "([1-9]+[0-9]*)");  private static Pattern pushPattern = Pattern.compile(PUSH_PREFIX      + "([1-9]+[0-9]*)");  /**   * Loads attributes from given {@link Reader}.   *    * @param reader   *          Reader to read attributes from.   * @throws IOException   *           if read error occurred.   * @since 1.1   */  public void load(Reader reader) throws IOException  {    BufferedReader bufReader = new BufferedReader(reader);    for (String line = bufReader.readLine(); line != null; line = bufReader        .readLine())    {      Matcher matcher = attributePattern.matcher(line);      if (!matcher.matches()) throw new IllegalArgumentException(          "invalid line in jad file " + line);      else setProperty(checkName(matcher.group(1)),          checkValue(matcher.group(2)));    }    bufReader.close();  }  /**   * Loads attributes from given manifest.   *    * @param man   *          Manifest to read attributes from.   * @throws IOException   *           if read error occurred.   * @since 1.1   */  public void load(Manifest man) throws IOException  {    if (man == null) throw new NullPointerException("manifest");    Attributes attrs = man.getMainAttributes();    for (Iterator i = attrs.keySet().iterator(); i.hasNext();)    {      String attrName = i.next().toString();      setProperty(attrName, attrs.getValue(attrName));    }  }  /**   * Loads attributes from given jar archive.   *    * @param jar   *          jar archive containing manifest to read attributes from.   * @throws IOException   *           if read error occurred.   * @since 1.1   */  public void load(JarFile jar) throws IOException  {    if (jar == null) throw new NullPointerException("jar");    load(jar.getManifest());  }  /**   * Loads attributes from given file in given encoding.   *    * @param in   *          FIle to load attributes from.   * @param encoding   *          encoding to use.   * @throws IOException   *           if read error occurred.   * @since 1.1   */  public void load(File in, String encoding) throws IOException  {    load(new FileInputStream(in), encoding);  }  /**   * Loads attributes from given {@link InputStream} in given encoding.   *    * @param in   *          InputStream to read attributes from.   * @param encoding   *          encoding to use.   * @throws IOException   *           if read error occurred.   * @since 1.1   */  public void load(InputStream in, String encoding) throws IOException  {    load(new InputStreamReader(in, encoding));  }  private void checkJAD()  {    if (getName() == null) throw new IllegalStateException(        "Required Attribute " + NAME + " is not set.");    if (getVendor() == null) throw new IllegalStateException(        "Required Attribute " + VENDOR + " is not set.");    if (getVersion() == null) throw new IllegalStateException(        "Required Attribute " + VERSION + " is not set.");    if (getJar() == null) throw new IllegalStateException("Required Attribute "        + JAR + " is not set.");    if (getJarSize() == null) throw new IllegalStateException(        "Required Attribute " + JAR_SIZE + " is not set.");  }  /**   * Returns attributes that designate midlet records as {@link Properties}.   *    * @return the attributes that designate midlet.   * @since 1.1   */  public Properties getMIDletProperties()  {    Properties res = new Properties();    for (int i = 1; i <= this.maxMIDletNumber; i++)    {      MIDletInfo mi = (MIDletInfo) getMIDlet(i);      if (mi != null) res.setProperty(MIDLET_PREFIX + i, mi.getProperty());    }    return res;  }  /**   * Returns attributes that designate push records as {@link Properties}.   *    * @return the attributes that designates push records.   * @since 1.1   */  public Properties getPushInfoProperties()  {    Properties res = new Properties();    for (int i = 1; i <= this.maxPushNumber; i++)    {      PushInfo pi = (PushInfo) getPush(i);      if (pi != null) res.setProperty(PUSH_PREFIX + i, pi.getProperty());    }    return res;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -