01: // IPTemplatesAttribute.java
02: // $Id: IPTemplatesAttribute.java,v 1.12 2002/06/09 11:25:12 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.auth;
07:
08: import org.w3c.tools.resources.ArrayAttribute;
09: import org.w3c.tools.resources.Attribute;
10:
11: /**
12: * The IPTemplates attribute description.
13: * Maintains a list of IP templates (short arrays, to allow for the splash).
14: */
15:
16: public class IPTemplatesAttribute extends ArrayAttribute {
17:
18: /**
19: * Is the given value a valid IPTemplates value ?
20: * @param obj The object to test.
21: * @exception IllegalAttributeAccess If the provided value doesn't pass the
22: * test.
23: */
24:
25: public boolean checkValue(Object obj) {
26: return ((obj == null) || (obj instanceof short[][]));
27: }
28:
29: public String[] pickle(Object array) {
30: short ips[][] = (short[][]) array;
31: String str[] = new String[ips.length];
32: for (int i = 0; i < ips.length; i++) {
33: str[i] = ips[i][0] + "." + ips[i][1] + "." + ips[i][2]
34: + "." + ips[i][3];
35: }
36: return str;
37: }
38:
39: public Object unpickle(String array[]) {
40: if (array.length < 1)
41: return null;
42: short ips[][] = new short[array.length][4];
43: for (int i = 0; i < array.length; i++) {
44: String ip = array[i];
45: int idx1;
46: int idx2;
47: idx1 = ip.indexOf('.');
48: ips[i][0] = Short.parseShort(ip.substring(0, idx1));
49: idx1++;
50: idx2 = ip.indexOf('.', idx1);
51: ips[i][1] = Short.parseShort(ip.substring(idx1, idx2));
52: idx1 = ++idx2;
53: idx2 = ip.indexOf('.', idx1);
54: ips[i][2] = Short.parseShort(ip.substring(idx1, idx2));
55: idx1 = ++idx2;
56: ips[i][3] = Short.parseShort(ip.substring(idx1));
57: }
58: return ips;
59: }
60:
61: public IPTemplatesAttribute(String name, short defs[][], int flags) {
62: super (name, defs, flags);
63: this .type = "[[S".intern();
64: }
65:
66: public IPTemplatesAttribute() {
67: super ();
68: this .type = "[[S".intern();
69: }
70:
71: }
|