Source Code Cross Referenced for AttributeList.java in  » Graphic-Library » jcommon-components » org » jfree » xml » writer » 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.writer 
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:         * AttributeList.java
029:         * ------------------
030:         * (C)opyright 2003-2005, by Thomas Morgner and Contributors.
031:         *
032:         * Original Author:  Thomas Morgner;
033:         * Contributor(s):   David Gilbert (for Object Refinery Limited);
034:         *
035:         * $Id: AttributeList.java,v 1.3 2005/10/18 13:35:06 mungady Exp $
036:         *
037:         * Changes
038:         * -------
039:         * 25-Sep-2003 : Initial version (TM);
040:         * 26-Nov-2003 : Javadoc updates (DG);
041:         *
042:         */
043:
044:        package org.jfree.xml.writer;
045:
046:        import java.util.Iterator;
047:        import java.util.List;
048:
049:        /**
050:         * The attribute list is used by a writer to specify the attributes
051:         * of an XML element in a certain order.
052:         *
053:         * @author Thomas Morgner
054:         */
055:        public class AttributeList {
056:
057:            /**
058:             * A name/value pair of the attribute list.
059:             */
060:            private static class AttributeEntry {
061:
062:                /** The name of the attribute entry. */
063:                private String name;
064:
065:                /** The value of the attribute entry. */
066:                private String value;
067:
068:                /**
069:                 * Creates a new attribute entry for the given name and value.
070:                 *
071:                 * @param name  the attribute name (<code>null</code> not permitted).
072:                 * @param value the attribute value (<code>null</code> not permitted).
073:                 */
074:                public AttributeEntry(final String name, final String value) {
075:                    if (name == null) {
076:                        throw new NullPointerException(
077:                                "Name must not be null. [" + name + ", "
078:                                        + value + "]");
079:                    }
080:                    if (value == null) {
081:                        throw new NullPointerException(
082:                                "Value must not be null. [" + name + ", "
083:                                        + value + "]");
084:                    }
085:                    this .name = name;
086:                    this .value = value;
087:                }
088:
089:                /**
090:                 * Returns the attribute name.
091:                 * 
092:                 * @return the name.
093:                 */
094:                public String getName() {
095:                    return this .name;
096:                }
097:
098:                /**
099:                 * Returns the value of this attribute entry.
100:                 * 
101:                 * @return the value of the entry.
102:                 */
103:                public String getValue() {
104:                    return this .value;
105:                }
106:
107:                /**
108:                 * Checks whether the given object is an attribute entry with the same name.
109:                 * 
110:                 * @param o  the suspected other attribute entry.
111:                 * 
112:                 * @return <code>true</code> if the given object is equal, <code>false</code> otherwise.
113:                 */
114:                public boolean equals(final Object o) {
115:                    if (this  == o) {
116:                        return true;
117:                    }
118:                    if (!(o instanceof  AttributeEntry)) {
119:                        return false;
120:                    }
121:
122:                    final AttributeEntry attributeEntry = (AttributeEntry) o;
123:                    if (!this .name.equals(attributeEntry.name)) {
124:                        return false;
125:                    }
126:                    return true;
127:                }
128:
129:                /**
130:                 * Computes an hashcode for this entry.
131:                 * 
132:                 * @return the hashcode.
133:                 */
134:                public int hashCode() {
135:                    return this .name.hashCode();
136:                }
137:            }
138:
139:            /**
140:             * An iterator over the attribute names of this list.
141:             */
142:            private static class AttributeIterator implements  Iterator {
143:
144:                /** The backend is an iterator over the attribute entries. */
145:                private Iterator backend;
146:
147:                /**
148:                 * Creates a new attribute iterator using the given iterator as backend.
149:                 * 
150:                 * @param backend  an iterator over the attribute entries (<code>null</code> not permitted).
151:                 */
152:                public AttributeIterator(final Iterator backend) {
153:                    if (backend == null) {
154:                        throw new NullPointerException();
155:                    }
156:                    this .backend = backend;
157:                }
158:
159:                /**
160:                 * Returns <tt>true</tt> if the iteration has more elements. (In other
161:                 * words, returns <tt>true</tt> if <tt>next</tt> would return an element
162:                 * rather than throwing an exception.)
163:                 *
164:                 * @return <tt>true</tt> if the iterator has more elements.
165:                 */
166:                public boolean hasNext() {
167:                    return this .backend.hasNext();
168:                }
169:
170:                /**
171:                 * Returns the next element in the iteration.
172:                 *
173:                 * @return the next element in the iteration.
174:                 */
175:                public Object next() {
176:                    final AttributeEntry entry = (AttributeEntry) this .backend
177:                            .next();
178:                    if (entry != null) {
179:                        return entry.getName();
180:                    }
181:                    return entry;
182:                }
183:
184:                /**
185:                 *
186:                 * Removes from the underlying collection the last element returned by the
187:                 * iterator (optional operation).  This method can be called only once per
188:                 * call to <tt>next</tt>.  The behavior of an iterator is unspecified if
189:                 * the underlying collection is modified while the iteration is in
190:                 * progress in any way other than by calling this method.
191:                 */
192:                public void remove() {
193:                    this .backend.remove();
194:                }
195:            }
196:
197:            /** The storage for all entries of this list. */
198:            private List entryList;
199:
200:            /**
201:             * Creates an empty attribute list with no default values.
202:             */
203:            public AttributeList() {
204:                this .entryList = new java.util.ArrayList();
205:            }
206:
207:            /**
208:             * Returns an iterator over all attribute names. The names are returned
209:             * in their oder of addition to the list. The iterator contains strings.
210:             *
211:             * @return the iterator over all attribute names.
212:             */
213:            public Iterator keys() {
214:                return new AttributeIterator(this .entryList.iterator());
215:            }
216:
217:            /**
218:             * Defines an attribute.
219:             * 
220:             * @param name the name of the attribute to be defined
221:             * @param value the value of the attribute.
222:             */
223:            public synchronized void setAttribute(final String name,
224:                    final String value) {
225:                final AttributeEntry entry = new AttributeEntry(name, value);
226:                final int pos = this .entryList.indexOf(entry);
227:                if (pos != -1) {
228:                    this .entryList.remove(pos);
229:                }
230:                this .entryList.add(entry);
231:            }
232:
233:            /**
234:             * Returns the attribute value for the given attribute name or null,
235:             * if the attribute is not defined in this list.
236:             *
237:             * @param name the name of the attribute
238:             * @return the attribute value or null.
239:             */
240:            public synchronized String getAttribute(final String name) {
241:                return getAttribute(name, null);
242:            }
243:
244:            /**
245:             * Returns the attribute value for the given attribute name or the given
246:             * defaultvalue, if the attribute is not defined in this list.
247:             *
248:             * @param name the name of the attribute.
249:             * @param defaultValue  the default value.
250:             * 
251:             * @return the attribute value or the defaultValue.
252:             */
253:            public synchronized String getAttribute(final String name,
254:                    final String defaultValue) {
255:                for (int i = 0; i < this .entryList.size(); i++) {
256:                    final AttributeEntry ae = (AttributeEntry) this .entryList
257:                            .get(i);
258:                    if (ae.getName().equals(name)) {
259:                        return ae.getValue();
260:                    }
261:                }
262:                return defaultValue;
263:            }
264:
265:            /**
266:             * Removes the attribute with the given name from the list.
267:             *
268:             * @param name the name of the attribute which should be removed..
269:             */
270:            public synchronized void removeAttribute(final String name) {
271:                for (int i = 0; i < this .entryList.size(); i++) {
272:                    final AttributeEntry ae = (AttributeEntry) this.entryList
273:                            .get(i);
274:                    if (ae.getName().equals(name)) {
275:                        this.entryList.remove(ae);
276:                        return;
277:                    }
278:                }
279:            }
280:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.