001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal;
022:
023: import java.io.*;
024:
025: import com.db4o.*;
026: import com.db4o.config.*;
027:
028: /**
029: * @exclude
030: */
031: public final class Messages {
032:
033: public final static int INCOMPATIBLE_FORMAT = 17;
034: public final static int CLOSED_OR_OPEN_FAILED = 20;
035: public final static int FAILED_TO_SHUTDOWN = 28;
036: public final static int FATAL_MSG_ID = 44;
037: public final static int NOT_IMPLEMENTED = 49;
038: public final static int OLD_DATABASE_FORMAT = 65;
039: public final static int ONLY_FOR_INDEXED_FIELDS = 66;
040: public final static int CLIENT_SERVER_UNSUPPORTED = 67;
041: public final static int COULD_NOT_OPEN_PORT = 30;
042: public final static int SERVER_LISTENING_ON_PORT = 31;
043:
044: private static String[] i_messages;
045:
046: public static String get(int a_code) {
047: return get(a_code, null);
048: }
049:
050: public static String get(int a_code, String param) {
051: if (a_code < 0) {
052: return param;
053: }
054: load();
055: if (i_messages == null || a_code > i_messages.length - 1) {
056: return "msg[" + a_code + "]";
057: }
058: String msg = i_messages[a_code];
059: if (param != null) {
060: int pos = msg.indexOf("%", 0);
061: if (pos > -1) {
062: msg = msg.substring(0, pos) + "'" + param + "'"
063: + msg.substring(pos + 1);
064: }
065: }
066: return msg;
067: }
068:
069: private static void load() {
070: if (i_messages == null) {
071: if (Tuning.readableMessages) {
072:
073: i_messages = new String[] {
074: "", // unused
075: "blocksize should be between 1 and 127",
076: "% close request",
077: "% closed",
078: "Exception opening %",
079: "% opened O.K.", // 5
080: "Class %: Instantiation failed. \n Check custom ObjectConstructor code.",
081: "Class %: Instantiation failed.\n Add a constructor for use with db4o, ideally with zero arguments.",
082: "renaming %",
083: "rename not possible. % already exists",
084: "rename failed", // 10
085: "File close failed.",
086: "File % not available for readwrite access.",
087: "File read access failed.",
088: "File not found: % Creating new file",
089: "Creation of file failed: %", // 15
090: "File write failed.",
091: "File format incompatible.",
092: "Uncaught Exception. Engine closed.",
093: "writing log for %",
094: "% is closed. close() was called or open() failed.", // 20
095: "Filename not specified.",
096: "The database file is locked by another process.",
097: "Class not available: %. Check CLASSPATH settings.",
098: "finalized while performing a task.\n DO NOT USE CTRL + C OR System.exit() TO STOP THE ENGINE.",
099: "Please mail the following to exception@db4o.com:\n <db4o "
100: + Db4oVersion.NAME + " stacktrace>", // 25
101: "</db4o " + Db4oVersion.NAME + " stacktrace>",
102: "Creation of lock file failed: %",
103: "Previous session was not shut down correctly",
104: "This method call is only possible on stored objects",
105: "Could not open port: %", // 30
106: "Server listening on port: %",
107: "Client % connected.",
108: "Client % timed out and closed.",
109: "Connection closed by client %.",
110: "Connection closed by server. %.",// 35
111: "% connected to server.",
112: "The directory % can neither be found nor created.",
113: "This blob was never stored.",
114: "Blob file % not available.",
115: "Failure finding blob filename.", // 40
116: "File does not exist %.",
117: "Failed to connect to server.",
118: "No blob data stored.",
119: "Uncaught Exception. db4o engine closed.",
120: "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
121: "This method can only be called before opening the database file.",
122: "AccessibleObject#setAccessible() is not available. Private fields can not be stored.",
123: "ObjectTranslator could not be installed: %.",
124: "Not implemented",
125: "% closed by ShutdownHook.", // 50
126: "This constraint is not persistent. It has no database identity.",
127: "Add at least one ObjectContainer to the Cluster",
128: "Unsupported Operation",
129: "Database password does not match user-provided password.",
130: "Thread interrupted.", // 55
131: "Password can not be null.",
132: "Classes does not match.",
133: "rename() needs to be executed on the server.",
134: "Primitive types like % can not be stored directly. Store and retrieve them in wrapper objects.",
135: "Backups can not be run from clients and memory files.", // 60
136: "Backup in progress.",
137: "Only use persisted first class objects as keys for IdentityHashMap.",
138: "This functionality is only available from version 5.0 onwards.",
139: "By convention a Predicate needs the following method: public boolean match(ExtentClass extent){}",
140: "Old database file format detected. To allow automatic updates call Db4o.configure().allowVersionUpdates(true).", // 65
141: "This functionality is only available for indexed fields.", // 66
142: "This functionality is not supported for db4o clients in Client/Server mode.", // 67
143: "Invalid address: %",
144: "Maximum file size reached", // 69
145: };
146: } else {
147: i_messages = new String[0];
148: }
149: }
150:
151: }
152:
153: public static void logErr(Configuration config, int code,
154: String msg, Throwable t) {
155: if (config == null) {
156: config = Db4o.configure();
157: }
158: PrintStream ps = ((Config4Impl) config).errStream();
159: new Message(msg, code, ps);
160: if (t != null) {
161: new Message(null, 25, ps);
162: t.printStackTrace(ps);
163: new Message(null, 26, ps, false);
164: }
165: }
166:
167: public static void logMsg(Configuration config, int code, String msg) {
168: if (Deploy.debug) {
169: if (code == 0) {
170: System.out.println(msg);
171: return;
172: }
173: }
174: Config4Impl c4i = (Config4Impl) config;
175: if (c4i == null) {
176: c4i = (Config4Impl) Db4o.configure();
177: }
178:
179: if (c4i.messageLevel() > Const4.NONE) {
180: new Message(msg, code, c4i.outStream());
181: }
182: }
183: }
|