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