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 UDADeviceType extends DeviceType {
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 + ":device:(" + Constants.REGEX_TYPE + "):([0-9]+).*");
35
36 public UDADeviceType(String type) {
37 super(DEFAULT_NAMESPACE, type, 1);
38 }
39
40 public UDADeviceType(String type, int version) {
41 super(DEFAULT_NAMESPACE, type, version);
42 }
43
44 public static UDADeviceType valueOf(String s) throws InvalidValueException {
45 Matcher matcher = PATTERN.matcher(s);
46
47 try {
48 if (matcher.matches())
49 return new UDADeviceType(matcher.group(1), Integer.valueOf(matcher.group(2)));
50 } catch(RuntimeException e) {
51 throw new InvalidValueException(String.format(
52 "Can't parse UDA device type string (namespace/type/version) '%s': %s", s, e.toString()
53 ));
54 }
55 throw new InvalidValueException("Can't parse UDA device type string (namespace/type/version): " + s);
56 }
57
58 }