Source Code Cross Referenced for AttributeRegistry.java in  » Web-Server » Jigsaw » org » w3c » tools » resources » upgrade » 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 » Web Server » Jigsaw » org.w3c.tools.resources.upgrade 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // AttributeRegistry.java
002:        // $Id: AttributeRegistry.java,v 1.3 2000/08/16 21:37:55 ylafon Exp $
003:        // (c) COPYRIGHT MIT and INRIA, 1996.
004:        // Please first read the full copyright statement in file COPYRIGHT.html
005:
006:        package org.w3c.tools.resources.upgrade;
007:
008:        import java.util.Hashtable;
009:        import java.util.Vector;
010:
011:        class ClassAttributes {
012:            Attribute fixed[] = null;
013:            Vector attrs = null;
014:            int nextid = 0;
015:
016:            /**
017:             * Fix the description of the attributes for this record.
018:             */
019:
020:            void fix() {
021:                if (fixed == null) {
022:                    fixed = new Attribute[attrs.size()];
023:                    attrs.copyInto(fixed);
024:                    attrs = null;
025:                }
026:            }
027:
028:            /**
029:             * Add a new attribute description into this record.
030:             * @param attr The new attribute description.
031:             * @return The attribute index.
032:             */
033:
034:            int add(Attribute attr) {
035:                if (attrs == null)
036:                    throw new RuntimeException("add in a fixed record.");
037:                attrs.addElement(attr);
038:                return nextid++;
039:            }
040:
041:            ClassAttributes(int idx) {
042:                this .fixed = null;
043:                this .attrs = new Vector();
044:                this .nextid = idx;
045:            }
046:
047:            ClassAttributes(ClassAttributes sup) {
048:                this .fixed = null;
049:                this .attrs = new Vector(sup.fixed.length);
050:                this .nextid = sup.nextid;
051:                for (int i = 0; i < sup.fixed.length; i++)
052:                    attrs.addElement(sup.fixed[i]);
053:            }
054:        }
055:
056:        public class AttributeRegistry {
057:            private static Hashtable registery = new Hashtable();
058:            private static Class top = null;
059:
060:            static {
061:                try {
062:                    top = Class
063:                            .forName("org.w3c.tools.resources.AttributeHolder");
064:                } catch (Exception ex) {
065:                    ex.printStackTrace();
066:                    System.exit(1);
067:                }
068:            }
069:
070:            /**
071:             * Register a new attribute for a given class.
072:             * This method create the approrpriate attribute description record if
073:             * required, and return the index of this attribute in the corresponding
074:             * holder instances.
075:             * @param cls The class that defines this attribute.
076:             * @param attr The attribute to declare.
077:             * @return The attribute index.
078:             */
079:
080:            public static synchronized int registerAttribute(Class cls,
081:                    Attribute attr) {
082:                // Do we have a description record for this class ?
083:                ClassAttributes record = (ClassAttributes) registery.get(cls);
084:                if (record == null) {
085:                    // Create and register the record:
086:                    if (cls == top) {
087:                        record = new ClassAttributes(0);
088:                    } else {
089:                        // Get our super class record:
090:                        for (Class clsptr = cls.getSuperclass(); (record == null); clsptr = clsptr
091:                                .getSuperclass()) {
092:                            record = (ClassAttributes) registery.get(clsptr);
093:                            if (clsptr == top) {
094:                                if (record == null)
095:                                    record = new ClassAttributes(0);
096:                                break;
097:                            }
098:                        }
099:                        if (record == null)
100:                            throw new RuntimeException("inconsistent state.");
101:                        record.fix();
102:                        record = new ClassAttributes(record);
103:                    }
104:                    registery.put(cls, record);
105:                }
106:                return record.add(attr);
107:            }
108:
109:            /**
110:             * Get this class declared attributes.
111:             * @param cls The class we are querying.
112:             * @return An array of Attribute instances, describing each of the 
113:             *    attributes of all instances of the class, or <strong>null</strong>
114:             *    if the class hasn't defined any attributes.
115:             */
116:
117:            public static synchronized Attribute[] getClassAttributes(Class cls) {
118:                Object result = registery.get(cls);
119:                while ((cls != top) && (result == null)) {
120:                    cls = cls.getSuperclass();
121:                    result = registery.get(cls);
122:                }
123:                // Fix the resulting record before returning it:
124:                if (result == null)
125:                    return null;
126:                ClassAttributes record = (ClassAttributes) result;
127:                record.fix();
128:                return record.fixed;
129:            }
130:
131:            /**
132:             * Get the name of the class that has declared this attribute.
133:             * @param cls The class that makes the starting point of lookup.
134:             * @param attr The attribute we are looking for.
135:             * @return The name of the class that defined that attribute, or <strong>
136:             * null</strong>.
137:             */
138:
139:            public static Class getAttributeClass(Class cls, String attrname) {
140:                Class lookup = cls;
141:                // We lookup until we find the class that doesn't have this attribute:
142:                while (true) {
143:                    boolean found = false;
144:                    Attribute a[] = getClassAttributes(cls);
145:                    // Lookup the attribute in that set:
146:                    if (a != null) {
147:                        for (int i = 0; i < a.length; i++) {
148:                            if ((found = a[i].getName().equals(attrname)))
149:                                break;
150:                        }
151:                    }
152:                    if (found) {
153:                        lookup = cls;
154:                        cls = cls.getSuperclass();
155:                    } else {
156:                        return (lookup == cls) ? null : lookup;
157:                    }
158:                }
159:
160:            }
161:
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.