01: // Copyright (c) 2004 Brian Wellington (bwelling@xbill.org)
02:
03: package org.xbill.DNS;
04:
05: import java.io.*;
06:
07: /**
08: * X25 - identifies the PSDN (Public Switched Data Network) address in the
09: * X.121 numbering plan associated with a name.
10: *
11: * @author Brian Wellington
12: */
13:
14: public class X25Record extends Record {
15:
16: private byte[] address;
17:
18: X25Record() {
19: }
20:
21: Record getObject() {
22: return new X25Record();
23: }
24:
25: private static final byte[] checkAndConvertAddress(String address) {
26: int length = address.length();
27: byte[] out = new byte[length];
28: for (int i = 0; i < length; i++) {
29: char c = address.charAt(i);
30: if (!Character.isDigit(c))
31: return null;
32: out[i] = (byte) c;
33: }
34: return out;
35: }
36:
37: /**
38: * Creates an X25 Record from the given data
39: * @param address The X.25 PSDN address.
40: * @throws IllegalArgumentException The address is not a valid PSDN address.
41: */
42: public X25Record(Name name, int dclass, long ttl, String address) {
43: super (name, Type.X25, dclass, ttl);
44: this .address = checkAndConvertAddress(address);
45: if (this .address == null) {
46: throw new IllegalArgumentException("invalid PSDN address "
47: + address);
48: }
49: }
50:
51: void rrFromWire(DNSInput in) throws IOException {
52: address = in.readCountedString();
53: }
54:
55: void rdataFromString(Tokenizer st, Name origin) throws IOException {
56: String addr = st.getString();
57: this .address = checkAndConvertAddress(addr);
58: if (this .address == null)
59: throw st.exception("invalid PSDN address " + addr);
60: }
61:
62: /**
63: * Returns the X.25 PSDN address.
64: */
65: public String getAddress() {
66: return byteArrayToString(address, false);
67: }
68:
69: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
70: out.writeCountedString(address);
71: }
72:
73: String rrToString() {
74: return byteArrayToString(address, true);
75: }
76:
77: }
|