コード例 #1
0
  private void parseValues(String name, NodeList nodeList) {
    MAttr attr = null;
    for (int count = 0; count < nodeList.getLength(); count++) {
      Node tempNode = nodeList.item(count);
      if (tempNode.getNodeType() == Node.ELEMENT_NODE && tempNode.hasAttributes()) {

        if (attr == null) {
          if (tempNode.getNodeName().equals("enum")) {
            attr = new MAttr(MAttrType.ENUM);
          } else if (tempNode.getNodeName().equals("flag")) {
            attr = new MAttr(MAttrType.FLAG);
          }
          if (attr == null) {
            return;
          }
          attrMap.put(name, attr);
        }

        NamedNodeMap attributes = tempNode.getAttributes();
        Node nameNode = attributes.getNamedItem("name");
        if (nameNode != null) {
          Node valueNode = attributes.getNamedItem("value");
          if (valueNode != null) {
            try {
              long key;
              String nodeValue = valueNode.getNodeValue();
              if (nodeValue.startsWith("0x")) {
                nodeValue = nodeValue.substring(2);
                key = Long.parseLong(nodeValue, 16);
              } else {
                key = Long.parseLong(nodeValue);
              }
              attr.getValues().put(key, nameNode.getNodeValue());
            } catch (NumberFormatException e) {
              LOG.debug("Failed parse manifest number", e);
            }
          }
        }
      }
    }
  }
コード例 #2
0
 public String decode(String attrName, long value) {
   MAttr attr = attrMap.get(attrName);
   if (attr == null) {
     return null;
   }
   if (attr.getType() == MAttrType.ENUM) {
     String name = attr.getValues().get(value);
     if (name != null) {
       return name;
     }
   } else if (attr.getType() == MAttrType.FLAG) {
     StringBuilder sb = new StringBuilder();
     for (Map.Entry<Long, String> entry : attr.getValues().entrySet()) {
       if ((value & entry.getKey()) != 0) {
         sb.append(entry.getValue()).append('|');
       }
     }
     if (sb.length() != 0) {
       return sb.deleteCharAt(sb.length() - 1).toString();
     }
   }
   return "UNKNOWN_DATA_0x" + Long.toHexString(value);
 }