KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: DataFieldEnumerationValueElement.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 org.jdesktop.swing.data.ConversionException;
11 import org.jdesktop.swing.data.Converter;
12 import org.jdesktop.swing.data.MetaData;
13
14 import org.jdesktop.jdnc.markup.ElementTypes;
15 import org.jdesktop.jdnc.markup.Attributes;
16 import org.jdesktop.jdnc.markup.Namespace;
17
18 import org.jdesktop.jdnc.markup.attr.NullAttribute;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Hashtable JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import net.openmarkup.ElementAssimilator;
26 import net.openmarkup.ElementHandler;
27 import net.openmarkup.ElementType;
28 import net.openmarkup.Realizable;
29
30 import org.w3c.dom.Element JavaDoc;
31 import org.w3c.dom.Node JavaDoc;
32 import org.w3c.dom.NodeList JavaDoc;
33
34 /**
35  * @author Amy Fowler
36  */

37 public class DataFieldEnumerationValueElement extends ElementProxy {
38
39     private static final Map JavaDoc attrMap = new Hashtable JavaDoc();
40
41     public DataFieldEnumerationValueElement(Element JavaDoc element, ElementType elementType) {
42         super(element, elementType);
43     }
44
45     public Object JavaDoc instantiate() {
46
47         Realizable metaDataElement = ElementProxy.getRealizable(
48                                   (Element JavaDoc)(getParentNode().getParentNode()));
49         MetaData metaData = (MetaData)metaDataElement.getObject();
50         String JavaDoc elementValue = getAttributeNSOptional(Namespace.JDNC,
51                                                 Attributes.VALUE);
52 /*
53         NodeList children = getChildNodes();
54         for(int i = 0; i < children.getLength(); i++) {
55             Node child = children.item(i);
56             if (child.getNodeType() == Node.TEXT_NODE) {
57                 elementValue = child.getNodeValue();
58                 break;
59             }
60         }
61             */

62
63         Object JavaDoc value = null;
64         Converter converter = metaData.getConverter();
65         try {
66             value = converter.decode(elementValue,
67                                              metaData.getDecodeFormat());
68         } catch (ConversionException e) {
69             System.out.println(e);
70         }
71         return value;
72     }
73
74     protected Map JavaDoc registerAttributeHandlers() {
75         Map JavaDoc handlerMap = super.registerAttributeHandlers();
76         if (handlerMap != null) {
77         // Register null appliers. These attributes are handled elsewhere
78
handlerMap.put(Namespace.JDNC + ":" + Attributes.VALUE,
79                            NullAttribute.valueHandler);
80     }
81     return handlerMap;
82     }
83
84     protected Map JavaDoc getAttributeHandlerMap() {
85         return attrMap;
86     }
87
88 }
89
Popular Tags