Source Code Cross Referenced for ResourceManagerException.java in  » Database-JDBC-Connection-Pool » Apache-commons-transaction-1.2 » org » apache » commons » transaction » file » 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 » Database JDBC Connection Pool » Apache commons transaction 1.2 » org.apache.commons.transaction.file 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.transaction.file;
018:
019:        import java.io.PrintWriter;
020:        import java.io.StringWriter;
021:
022:        /**
023:         * Signals any kind of error or failure state in a {@link ResourceManager}.
024:         * 
025:         * @version $Id: ResourceManagerException.java 493628 2007-01-07 01:42:48Z joerg $
026:         */
027:        public class ResourceManagerException extends Exception implements 
028:                ResourceManagerErrorCodes {
029:
030:            private static final int[] ERROR_CODES = { ERR_SYSTEM,
031:                    ERR_SYSTEM_INCONSISTENT, ERR_NO_TX, ERR_TXID_INVALID,
032:                    ERR_TX_INACTIVE, ERR_TX_INCONSISTENT, ERR_DUP_TX,
033:                    ERR_THREAD_INVALID, ERR_ISOLATION_LEVEL_UNSUPPORTED,
034:                    ERR_RESOURCEID_INVALID, ERR_RESOURCE_EXISTS,
035:                    ERR_NO_SUCH_RESOURCE, ERR_LOCK, ERR_NO_LOCK,
036:                    ERR_MARKED_FOR_ROLLBACK, };
037:
038:            private static final String[] ERROR_CODE_STRINGS = { "ERR_SYSTEM",
039:                    "ERR_SYSTEM_INCONSISTENT", "ERR_NO_TX", "ERR_TXID_INVALID",
040:                    "ERR_TX_INACTIVE", "ERR_TX_INCONSISTENT", "ERR_DUP_TX",
041:                    "ERR_THREAD_INVALID", "ERR_ISOLATION_LEVEL_UNSUPPORTED",
042:                    "ERR_RESOURCEID_INVALID", "ERR_RESOURCE_EXISTS",
043:                    "ERR_NO_SUCH_RESOURCE", "ERR_LOCK", "ERR_NO_LOCK",
044:                    "ERR_MARKED_FOR_ROLLBACK", };
045:
046:            private static final String[] ERROR_CODE_TEXTS = { "System error",
047:                    "Inconsistent system data", "Unknown transaction",
048:                    "Invalid transaction id", "Transaction inactive",
049:                    "Inconsistent transaction data",
050:                    "Duplicate transaction id",
051:                    "Thread of control is the one that not start tx",
052:                    "Isolation level unsupported",
053:                    "Specified resource id is invalid",
054:                    "Resource already exists", "No such resource",
055:                    "Locking error", "Could not acquire lock",
056:                    "Transaction already marked for rollback" };
057:
058:            public static final String ERR_UNKNOWN_TEXT = "Unknown error";
059:            public static final String ERR_UNKNOWN_CODE = "ERR_UNKNOWN";
060:
061:            protected final int status;
062:            protected final Object txId;
063:
064:            protected static final String composeMessage(String msg,
065:                    int status, Object txId, Throwable cause) {
066:                String message = composeMessage(msg, status, txId);
067:                StringBuffer messageBuffer = new StringBuffer(message);
068:                messageBuffer.append("\nCaused by: ");
069:                StringWriter sw = new StringWriter();
070:                cause.printStackTrace(new PrintWriter(sw));
071:                messageBuffer.append(sw.getBuffer());
072:                return messageBuffer.toString();
073:            }
074:
075:            protected static final String composeMessage(String msg,
076:                    int status, Object txId) {
077:                StringBuffer composed = new StringBuffer();
078:                if (txId != null) {
079:                    composed.append(txId).append(": ");
080:                }
081:                if (msg != null) {
082:                    composed.append(msg);
083:                    if (status != -1) {
084:                        composed.append(" (").append(statusToCode(status))
085:                                .append(')');
086:                    }
087:                } else if (status != -1) {
088:                    composed.append(statusToText(status));
089:                }
090:
091:                return composed.toString();
092:            }
093:
094:            public static final String statusToText(int status) {
095:                if (status == ERR_UNKNOWN) {
096:                    return ERR_UNKNOWN_TEXT;
097:                } else {
098:                    int pos = -1;
099:                    for (int i = 0; i < ERROR_CODES.length; i++) {
100:                        int code = ERROR_CODES[i];
101:                        if (status == code) {
102:                            pos = i;
103:                            break;
104:                        }
105:                    }
106:                    if (pos == -1) {
107:                        return ERR_UNKNOWN_TEXT + ", code: " + status;
108:                    } else {
109:                        return ERROR_CODE_TEXTS[pos];
110:                    }
111:                }
112:            }
113:
114:            public static final String statusToCode(int status) {
115:                if (status == ERR_UNKNOWN) {
116:                    return ERR_UNKNOWN_CODE;
117:                } else {
118:                    int pos = -1;
119:                    for (int i = 0; i < ERROR_CODES.length; i++) {
120:                        int code = ERROR_CODES[i];
121:                        if (status == code) {
122:                            pos = i;
123:                            break;
124:                        }
125:                    }
126:                    if (pos == -1) {
127:                        return ERR_UNKNOWN_CODE + ": " + status;
128:                    } else {
129:                        return ERROR_CODE_STRINGS[pos];
130:                    }
131:                }
132:            }
133:
134:            public ResourceManagerException(String message, int status,
135:                    Object txId) {
136:                super (ResourceManagerException.composeMessage(message, status,
137:                        txId));
138:                this .status = status;
139:                this .txId = txId;
140:            }
141:
142:            public ResourceManagerException(int status, Object txId) {
143:                this (null, status, txId);
144:            }
145:
146:            public ResourceManagerException(String message) {
147:                super (message);
148:                this .status = ERR_UNKNOWN;
149:                this .txId = null;
150:            }
151:
152:            public ResourceManagerException(String message, int status,
153:                    Object txId, Throwable cause) {
154:                // XXX can not do this, as 1.3 Throwable does not allow cause in ctor :( 
155:                //        super(ResourceManagerException.composeMessage(message, status, txId), cause);
156:                // for now format cause by ourselves
157:                super (ResourceManagerException.composeMessage(message, status,
158:                        txId, cause));
159:                this .status = status;
160:                this .txId = txId;
161:            }
162:
163:            public ResourceManagerException(String message, int status,
164:                    Throwable cause) {
165:                this (message, status, null, cause);
166:            }
167:
168:            public ResourceManagerException(String message, Throwable cause) {
169:                this (message, ERR_UNKNOWN, cause);
170:            }
171:
172:            public ResourceManagerException(int status, Object txId,
173:                    Throwable cause) {
174:                this (null, status, txId, cause);
175:            }
176:
177:            public String statusToString() {
178:                return ResourceManagerException.statusToText(status);
179:            }
180:
181:            public int getStatus() {
182:                return status;
183:            }
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.