in tester/src/main/java/org/apache/james/jspf/tester/DNSTestingServer.java [132:248]
public synchronized void setData(Map<String, List<?>> map) {
try {
this.timeoutServers = new HashSet<Name>();
List<Record> records = new LinkedList<Record>();
records.add(new SOARecord(Name.root, DClass.IN, 3600, Name.root,
Name.root, 857623948, 0, 0, 0, 0));
records.add(new NSRecord(Name.root, DClass.IN, 3600, Name.root));
Iterator<String> hosts = map.keySet().iterator();
while (hosts.hasNext()) {
String host = (String) hosts.next();
Name hostname;
if (!host.endsWith(".")) {
hostname = Name.fromString(host + ".");
} else {
hostname = Name.fromString(host);
}
List<?> l = map.get(host);
if (l != null)
for (Iterator<?> i = l.iterator(); i.hasNext();) {
Object o = i.next();
if (o instanceof Map) {
Map<String, ?> hm = (Map) o;
Iterator<String> types = hm.keySet().iterator();
while (types.hasNext()) {
String type = (String) types.next();
if ("MX".equals(type)) {
List<?> mxList = (List<?>) hm.get(type);
Iterator<?> mxs = mxList.iterator();
while (mxs.hasNext()) {
Long prio = (Long) mxs.next();
String cname = (String) mxs.next();
if (cname != null) {
if (cname.length() > 0 && !cname.endsWith(".")) cname += ".";
records.add(new MXRecord(hostname,
DClass.IN, 3600, prio
.intValue(), Name
.fromString(cname)));
}
}
} else {
Object value = hm.get(type);
if ("A".equals(type)) {
records.add(new ARecord(hostname,
DClass.IN, 3600, Address
.getByAddress((String) value)));
} else if ("AAAA".equals(type)) {
records.add(new AAAARecord(hostname,
DClass.IN, 3600, Address
.getByAddress((String) value)));
} else if ("SPF".equals(type)) {
if (value instanceof List<?>) {
records.add(new SPFRecord(hostname,
DClass.IN, 3600L, (List<String>) value));
} else {
records.add(new SPFRecord(hostname,
DClass.IN, 3600, (String) value));
}
} else if ("TXT".equals(type)) {
if (value instanceof List<?>) {
records.add(new TXTRecord(hostname,
DClass.IN, 3600L, (List<String>) value));
} else {
records.add(new TXTRecord(hostname,
DClass.IN, 3600, (String) value));
}
} else {
if (!((String) value).endsWith(".")) {
value = ((String) value)+".";
}
if ("PTR".equals(type)) {
records
.add(new PTRRecord(
hostname,
DClass.IN,
3600,
Name
.fromString((String) value)));
} else if ("CNAME".equals(type)) {
records.add(new CNAMERecord(
hostname, DClass.IN, 3600,
Name.fromString((String) value)));
} else {
throw new IllegalStateException(
"Unsupported type: " + type);
}
}
}
}
} else if ("TIMEOUT".equals(o)) {
timeoutServers.add(hostname);
} else {
throw new IllegalStateException(
"getRecord found an unexpected data");
}
}
}
zone = new Zone(Name.root, (Record[]) records
.toArray(new Record[] {}));
} catch (TextParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}