-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSAnswerGuiDecorator.java
More file actions
203 lines (177 loc) · 5.21 KB
/
DNSAnswerGuiDecorator.java
File metadata and controls
203 lines (177 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import javax.swing.tree.DefaultMutableTreeNode;
/**
* A decorator for the DNSAnswer interface that uses a tree to
* create a representaiton of state that can be displayed graphically.
*
* @author chris Blades
* @version 21/3/10
*/
public class DNSAnswerGuiDecorator extends DefaultMutableTreeNode
implements DNSAnswer {
/**
* DNSAnswer object that this decorator wraps
*/
private DNSAnswer answer;
/**
* Creates a new DNSAnswerGuiDecorator that contains the given
* DNSAnswer.
*
* @param answer the DNSAnswer this object should wrap and whose state
* it should reflect
*/
public DNSAnswerGuiDecorator(DNSAnswer answer) {
this.answer = answer;
setupGui();
}
/**
* Create a tree that reflects answer's state.
*/
private void setupGui() {
// since this will be rebuilt everytime the state of answer changes,
// scratch everything
super.removeAllChildren();
// set name of root node for this tree
super.setUserObject(answer.getName().getData());
// add answer's name
super.add(new DefaultMutableTreeNode("Name: " +
answer.getName().getData()));
// add answer's type
super.add(new DefaultMutableTreeNode("Type: " +
answer.getType().getName()));
// add answer's class
super.add(new DefaultMutableTreeNode("Class: " +
answer.getRecordClass().getName()));
// add answers TTL
super.add(new DefaultMutableTreeNode("Time to Live: " +
answer.getTTL() + " seconds"));
// add answer's data length
super.add(new DefaultMutableTreeNode("Data Length: " +
answer.getDataLength() + " bytes"));
// add answers data
super.add(new DefaultMutableTreeNode("Address: " +
answer.getData().getData() ));
}
//
// DNSAnswer
//
/*
* Returns the name of answer.
*
* @returns the name of answer
*/
public DNSUrl getName() {
return answer.getName();
}
/**
* returns the type of record answer.
*
* @return answer's record type
*/
public DNSRecordType getType() {
return answer.getType();
}
/**
* returns answer's DNS class
*
* @return answer's DNS class
*/
public DNSRecordClass getRecordClass() {
return answer.getRecordClass();
}
/**
* Set the name of the underlying DNSAnswer object and
* regenerates the tree.
*
* @param name the new name of answer
*/
public void setName(DNSUrl name) {
answer.setName(name);
setupGui();
}
/**
* Sets the type of the underlying DNSAnswer object and
* regenerates the tree.
*
* @param type new DNS type of answer
*/
public void setType(DNSRecordType type) {
answer.setType(type);
setupGui();
}
/**
* Sets the DNS class of the underlying DNSAnswer object
* and regenerates the tree
*
* @param recordClass new DNS class of answer
*/
public void setClass(DNSRecordClass recordClass) {
answer.setClass(recordClass);
setupGui();
}
/**
* Returns the Time-to-Live of the underlying DNSAnswer object.
*
* @return the TTL of the underlying DNSAnswer
*/
public int getTTL() {
return answer.getTTL();
}
/**
* returns the data length of hte underlying DNSAnswer object.
*
* @return the data length of the underying DNSAnswer
*/
public int getDataLength() {
return answer.getDataLength();
}
/**
* Returns the data contained in the underlying DNSAnswer object.
*
* @return the data of the underlying DNSAnswer
*/
public DNSResource getData() {
return answer.getData();
}
/**
* Sets the TTL of the underlying DNSAnswer
*
* @param TTL new time to live
*/
public void setTTL(int TTL) {
answer.setTTL(TTL);
setupGui();
}
/**
* sets the data contained within the underlying DNSAnswer
*
* @param data new data contained within the underlying DNSAnswer
*/
public void setData(DNSResource data) {
answer.setData(data);
setupGui();
}
/**
* Returns the length of the underlying DNSAnswer in serialized form
*
* @return the length of the serialized form of this DNSAnswer
*/
public int getLength() {
return answer.getLength();
}
/**
* Returns the serialized version of the underlying DNSAnswer.
*
* @return DNSAnswer serialized according to DNS protocol
*/
public byte[] serialize() {
return answer.serialize();
}
/**
* Returns a mapping of the state values of the underlying DNSAnswer
*
* @return mapping of the state of DNSAnswer
*/
public Map stateValues() {
return answer.stateValues();
}
}