Changed logging infrastructure to be aware of localization; changed localization to return log-ready Message instances instead of strings. Changed tons of code to use the new logging and localization calls.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@429535 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2006-08-08 01:42:34 +00:00
parent f44dd067d8
commit 6234f8d3da
89 changed files with 478 additions and 409 deletions

View File

@ -185,7 +185,8 @@ public class MappingToolTask
conf.setClassResolver(resolver);
if (!MappingTool.run(conf, files, flags, loader))
throw new BuildException(_loc.get("bad-conf", "MappingToolTask"));
throw new BuildException(_loc.get("bad-conf", "MappingToolTask")
.getMessage());
}
public static class Action

View File

@ -133,7 +133,8 @@ public class SchemaToolTask
flags.writer = Files.getWriter(file, loader);
if (!SchemaTool.run((JDBCConfiguration) getConfiguration(), files,
flags, loader))
throw new BuildException(_loc.get("bad-conf", "SchemaToolTask"));
throw new BuildException(_loc.get("bad-conf", "SchemaToolTask")
.getMessage());
}
public static class Action

View File

@ -97,7 +97,7 @@ class PreparedStatementManagerImpl
else if (row.getAction() == Row.ACTION_INSERT)
throw new SQLException(_loc.get(
"update-failed-no-failed-obj", String.valueOf(count),
sql));
sql).getMessage());
}
} catch (SQLException se) {
throw SQLExceptions.getStore(se, row.getFailedObject(), _dict);

View File

@ -322,7 +322,7 @@ public class TableJDBCSeq
if (!setSequence(mapping, stat, alloc, updateStatSeq,
getConnection(store)))
throw(err != null) ? err : new SQLException(_loc.get
("no-seq-row", mapping, _table));
("no-seq-row", mapping, _table).getMessage());
}
}
catch (SQLException se2) {

View File

@ -34,9 +34,11 @@ import org.apache.openjpa.jdbc.schema.Unique;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.meta.MetaDataContext;
import org.apache.openjpa.util.MetaDataException;
import serp.util.Strings;
/**
@ -315,7 +317,7 @@ public abstract class MappingInfo {
return;
}
String msg = _loc.get("unexpected-cols", context);
Message msg = _loc.get("unexpected-cols", context);
if (die)
throw new MetaDataException(msg);
context.getRepository().getLog().warn(msg);
@ -344,7 +346,7 @@ public abstract class MappingInfo {
else
strat = contextStrat.getClass().getName();
String msg = _loc.get("unexpected-strategy", context, expected,
Message msg = _loc.get("unexpected-strategy", context, expected,
strat);
if (die)
throw new MetaDataException(msg);
@ -358,7 +360,7 @@ public abstract class MappingInfo {
if (_idx == null)
return;
String msg = _loc.get("unexpected-index", context);
Message msg = _loc.get("unexpected-index", context);
if (die)
throw new MetaDataException(msg);
context.getRepository().getLog().warn(msg);
@ -372,7 +374,7 @@ public abstract class MappingInfo {
if (_unq == null)
return;
String msg = _loc.get("unexpected-unique", context);
Message msg = _loc.get("unexpected-unique", context);
if (die)
throw new MetaDataException(msg);
context.getRepository().getLog().warn(msg);
@ -385,7 +387,7 @@ public abstract class MappingInfo {
if (_fk == null)
return;
String msg = _loc.get("unexpected-fk", context);
Message msg = _loc.get("unexpected-fk", context);
if (die)
throw new MetaDataException(msg);
context.getRepository().getLog().warn(msg);
@ -407,7 +409,7 @@ public abstract class MappingInfo {
if (!join)
return;
String msg = _loc.get("unexpected-join", context);
Message msg = _loc.get("unexpected-join", context);
if (die)
throw new MetaDataException(msg);
context.getRepository().getLog().warn(msg);
@ -643,7 +645,7 @@ public abstract class MappingInfo {
} else if ((compat || !ttype) && !col.isCompatible(type, size)) {
// if existing column isn't compatible with desired type, die if
// can't adapt, else warn and change the existing column type
String msg = _loc.get(prefix + "-bad-col", context,
Message msg = _loc.get(prefix + "-bad-col", context,
Schemas.getJDBCName(type), col.getDescription());
if (!adapt)
throw new MetaDataException(msg);

View File

@ -90,7 +90,7 @@ public class ClassNameDiscriminatorStrategy
className = dict.getString(rs, 1);
if (className == null || className.length() == 0)
throw new ClassNotFoundException(_loc.get("no-class-name",
disc.getClassMapping(), col));
disc.getClassMapping(), col).getMessage());
Class.forName(className, true, loader);
}
disc.setSubclassesLoaded(true);

View File

@ -95,7 +95,7 @@ public class ValueMapDiscriminatorStrategy
throw new ClassNotFoundException(_loc.get("unknown-discrim-value",
new Object[]{ str,
disc.getClassMapping().getDescribedType().getName(),
new TreeSet(_vals.keySet()) }));
new TreeSet(_vals.keySet()) }).getMessage());
}
/**

View File

@ -113,9 +113,10 @@ public class ForeignKey
String msg;
if (closest != null)
msg = _loc.get("bad-fk-action-hint", name, closest, recognized);
msg = _loc.get("bad-fk-action-hint", name, closest, recognized)
.getMessage();
else
msg = _loc.get("bad-fk-action", name, recognized);
msg = _loc.get("bad-fk-action", name, recognized).getMessage();
throw new IllegalArgumentException(msg);
}

View File

@ -51,7 +51,8 @@ public class NameSet {
protected void addName(String name, boolean validate) {
if (name == null || name.length() == 0) {
if (validate)
throw new IllegalArgumentException(_loc.get("bad-name", name));
throw new IllegalArgumentException(_loc.get("bad-name", name)
.getMessage());
return;
}

View File

@ -772,7 +772,7 @@ public class SchemaGenerator {
pkTable = group.findTable(pkTableName);
if (pkTable == null)
throw new SQLException(_loc.get("gen-nofktable",
table, pkTableName));
table, pkTableName).getMessage());
// this sucks, because it is *not* guaranteed to work;
// the fk resultset is ordered by primary key table, then
@ -870,7 +870,8 @@ public class SchemaGenerator {
for (Iterator i = _listeners.iterator(); i.hasNext();) {
Listener l = (Listener) i.next();
if (!l.schemaObjectGenerated(e))
throw new SQLException(_loc.get("refresh-cancelled"));
throw new SQLException(_loc.get("refresh-cancelled")
.getMessage());
}
}

View File

@ -28,6 +28,7 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.lib.meta.XMLMetaDataParser;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.util.UserException;
/**
@ -553,8 +554,8 @@ public class XMLSchemaParser
return new Double(val);
}
private void throwUserException(String msg) {
throw new UserException(getSourceName() + ": " + msg);
private void throwUserException(Message msg) {
throw new UserException(getSourceName() + ": " + msg.getMessage());
}
/**

View File

@ -81,6 +81,7 @@ import org.apache.openjpa.lib.jdbc.ConnectionDecorator;
import org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.GeneralException;
@ -1362,7 +1363,7 @@ public class DBDictionary
if (storageLimitationsFatal || (warn && log.isWarnEnabled())
|| (!warn && log.isTraceEnabled())) {
String msg = _loc.get("storage-restriction", new Object[]{
Message msg = _loc.get("storage-restriction", new Object[]{
platform,
orig,
orig.getClass().getName(),

View File

@ -19,6 +19,7 @@ import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.util.OpenJPAException;
import org.apache.openjpa.util.StoreException;
@ -63,6 +64,14 @@ public class SQLExceptions {
return getStore(se.getMessage(), se, failed, dict);
}
/**
* Convert the specified exception into a {@link StoreException}.
*/
public static OpenJPAException getStore(Message msg, SQLException se,
DBDictionary dict) {
return getStore(msg.getMessage(), se, null, dict);
}
/**
* Convert the specified exception into a {@link StoreException}.
*/

View File

@ -140,3 +140,4 @@ illegal-method: {0}.{1}() is illegal to be invoked
column-not-mapped: SQLResultSetMapping "{0}" does not map the columns "{1}" \
that are selected by the SQL query\r\n "{2}"
batch-license: Your license does not have SQL batching capabilities.
dictionary-configuration: DBDictionary configuration: \n{0}

View File

@ -73,7 +73,8 @@ public class MetaDataToolTask
flags.file = Files.getFile(fileName, loader);
if (!MetaDataTool.run((OpenJPAConfiguration) getConfiguration(), files,
flags, null, loader))
throw new BuildException(_loc.get("bad-conf", "MetaDataToolTask"));
throw new BuildException(_loc.get("bad-conf", "MetaDataToolTask")
.getMessage());
}
public static class Action

View File

@ -51,7 +51,7 @@ public class ProductDerivations {
if (derivations.isEmpty()) {
Localizer loc = Localizer.forPackage(ProductDerivations.class);
throw new MissingResourceException(loc.get("no-product-derivations",
ProductDerivation.class.getName()),
ProductDerivation.class.getName()).getMessage(),
ProductDerivations.class.getName(), "derivations");
}

View File

@ -47,7 +47,7 @@ class Caches {
classes = new HashSet();
classes.add(cls);
} catch (Throwable t) {
conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(t, t);
conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(null, t);
}
}
return classes;

View File

@ -96,7 +96,7 @@ public class DataCacheScheduler
_caches.put(cache, schedule);
_stop = false;
if (_thread == null) {
_thread = new Thread(this, _loc.get("scheduler-name"));
_thread = new Thread(this, _loc.get("scheduler-name").getMessage());
_thread.start();
if (_log.isTraceEnabled())
_log.trace(_loc.get("scheduler-start", _thread.getName()));
@ -191,7 +191,7 @@ public class DataCacheScheduler
}
private int[] parse(String token, int min, int max) {
if (token.trim().equals("*"))
if ("*".equals(token.trim()))
return WILDCARD;
String[] tokens = Strings.split(token, ",", 0);
int [] times = new int[tokens.length];

View File

@ -89,8 +89,8 @@ public class PCDataGenerator
if (storage == null) {
storage = generateStorage(meta);
_generated.put(type, storage);
if (_log.isDebugEnabled())
_log.debug(_loc.get("pcdata-created", type.getName(), meta));
if (_log.isTraceEnabled())
_log.trace(_loc.get("pcdata-created", type.getName(), meta));
}
DynamicPCData data = (DynamicPCData) storage.newInstance();
data.setId(oid);
@ -103,8 +103,8 @@ public class PCDataGenerator
* Actually generate the factory instance.
*/
private DynamicStorage generateStorage(ClassMetaData meta) {
if (_log.isDebugEnabled())
_log.debug(_loc.get("pcdata-generate", meta));
if (_log.isTraceEnabled())
_log.trace(_loc.get("pcdata-generate", meta));
FieldMetaData[] fields = meta.getFields();
int[] types = new int[fields.length];

View File

@ -51,6 +51,7 @@ import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Options;
import org.apache.openjpa.lib.util.Services;
import org.apache.openjpa.lib.util.TemporaryClassLoader;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.meta.JavaTypes;
@ -513,7 +514,7 @@ public class PCEnhancer {
if (itr.hasNext())
buf.append(sep);
}
String msg = _loc.get("property-violations", buf);
Message msg = _loc.get("property-violations", buf);
if (_fail)
throw new UserException(msg);
@ -730,7 +731,7 @@ public class PCEnhancer {
if (fmds[i].getManagement() != FieldMetaData.MANAGE_PERSISTENT)
continue;
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
switch (fmds[i].getDeclaredTypeCode()) {
case JavaTypes.BOOLEAN:
case JavaTypes.BYTE:
@ -884,11 +885,11 @@ public class PCEnhancer {
// <field> = pcStateManager.provided<type>Field
// (this, fieldNumber);
for (int i = 0; i < fmds.length; i++) {
tabins.addTarget(loadManagedInstance(code, false, false));
tabins.addTarget(loadManagedInstance(code, false));
code.getfield().setField(SM, SMTYPE);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.iload().setParam(0);
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
addGetManagedValueCode(code, fmds[i]);
code.invokeinterface().setMethod(getStateManagerMethod
(fmds[i].getDeclaredType(), "provided", false, false));
@ -935,11 +936,11 @@ public class PCEnhancer {
// (this, fieldNumber);
for (int i = 0; i < fmds.length; i++) {
// for the addSetManagedValueCode call below.
tabins.addTarget(loadManagedInstance(code, true, false));
tabins.addTarget(loadManagedInstance(code, false));
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.iload().setParam(0);
code.invokeinterface().setMethod(getStateManagerMethod
(fmds[i].getDeclaredType(), "replace", true, false));
@ -990,7 +991,7 @@ public class PCEnhancer {
for (int i = 0; i < fmds.length; i++) {
// <field> = other.<field>;
// or set<field> (other.get<field>);
tabins.addTarget(loadManagedInstance(code, true, false));
tabins.addTarget(loadManagedInstance(code, false));
code.aload().setParam(0);
addGetManagedValueCode(code, fmds[i]);
addSetManagedValueCode(code, fmds[i]);
@ -1035,7 +1036,7 @@ public class PCEnhancer {
// no super: if (rel < 0) throw new IllegalArgumentException ();
JumpInstruction ifins = code.ifge();
if (_meta.getPCSuperclass() != null) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
String[] args;
if (copy) {
args = new String[]{ _meta.getPCSuperclass().getName(),
@ -1087,7 +1088,7 @@ public class PCEnhancer {
// throw new IllegalArgumentException
code.aload().setLocal(inst);
code.getfield().setField(SM, SMTYPE);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
JumpInstruction ifins = code.ifacmpeq();
throwException(code, IllegalArgumentException.class);
@ -1095,7 +1096,7 @@ public class PCEnhancer {
// if (pcStateManager == null)
// throw new IllegalStateException
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
ifins = code.ifnonnull();
throwException(code, IllegalStateException.class);
@ -1109,7 +1110,7 @@ public class PCEnhancer {
JumpInstruction testins = code.go2();
// <method> (fields[i]);
Instruction bodyins = loadManagedInstance(code, false, false);
Instruction bodyins = loadManagedInstance(code, false);
if (copy)
code.aload().setLocal(inst);
code.aload().setParam(fieldNumbers);
@ -1178,7 +1179,7 @@ public class PCEnhancer {
BCMethod meth = _pc.declareMethod(PRE + "GetStateManager",
StateManager.class, null);
Code code = meth.getCode(true);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, StateManager.class);
code.areturn();
code.calculateMaxStack();
@ -1202,7 +1203,7 @@ public class PCEnhancer {
Code code = method.getCode(true);
// if (pcStateManager == null) return <default>;
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
JumpInstruction ifins = code.ifnonnull();
if (returnType.equals(boolean.class))
@ -1212,7 +1213,7 @@ public class PCEnhancer {
code.xreturn().setType(returnType);
// return pcStateManager.<method> (<args>);
ifins.setTarget(loadManagedInstance(code, false, false));
ifins.setTarget(loadManagedInstance(code, false));
code.getfield().setField(SM, SMTYPE);
for (int i = 0; i < params.length; i++)
code.xload().setParam(i);
@ -1233,7 +1234,7 @@ public class PCEnhancer {
Code code = method.getCode(true);
// if (pcStateManager == null)
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
JumpInstruction ifins = code.ifnonnull();
FieldMetaData versionField = _meta.getVersionField();
@ -1247,7 +1248,7 @@ public class PCEnhancer {
code.anew().setType(wrapper);
code.dup();
}
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
addGetManagedValueCode(code, versionField);
if (wrapper != null)
code.invokespecial().setMethod(wrapper, "<init>", void.class,
@ -1256,7 +1257,7 @@ public class PCEnhancer {
code.areturn();
// return pcStateManager.getVersion ();
ifins.setTarget(loadManagedInstance(code, false, false));
ifins.setTarget(loadManagedInstance(code, false));
code.getfield().setField(SM, SMTYPE);
code.invokeinterface().setMethod(SMTYPE, "getVersion", Object.class,
null);
@ -1297,14 +1298,14 @@ public class PCEnhancer {
Code code = method.getCode(true);
// if (pcStateManager != null)
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
JumpInstruction ifins = code.ifnonnull();
code.vreturn();
// pcFlags = pcStateManager.replaceFlags ();
ifins.setTarget(loadManagedInstance(code, false, false));
loadManagedInstance(code, false, false);
ifins.setTarget(loadManagedInstance(code, false));
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
code.invokeinterface().setMethod(SMTYPE, "replaceFlags",
byte.class, null);
@ -1329,11 +1330,11 @@ public class PCEnhancer {
// if (pcStateManager != null)
// pcStateManager = pcStateManager.replaceStateManager(sm);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
JumpInstruction ifins = code.ifnull();
loadManagedInstance(code, false, false);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
code.aload().setParam(0);
code.invokeinterface().setMethod(SMTYPE, "replaceStateManager",
@ -1348,7 +1349,7 @@ public class PCEnhancer {
"getSecurityManager", SecurityManager.class, null));
// pcStateManager = sm;
ifins.setTarget(loadManagedInstance(code, false, false));
ifins.setTarget(loadManagedInstance(code, false));
code.aload().setParam(0);
code.putfield().setField(SM, SMTYPE);
code.vreturn();
@ -1438,7 +1439,7 @@ public class PCEnhancer {
// call superclass method
if (_meta.getPCSuperclass() != null) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
for (int i = 0; i < args.length; i++)
code.aload().setParam(i);
code.invokespecial().setMethod(_meta.getPCSuperclass().getName(),
@ -1496,7 +1497,7 @@ public class PCEnhancer {
&& !type.getName().equals(String.class.getName()))
code.checkcast().setType(type);
} else {
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
addGetManagedValueCode(code, fmds[i]);
}
@ -1531,7 +1532,7 @@ public class PCEnhancer {
// call superclass method
if (_meta.getPCSuperclass() != null) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
for (int i = 0; i < args.length; i++)
code.aload().setParam(i);
code.invokespecial().setMethod(_meta.getPCSuperclass().getName(),
@ -1585,7 +1586,7 @@ public class PCEnhancer {
code.iload().setLocal(inherited);
code.iadd();
} else
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
if (unwrapped != type) {
code.anew().setType(type);
@ -1710,7 +1711,7 @@ public class PCEnhancer {
if (obj && usesClsString == null) {
// throw new IllegalArgumentException (...);
String msg = _loc.get("str-cons", oidType,
_meta.getDescribedType());
_meta.getDescribedType()).getMessage();
code.anew().setType(IllegalArgumentException.class);
code.dup();
code.constant().setValue(msg);
@ -1745,7 +1746,7 @@ public class PCEnhancer {
args = new Class[]{ String.class };
} else if (_meta.isOpenJPAIdentity()) {
// new <type>Identity (XXX.class, <pk>);
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
FieldMetaData pk = _meta.getPrimaryKeyFields()[0];
addGetManagedValueCode(code, pk);
if (_meta.getObjectIdType() == ObjectId.class)
@ -2112,7 +2113,7 @@ public class PCEnhancer {
code.beforeFirst();
// bool clear = pcSerializing ();
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.invokevirtual().setMethod(PRE + "Serializing",
boolean.class, null);
int clear = code.getNextLocalsIndex();
@ -2135,7 +2136,7 @@ public class PCEnhancer {
// if (clear) pcSetDetachedState (null);
code.iload().setLocal(clear);
toret = code.ifeq();
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.constant().setNull();
code.invokevirtual().setMethod(PRE + "SetDetachedState",
void.class, new Class[]{ Object.class });
@ -2157,7 +2158,7 @@ public class PCEnhancer {
// if this instance uses synthetic detached state, note that it has
// been deserialized
if (ClassMetaData.SYNTHETIC.equals(_meta.getDetachedState())) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getstatic().setField(PersistenceCapable.class,
"DESERIALIZED", Object.class);
code.invokevirtual().setMethod(PRE + "SetDetachedState",
@ -2207,10 +2208,10 @@ public class PCEnhancer {
// if (sm != null)
// return (sm.isDetached ()) ? Boolean.TRUE : Boolean.FALSE;
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
JumpInstruction ifins = code.ifnull();
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
code.invokeinterface().setMethod(SMTYPE, "isDetached",
boolean.class, null);
@ -2229,11 +2230,11 @@ public class PCEnhancer {
JumpInstruction notdeser = null;
Instruction target;
if (state != Boolean.FALSE) {
ifins.setTarget(loadManagedInstance(code, false, false));
ifins.setTarget(loadManagedInstance(code, false));
code.invokevirtual().setMethod(PRE + "GetDetachedState",
Object.class, null);
ifins = code.ifnull();
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.invokevirtual().setMethod(PRE + "GetDetachedState",
Object.class, null);
code.getstatic().setField(PersistenceCapable.class,
@ -2269,7 +2270,7 @@ public class PCEnhancer {
if (state != Boolean.TRUE && version != null) {
// if (<version> != <default>)
// return true;
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
addGetManagedValueCode(code, version);
ifins = ifDefaultValue(code, version);
code.getstatic().setField(Boolean.class, "TRUE", Boolean.class);
@ -2300,7 +2301,7 @@ public class PCEnhancer {
if (state == null) {
// if (pcGetDetachedState () == null) // instead of DESERIALIZED
// return Boolean.FALSE;
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.invokevirtual().setMethod(PRE + "GetDetachedState",
Object.class, null);
ifins = code.ifnonnull();
@ -2322,7 +2323,7 @@ public class PCEnhancer {
if (pks[i].getValueStrategy() == ValueStrategies.NONE)
continue;
target = loadManagedInstance(code, false, false);
target = loadManagedInstance(code, false);
if (ifins != null)
ifins.setTarget(target);
if (ifins2 != null)
@ -2333,7 +2334,7 @@ public class PCEnhancer {
ifins = ifDefaultValue(code, pks[i]);
if (pks[i].getDeclaredTypeCode() == JavaTypes.STRING) {
code.constant().setValue("");
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
addGetManagedValueCode(code, pks[i]);
code.invokevirtual().setMethod(String.class, "equals",
boolean.class, new Class[]{ Object.class });
@ -2451,7 +2452,7 @@ public class PCEnhancer {
code = clone.getCode(true);
// return super.clone ();
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
code.invokespecial().setMethod(_pc.getSuperclassName(),
"clone", Object.class.getName(), null);
code.areturn();
@ -2681,7 +2682,7 @@ public class PCEnhancer {
byte fieldFlag = getFieldFlag(fmd);
if ((fieldFlag & PersistenceCapable.CHECK_READ) == 0
&& (fieldFlag & PersistenceCapable.MEDIATE_READ) == 0) {
loadManagedInstance(code, true, true);
loadManagedInstance(code, true);
addGetManagedValueCode(code, fmd);
code.xreturn().setType(fmd.getDeclaredType());
@ -2693,21 +2694,21 @@ public class PCEnhancer {
// dfg: if (inst.pcFlags <= 0) return inst.<field>;
JumpInstruction ifins = null;
if ((fieldFlag & PersistenceCapable.CHECK_READ) > 0) {
loadManagedInstance(code, false, true);
loadManagedInstance(code, true);
code.getfield().setField(PRE + "Flags", byte.class);
ifins = code.ifgt();
loadManagedInstance(code, true, true);
loadManagedInstance(code, true);
addGetManagedValueCode(code, fmd);
code.xreturn().setType(fmd.getDeclaredType());
}
// if (inst.pcStateManager == null) return inst.<field>;
Instruction ins = loadManagedInstance(code, false, true);
Instruction ins = loadManagedInstance(code, true);
if (ifins != null)
ifins.setTarget(ins);
code.getfield().setField(SM, SMTYPE);
ifins = code.ifnonnull();
loadManagedInstance(code, true, true);
loadManagedInstance(code, true);
addGetManagedValueCode(code, fmd);
code.xreturn().setType(fmd.getDeclaredType());
@ -2720,12 +2721,12 @@ public class PCEnhancer {
// inst.pcStateManager.accessingField (field);
// return inst.<field>;
loadManagedInstance(code, false, true);
loadManagedInstance(code, true);
code.getfield().setField(SM, SMTYPE);
code.iload().setLocal(fieldLocal);
code.invokeinterface().setMethod(SMTYPE, "accessingField", void.class,
new Class[]{ int.class });
loadManagedInstance(code, true, true);
loadManagedInstance(code, true);
addGetManagedValueCode(code, fmd);
code.xreturn().setType(fmd.getDeclaredType());
@ -2753,35 +2754,35 @@ public class PCEnhancer {
JumpInstruction ifins = null;
byte fieldFlag = getFieldFlag(fmd);
if ((fieldFlag & PersistenceCapable.CHECK_WRITE) > 0) {
loadManagedInstance(code, false, true);
loadManagedInstance(code, true);
code.getfield().setField(PRE + "Flags", byte.class);
ifins = code.ifne();
loadManagedInstance(code, true, true);
loadManagedInstance(code, true);
code.xload().setParam(firstParamOffset);
addSetManagedValueCode(code, fmd);
code.vreturn();
}
// if (inst.pcStateManager == null) inst.<field> = value;
Instruction ins = loadManagedInstance(code, false, true);
Instruction ins = loadManagedInstance(code, true);
if (ifins != null)
ifins.setTarget(ins);
code.getfield().setField(SM, SMTYPE);
ifins = code.ifnonnull();
loadManagedInstance(code, true, true);
loadManagedInstance(code, true);
code.xload().setParam(firstParamOffset);
addSetManagedValueCode(code, fmd);
code.vreturn();
// inst.pcStateManager.setting<fieldType>Field (inst,
// pcInheritedFieldCount + <index>, inst.<field>, value, 0);
ifins.setTarget(loadManagedInstance(code, false, true));
ifins.setTarget(loadManagedInstance(code, true));
code.getfield().setField(SM, SMTYPE);
loadManagedInstance(code, false, true);
loadManagedInstance(code, true);
code.getstatic().setField(INHERIT, int.class);
code.constant().setValue(index);
code.iadd();
loadManagedInstance(code, true, true);
loadManagedInstance(code, true);
addGetManagedValueCode(code, fmd);
code.xload().setParam(firstParamOffset);
code.constant().setValue(0);
@ -2860,7 +2861,7 @@ public class PCEnhancer {
Code code = method.getCode(true);
if (impl) {
// return pcDetachedState;
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
code.getfield().setField(declarer, name, Object.class.getName());
} else
code.constant().setNull();
@ -2875,7 +2876,7 @@ public class PCEnhancer {
code = method.getCode(true);
if (impl) {
// pcDetachedState = state;
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.putfield().setField(declarer, name,
Object.class.getName());
@ -2941,21 +2942,21 @@ public class PCEnhancer {
// super.readExternal (in);
Class sup = _meta.getDescribedType().getSuperclass();
if (!parentDetachable && Externalizable.class.isAssignableFrom(sup)) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokespecial().setMethod(sup, "readExternal",
void.class, inargs);
}
// readUnmanaged (in);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokevirtual().setMethod(_meta.getDescribedType(),
PRE + "ReadUnmanaged", void.class, inargs);
if (detachedState) {
// pcSetDetachedState (in.readObject ());
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokeinterface().setMethod(ObjectInput.class, "readObject",
Object.class, null);
@ -2963,7 +2964,7 @@ public class PCEnhancer {
void.class, new Class[]{ Object.class });
// pcReplaceStateManager ((StateManager) in.readObject ());
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokeinterface().setMethod(ObjectInput.class, "readObject",
Object.class, null);
@ -3000,7 +3001,7 @@ public class PCEnhancer {
// super.readUnmanaged (in);
if (parentDetachable) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokespecial().setMethod(_meta.getPCSuperclass(),
PRE + "ReadUnmanaged", void.class, inargs);
@ -3033,7 +3034,7 @@ public class PCEnhancer {
methName = "readObject";
// <field> = in.read<type> ();
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
Class ret = (type.isPrimitive()) ? type : Object.class;
code.invokeinterface().setMethod(ObjectInput.class, methName,
@ -3053,10 +3054,10 @@ public class PCEnhancer {
case JavaTypes.CALENDAR:
// if (sm != null)
// sm.proxyDetachedDeserialized (<index>);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
IfInstruction ifins = code.ifnull();
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
code.constant().setValue(fmd.getIndex());
code.invokeinterface().setMethod(SMTYPE,
@ -3082,14 +3083,14 @@ public class PCEnhancer {
// super.writeExternal (out);
Class sup = _meta.getDescribedType().getSuperclass();
if (!parentDetachable && Externalizable.class.isAssignableFrom(sup)) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokespecial().setMethod(sup, "writeExternal",
void.class, outargs);
}
// writeUnmanaged (out);
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokevirtual().setMethod(_meta.getDescribedType(),
PRE + "WriteUnmanaged", void.class, outargs);
@ -3099,10 +3100,10 @@ public class PCEnhancer {
// if (sm != null)
// if (sm.writeDetached (out))
// return;
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
IfInstruction ifnull = code.ifnull();
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.getfield().setField(SM, SMTYPE);
code.aload().setParam(0);
code.invokeinterface().setMethod(SMTYPE, "writeDetached",
@ -3114,7 +3115,7 @@ public class PCEnhancer {
// out.writeObject (pcGetDetachedState ());
Class[] objargs = new Class[]{ Object.class };
ifnull.setTarget(code.aload().setParam(0));
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.invokevirtual().setMethod(PRE + "GetDetachedState",
Object.class, null);
code.invokeinterface().setMethod(ObjectOutput.class,
@ -3133,7 +3134,7 @@ public class PCEnhancer {
for (int i = 0; i < fmds.length; i++)
if (!fmds[i].isTransient())
writeExternal(code, fmds[i].getName(),
fmds[i].getDeclaredType(), i, fmds[i]);
fmds[i].getDeclaredType(), fmds[i]);
// return
code.vreturn();
@ -3156,7 +3157,7 @@ public class PCEnhancer {
// super.writeUnmanaged (out);
if (parentDetachable) {
loadManagedInstance(code, false, false);
loadManagedInstance(code, false);
code.aload().setParam(0);
code.invokespecial().setMethod(_meta.getPCSuperclass(),
PRE + "WriteUnmanaged", void.class, outargs);
@ -3166,7 +3167,7 @@ public class PCEnhancer {
BCField field;
for (Iterator itr = unmgd.iterator(); itr.hasNext();) {
field = (BCField) itr.next();
writeExternal(code, field.getName(), field.getType(), -1, null);
writeExternal(code, field.getName(), field.getType(), null);
}
code.vreturn();
code.calculateMaxStack();
@ -3177,7 +3178,7 @@ public class PCEnhancer {
* Helper method to write a field to an externalization output stream.
*/
private void writeExternal(Code code, String fieldName, Class type,
int idx, FieldMetaData fmd)
FieldMetaData fmd)
throws NoSuchMethodException {
String methName;
if (type.isPrimitive()) {
@ -3190,7 +3191,7 @@ public class PCEnhancer {
// out.write<type> (<field>);
code.aload().setParam(0);
loadManagedInstance(code, true, false);
loadManagedInstance(code, false);
if (fmd == null)
code.getfield().setField(fieldName, type);
else
@ -3256,7 +3257,7 @@ public class PCEnhancer {
*
* @return the first instruction added to <code>code</code>.
*/
private Instruction loadManagedInstance(Code code, boolean userObject,
private Instruction loadManagedInstance(Code code,
boolean forAccessor) {
if (_meta.getAccessType() == ClassMetaData.ACCESS_FIELD && forAccessor)
return code.aload().setParam(0);

View File

@ -82,10 +82,6 @@ public class LogOrphanedKeyAction
if (log.isTraceEnabled())
log.trace(_loc.get(msg, oid, vmd, owner));
break;
case Log.DEBUG:
if (log.isDebugEnabled())
log.debug(_loc.get(msg, oid, vmd, owner));
break;
case Log.INFO:
if (log.isInfoEnabled())
log.info(_loc.get(msg, oid, vmd, owner));

View File

@ -235,7 +235,8 @@ public abstract class AbstractBrokerFactory
try {
Class.forName((String) itr.next(), true, loader);
} catch (Throwable t) {
_conf.getLog(OpenJPAConfiguration.LOG_RUNTIME).warn(t, t);
_conf.getLog(OpenJPAConfiguration.LOG_RUNTIME)
.warn(null, t);
}
}
}
@ -515,7 +516,7 @@ public abstract class AbstractBrokerFactory
if (itr.hasNext())
buf.append(lineSep);
}
log.trace(buf.toString());
log.trace(_loc.get("factory-properties", buf.toString()));
}
// setup transient state

View File

@ -3989,7 +3989,7 @@ public class BrokerImpl
//### JDO2
if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers()))
throw new UnsupportedOperationException(_loc.get
("new-abstract", cls));
("new-abstract", cls).getMessage());
// 1.5 doesn't initialize classes without a true Class.forName
if (!PCRegistry.isRegistered(cls)) {

View File

@ -18,7 +18,6 @@ package org.apache.openjpa.kernel;
import java.util.BitSet;
import org.apache.openjpa.enhance.PersistenceCapable;
import org.apache.openjpa.event.LifecycleEvent;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;

View File

@ -378,7 +378,7 @@ public class DetachedStateManager
public void accessingField(int idx) {
if (!_access && !_loaded.get(idx))
throw new IllegalStateException(_loc.get("unloaded-detached",
_pc));
_pc).getMessage());
}
public boolean serializing() {

View File

@ -276,7 +276,7 @@ public class Filters {
}
if (!num)
throw new ClassCastException(_loc.get("cant-convert", o,
o.getClass(), type));
o.getClass(), type).getMessage());
if (type == Integer.class) {
return Numbers.valueOf(((Number) o).intValue());

View File

@ -24,6 +24,7 @@ import java.util.Set;
import org.apache.openjpa.kernel.Filters;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.util.InternalException;
@ -97,11 +98,11 @@ public abstract class AbstractExpressionBuilder {
Exception nest) {
String argStr;
if (args == null)
argStr = getLocalizer().get(token);
argStr = getLocalizer().get(token).getMessage();
else
argStr = getLocalizer().get(token, args);
argStr = getLocalizer().get(token, args).getMessage();
String msg = _loc.get("parse-error", argStr, currentQuery());
Message msg = _loc.get("parse-error", argStr, currentQuery());
switch (e) {
case EX_FATAL:
@ -361,14 +362,14 @@ public abstract class AbstractExpressionBuilder {
String right;
if (val1 instanceof Path && ((Path) val1).last() != null)
left = _loc.get("non-numeric-path", ((Path) val1).last().
getName(), t1.getName());
getName(), t1.getName()).getMessage();
else
left = _loc.get("non-numeric-value", t1.getName());
left = _loc.get("non-numeric-value", t1.getName()).getMessage();
if (val2 instanceof Path && ((Path) val2).last() != null)
right = _loc.get("non-numeric-path", ((Path) val2).last().
getName(), t2.getName());
getName(), t2.getName()).getMessage();
else
right = _loc.get("non-numeric-value", t2.getName());
right = _loc.get("non-numeric-value", t2.getName()).getMessage();
throw new UserException(_loc.get("non-numeric-comparison",
left, right));
}

View File

@ -18,6 +18,7 @@ package org.apache.openjpa.kernel.jpql;
import java.util.TreeSet;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.util.UserException;
/**
@ -28,7 +29,8 @@ import org.apache.openjpa.util.UserException;
public class ParseException
extends UserException {
private static Localizer _loc = Localizer.forPackage(ParseException.class);
private static final Localizer _loc =
Localizer.forPackage(ParseException.class);
/**
* This constructor is used by the method "generateParseException"
@ -59,10 +61,6 @@ public class ParseException
super();
}
public ParseException(String message) {
super(message);
}
/**
* This method has the standard behavior when this object has been
* created using the standard constructors. Otherwise, it uses
@ -73,7 +71,7 @@ public class ParseException
* of the final stack trace, and hence the correct error message
* gets displayed.
*/
private static String initMessage(Token currentToken,
private static Message initMessage(Token currentToken,
int[][]expectedTokenSequences, String[]tokenImage) {
TreeSet expected = new TreeSet();

View File

@ -320,7 +320,7 @@ public abstract class Extensions {
// way a new vendor could theoretically add in their
// own prefix into the localizer.properties file and
// not have to issue warnings for their extensions
String prefixes = _loc.get("extension-datastore-prefix");
String prefixes = _loc.get("extension-datastore-prefix").getMessage();
String[] allowedPrefixes = null;
if (prefixes != null)
allowedPrefixes = Strings.split(prefixes, ",", 0);

View File

@ -80,9 +80,10 @@ public class UpdateStrategies {
String msg;
if (closest != null)
msg = _loc.get("bad-update-strategy-hint", new Object[]{
context, val, closest, opts });
context, val, closest, opts }).getMessage();
else
msg = _loc.get("bad-update-strategy", context, val, opts);
msg = _loc.get("bad-update-strategy", context, val, opts)
.getMessage();
throw new IllegalArgumentException(msg);
}
}

View File

@ -108,9 +108,10 @@ public class ValueStrategies {
String msg;
if (closest != null)
msg = _loc.get("bad-value-strategy-hint", new Object[]{
context, val, closest, _map.keySet() });
context, val, closest, _map.keySet() }).getMessage();
else
msg = _loc.get("bad-value-strategy", context, val, _map.keySet());
msg = _loc.get("bad-value-strategy", context, val, _map.keySet())
.getMessage();
throw new IllegalArgumentException(msg);
}

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type thrown when an error occurs in a callback.
*
@ -24,18 +26,10 @@ package org.apache.openjpa.util;
public class CallbackException
extends UserException {
public CallbackException() {
}
public CallbackException(String msg) {
public CallbackException(Message msg) {
super(msg);
}
public CallbackException(String msg, Object failed) {
super(msg);
setFailedObject(failed);
}
public int getSubtype() {
return CALLBACK;
}

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* General exception type.
*
@ -30,11 +32,15 @@ public class GeneralException
super(msg);
}
public GeneralException(Message msg) {
super(msg);
}
public GeneralException(Throwable cause) {
super(cause);
}
public GeneralException(String msg, Throwable cause) {
public GeneralException(Message msg, Throwable cause) {
super(msg, cause);
}

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type for internal errors.
*
@ -33,6 +35,11 @@ public class InternalException
setFatal(true);
}
public InternalException(Message msg) {
super(msg);
setFatal(true);
}
public InternalException(Throwable cause) {
super(cause);
setFatal(true);
@ -43,6 +50,11 @@ public class InternalException
setFatal(true);
}
public InternalException(Message msg, Throwable cause) {
super(msg, cause);
setFatal(true);
}
public int getType() {
return INTERNAL;
}

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type thrown when attempting to execute an operation that
* is not allowed by the current state.
@ -25,14 +27,11 @@ package org.apache.openjpa.util;
public class InvalidStateException
extends UserException {
public InvalidStateException() {
}
public InvalidStateException(String msg) {
public InvalidStateException(Message msg) {
super(msg);
}
public InvalidStateException(String msg, Object failed) {
public InvalidStateException(Message msg, Object failed) {
super(msg);
setFailedObject(failed);
}

View File

@ -35,13 +35,6 @@ public class LockException
private int timeout = -1;
public LockException() {
}
public LockException(String msg) {
super(msg);
}
public LockException(Object failed) {
super(_loc.get("lock-failed", Exceptions.toString(failed)));
setFailedObject(failed);

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type reserved for missing or invalid metadata.
*
@ -33,7 +35,12 @@ public class MetaDataException
setFatal(true);
}
public MetaDataException(String msg, Object failed) {
public MetaDataException(Message msg) {
super(msg);
setFatal(true);
}
public MetaDataException(Message msg, Object failed) {
super(msg);
setFatal(true);
setFailedObject(failed);

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type thrown when attempting a transactional operation without
* an active transaction.
@ -25,18 +27,10 @@ package org.apache.openjpa.util;
public class NoTransactionException
extends InvalidStateException {
public NoTransactionException() {
}
public NoTransactionException(String msg) {
public NoTransactionException(Message msg) {
super(msg);
}
public NoTransactionException(String msg, Object failed) {
super(msg);
setFailedObject(failed);
}
public int getSubtype() {
return NO_TRANSACTION;
}

View File

@ -15,7 +15,7 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type reserved for conflicts with existing objects.
@ -25,21 +25,10 @@ import org.apache.openjpa.lib.util.Localizer;
public class ObjectExistsException
extends StoreException {
private static final transient Localizer _loc = Localizer.forPackage
(ObjectExistsException.class);
public ObjectExistsException() {
}
public ObjectExistsException(String msg) {
public ObjectExistsException(Message msg) {
super(msg);
}
public ObjectExistsException(Object failed) {
super(_loc.get("obj-exists", Exceptions.toString(failed)));
setFailedObject(failed);
}
public int getSubtype() {
return OBJECT_EXISTS;
}

View File

@ -18,6 +18,7 @@ package org.apache.openjpa.util;
import java.util.Collection;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type reserved for failed object lookups.
@ -30,10 +31,7 @@ public class ObjectNotFoundException
private static final transient Localizer _loc = Localizer.forPackage
(ObjectNotFoundException.class);
public ObjectNotFoundException() {
}
public ObjectNotFoundException(String msg) {
public ObjectNotFoundException(Message msg) {
super(msg);
}

View File

@ -22,6 +22,8 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type for all OpenJPA exceptions. Meant to be easily
* transformed into an appropriate exception at the API layer, since most APIs
@ -51,6 +53,13 @@ public abstract class OpenJPAException
super(msg);
}
/**
* Constructor; supply message.
*/
public OpenJPAException(Message msg) {
super(msg.getMessage());
}
/**
* Construct with cause.
*/
@ -66,6 +75,14 @@ public abstract class OpenJPAException
setCause(cause);
}
/**
* Construct with message and cause.
*/
public OpenJPAException(Message msg, Throwable cause) {
super(msg.getMessage());
setCause(cause);
}
/**
* Exception type.
*/

View File

@ -18,6 +18,7 @@ package org.apache.openjpa.util;
import java.util.Collection;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type for optimistic concurrency violations.
@ -32,10 +33,7 @@ public class OptimisticException
private static final transient Localizer _loc = Localizer.forPackage
(OptimisticException.class);
public OptimisticException() {
}
public OptimisticException(String msg) {
public OptimisticException(Message msg) {
super(msg);
}

View File

@ -40,9 +40,6 @@ public class ReferentialIntegrityException
private int _iv = IV_UNKNOWN;
public ReferentialIntegrityException() {
}
public ReferentialIntegrityException(String msg) {
super(msg);
}
@ -55,11 +52,11 @@ public class ReferentialIntegrityException
private static String getMessage(int iv) {
switch (iv) {
case IV_DUPLICATE_OID:
return _loc.get("dup-oid");
return _loc.get("dup-oid").getMessage();
case IV_UNIQUE:
return _loc.get("unique");
return _loc.get("unique").getMessage();
default:
return _loc.get("ref-integrity");
return _loc.get("ref-integrity").getMessage();
}
}

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Base exception for data store errors.
*
@ -30,21 +32,18 @@ public class StoreException
public static final int REFERENTIAL_INTEGRITY = 4;
public static final int OBJECT_EXISTS = 5;
public StoreException() {
}
public StoreException(String msg) {
super(msg);
}
public StoreException(Message msg) {
super(msg.getMessage());
}
public StoreException(Throwable cause) {
super(cause);
}
public StoreException(String msg, Throwable cause) {
super(msg, cause);
}
public int getType() {
return STORE;
}

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Exception type for attempts to perform unsupported operations.
*
@ -33,12 +35,12 @@ public class UnsupportedException
setFatal(true);
}
public UnsupportedException(Throwable cause) {
super(cause);
public UnsupportedException(Message msg) {
super(msg);
setFatal(true);
}
public UnsupportedException(String msg, Throwable cause) {
public UnsupportedException(Message msg, Throwable cause) {
super(msg, cause);
setFatal(true);
}

View File

@ -15,6 +15,8 @@
*/
package org.apache.openjpa.util;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Base exception type for user errors.
*
@ -36,6 +38,10 @@ public class UserException
super(msg);
}
public UserException(Message msg) {
super(msg);
}
public UserException(Throwable cause) {
super(cause);
}
@ -44,6 +50,10 @@ public class UserException
super(msg, cause);
}
public UserException(Message msg, Throwable cause) {
super(msg, cause);
}
public int getType() {
return USER;
}

View File

@ -161,6 +161,7 @@ objectid-abstract: Cannot create new application identity instance for \
bad-id-value: The given value "{0}" cannot be converted into an identity \
for "{2}". The value is the wrong type ({1}).
factory-init: Starting OpenJPA {0}
factory-properties: Properties: {0}
inverse-consistency: An inverse inconsistency in the object model was \
detected while flushing the field "{0}" of the instance with id "{1}" \
in context "{2}".

View File

@ -126,7 +126,7 @@ public abstract class AbstractTask extends MatchingTask {
*/
protected void assertFiles(String[] files) {
if (files.length == 0)
throw new BuildException(_loc.get("no-filesets"));
throw new BuildException(_loc.get("no-filesets").getMessage());
}
public void setClasspath(Path classPath) {

View File

@ -276,7 +276,7 @@ public class ConfigurationImpl
}
if (errs != null)
throw new RuntimeException(_loc.get("get-prop-errs",
errs.toString()));
errs.toString()).getMessage());
}
public boolean isReadOnly() {
@ -503,7 +503,7 @@ public class ConfigurationImpl
if (scope != null) {
loc = Localizer.forPackage(scope);
try {
return loc.getFatal(key);
return loc.getFatal(key).getMessage();
} catch (MissingResourceException mse) {
}
}
@ -512,7 +512,7 @@ public class ConfigurationImpl
cls = cls.getSuperclass()) {
loc = Localizer.forPackage(cls);
try {
return loc.getFatal(key);
return loc.getFatal(key).getMessage();
} catch (MissingResourceException mse) {
}
}
@ -670,7 +670,8 @@ public class ConfigurationImpl
// if we've already found a property with a previous prefix,
// then this is a collision.
throw new IllegalStateException(
_loc.get("dup-with-different-prefixes", firstKey, key));
_loc.get("dup-with-different-prefixes", firstKey, key)
.getMessage());
}
}
if (firstKey != null && setLoadKey)
@ -761,7 +762,7 @@ public class ConfigurationImpl
*/
public void assertNotReadOnly() {
if (isReadOnly())
throw new IllegalStateException(_loc.get("read-only"));
throw new IllegalStateException(_loc.get("read-only").getMessage());
}
/**

View File

@ -140,7 +140,7 @@ public class Configurations {
throw re;
Log log = (conf == null) ? null : conf.getConfigurationLog();
if (log != null && log.isErrorEnabled())
log.error(re);
log.error(_loc.get("plugin-creation-exception", val), re);
return null;
}
@ -148,12 +148,12 @@ public class Configurations {
return cls.newInstance();
} catch (Exception e) {
RuntimeException re = new NestableRuntimeException(_loc.get
("obj-create", cls), e);
("obj-create", cls).getMessage(), e);
if (fatal)
throw re;
Log log = (conf == null) ? null : conf.getConfigurationLog();
if (log != null && log.isErrorEnabled())
log.error(re);
log.error(_loc.get("plugin-creation-exception", val), re);
return null;
}
}
@ -279,7 +279,7 @@ public class Configurations {
((GenericConfigurable) obj).setInto(invalidEntries);
if (!invalidEntries.isEmpty() && configurationName != null) {
String msg = null;
Localizer.Message msg = null;
String first = (String) invalidEntries.keySet().iterator().next();
if (invalidEntries.keySet().size() == 1 &&
first.indexOf('.') == -1) {
@ -460,7 +460,7 @@ public class Configurations {
Configurations.class.getName(), "defaults");
if (providerCount == 0)
throw new MissingResourceException(_loc.get ("no-providers",
ConfigurationProvider.class.getName()),
ConfigurationProvider.class.getName()).getMessage(),
Configurations.class.getName(), "defaults");
return null;
}
@ -518,9 +518,9 @@ public class Configurations {
msg = errs.toString();
else if (providerCount == 0)
msg = _loc.get("no-providers",
ConfigurationProvider.class.getName());
ConfigurationProvider.class.getName()).getMessage();
else
msg = _loc.get("no-provider", resource);
msg = _loc.get("no-provider", resource).getMessage();
throw new MissingResourceException(msg,
Configurations.class.getName(), resource);
@ -572,8 +572,8 @@ public class Configurations {
ctx = new InitialContext();
return ctx.lookup(name);
} catch (NamingException ne) {
throw new NestableRuntimeException(_loc.get("naming-err", name),
ne);
throw new NestableRuntimeException(
_loc.get("naming-err", name).getMessage(), ne);
} finally {
if (ctx != null)
try {

View File

@ -107,7 +107,7 @@ public class ObjectValue extends Value {
set(null);
else
throw new IllegalArgumentException(_loc.get("cant-set-string",
getProperty()));
getProperty()).getMessage());
}
protected void setInternalObject(Object obj) {

View File

@ -106,7 +106,7 @@ public class PluginValue extends ObjectValue {
public void set(Object obj, boolean derived) {
if (!_singleton)
throw new IllegalStateException(_loc.get("not-singleton",
getProperty()));
getProperty()).getMessage());
super.set(obj, derived);
}

View File

@ -19,6 +19,7 @@ import java.sql.Connection;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.log.NoneLogFactory;
import org.apache.openjpa.lib.util.Localizer;
/**
* Provies basic logging facilities to a DataSource.
@ -28,6 +29,9 @@ import org.apache.openjpa.lib.log.NoneLogFactory;
*/
public class DataSourceLogs {
private static final Localizer _loc =
Localizer.forPackage(DataSourceLogs.class);
private Log _jdbcLog = null;
private Log _sqlLog = null;
@ -136,12 +140,12 @@ public class DataSourceLogs {
buf.append(", ").append(conn);
buf.append("> ");
// in the time != -1, append time profiling information
// if the time != -1, append time profiling information
if (totalTime != -1)
buf.append("[").append(totalTime).append(" ms] ");
buf.append(msg);
log.trace(buf.toString());
log.trace(_loc.get("datasource-trace-data", buf.toString()));
}
}

View File

@ -557,7 +557,8 @@ public class DelegatingConnection implements Connection, Closeable {
private static void assertJDBC3() {
if (_jdbc3 == null)
throw new UnsupportedOperationException(_loc.get("not-jdbc3"));
throw new UnsupportedOperationException(_loc.get("not-jdbc3")
.getMessage());
}
private Object invokeJDBC3(Method m, Object[] args) throws SQLException {
@ -566,7 +567,8 @@ public class DelegatingConnection implements Connection, Closeable {
} catch (Throwable t) {
if (t instanceof SQLException)
throw(SQLException) t;
throw new NestableRuntimeException(_loc.get("invoke-jdbc3"), t);
throw new NestableRuntimeException(_loc.get("invoke-jdbc3")
.getMessage(), t);
}
}
@ -577,7 +579,8 @@ public class DelegatingConnection implements Connection, Closeable {
_jdbc3.put(key, m);
return m;
} catch (Throwable t) {
throw new NestableRuntimeException(_loc.get("error-jdbc3"), t);
throw new NestableRuntimeException(_loc.get("error-jdbc3")
.getMessage(), t);
}
}
}

View File

@ -44,10 +44,6 @@ public abstract class AbstractLog implements Log {
return isEnabled(TRACE);
}
public boolean isDebugEnabled() {
return isEnabled(DEBUG);
}
public boolean isInfoEnabled() {
return isEnabled(INFO);
}
@ -73,15 +69,6 @@ public abstract class AbstractLog implements Log {
log(TRACE, toString(message), throwableParam(message, t));
}
public void debug(Object message) {
debug(message, throwableParam(message, null));
}
public void debug(Object message, Throwable t) {
if (isDebugEnabled())
log(DEBUG, toString(message), throwableParam(message, t));
}
public void info(Object message) {
info(message, throwableParam(message, null));
}

View File

@ -49,10 +49,6 @@ public class CommonsLogFactory extends LogFactoryAdapter {
return _log;
}
public boolean isDebugEnabled() {
return _log.isDebugEnabled();
}
public boolean isErrorEnabled() {
return _log.isErrorEnabled();
}
@ -81,14 +77,6 @@ public class CommonsLogFactory extends LogFactoryAdapter {
_log.trace(o, t);
}
public void debug(Object o) {
_log.debug(o);
}
public void debug(Object o, Throwable t) {
_log.debug(o, t);
}
public void info(Object o) {
_log.info(o);
}

View File

@ -24,7 +24,7 @@ package org.apache.openjpa.lib.log;
public interface Log {
public static final short TRACE = 1;
public static final short DEBUG = 2;
// the old DEBUG constant was 2. Leaving a hole for compatibility.
public static final short INFO = 3;
public static final short WARN = 4;
public static final short ERROR = 5;
@ -35,11 +35,6 @@ public interface Log {
*/
public boolean isTraceEnabled();
/**
* Returns if the {@link #DEBUG} log level is enabled.
*/
public boolean isDebugEnabled();
/**
* Returns if the {@link #INFO} log level is enabled.
*/
@ -74,20 +69,6 @@ public interface Log {
*/
public void trace(Object o, Throwable t);
/**
* Write out a log message at the {@link #DEBUG}
* level with the stringification of <code>o</code> as the body
* of the message, also outputting <code>t</code> to the log.
*/
public void debug(Object o);
/**
* Write out a log message at the {@link #DEBUG}
* level with the stringification of <code>o</code> as the body
* of the message, also outputting <code>t</code> to the log.
*/
public void debug(Object o, Throwable t);
/**
* Write out a log message at the {@link #INFO}
* level with the stringification of <code>o</code> as the body

View File

@ -46,10 +46,6 @@ public class Log4JLogFactory extends LogFactoryAdapter {
}
public boolean isTraceEnabled() {
return isDebugEnabled();
}
public boolean isDebugEnabled() {
return _log.getEffectiveLevel().toInt() >= Level.DEBUG_INT;
}
@ -77,14 +73,6 @@ public class Log4JLogFactory extends LogFactoryAdapter {
_log.debug(o, t);
}
public void debug(Object o) {
_log.debug(o);
}
public void debug(Object o, Throwable t) {
_log.debug(o, t);
}
public void info(Object o) {
_log.info(o);
}

View File

@ -42,12 +42,11 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
private static Localizer _loc = Localizer.forPackage(LogFactoryImpl.class);
public static final String TRACE_STR = _loc.get("log-trace");
public static final String DEBUG_STR = _loc.get("log-debug");
public static final String INFO_STR = _loc.get("log-info");
public static final String WARN_STR = _loc.get("log-warn");
public static final String ERROR_STR = _loc.get("log-error");
public static final String FATAL_STR = _loc.get("log-fatal");
public static final String TRACE_STR = _loc.get("log-trace").getMessage();
public static final String INFO_STR = _loc.get("log-info").getMessage();
public static final String WARN_STR = _loc.get("log-warn").getMessage();
public static final String ERROR_STR = _loc.get("log-error").getMessage();
public static final String FATAL_STR = _loc.get("log-fatal").getMessage();
public static final String STDOUT = "stdout";
public static final String STDERR = "stderr";
@ -187,8 +186,6 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
switch (level) {
case Log.TRACE:
return TRACE_STR;
case Log.DEBUG:
return DEBUG_STR;
case Log.INFO:
return INFO_STR;
case Log.WARN:
@ -198,7 +195,7 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
case Log.FATAL:
return FATAL_STR;
default:
return _loc.get("log-unknown");
return _loc.get("log-unknown").getMessage();
}
}
@ -208,7 +205,6 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
public static short getLevel(String str) {
str = str.toUpperCase().trim();
short val = TRACE_STR.equals(str) ? Log.TRACE :
DEBUG_STR.equals(str) ? Log.DEBUG :
INFO_STR.equals(str) ? Log.INFO :
WARN_STR.equals(str) ? Log.WARN :
ERROR_STR.equals(str) ? Log.ERROR :
@ -216,7 +212,7 @@ public class LogFactoryImpl implements LogFactory, GenericConfigurable {
if (val == -1)
throw new IllegalArgumentException
(_loc.get("log-bad-constant", str));
(_loc.get("log-bad-constant", str).getMessage());
return val;
}

View File

@ -69,9 +69,6 @@ public class LogOutputStream extends ByteArrayOutputStream {
case Log.TRACE:
_log.trace(msg);
break;
case Log.DEBUG:
_log.debug(msg);
break;
case Log.INFO:
_log.info(msg);
break;

View File

@ -122,16 +122,6 @@ public class MultiLogFactory implements LogFactory {
_logs[i].info(msg, t);
}
public void debug(Object msg) {
for (int i = 0; i < _logs.length; i++)
_logs[i].debug(msg);
}
public void debug(Object msg, Throwable t) {
for (int i = 0; i < _logs.length; i++)
_logs[i].debug(msg, t);
}
public void warn(Object msg) {
for (int i = 0; i < _logs.length; i++)
_logs[i].warn(msg);
@ -183,13 +173,6 @@ public class MultiLogFactory implements LogFactory {
return false;
}
public boolean isDebugEnabled() {
for (int i = 0; i < _logs.length; i++)
if (_logs[i].isDebugEnabled())
return true;
return false;
}
public boolean isErrorEnabled() {
for (int i = 0; i < _logs.length; i++)
if (_logs[i].isErrorEnabled())

View File

@ -38,10 +38,6 @@ public class NoneLogFactory implements LogFactory {
return s_log;
}
public final boolean isDebugEnabled() {
return false;
}
public final boolean isErrorEnabled() {
return false;
}
@ -68,12 +64,6 @@ public class NoneLogFactory implements LogFactory {
public final void trace(Object o, Throwable t) {
}
public final void debug(Object o) {
}
public final void debug(Object o, Throwable t) {
}
public final void info(Object o) {
}

View File

@ -279,7 +279,7 @@ public class CFMetaDataParser extends XMLMetaDataParser {
return null;
Class cls = classForName(name, _package, resolve, currentClassLoader());
if (cls == null)
throw getException(_loc.get("invalid-class", name));
throw getException(_loc.get("invalid-class", name).getMessage());
return cls;
}

View File

@ -101,12 +101,12 @@ public class ClassArgParser {
if (i == 0) {
if (charIdx == packageElementName.length())
throw new UnsupportedOperationException(_loc.get
("cant-diff-elems"));
("cant-diff-elems").getMessage());
buf[i] = packageElementName.charAt(charIdx);
} else {
if (charIdx == classElementNames[i - 1].length())
throw new UnsupportedOperationException(_loc.get
("cant-diff-elems"));
("cant-diff-elems").getMessage());
buf[i] = classElementNames[i - 1].charAt(charIdx);
}
}
@ -212,7 +212,8 @@ public class ClassArgParser {
return (String[]) col.toArray(new String[col.size()]);
}
} catch (Exception e) {
throw new NestableRuntimeException(_loc.get("class-arg", arg), e);
throw new NestableRuntimeException(
_loc.get("class-arg", arg).getMessage(), e);
}
// must be a class name
@ -234,8 +235,8 @@ public class ClassArgParser {
appendTypeNames(source, itr.getInputStream(), names);
}
} catch (Exception e) {
throw new NestableRuntimeException(_loc.get("class-arg", source),
e);
throw new NestableRuntimeException(
_loc.get("class-arg", source).getMessage(), e);
}
return (String[]) names.toArray(new String[names.size()]);
}
@ -279,8 +280,8 @@ public class ClassArgParser {
names.clear();
}
} catch (Exception e) {
throw new NestableRuntimeException(_loc.get("class-arg", source),
e);
throw new NestableRuntimeException(
_loc.get("class-arg", source).getMessage(), e);
}
return map;
}

View File

@ -74,7 +74,7 @@ public class FileMetaDataIterator implements MetaDataIterator {
Collection metas, int scanned) throws IOException {
if (scanned > SCAN_LIMIT)
throw new IllegalStateException(_loc.get("too-many-files",
String.valueOf(SCAN_LIMIT)));
String.valueOf(SCAN_LIMIT)).getMessage());
scanned++;
if (filter == null)

View File

@ -42,7 +42,7 @@ public class SourceTrackers {
String sourceFilePath;
for (int i = 0; i < trackers.length; i++) {
sourceFilePath = (trackers[i].getSourceFile() == null ?
_loc.get("source-tracker-file-unknown") :
_loc.get("source-tracker-file-unknown").getMessage() :
trackers[i].getSourceFile().getAbsolutePath());
buf.append(" ").append(_loc.get(
"source-trackers-location-line-item",

View File

@ -40,6 +40,7 @@ import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.JavaVersions;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.lib.xml.Commentable;
import org.apache.openjpa.lib.xml.DocTypeReader;
@ -655,9 +656,19 @@ public abstract class XMLMetaDataParser extends DefaultHandler
* Returns a SAXException with the source file name and the given error
* message.
*/
protected SAXException getException(String msg, Throwable cause) {
protected SAXException getException(Message msg) {
return new SAXException(getSourceName() + currentLocation() +
": " + msg.getMessage());
}
/**
* Returns a SAXException with the source file name and the given error
* message.
*/
protected SAXException getException(Message msg, Throwable cause) {
if (cause != null && _log != null && _log.isTraceEnabled())
_log.trace(cause);
_log.trace(_loc.get("sax-exception",
getSourceName(), _location.getLocation()), cause);
return new SAXException(getSourceName() + currentLocation() +
": " + msg + " [" + cause + "]");
}

View File

@ -31,14 +31,17 @@ abstract class AbstractListIterator implements ListIterator {
(AbstractListIterator.class);
public void add(Object o) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw new UnsupportedOperationException(_loc.get("read-only")
.getMessage());
}
public void set(Object o) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw new UnsupportedOperationException(_loc.get("read-only")
.getMessage());
}
public void remove() {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw new UnsupportedOperationException(_loc.get("read-only")
.getMessage());
}
}

View File

@ -33,43 +33,48 @@ public abstract class AbstractResultList implements ResultList {
(AbstractResultList.class);
public void add(int index, Object element) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
private UnsupportedOperationException readOnly() {
return new UnsupportedOperationException(_loc.get("read-only")
.getMessage());
}
public boolean add(Object o) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public boolean addAll(Collection c) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public boolean addAll(int index, Collection c) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public Object remove(int index) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public boolean remove(Object o) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public boolean removeAll(Collection c) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public boolean retainAll(Collection c) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public Object set(int index, Object element) {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public void clear() {
throw new UnsupportedOperationException(_loc.get("read-only"));
throw readOnly();
}
public List subList(int from, int to) {
@ -83,6 +88,6 @@ public abstract class AbstractResultList implements ResultList {
protected void assertOpen() {
if (isClosed())
throw new NoSuchElementException(_loc.get("closed"));
throw new NoSuchElementException(_loc.get("closed").getMessage());
}
}

View File

@ -57,7 +57,7 @@ public class RangeResultObjectProvider implements ResultObjectProvider {
_delegate = delegate;
if (startIdx > Integer.MAX_VALUE || endIdx > Integer.MAX_VALUE)
throw new IllegalArgumentException(_loc.get("range-too-high",
String.valueOf(startIdx), String.valueOf(endIdx)));
String.valueOf(startIdx), String.valueOf(endIdx)).getMessage());
_startIdx = (int) startIdx;
_endIdx = (int) endIdx;

View File

@ -56,7 +56,7 @@ public class ResultListIterator extends AbstractListIterator {
public Object next() {
if (_rl.isClosed())
throw new NoSuchElementException(_loc.get("closed"));
throw new NoSuchElementException(_loc.get("closed").getMessage());
return _li.next();
}

View File

@ -557,7 +557,7 @@ public class FormatPreservingProperties extends Properties {
public DuplicateKeyException(String key, Object firstVal,
String secondVal) {
super(_loc.get("dup-key", key, firstVal, secondVal));
super(_loc.get("dup-key", key, firstVal, secondVal).getMessage());
}
}

View File

@ -56,6 +56,9 @@ public class Localizer {
// the local file name and class' classloader
private ResourceBundle _bundle = null;
// the package that this localizer was created for.
private Package _package;
/**
* Return a Localizer instance that will access the properties file
* in the package of the given class using the system default locale.
@ -106,7 +109,7 @@ public class Localizer {
}
// cache the localizer
loc = new Localizer();
loc = new Localizer(cls == null ? null : cls.getPackage());
loc._bundle = bundle;
_localizers.put(key, loc);
return loc;
@ -126,18 +129,22 @@ public class Localizer {
return _providers.remove(provider);
}
/**
* Return the localized string matching the given key.
*/
public String get(String key) {
return get(key, false);
private Localizer(Package p) {
_package = p;
}
/**
* Return the localized string matching the given key.
*/
public String getFatal(String key) {
return get(key, true);
public Message get(String key) {
return get(key, null);
}
/**
* Return the localized string matching the given key.
*/
public Message getFatal(String key) {
return getFatal(key, null);
}
/**
@ -148,7 +155,7 @@ public class Localizer {
*
* @see #get(String)
*/
public String get(String key, Object sub) {
public Message get(String key, Object sub) {
return get(key, new Object[]{ sub });
}
@ -160,7 +167,7 @@ public class Localizer {
*
* @see #getFatal(String)
*/
public String getFatal(String key, Object sub) {
public Message getFatal(String key, Object sub) {
return getFatal(key, new Object[]{ sub });
}
@ -169,7 +176,7 @@ public class Localizer {
*
* @see #get(String,Object)
*/
public String get(String key, Object sub1, Object sub2) {
public Message get(String key, Object sub1, Object sub2) {
return get(key, new Object[]{ sub1, sub2 });
}
@ -178,7 +185,7 @@ public class Localizer {
*
* @see #getFatal(String,Object)
*/
public String getFatal(String key, Object sub1, Object sub2) {
public Message getFatal(String key, Object sub1, Object sub2) {
return getFatal(key, new Object[]{ sub1, sub2 });
}
@ -187,7 +194,7 @@ public class Localizer {
*
* @see #get(String,Object)
*/
public String get(String key, Object sub1, Object sub2, Object sub3) {
public Message get(String key, Object sub1, Object sub2, Object sub3) {
return get(key, new Object[]{ sub1, sub2, sub3 });
}
@ -199,9 +206,8 @@ public class Localizer {
*
* @see #get(String)
*/
public String get(String key, Object[] subs) {
String str = get(key);
return MessageFormat.format(str, subs);
public Message get(String key, Object[] subs) {
return new Message(key, subs, false);
}
/**
@ -212,24 +218,70 @@ public class Localizer {
*
* @see #getFatal(String)
*/
public String getFatal(String key, Object[] subs) {
String str = getFatal(key);
return MessageFormat.format(str, subs);
public Message getFatal(String key, Object[] subs) {
return new Message(key, subs, true);
}
private String get(String key, boolean fatal) {
/**
* A <code>Message</code> can provide a localized message via the
* {@link #getMessage} method call, and can also provide the original key,
* package, and substitution array that were used to assemble the message.
*/
public class Message {
private final String key;
private final Object[] subs;
private String localizedMessage;
private boolean messageFound = false;
private Message(String key, Object[] subs, boolean fatal) {
this.key = key;
this.subs = subs;
if (_bundle == null) {
if (fatal)
throw new MissingResourceException(key, key, key);
return key;
else {
localizedMessage = key;
messageFound = false;
}
} else {
try {
return _bundle.getString(key);
localizedMessage = _bundle.getString(key);
messageFound = true;
} catch (MissingResourceException mre) {
if (!fatal)
return key;
localizedMessage = key;
else
throw mre;
}
}
}
/**
* The localized message.
*/
public String getMessage() {
if (messageFound)
return MessageFormat.format(localizedMessage, subs);
else
return key;
}
public String getKey() {
return key;
}
public Object[] getSubstitutions() {
return subs;
}
public Package getPackage() {
return _package;
}
public String toString() {
return getMessage();
}
}
}

View File

@ -33,6 +33,10 @@ public class ParseException extends NestableRuntimeException {
super(msg);
}
public ParseException(Localizer.Message msg) {
super(msg.getMessage());
}
public ParseException(Throwable cause) {
super(cause);
}
@ -40,4 +44,8 @@ public class ParseException extends NestableRuntimeException {
public ParseException(String msg, Throwable cause) {
super(msg, cause);
}
public ParseException(Localizer.Message msg, Throwable cause) {
super(msg.getMessage(), cause);
}
}

View File

@ -47,17 +47,16 @@ public class Location {
if (_locator == null) {
if (_nullOnNoLocator)
return null;
return _loc.get("no-locator");
return _loc.get("no-locator").getMessage();
}
String forma = MessageFormat.format(format, new Object []{
return MessageFormat.format(format, new Object []{
Numbers.valueOf(_locator.getLineNumber()),
Numbers.valueOf(_locator.getColumnNumber()), _locator.getPublicId(),
_locator.getSystemId() });
return forma;
}
public String getLocation() {
return getLocation(_loc.get("location-format"));
return getLocation(_loc.get("location-format").getMessage());
}
public void setLocator(Locator locator) {

View File

@ -60,6 +60,8 @@ closeable-ex: An exception occurred while invoking close() on "{0}". This \
exception will be consumed.
dup-with-different-prefixes: Found multiple properties with different valid \
prefixes. Properties: {0}, {1}.
plugin-creation-exception: An exception occurred while creating a plugin for \
value {0}. This exception will be consumed.
Log-name: Log factory
Log-desc: LogFactory and configuration

View File

@ -84,3 +84,4 @@ login-timeout-desc: The maximum number of milliseconds to block for database \
login.
close-pool: Shutting down connection pool.
close-pool-fail: Error caught when issuing close pool SQL: {0}
datasource-trace-data: {0}

View File

@ -1,14 +1,14 @@
log-trace: TRACE
log-debug: DEBUG
log-info: INFO
log-warn: WARN
log-error: ERROR
log-fatal: FATAL
log-unknown: UNKNOWN
log-bad-constant: The log level string "{0}" is not valid. Valid values are \
TRACE, DEBUG, INFO, WARN, ERROR or FATAL.
TRACE, INFO, WARN, ERROR or FATAL.
log-bad-file: The file name "{0}" is not valid.
could-not-create-factory: An error occurred while trying to create a \
LogFactory of type "{0}", as specified by the \
org.apache.openjpa.lib.log.LogFactory system property. Created a \
openjpa.Log system property. Created a \
org.apache.openjpa.lib.log.LogFactoryImpl instead.
log-output-stream-data: {0}

View File

@ -23,3 +23,6 @@ source-trackers-location-line-item: {0}: {1}
source-tracker-file-unknown: <file location unknown>
parser-schema-bug: XML schema validation is disabled due to bugs detected \
in the SAX parser.
sax-exception: An exception occurred while parsing {0} at location {1}. \
This exception has been translated to a SAXException, and will be \
re-thrown. The original exception is being logged along with this message.

View File

@ -61,6 +61,7 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.log.LogFactoryImpl;
import org.apache.openjpa.lib.util.Localizer;
/**
* TestCase framework to run various tests against solarmetric code.
@ -85,6 +86,9 @@ public abstract class AbstractTestCase extends TestCase {
public static final String SKIP_TOKEN = "SOLARSKIP";
public static final String SKIP_DELIMITER = "|";
private static final Localizer _loc =
Localizer.forPackage(AbstractTestCase.class);
protected String multiThreadExecuting = null;
protected boolean inTimeoutThread = false;
@ -148,7 +152,7 @@ public abstract class AbstractTestCase extends TestCase {
try {
_lastTest.tearDownTestClass();
} catch (Throwable t) {
getLog().error(t);
getLog().error(null, t);
}
}
@ -156,7 +160,7 @@ public abstract class AbstractTestCase extends TestCase {
try {
setUpTestClass();
} catch (Throwable t) {
getLog().error(t);
getLog().error(null, t);
}
}
@ -875,8 +879,8 @@ public abstract class AbstractTestCase extends TestCase {
if (time != null)
elapsed = System.currentTimeMillis() - time.longValue();
getLog()
.info(name + ": " + (time == null ? "???" : "" + elapsed) + "ms");
getLog().info(_loc.get("profile-info", name,
(time == null ? "???" : "" + elapsed)));
return elapsed;
}
@ -1234,9 +1238,10 @@ public abstract class AbstractTestCase extends TestCase {
long used = total - free;
NumberFormat nf = NumberFormat.getInstance();
getLog().warn("memory:" + " used: " + nf.format(used)
+ " total: " + nf.format(total)
+ " free: " + nf.format(free));
getLog().warn(_loc.get("mem-info",
nf.format(used),
nf.format(total),
nf.format(free)));
}
/**

View File

@ -19,6 +19,8 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.lib.util.testlocalizer.LocalizerTestHelper;
/**
@ -109,6 +111,10 @@ public class TestLocalizer extends TestCase {
}
}
public static void assertEquals(String s, Message m) {
assertEquals(s, m.getMessage());
}
public static Test suite() {
return new TestSuite(TestLocalizer.class);
}

View File

@ -25,6 +25,8 @@ import java.io.Serializable;
import org.apache.openjpa.util.ExceptionInfo;
import org.apache.openjpa.util.Exceptions;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Extended {@link IllegalArgumentException}.
*
@ -48,6 +50,11 @@ public class ArgumentException
_fatal = fatal;
}
public ArgumentException(Message msg, Throwable[] nested, Object failed,
boolean fatal) {
this(msg.getMessage(), nested, failed, fatal);
}
public int getType() {
return USER;
}

View File

@ -180,7 +180,7 @@ public class ConfigurationProviderImpl
String msg = (pinfo == null) ? "missing-xml-config"
: "cantload-xml-config";
throw new MissingResourceException(_loc.get(msg, rsrc,
String.valueOf(name)), getClass().getName(), rsrc);
String.valueOf(name)).getMessage(), getClass().getName(), rsrc);
}
return true;
}

View File

@ -386,7 +386,8 @@ public class EntityManagerImpl
public boolean getRollbackOnly() {
if (!isActive())
throw new IllegalStateException(_loc.get("no-transaction"));
throw new IllegalStateException(_loc.get("no-transaction")
.getMessage());
return _broker.getRollbackOnly();
}

View File

@ -25,6 +25,7 @@ import java.io.Serializable;
import org.apache.openjpa.util.ExceptionInfo;
import org.apache.openjpa.util.Exceptions;
import org.apache.openjpa.util.UserException;
import org.apache.openjpa.lib.util.Localizer.Message;
/**
* Extended {@link IllegalStateException}.
@ -41,6 +42,11 @@ public class InvalidStateException
private transient Object _failed = null;
private transient Throwable[] _nested = null;
public InvalidStateException(Message msg, Throwable[] nested, Object failed,
boolean fatal) {
this(msg.getMessage(), nested, failed, fatal);
}
public InvalidStateException(String msg, Throwable[] nested, Object failed,
boolean fatal) {
super(msg);

View File

@ -168,8 +168,8 @@ public class PersistenceExceptions
Exception e;
switch (ke.getSubtype()) {
case UserException.NO_TRANSACTION:
e =
new org.apache.openjpa.persistence.TransactionRequiredException
e = new
org.apache.openjpa.persistence.TransactionRequiredException
(ke.getMessage(), getNestedThrowables(ke),
getFailedObject(ke), ke.isFatal());
break;

View File

@ -215,7 +215,8 @@ public class PersistenceUnitInfoImpl
}
}
}
throw new IllegalArgumentException(s_loc.get("bad-jar-name", name));
throw new IllegalArgumentException(s_loc.get("bad-jar-name", name)
.getMessage());
}
public List<String> getManagedClassNames() {

View File

@ -278,11 +278,11 @@ public class QueryImpl
Iterator itr = res.iterator();
if (!itr.hasNext())
throw new NoResultException(_loc.get("no-results",
_query.getQueryString()), null, null, false);
_query.getQueryString()).getMessage(), null, null, false);
Object ret = itr.next();
if (itr.hasNext())
throw new NonUniqueResultException(_loc.get("mult-results",
_query.getQueryString()), null, null, false);
_query.getQueryString()).getMessage(), null, null, false);
return ret;
} finally {
OpenJPAPersistence.close(res);

View File

@ -22,6 +22,7 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import org.apache.openjpa.lib.util.Localizer.Message;
import org.apache.openjpa.util.ExceptionInfo;
import org.apache.openjpa.util.Exceptions;
import org.apache.openjpa.util.UserException;
@ -41,6 +42,11 @@ public class TransactionRequiredException
private transient Object _failed = null;
private transient Throwable[] _nested = null;
public TransactionRequiredException(Message msg, Throwable[] nested,
Object failed, boolean fatal) {
this(msg.getMessage(), nested, failed, fatal);
}
public TransactionRequiredException(String msg, Throwable[] nested,
Object failed, boolean fatal) {
super(msg);