Source Code Cross Referenced for Messages.java in  » Web-Framework » calyxo » de » odysseus » calyxo » base » 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 Framework » calyxo » de.odysseus.calyxo.base 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004, 2005, 2006 Odysseus Software GmbH
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package de.odysseus.calyxo.base;
017:
018:        import java.util.ArrayList;
019:        import java.util.Collections;
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Map;
024:        import java.util.NoSuchElementException;
025:
026:        import de.odysseus.calyxo.base.util.ListOrderedMap;
027:
028:        /**
029:         * This class collects messages. Messages may be added and retreived
030:         * by specifying a (optional) key.
031:         * 
032:         * @see de.odysseus.calyxo.base.Message
033:         * @author Christoph Beck
034:         */
035:        public class Messages {
036:            public static final String GLOBAL_KEY = null;
037:
038:            private Map messagesMap = ListOrderedMap.decorate(new HashMap());
039:
040:            /**
041:             * Default constructor
042:             */
043:            public Messages() {
044:                super ();
045:            }
046:
047:            /**
048:             * Add message.
049:             * @param key the key under which to add the message
050:             * @param message the message to add
051:             */
052:            public void addMessage(String key, Message message) {
053:                Object o = messagesMap.get(key);
054:                if (o instanceof  List) {
055:                    ((List) o).add(message);
056:                } else if (o instanceof  Message) {
057:                    List l = new ArrayList(4);
058:                    l.add(o);
059:                    l.add(message);
060:                    messagesMap.put(key, l);
061:                } else { // o == null
062:                    messagesMap.put(key, message);
063:                }
064:            }
065:
066:            /**
067:             * Get all the keys.
068:             * If global messages have been added, this Iterator will also
069:             * contain <code>Messages.GLOBAL_KEY</code>.
070:             */
071:            public Iterator getKeys() {
072:                return messagesMap.keySet().iterator();
073:            }
074:
075:            /**
076:             * Answer true iff no messages have been added yet.
077:             */
078:            public boolean isEmpty() {
079:                return messagesMap.isEmpty();
080:            }
081:
082:            /**
083:             * Answer true iff there are message for the specified key
084:             */
085:            public boolean containsMessages(String key) {
086:                return messagesMap.containsKey(key);
087:            }
088:
089:            /**
090:             * Answer true iff there are global messages
091:             * Same as <code>containsGlobalMessages(Messages.GLOBAL_KEY)</code>.
092:             */
093:            public boolean containsGlobalMessages() {
094:                return containsMessages(GLOBAL_KEY);
095:            }
096:
097:            /**
098:             * Add a global message.
099:             * Same as <code>addMessage(Messages.GLOBAL_KEY, message)</code>.
100:             * @param message message to add
101:             */
102:            public void addGlobalMessage(Message message) {
103:                addMessage(GLOBAL_KEY, message);
104:            }
105:
106:            /**
107:             * Get the first message added for the specified key
108:             */
109:            public Message getFirstMessage(String key) {
110:                Object o = messagesMap.get(key);
111:                if (o instanceof  List) {
112:                    return (Message) ((List) o).get(0);
113:                }
114:                // o == null  || o instanceof Message
115:                return (Message) o;
116:            }
117:
118:            /**
119:             * Get the first added global message
120:             * Same as <code>getFirstMessage(Messages.GLOBAL_KEY)</code>.
121:             */
122:            public Message getFirstGlobalMessage() {
123:                return getFirstMessage(GLOBAL_KEY);
124:            }
125:
126:            /**
127:             * Get messages (instances of {@link Message}) which have been
128:             * added with the specified key (in the order they have been added).
129:             * @param key the message key
130:             */
131:            public Iterator getMessages(final String key) {
132:                final Object o = messagesMap.get(key);
133:                if (o instanceof  List) {
134:                    return new Iterator() {
135:                        Iterator delegate = ((List) o).iterator();
136:
137:                        public boolean hasNext() {
138:                            return delegate.hasNext();
139:                        }
140:
141:                        public Object next() {
142:                            return delegate.next();
143:                        }
144:
145:                        public void remove() {
146:                            delegate.remove();
147:                            if (((List) o).isEmpty()) {
148:                                messagesMap.remove(key);
149:                            }
150:                        }
151:                    };
152:                } else if (o instanceof  Message) {
153:                    return new Iterator() {
154:                        boolean next = true;
155:
156:                        public boolean hasNext() {
157:                            return next;
158:                        }
159:
160:                        public Object next() {
161:                            if (next) {
162:                                next = false;
163:                                return o;
164:                            }
165:                            throw new NoSuchElementException(
166:                                    "No more messages...");
167:                        }
168:
169:                        public void remove() {
170:                            messagesMap.remove(key);
171:                        }
172:                    };
173:                } else { // o == null
174:                    return Collections.EMPTY_LIST.iterator();
175:                }
176:            }
177:
178:            /**
179:             * Get global messages (instances of {@link Message}).
180:             * Same as <code>getMessages(Messages.GLOBAL_KEY)</code>.
181:             */
182:            public Iterator getGlobalMessages() {
183:                return getMessages(GLOBAL_KEY);
184:            }
185:
186:            /**
187:             * Get all messages (instances of {@link Message}) in the
188:             * order they have been added.
189:             */
190:            public Iterator getAllMessages() {
191:                final Iterator keys = messagesMap.keySet().iterator();
192:                return new Iterator() {
193:                    Iterator delegate;
194:
195:                    public boolean hasNext() {
196:                        return delegate != null && delegate.hasNext()
197:                                || keys.hasNext();
198:                    }
199:
200:                    public Object next() {
201:                        if (delegate == null || !delegate.hasNext()) {
202:                            delegate = getMessages((String) keys.next());
203:                        }
204:                        return delegate.next();
205:                    }
206:
207:                    public void remove() {
208:                        delegate.remove();
209:                    }
210:                };
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.