Source Code Cross Referenced for ClassMap.java in  » XML-UI » JAXX » jaxx » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML UI » JAXX » jaxx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * Copyright 2006 Ethan Nicholas. All rights reserved.
03:         * Use is subject to license terms.
04:         */
05:        package jaxx;
06:
07:        import jaxx.reflect.*;
08:
09:        import java.util.*;
10:
11:        /** A Map implementation which uses Classes as keys.  <code>ClassMap</code> differs from typical maps 
12:         * in that it takes subclasses into account;  mapping a class to a value also maps all subclasses of 
13:         * that class to the value.
14:         * <p>
15:         * A <code>get</code> operation will return the value associated with the class itself, or failing
16:         * that, with its nearest ancestor for which there exists a mapping.
17:         */
18:        public class ClassMap extends HashMap {
19:            /** Keeps track of automatically-added Classes so we can distinguish them from user-added
20:             * Classes.  Unknown Classes are automatically added to the map during <code>get</code>
21:             * calls to speed up subsequent requests, but they must be updated when the mappings
22:             * for their superclasses are modified.
23:             */
24:            private List/*<ClassDescriptor>*/autoKeys = new ArrayList/*<ClassDescriptor>*/();
25:
26:            /** Returns the value associated with the key <code>Class</code>.  If the class itself does not have
27:             * a mapping, its superclass will be checked, and so on until an ancestor class with a mapping is 
28:             * located.  If none of the class' ancestors have a mapping, <code>null</code> is returned.
29:             *
30:             *@param key the class to check
31:             *@return the mapping for the class
32:             */
33:            public Object get(Object key) {
34:                Object result = null;
35:                ClassDescriptor c = (ClassDescriptor) key;
36:                while (c != null) {
37:                    result = super .get(c);
38:                    if (result != null)
39:                        break;
40:                    c = c.getSuperclass();
41:                }
42:
43:                if (result == null && ((ClassDescriptor) key).isInterface()) {
44:                    result = get(ClassDescriptorLoader
45:                            .getClassDescriptor(Object.class));
46:                }
47:
48:                if (c != key && result != null) { // no mapping for the class itself, but found one for a superclass
49:                    put(key, result);
50:                    autoKeys.add(key);
51:                }
52:                return result;
53:            }
54:
55:            /** Associates a value with a class and all of its descendents.
56:             *
57:             *@param key the class to map
58:             *@param value the value to map to the class
59:             *@return the old value associated with the class
60:             */
61:            public Object put(Object key, Object value) {
62:                if (!(key instanceof  ClassDescriptor))
63:                    throw new IllegalArgumentException(
64:                            "expected ClassDescriptor, got " + key);
65:                if (autoKeys.size() > 0) { // remove all automatic keys which descend from the class being modified
66:                    ClassDescriptor c = (ClassDescriptor) key;
67:                    Iterator/*<Class>*/i = autoKeys.iterator();
68:                    while (i.hasNext()) {
69:                        ClassDescriptor auto = (ClassDescriptor) i.next();
70:                        if (c.isAssignableFrom(auto)) {
71:                            i.remove();
72:                            remove(auto);
73:                        }
74:                    }
75:                }
76:                return super.put(key, value);
77:            }
78:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.