1
2
3
4
5 package net.sourceforge.jsdp;
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public class Version implements Field {
20
21
22 private static final long serialVersionUID = 5365815747331173108L;
23
24
25 public static final Version DEFAULT_VERSION = new Version();
26
27
28 protected int version;
29
30
31
32
33 protected Version() {
34
35 super();
36
37 this.version = 0;
38 }
39
40
41
42
43
44
45
46
47
48
49 public static Version parse(final String field) throws SDPParseException {
50
51 if (!field.startsWith("v=")) {
52 throw new SDPParseException("The string \"" + field + "\" isn't a version field");
53 }
54
55 try {
56
57 int version = Integer.parseInt(field.substring(2));
58
59 if (version != 0) {
60 throw new SDPParseException("Invalid SDP protocol version: the only allowed value is 0");
61 }
62 }
63 catch (NumberFormatException parseException) {
64 throw new SDPParseException("The string \"" + field + "\" isn't a valid version field", parseException);
65 }
66
67 return DEFAULT_VERSION;
68 }
69
70
71
72
73
74
75 public Object clone() {
76
77 Version field = new Version();
78 field.version = this.version;
79
80 return field;
81 }
82
83
84
85
86
87
88 public char getType() {
89
90 return Field.VERSION_FIELD;
91 }
92
93
94
95
96
97
98 public int getValue() {
99
100 return version;
101 }
102
103
104
105
106
107
108
109
110
111 protected void setValue(final int version) throws SDPException {
112
113 if (version != 0) {
114 throw new SDPException("Invalid SDP protocol version: the only allowed value is 0");
115 }
116
117 this.version = version;
118 }
119
120
121
122
123
124
125
126 public String toString() {
127
128 return getType() + "=" + version;
129 }
130 }