KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > Messages


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o;
22
23 import java.io.*;
24
25 import com.db4o.config.*;
26
27 /**
28  * @exclude
29  */

30 public final class Messages
31 {
32     public final static int CLOSED_OR_OPEN_FAILED = 20;
33     public final static int FATAL_MSG_ID=44;
34     public final static int NOT_IMPLEMENTED=49;
35     public final static int ONLY_FOR_INDEXED_FIELDS=66;
36     public final static int CLIENT_SERVER_UNSUPPORTED=67;
37     
38     private static String JavaDoc[] i_messages;
39     
40     public static String JavaDoc get(int a_code){
41         return get(a_code, null);
42     }
43
44     public static String JavaDoc get(int a_code, String JavaDoc param){
45         if(a_code < 0){
46             return param;
47         }
48         load();
49         if(i_messages == null || a_code > i_messages.length - 1){
50             return "msg[" + a_code + "]";
51         }
52         String JavaDoc msg = i_messages[a_code];
53         if(param != null){
54             int pos = msg.indexOf("%",0);
55             if(pos > -1){
56                 msg = msg.substring(0, pos)
57                       + "'"
58                       + param
59                       + "'"
60                       + msg.substring(pos + 1);
61             }
62         }
63         return msg;
64     }
65     
66     private static void load(){
67         if(i_messages == null) {
68              if(Tuning.readableMessages){
69                         
70                 i_messages = new String JavaDoc[] {
71                         "", // unused
72
"blocksize should be between 1 and 127",
73                         "% close request",
74                         "% closed",
75                         "Exception opening %",
76                         "% opened O.K.", // 5
77
"Class %: Instantiation failed. \n Check custom ObjectConstructor code.",
78                         "Class %: Instantiation failed.\n Add a constructor for use with db4o, ideally with zero arguments.",
79                         "renaming %",
80                         "rename not possible. % already exists",
81                         "rename failed", // 10
82
"File close failed.",
83                         "File % not available for readwrite access.",
84                         "File read access failed.",
85                         "File not found: % Creating new file",
86                         "Creation of file failed: %", // 15
87
"File write failed.",
88                         "File format incompatible.",
89                         "Uncaught Exception. Engine closed.",
90                         "writing log for %",
91                         "% is closed. close() was called or open() failed.", // 20
92
"Filename not specified.",
93                         "The database file is locked by another process.",
94                         "Class not available: %. Check CLASSPATH settings.",
95                         "finalized while performing a task.\n DO NOT USE CTRL + C OR System.exit() TO STOP THE ENGINE.",
96                         "Please mail the following to exception@db4o.com:\n <db4o " + Db4oVersion.NAME + " stacktrace>", // 25
97
"</db4o " + Db4oVersion.NAME + " stacktrace>",
98                         "Creation of lock file failed: %",
99                         "Previous session was not shut down correctly",
100                         "This method call is only possible on stored objects",
101                         "Could not open port: %", // 30
102
"Server listening on port: %",
103                         "Client % connected.",
104                         "Client % timed out and closed.",
105                         "Connection closed by client %.",
106                         "Connection closed by server. %.",// 35
107
"% connected to server.",
108                         "The directory % can neither be found nor created.",
109                         "This blob was never stored.",
110                         "Blob file % not available.",
111                         "Failure finding blob filename.", // 40
112
"File does not exist %.",
113                         "Failed to connect to server.",
114                         "No blob data stored.",
115                         "Uncaught Exception. db4o engine closed.",
116                         "Add constructor that won't throw exceptions, configure constructor calls, or provide a translator to class % and make sure the class is deployed to the server with the same package/namespace + assembly name.", // 45
117
"This method can only be called before opening the database file.",
118                         "AccessibleObject#setAccessible() is not available. Private fields can not be stored.",
119                         "ObjectTranslator could not be installed: %.",
120                         "Not implemented",
121                         "% closed by ShutdownHook.", // 50
122
"This constraint is not persistent. It has no database identity.",
123                         "Add at least one ObjectContainer to the Cluster",
124                         "Unsupported Operation",
125                         "Database password does not match user-provided password.",
126                         "Thread interrupted.", // 55
127
"Password can not be null.",
128                         "Classes does not match.",
129                         "rename() needs to be executed on the server.",
130                         "Primitive types like % can not be stored directly. Store and retrieve them in wrapper objects.",
131                         "Backups can not be run from clients and memory files.", // 60
132
"Backup in progress.",
133                         "Only use persisted first class objects as keys for IdentityHashMap.",
134                         "This functionality is only available from version 5.0 onwards.",
135                         "By convention a Predicate needs the following method: public boolean match(ExtentClass extent){}",
136                         "Old database file format detected. To allow automatic updates call Db4o.configure().allowVersionUpdates(true).", // 65
137
"This functionality is only available for indexed fields.", // 66
138
"This functionality is not supported for db4o clients in Client/Server mode.", // 67
139
"Invalid address: %", // 68
140
};
141                 }else{
142                     i_messages = new String JavaDoc[0];
143                 }
144             }
145
146     }
147
148     public static void logErr (Configuration config, int code, String JavaDoc msg, Throwable JavaDoc t) {
149         if(config == null){
150             config = Db4o.configure();
151         }
152         PrintStream ps = ((Config4Impl)config).errStream();
153         new Message(msg, code,ps);
154         if(t != null){
155             new Message(null,25,ps);
156             t.printStackTrace(ps);
157             new Message(null,26,ps, false);
158         }
159     }
160
161     public static void logMsg (Configuration config, int code, String JavaDoc msg) {
162         if(Deploy.debug){
163             if(code == 0){
164                 System.out.println(msg);
165                 return;
166             }
167         }
168         Config4Impl c4i = (Config4Impl)config;
169         if(c4i == null){
170             c4i = (Config4Impl)Db4o.configure();
171         }
172         
173         if(c4i.messageLevel() > YapConst.NONE){
174             new Message(msg,code,c4i.outStream());
175         }
176     }
177 }
178
179
Popular Tags