KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > attr > HierarchicalDataAttributes


1 /*
2  * $Id: HierarchicalDataAttributes.java,v 1.2 2005/01/27 13:32:01 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.attr;
9
10 import org.jdesktop.swing.data.DefaultTableModelExt;
11 import org.jdesktop.swing.data.DOMAdapter;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import javax.xml.parsers.DocumentBuilder JavaDoc;
17 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
18
19 import net.openmarkup.ApplierException;
20 import net.openmarkup.AttributeApplier;
21 import net.openmarkup.Realizable;
22
23 import org.w3c.dom.Document JavaDoc;
24
25 import org.jdesktop.jdnc.markup.Attributes;
26 import org.jdesktop.jdnc.markup.ElementTypes;
27 import org.jdesktop.jdnc.markup.Namespace;
28
29 /**
30  * @author Ramesh Gupta
31  */

32 public class HierarchicalDataAttributes {
33     public static final AttributeApplier sourceApplier = new AttributeApplier() {
34         public void apply(Realizable target, String JavaDoc namespaceURI,
35                           String JavaDoc attributeName, String JavaDoc attributeValue) throws ApplierException {
36             try {
37                 DocumentBuilderFactory JavaDoc dbf = DocumentBuilderFactory.newInstance();
38                 dbf.setNamespaceAware(true);
39                 dbf.setIgnoringComments(true);
40                 URL JavaDoc url = target.getResolvedURL(attributeValue);
41                 Document JavaDoc dom = dbf.newDocumentBuilder().parse(url.toExternalForm());
42                 ((DOMAdapter) target.getObject()).bind(dom);
43             }
44             catch (Exception JavaDoc ex) {
45                 throw new ApplierException("Couldn't set data source " +
46                     attributeName + "=" + attributeValue, ex);
47             }
48         }
49     };
50 }
51
Popular Tags