Ejemplo n.º 1
0
  public static String idToClass(String repid) {
    // debug
    logger.finer("idToClass " + repid);

    if (repid.startsWith("IDL:")) {

      ByteString id = new ByteString(repid);

      try {
        int end = id.lastIndexOf(':');
        ByteString s = end < 0 ? id.substring(4) : id.substring(4, end);

        ByteBuffer bb = new ByteBuffer();

        //
        // reverse order of dot-separated name components up
        // till the first slash.
        //
        int firstSlash = s.indexOf('/');
        if (firstSlash > 0) {
          ByteString prefix = s.substring(0, firstSlash);
          ByteString[] elems = prefix.split('.');

          for (int i = elems.length - 1; i >= 0; i--) {
            bb.append(fixName(elems[i]));
            bb.append('.');
          }

          s = s.substring(firstSlash + 1);
        }

        //
        // Append slash-separated name components ...
        //
        ByteString[] elems = s.split('/');
        for (int i = 0; i < elems.length; i++) {
          bb.append(fixName(elems[i]));
          if (i != elems.length - 1) bb.append('.');
        }

        String result = bb.toString();

        logger.finer("idToClassName " + repid + " => " + result);

        return result;
      } catch (IndexOutOfBoundsException ex) {
        logger.log(Level.FINE, "idToClass " + ex.getMessage(), ex);
        return null;
      }

    } else if (repid.startsWith("RMI:")) {
      int end = repid.indexOf(':', 4);
      return end < 0 ? repid.substring(4) : repid.substring(4, end);
    }

    return null;
  }
Ejemplo n.º 2
0
  static ByteString fixName(ByteString name) {
    if (keyWords.contains(name)) {
      ByteBuffer buf = new ByteBuffer();
      buf.append('_');
      buf.append(name);
      return buf.toByteString();
    }

    ByteString result = name;
    ByteString current = name;

    boolean match = true;
    while (match) {

      int len = current.length();
      match = false;

      for (ByteString reservedPostfixe : reservedPostfixes) {
        if (current.endsWith(reservedPostfixe)) {
          ByteBuffer buf = new ByteBuffer();
          buf.append('_');
          buf.append(result);
          result = buf.toByteString();

          int resultLen = reservedPostfixe.length();
          if (len > resultLen) current = current.substring(0, len - resultLen);
          else current = new ByteString("");

          match = true;
          break;
        }
      }
    }

    return name;
  }