KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: AppElement.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.Application;
11
12 import java.util.Hashtable JavaDoc;
13 import java.util.Map JavaDoc;
14 import java.util.Vector JavaDoc;
15
16 import org.w3c.dom.Element JavaDoc;
17
18 import net.openmarkup.AttributeHandler;
19 import net.openmarkup.ElementAssimilator;
20 import net.openmarkup.ElementHandler;
21 import net.openmarkup.ElementType;
22 import net.openmarkup.Realizable;
23 import org.jdesktop.jdnc.markup.Attributes;
24 import org.jdesktop.jdnc.markup.ElementTypes;
25 import org.jdesktop.jdnc.markup.Namespace;
26 import org.jdesktop.jdnc.markup.attr.AppAttributes;
27
28 /**
29  *
30  * @author Amy Fowler
31  */

32 public class AppElement extends ElementProxy {
33
34     private static final Map JavaDoc attrMap = new Hashtable JavaDoc();
35
36     public AppElement(Element JavaDoc element, ElementType elementType) {
37         super(element, elementType);
38     }
39
40     protected Object JavaDoc instantiate() {
41         Application app = null;
42         String JavaDoc id = this.getAttributeNSOptional(Namespace.JDNC, Attributes.ID);
43         if (id.length() > 0) {
44             app = Application.getInstance(id);
45         } else {
46             app = Application.getInstance();
47         }
48     app.setBaseURL(getObjectRealizer().getDefaultBaseURL());
49     // Store the id so that the application instance can be retrieved.
50
putORValue("ApplicationID", id);
51
52         return app;
53     }
54
55     public AttributeHandler getAttributeHandler(String JavaDoc namespaceURI, String JavaDoc attrName) {
56         Map JavaDoc handlerMap = getAttributeHandlerMap();
57         return handlerMap == null ? null : (AttributeHandler) attrMap.get(namespaceURI + ":" + attrName);
58     }
59
60     protected Map JavaDoc getAttributeHandlerMap() {
61         return attrMap;
62     }
63
64     protected void applyAttributesAfter() {
65         super.applyAttributesAfter();
66         applyAttribute(Namespace.JDNC, Attributes.TITLE);
67         applyAttribute(Namespace.JDNC, Attributes.VERSION_STRING);
68     }
69
70     protected Map JavaDoc registerAttributeHandlers() {
71         Map JavaDoc handlerMap = super.registerAttributeHandlers();
72         if (handlerMap != null) {
73             handlerMap.put(Namespace.JDNC + ":" + Attributes.TITLE,
74                            titleHandler);
75             handlerMap.put(Namespace.JDNC + ":" + Attributes.VERSION_STRING,
76                            versionStringHandler);
77         }
78         return handlerMap;
79     }
80
81     protected static final AttributeHandler titleHandler =
82         new AttributeHandler(Namespace.JDNC, Attributes.TITLE,
83                              AppAttributes.titleApplier);
84
85     protected static final AttributeHandler versionStringHandler =
86         new AttributeHandler(Namespace.JDNC, Attributes.VERSION_STRING,
87                              AppAttributes.versionStringApplier);
88
89 }
90
Popular Tags