Source Code Cross Referenced for MessageConst.java in  » Ajax » zk » org » zkoss » mesg » 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 » Ajax » zk » org.zkoss.mesg 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* MessageConst.java
002:
003:        {{IS_NOTE
004:
005:        	Purpose: Defines message types
006:        	Description:
007:        	History:
008:        	 2001/4/2 2001/4/2, Tom M. Yeh: Created.
009:
010:        }}IS_NOTE
011:
012:        Copyright (C) 2001 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.mesg;
020:
021:        import java.util.List;
022:        import java.util.ArrayList;
023:
024:        import org.zkoss.lang.D;
025:        import org.zkoss.lang.Objects;
026:
027:        /**
028:         * Defines the constants of message types.
029:         *
030:         * @author tomyeh
031:         * @see Messages
032:         */
033:        public interface MessageConst {
034:            /** Denotes a non-existent code. */
035:            public static final int NULL_CODE = 0;
036:
037:            /** The info of each message bundle.
038:             * <p>Each bundle is associated with a class and a set of files.
039:             */
040:            public static class BundleInfo {
041:                public final Class klass;
042:                public final String filename;
043:
044:                private BundleInfo(Class klass, String filename) {
045:                    this .klass = klass;
046:                    this .filename = filename;
047:                }
048:
049:                public String toString() {
050:                    return "[" + this .klass + ", " + this .filename + ']';
051:                }
052:            }
053:
054:            /** Used to handle the mapping of a message code to a filename.
055:             *
056:             * <p>FUTURE: we might consider to use hashCode or other to represents
057:             * the identifier such that the client will have the same code as the server.
058:             */
059:            public static class Aide {
060:                private static BundleInfo[] _bis = new BundleInfo[0];
061:
062:                /** Registers a message filename, and returns an identifier to
063:                 * represent it.
064:                 *
065:                 * <p>The path is assumed to be /metainfo/mesg.
066:                 *
067:                 * @param filename the filename without path and extension, e.g, "msgacc"
068:                 * @return an identifier to represent this message file.
069:                 */
070:                public static final int register(Class klass, String filename) {
071:                    if (filename.indexOf('/') >= 0
072:                            || filename.indexOf('.') >= 0)
073:                        throw new IllegalArgumentException(
074:                                "Neither path nor extension is allowed: "
075:                                        + filename);
076:                    if (klass == null)
077:                        throw new IllegalArgumentException("null class");
078:
079:                    filename = "/metainfo/mesg/" + filename;
080:                    final BundleInfo bi = new BundleInfo(klass, filename);
081:                    synchronized (Aide.class) {
082:                        final int sz = _bis.length + 1;
083:                        final List bis = new ArrayList(sz);
084:                        for (int j = 0; j < _bis.length; ++j) {
085:                            if (_bis[j].filename.equals(filename)
086:                                    || _bis[j].klass.equals(klass))
087:                                throw new IllegalStateException(
088:                                        "Replicate message: "
089:                                                + bi
090:                                                + "\nRegistered message files: "
091:                                                + Objects.toString(bis));
092:                            bis.add(_bis[j]);
093:                        }
094:                        bis.add(bi);
095:                        _bis = (BundleInfo[]) bis.toArray(new BundleInfo[sz]);
096:                        return (sz << 16); //as the high word; starting from (1<<16)
097:                    }
098:                }
099:
100:                /** Returns the filename with path, but without extension, of the
101:                 * specified message code.
102:                 */
103:                public static final BundleInfo getBundleInfo(int code) {
104:                    final BundleInfo[] bis = _bis; //so no sync is required
105:                    final int j = (code >>> 16) - 1; //starting from 1
106:                    if (j < 0 || j >= bis.length)
107:                        throw new IllegalArgumentException(
108:                                "Wrong message code: " + code
109:                                        + "\nRegistered messages: "
110:                                        + Objects.toString(bis));
111:                    return bis[j];
112:                }
113:            }
114:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.