Source Code Cross Referenced for ClassFactoryImpl.java in  » Graphic-Library » jcommon-components » org » jfree » xml » factory » objects » 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 » Graphic Library » jcommon components » org.jfree.xml.factory.objects 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ========================================================================
002:         * JCommon : a free general purpose class library for the Java(tm) platform
003:         * ========================================================================
004:         *
005:         * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006:         * 
007:         * Project Info:  http://www.jfree.org/jcommon/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         * 
027:         * ---------------------
028:         * ClassFactoryImpl.java
029:         * ---------------------
030:         * (C)opyright 2003, 2004, by Thomas Morgner and Contributors.
031:         *
032:         * Original Author:  Thomas Morgner;
033:         * Contributor(s):   David Gilbert (for Object Refinery Limited);
034:         *
035:         * $Id: ClassFactoryImpl.java,v 1.6 2006/01/25 23:15:03 taqua Exp $
036:         *
037:         * Changes (from 19-Feb-2003)
038:         * -------------------------
039:         * 19-Feb-2003 : Added standard header and Javadocs (DG);
040:         * 29-Apr-2003 : Distilled from the JFreeReport project and moved into JCommon
041:         * 29-Jul-2004 : Replaced 'enum' variable name (reserved word in JDK 1.5) (DG);
042:         *
043:         */
044:
045:        package org.jfree.xml.factory.objects;
046:
047:        import java.util.HashMap;
048:        import java.util.Iterator;
049:
050:        import org.jfree.util.Configuration;
051:        import org.jfree.util.ClassComparator;
052:
053:        /**
054:         * An abstract class that implements the {@link ClassFactory} interface.
055:         *
056:         * @author Thomas Morgner.
057:         */
058:        public abstract class ClassFactoryImpl implements  ClassFactory {
059:
060:            /** Storage for the classes. */
061:            private HashMap classes;
062:            /** A class comparator for searching the super class */
063:            private ClassComparator comparator;
064:            /** The parser/report configuration */
065:            private Configuration config;
066:
067:            /**
068:             * Creates a new class factory.
069:             */
070:            public ClassFactoryImpl() {
071:                this .classes = new HashMap();
072:                this .comparator = new ClassComparator();
073:            }
074:
075:            /**
076:             * Returns the class comparator used to sort the super classes of an object.
077:             *
078:             * @return the class comparator.
079:             */
080:            public ClassComparator getComparator() {
081:                return this .comparator;
082:            }
083:
084:            /**
085:             * Returns an object-description for a class.
086:             *
087:             * @param c  the class.
088:             *
089:             * @return An object description.
090:             */
091:            public ObjectDescription getDescriptionForClass(final Class c) {
092:                final ObjectDescription od = (ObjectDescription) this .classes
093:                        .get(c);
094:                if (od == null) {
095:                    return null;
096:                }
097:                return od.getInstance();
098:            }
099:
100:            /**
101:             * Returns the most concrete object-description for the super class of a class.
102:             *
103:             * @param d  the class.
104:             * @param knownSuperClass a known supported superclass or null, if no superclass
105:             * is known yet.
106:             *
107:             * @return The object description.
108:             */
109:            public ObjectDescription getSuperClassObjectDescription(
110:                    final Class d, ObjectDescription knownSuperClass) {
111:
112:                if (d == null) {
113:                    throw new NullPointerException(
114:                            "Description class must not be null.");
115:                }
116:                final Iterator iterator = this .classes.keySet().iterator();
117:                while (iterator.hasNext()) {
118:                    final Class keyClass = (Class) iterator.next();
119:                    if (keyClass.isAssignableFrom(d)) {
120:                        final ObjectDescription od = (ObjectDescription) this .classes
121:                                .get(keyClass);
122:                        if (knownSuperClass == null) {
123:                            knownSuperClass = od;
124:                        } else {
125:                            if (this .comparator.isComparable(knownSuperClass
126:                                    .getObjectClass(), od.getObjectClass())) {
127:                                if (this .comparator.compare(knownSuperClass
128:                                        .getObjectClass(), od.getObjectClass()) < 0) {
129:                                    knownSuperClass = od;
130:                                }
131:                            }
132:                        }
133:                    }
134:                }
135:                if (knownSuperClass == null) {
136:                    return null;
137:                }
138:                return knownSuperClass.getInstance();
139:            }
140:
141:            /**
142:             * Registers an object description with the factory.
143:             *
144:             * @param key  the key.
145:             * @param od  the object description.
146:             */
147:            protected void registerClass(final Class key,
148:                    final ObjectDescription od) {
149:                this .classes.put(key, od);
150:                if (this .config != null) {
151:                    od.configure(this .config);
152:                }
153:            }
154:
155:            /**
156:             * Returns an iterator that provides access to the registered object definitions.
157:             *
158:             * @return The iterator.
159:             */
160:            public Iterator getRegisteredClasses() {
161:                return this .classes.keySet().iterator();
162:            }
163:
164:            /**
165:             * Configures this factory. The configuration contains several keys and
166:             * their defined values. The given reference to the configuration object
167:             * will remain valid until the report parsing or writing ends.
168:             * <p>
169:             * The configuration contents may change during the reporting.
170:             *
171:             * @param config the configuration, never null
172:             */
173:            public void configure(final Configuration config) {
174:                if (config == null) {
175:                    throw new NullPointerException(
176:                            "The given configuration is null");
177:                }
178:                if (this .config != null) {
179:                    // already configured ... ignored
180:                    return;
181:                }
182:
183:                this .config = config;
184:                final Iterator it = this .classes.values().iterator();
185:                while (it.hasNext()) {
186:                    final ObjectDescription od = (ObjectDescription) it.next();
187:                    od.configure(config);
188:                }
189:            }
190:
191:            /**
192:             * Returns the currently set configuration or null, if none was set.
193:             *
194:             * @return the configuration.
195:             */
196:            public Configuration getConfig() {
197:                return this .config;
198:            }
199:
200:            /**
201:             * Tests for equality.
202:             * 
203:             * @param o  the object to test.
204:             * 
205:             * @return A boolean.
206:             */
207:            public boolean equals(final Object o) {
208:                if (this  == o) {
209:                    return true;
210:                }
211:                if (!(o instanceof  ClassFactoryImpl)) {
212:                    return false;
213:                }
214:
215:                final ClassFactoryImpl classFactory = (ClassFactoryImpl) o;
216:
217:                if (!this .classes.equals(classFactory.classes)) {
218:                    return false;
219:                }
220:
221:                return true;
222:            }
223:
224:            /**
225:             * Returns a hash code.
226:             * 
227:             * @return A hash code.
228:             */
229:            public int hashCode() {
230:                return this.classes.hashCode();
231:            }
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.