Annotation of java/classes/org/w3c/tools/resources/PropertiesAttribute.java, revision 1.2
1.1 bmahe 1: // PropertiesAttribute.java
1.2 ! ylafon 2: // $Id: PropertiesAttribute.java,v 1.1.2.4 1999/07/28 13:46:29 bmahe Exp $
1.1 bmahe 3: // (c) COPYRIGHT MIT and INRIA, 1996.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
6: package org.w3c.tools.resources ;
7:
8: import java.io.* ;
9: import java.util.*;
10:
11: import org.w3c.util.*;
12:
13: /**
14: * The generic description of an PropertiesAttribute.
15: * A PropertiesAttribute instance holds a String to String mapping, it
16: * should be used only with care, since people may act on a reference to
17: * it.
18: */
19:
1.2 ! ylafon 20: public class PropertiesAttribute extends ArrayAttribute {
1.1 bmahe 21:
22: /**
23: * Is the given object a valid PropertiesAttribute value ?
24: * @param obj The object to test.
25: * @return A boolean <strong>true</strong> if value is valid.
26: */
27:
28: public boolean checkValue(Object obj) {
29: return (obj == null) || (obj instanceof ArrayDictionary);
30: }
31:
32: /**
1.2 ! ylafon 33: * Unpickle an attribute array from a string array.
! 34: * @param array the String array
! 35: * @return a Object array
! 36: */
! 37: public Object unpickle(String array[]) {
! 38: if (array.length < 1)
! 39: return null;
! 40: ArrayDictionary a = new ArrayDictionary(array.length, 5);
! 41: for (int i = 0 ; i < array.length ; i++) {
! 42: String encoded = array[i];
! 43: int idx = encoded.indexOf('=');
! 44: if (idx != -1) {
! 45: String key = encoded.substring(0, idx);
! 46: String value = encoded.substring(idx+1);
! 47: a.put(key, value);
! 48: }
1.1 bmahe 49: }
1.2 ! ylafon 50: return a;
1.1 bmahe 51: }
52:
53: /**
1.2 ! ylafon 54: * Pickle an attribute array into a String array.
! 55: * @param array the attribute array
! 56: * @return a String array
! 57: */
! 58: public String[] pickle(Object o) {
! 59: ArrayDictionary a = (ArrayDictionary) o;
! 60: Enumeration e = a.keys();
! 61: int len = a.size();
! 62: String array[] = new String[len];
! 63:
! 64: for (int i = 0 ; i < len ; i++ ) {
! 65: String key = (String) e.nextElement();
! 66: array[i] = key+"="+(String) a.get(key);
1.1 bmahe 67: }
1.2 ! ylafon 68: return array;
1.1 bmahe 69: }
70:
71: /**
72: * Create a description for a generic property list attribute.
73: * @param name The attribute name.
74: * @param def The default value for these attributes.
75: * @param flags The associated flags.
76: */
77:
78: public PropertiesAttribute(String name, String def, int flags) {
79: super(name, def, flags) ;
1.2 ! ylafon 80: this.type = "java.lang.String";
! 81: }
! 82:
! 83: public PropertiesAttribute() {
! 84: super();
! 85: this.type = "java.lang.String";
1.1 bmahe 86: }
87:
88: }
89:
Webmaster