예제 #1
0
  // Couldn't get MessageFormat to work, so I cheated
  public static OID valueOf(String s) throws IllegalArgumentException {
    StringTokenizer st = new StringTokenizer(s, "[:{}],");
    if (st.countTokens() < 2) {
      st = new StringTokenizer(java.net.URLDecoder.decode(s), "[:{}],");

      if (st.countTokens() < 2) {
        throw new IllegalArgumentException(
            "Invalid OID '" + s + "'. It must have at least the object " + "type and the value");
      }
    }

    String type = st.nextToken();

    try {
      // we know that the first item is the type of the object
      // represented by this OID
      OID oid = new OID(type);

      // for the rest of them, we are going to "split" on the
      // "=" sign
      int nTokens = 0;
      while (st.hasMoreTokens()) {
        String nextToken = st.nextToken();
        int index = nextToken.indexOf("=");
        String key = (nextToken.substring(0, index));
        String value = nextToken.substring(index + 1);

        // we need the key to loose the single space before it that
        // is created by the HashMap.  We cannot use trim because
        // we don't want to loose trailing spaces
        if (nTokens > 0) {
          key = key.substring(1);
        }

        // if it can be a BigDecimal, that is what we make it
        boolean bigDecimal = true;
        for (int i = 0; i < value.length(); i++) {
          char c = value.charAt(i);
          if (!('0' <= c && c <= '9') && !((i == 0) && (c == '-'))) {
            bigDecimal = false;
            break;
          }
        }

        if (bigDecimal) {
          oid.set(key, new BigDecimal(value));
        } else {
          oid.set(key, value);
        }
        nTokens++;
      }
      return oid;
    } catch (PersistenceException e) {
      throw new IllegalArgumentException(
          "Invalid OID '" + s + "'. The type specified [" + type + "] is not defined");
    }
  }
예제 #2
0
  public static final PropertyMap pmap(Root root, OID oid) {
    com.redhat.persistence.metadata.ObjectType type = type(root, oid.getObjectType());
    PropertyMap result = new PropertyMap(type);
    for (Iterator it = oid.getProperties().entrySet().iterator(); it.hasNext(); ) {
      Map.Entry me = (Map.Entry) it.next();
      result.put(type.getProperty((String) me.getKey()), me.getValue());
    }

    return result;
  }