/** * Returns a ServiceType object representing the type specified in the String. * The argument is expected to be in the format returned by {@link #toString()}. * @param s the string to be parsed. * @return a ServiceType representing the type specified by the argument. * @throws IllegalArgumentException if the string cannot be parsed as a ServiceType. */ public static ServiceType valueOf(String s) { int i = s.IndexOf(','); String domain = (i < 0) ? s : s.Substring(0, i); String sublist = (i < 0) ? null : s.Substring(i + 1); i = domain.IndexOf('.'); if (i < 0) { throw new ArgumentException("No '.' in service type: " + s); } String type = domain.Substring(0, i); String transport = domain.Substring(i + 1); ServiceType res = new ServiceType(type, transport); if (sublist != null) { String[] subs = sublist.Split(','); foreach (String sub in subs) { if (sub.Trim().Equals("")) { throw new ArgumentException("Zero length subtype is not allowed: " + s); } } res = res.withSubtypes(subs); } return(res); }
/** * Returns a ServiceName object representing the service specified in the String. * The argument is expected to be in the format returned by {@link #toString()}. * @param s the string to be parsed. * @return a ServiceName representing the service specified by the argument. * @throws IllegalArgumentException if the string cannot be parsed as a ServiceName. */ public static ServiceName valueOf(String s) { int i = indexOfNonEscaped(s, '.'); if (i < 0) { throw new ArgumentException("No '.' in service name: " + s); } String name = unescape(s.Substring(0, i)); int j = s.IndexOf('.', i + 1); if (j < 0) { throw new ArgumentException("No '.' in service type: " + s); } j = s.IndexOf('.', j + 1); if (j < 0) { throw new ArgumentException("No '.' after service type: " + s); } ServiceType type = ServiceType.valueOf(s.Substring(i + 1, j - i - 1)); i = s.IndexOf(',', j + 1); String domain = (i < 0) ? s.Substring(j + 1) : s.Substring(j + 1, i - j - 1); if (i >= 0) { String sublist = s.Substring(i + 1); String[] subs = sublist.Split(','); foreach (String sub in subs) { if (sub.Equals("")) { throw new ArgumentException("Zero length subtype is not allowed: " + s); } } type = type.withSubtypes(subs); } return(new ServiceName(name, type, domain)); }