Source Code Cross Referenced for DefaultMessageImplementation.java in  » UML » MetaBoss » com » metaboss » enterprise » messages » 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 » UML » MetaBoss » com.metaboss.enterprise.messages 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002:        // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003:        // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004:        // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005:        // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006:        // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007:        // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008:        // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009:        // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010:        // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011:        // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012:        // POSSIBILITY OF SUCH DAMAGE.
013:        //
014:        // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015:        package com.metaboss.enterprise.messages;
016:
017:        import java.text.MessageFormat;
018:        import java.util.Locale;
019:        import java.util.ResourceBundle;
020:
021:        /** Default implementation of the message object. It can be used as a base class
022:         *  for the concrete messages as follows :
023:         *  <p><code><pre>
024:         *      public class GreetingMessage extends DefaultMessageImplementation
025:         *      {
026:         *          private UserName mUserName;
027:         *
028:         *          // Construct an instance of the greeting message
029:         *          public GreetingMessage(UserName pUserName)
030:         *          {
031:         *              super("HatMaker.Crm.Core.Greeting", false, false);
032:         *              mUserName = pUserName;
033:         *          }
034:         *
035:         *          // Overridden to return array of message arguments used to render the message.
036:         *          public Object[] getMessageArguments()
037:         *          {
038:         *              return new Object[] { mUserName.toPrimitiveValue(); };
039:         *          }
040:         *
041:         *          // Get the user name name
042:         *          public UserName getUserName()
043:         *          {
044:         *              return mUserName;
045:         *          }
046:         *      }
047:         *  </pre></code>
048:         *  The only method, which subclass might want to override is getMessageArguments().
049:         *
050:         */
051:        public abstract class DefaultMessageImplementation implements  Message {
052:            private String mMessageId;
053:            private boolean mIsFailure;
054:            private boolean mIsError;
055:            private boolean mIsWarning;
056:            private String mTextResourcePackage;
057:            private String mTextResourceId;
058:
059:            /** Constructs message object with specifed attrributes. This version of constructor assumes that the
060:             *  text resource bundle resides in the same package as the mesage class and that the text resource is equals the message id.
061:             *  This is really the most common occurrntce.
062:             * @param pMessageId - the unique identifier of the message.
063:             * @param pIsFailure - mutually exclusive with pIsError and pIsWarning parameters. Set to true if this message represents failure.
064:             * @param pIsError - mutually exclusive with pIsWarning and pIsFailure parameters. Set to true if this message represents error.
065:             * @param pIsWarning - mutually exclusive with pIsError and pIsFailure parameters. Set to true if this message represents warning.
066:             */
067:            public DefaultMessageImplementation(String pMessageId,
068:                    boolean pIsFailure, boolean pIsError, boolean pIsWarning) {
069:                mMessageId = pMessageId;
070:                mIsFailure = pIsFailure;
071:                mIsError = pIsError;
072:                mIsWarning = pIsWarning;
073:                // By default the TextResourceId equals MessageId
074:                mTextResourceId = pMessageId;
075:                // By default the TextResourcePackage is the same as the package of the message class
076:                String lFullClassName = getClass().getName();
077:                int lLastDot = lFullClassName.lastIndexOf(".");
078:                mTextResourcePackage = (lLastDot > 0) ? lFullClassName
079:                        .substring(0, lLastDot) : null;
080:            }
081:
082:            // Restrict access to the default constructor
083:            private DefaultMessageImplementation() {
084:            }
085:
086:            /** Returns unique string Id of the message. */
087:            public String getId() {
088:                return mMessageId;
089:            }
090:
091:            /** Returns true if this message is a failure message. */
092:            public boolean isFailure() {
093:                return mIsFailure;
094:            }
095:
096:            /** Returns true if this message is an error message. */
097:            public boolean isError() {
098:                return mIsError;
099:            }
100:
101:            /** Returns true if this message is a warning message. */
102:            public boolean isWarning() {
103:                return mIsWarning;
104:            }
105:
106:            /** Getter for the package name of the resource bundle where where text resource should be loaded from. */
107:            public String getTextResourcePackage() {
108:                return mTextResourcePackage;
109:            }
110:
111:            /** Setter for the package name of the resource bundle where where text resource should be loaded from. */
112:            public void setTextResourcePackage(String pTextResourcePackage) {
113:                mTextResourcePackage = pTextResourcePackage;
114:            }
115:
116:            /** Getter for the unique identifier of the text resource where message text is. */
117:            public String getTextResourceId() {
118:                return mTextResourceId;
119:            }
120:
121:            /** Setter for unique identifier of the text resource where message text is. */
122:            public void setTextResourceId(String pTextResourceId) {
123:                mTextResourceId = pTextResourceId;
124:            }
125:
126:            /** Returns an array of message arguments used to render the message.
127:             *  This version returns no arguments. Override to provide arguments relevant for the message. */
128:            public Object[] getMessageArguments() {
129:                return new Object[0];
130:            }
131:
132:            /** Returns human readable message text in default locale. */
133:            public String toString() {
134:                return toLocalizedString(Locale.getDefault());
135:            }
136:
137:            /** Returns human readable message text in specified locale. */
138:            public String toLocalizedString(Locale pDesiredLocale) {
139:                String lResourceBundleBaseName = getTextResourcePackage() != null ? (getTextResourcePackage() + ".Messages")
140:                        : "Messages";
141:
142:                ResourceBundle lBundle = ResourceBundle.getBundle(
143:                        lResourceBundleBaseName, pDesiredLocale);
144:                if (lBundle == null)
145:                    throw new java.lang.UnsupportedOperationException(
146:                            "Unable to load "
147:                                    + lResourceBundleBaseName
148:                                    + " resource bundle. toLocalizedString() operation can not be completed.");
149:                String lMessagePattern = lBundle.getString(getTextResourceId());
150:                if (lMessagePattern == null)
151:                    throw new java.lang.UnsupportedOperationException(
152:                            "Message text is not found in resource bundle. toLocalizedString() operation can not be completed.");
153:                return MessageFormat.format(lMessagePattern,
154:                        getMessageArguments());
155:            }
156:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.