KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: DataElement.java,v 1.3 2005/01/27 13:31:59 kleopatra 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.MetaData;
11 import org.jdesktop.swing.data.DefaultTableModelExt;
12
13 import org.jdesktop.swing.data.DOMAdapter;
14
15 import org.jdesktop.jdnc.markup.Attributes;
16 import org.jdesktop.jdnc.markup.ElementTypes;
17 import org.jdesktop.jdnc.markup.Namespace;
18 import org.jdesktop.jdnc.markup.attr.DataAttributes;
19
20 import java.io.IOException JavaDoc;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Hashtable JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import net.openmarkup.AttributeHandler;
28 import net.openmarkup.ElementAssimilator;
29 import net.openmarkup.ElementHandler;
30 import net.openmarkup.ElementType;
31 import net.openmarkup.Realizable;
32 import net.openmarkup.Scribe;
33
34 import org.w3c.dom.Element JavaDoc;
35
36 /**
37  *
38  * @author Amy Fowler
39  * @author Ramesh Gupta
40  */

41 public class DataElement extends ElementProxy {
42     private static final Map JavaDoc attrMap = new Hashtable JavaDoc();
43     private static final Map JavaDoc elementMap = new Hashtable JavaDoc();
44     private static final Map JavaDoc mediaTypeRepresentation = new Hashtable JavaDoc();
45
46     public DataElement(Element JavaDoc element, ElementType elementType) {
47         super(element, elementType);
48     }
49
50     protected void applyAttributesAfter() {
51         super.applyAttributesAfter();
52         applyAttribute(Namespace.JDNC, Attributes.IS_FIRST_ROW_HEADER);
53         applyAttribute(Namespace.JDNC, Attributes.COLUMN_DELIMITER);
54         applyAttribute(Namespace.JDNC, Attributes.SOURCE);
55         // ACTUATE must be applied LAST since it needs all attributes
56
// to be configured before loading the data
57
applyAttribute(Namespace.JDNC, Attributes.ACTUATE);
58         // if actuate attribute wasn't specified, then default is onLoad....
59
String JavaDoc actuateValue = this.getAttributeNSOptional(Namespace.JDNC, Attributes.ACTUATE);
60         if (actuateValue.length() == 0) {
61         try {
62         DataAttributes.actuateData((DefaultTableModelExt)getObject(), actuateValue);
63         } catch (Exception JavaDoc ex) {
64         Scribe.getLogger().warning("DataElement Error actuating data: " + ex.getMessage());
65         }
66         }
67     }
68
69     protected Map JavaDoc registerAttributeHandlers() {
70         Map JavaDoc handlerMap = super.registerAttributeHandlers();
71         if (handlerMap != null) {
72             handlerMap.put(Namespace.JDNC + ":" + Attributes.ACTUATE, actuateHandler);
73             handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_FIRST_ROW_HEADER, firstRowHeaderHandler);
74             handlerMap.put(Namespace.JDNC + ":" + Attributes.COLUMN_DELIMITER, columnDelimiterHandler);
75             handlerMap.put(Namespace.JDNC + ":" + Attributes.SOURCE, sourceHandler);
76         }
77         return handlerMap;
78     }
79
80     protected Map JavaDoc registerElementHandlers() {
81         Map JavaDoc handlerMap = super.registerElementHandlers();
82         if (handlerMap != null) {
83             // metaData doesn't allocate an object
84
handlerMap.put(Namespace.JDNC + ":" +ElementTypes.META_DATA.getLocalName(),
85                             metaDataElementHandler);
86         }
87         return handlerMap;
88     }
89
90     protected Map JavaDoc getAttributeHandlerMap() {
91         return attrMap;
92     }
93
94     protected Map JavaDoc getElementHandlerMap() {
95         return elementMap;
96     }
97
98     public static final ElementAssimilator metaDataAssimilator = new ElementAssimilator() {
99         public void assimilate(Realizable parent, Realizable child) {
100             DefaultTableModelExt data = (DefaultTableModelExt)parent.getObject();
101             List JavaDoc list = (List JavaDoc)child.getObject();
102             int columnCount = list.size();
103             data.setColumnCount(columnCount);
104             for(int i = 0; i < columnCount; i++) {
105                 data.setColumnMetaData(i, (MetaData)list.get(i));
106             }
107         }
108     };
109
110     private static final AttributeHandler actuateHandler =
111         new AttributeHandler(Namespace.JDNC, Attributes.ACTUATE, DataAttributes.actuateApplier);
112
113     private static final AttributeHandler columnDelimiterHandler =
114         new AttributeHandler(Namespace.JDNC, Attributes.COLUMN_DELIMITER, DataAttributes.columnDelimiterApplier);
115
116     private static final AttributeHandler firstRowHeaderHandler =
117         new AttributeHandler(Namespace.JDNC, Attributes.IS_FIRST_ROW_HEADER, DataAttributes.firstRowHeaderApplier);
118
119     private static final AttributeHandler sourceHandler =
120         new AttributeHandler(Namespace.JDNC, Attributes.SOURCE, DataAttributes.sourceApplier);
121
122     private static final ElementHandler metaDataElementHandler =
123           new ElementHandler(ElementTypes.META_DATA, metaDataAssimilator);
124
125
126 }
127
Popular Tags