KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > elem > EnumerationValuesElement


1 /*
2  * $Id: EnumerationValuesElement.java,v 1.1.1.1 2004/06/16 01:43:40 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup.elem;
9
10 import java.util.Hashtable JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import javax.swing.JLabel JavaDoc;
14
15 import org.w3c.dom.Element JavaDoc;
16 import net.openmarkup.ElementAssimilator;
17 import net.openmarkup.ElementHandler;
18 import net.openmarkup.ElementType;
19 import net.openmarkup.Realizable;
20 import org.jdesktop.jdnc.markup.ElementTypes;
21 import org.jdesktop.jdnc.markup.Namespace;
22
23 /**
24  *
25  * @author Ramesh Gupta
26  */

27 public class EnumerationValuesElement extends ElementProxy {
28     private static final Map JavaDoc elementMap = new Hashtable JavaDoc();
29
30     public EnumerationValuesElement(Element JavaDoc element, ElementType elementType) {
31         super(element, elementType);
32     }
33
34     protected Map JavaDoc registerElementHandlers() {
35         Map JavaDoc handlerMap = super.registerElementHandlers();
36         if (handlerMap != null) {
37             handlerMap.put(Namespace.JDNC + ":" +
38                            ElementTypes.ENUMERATION_VALUE.getLocalName(),
39                            enumerationElementHandler);
40         }
41         return handlerMap;
42     }
43
44     protected Map JavaDoc getElementHandlerMap() {
45         return elementMap;
46     }
47
48     protected void checkAttributes() {
49     // Overloaded as an empty implementation
50
// because elements are
51
}
52
53     public static final ElementAssimilator enumerationAssimilator = new ElementAssimilator() {
54         private final static String JavaDoc enumKey = Namespace.JDNC + ":" + net.openmarkup.Attributes.VALUE;
55         public void assimilate(Realizable parent, Realizable child) {
56             Map JavaDoc map = (Map JavaDoc) parent.getObject();
57             JLabel JavaDoc label = (JLabel JavaDoc) child.getObject();
58             // lookup key is specified by the "value" attribute
59
String JavaDoc key = child.getAttributeNSOptional(Namespace.JDNC, net.openmarkup.Attributes.VALUE);
60             if ((key != null) && (label != null)) {
61                 label.putClientProperty(enumKey, key);
62                 map.put(key, label);
63             }
64         }
65     };
66
67     private static final ElementHandler enumerationElementHandler =
68         new ElementHandler(ElementTypes.ENUMERATION_VALUE, enumerationAssimilator);
69
70 }
71
Popular Tags