1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.fourthline.cling.model.types;
17
18 import org.fourthline.cling.model.Constants;
19
20 import java.util.regex.Pattern;
21 import java.util.regex.Matcher;
22
23
24
25
26
27
28 public class UDAServiceType extends ServiceType {
29
30 public static final String DEFAULT_NAMESPACE = "schemas-upnp-org";
31
32
33 public static final Pattern PATTERN =
34 Pattern.compile("urn:" + DEFAULT_NAMESPACE + ":service:(" + Constants.REGEX_TYPE + "):([0-9]+).*");
35
36 public UDAServiceType(String type) {
37 this(type, 1);
38 }
39
40 public UDAServiceType(String type, int version) {
41 super(DEFAULT_NAMESPACE, type, version);
42 }
43
44 public static UDAServiceType valueOf(String s) throws InvalidValueException {
45 Matcher matcher = UDAServiceType.PATTERN.matcher(s);
46
47 try {
48 if (matcher.matches())
49 return new UDAServiceType(matcher.group(1), Integer.valueOf(matcher.group(2)));
50 } catch (RuntimeException e) {
51 throw new InvalidValueException(String.format(
52 "Can't parse UDA service type string (namespace/type/version) '%s': %s", s, e.toString()));
53 }
54 throw new InvalidValueException("Can't parse UDA service type string (namespace/type/version): " + s);
55 }
56
57 }