| Method from org.apache.openjpa.util.Exceptions Detail: |
public static void printNestedThrowables(ExceptionInfo e,
PrintStream out) {
// if this is Java 1.4 and there is exactly a single
// exception, then defer to 1.4's behavior of printing
// out the result of getCause(). This deferral happens in
// the calling code.
Throwable[] nested = e.getNestedThrowables();
int i = (JavaVersions.VERSION >= 4) ? 1 : 0;
if (i < nested.length) {
out.println("NestedThrowables:");
for (; i < nested.length; i++)
// guard against a nasty null in the array
if (nested[i] != null)
nested[i].printStackTrace(out);
}
}
Print the stack trace of the exception's nested throwables. |
public static void printNestedThrowables(ExceptionInfo e,
PrintWriter out) {
// if this is Java 1.4 and there is exactly a single
// exception, then defer to 1.4's behavior of printing
// out the result of getCause(). This deferral happens in
// the calling code.
Throwable[] nested = e.getNestedThrowables();
int i = (JavaVersions.VERSION >= 4) ? 1 : 0;
if (i < nested.length) {
out.println("NestedThrowables:");
for (; i < nested.length; i++)
// guard against a nasty null in the array
if (nested[i] != null)
nested[i].printStackTrace(out);
}
}
Print the stack trace of the exception's nested throwables. |
public static Object replaceFailedObject(Object ob) {
if (ob == null)
return null;
if (isSerializable(ob))
return ob;
// don't take oid of new objects since it can cause a flush if auto-inc
// and the id is meaningless anyway
Object oid = getObjectId(ob);
if (oid != null && isSerializable(oid))
return oid;
// last ditch: stringify the object
return toString(ob);
}
Convert the specified failed object into a serializable
object for when we are serializing an Exception. It will
try the following:
- if the object can be serialized, return the object itself
- if the object has a serializable oid, return the oid
- if the object has a non-serializable oid, return the oid's
toString and the object class
- return the object's toString
|
public static Throwable[] replaceNestedThrowables(Throwable[] nested) {
if (nested == null || nested.length == 0)
return nested;
if (isSerializable(nested))
return nested;
Throwable[] newNested = new Throwable[nested.length];
for (int i = 0; i < nested.length; i++) {
if (isSerializable(nested[i]))
newNested[i] = nested[i];
else
// guard against a nasty null in the array by using valueOf
// instead of toString to prevent throwing yet another
// exception
newNested[i] = new Exception(String.valueOf(nested[i]));
}
return newNested;
}
Convert the specified throwables into a serialzable array. If
any of the nested throwables cannot be serialized, they will
be converted into a Exception with the original message. |
public static String toString(Object ob) {
if (ob == null)
return "null";
// don't take oid of new objects since it can cause a flush if auto-inc
// and the id is meaningless anyway
Object oid = getObjectId(ob);
if (oid != null) {
if (oid instanceof Id)
return oid.toString();
return ob.getClass().getName() + "-" + oid.toString();
}
if (ImplHelper.isManagedType(null, ob.getClass())) {
// never call toString() on a PersistenceCapable, since
// it may access persistent fields; fall-back to using
// the standard object stringification mechanism. New
// instances that use proxying (property-access instances,
// for example) that were created with the 'new' keyword
// will not end up in this code, which is ok since they
// don't do lazy loading anyways, so they will stringify
// safely.
return ob.getClass().getName() + "@"
+ Integer.toHexString(System.identityHashCode(ob));
}
try {
String s = ob.toString();
if (s.indexOf(ob.getClass().getName()) == -1)
s += " [" + ob.getClass().getName() + "]";
return s;
} catch (Throwable t) {
return ob.getClass().getName();
}
}
Safely stringify the given object. |
public static String toString(Collection failed) {
StringBuffer buf = new StringBuffer();
buf.append("[");
for (Iterator itr = failed.iterator(); itr.hasNext();) {
buf.append(Exceptions.toString(itr.next()));
if (itr.hasNext())
buf.append(", ");
}
buf.append("]");
return buf.toString();
}
Safely stringify the given objects. |
public static String toString(ExceptionInfo e) {
int type = e.getType();
StringBuffer buf = new StringBuffer();
buf.append("< ").
append(OpenJPAVersion.VERSION_ID).
append(' ").
append(e.isFatal() ? "fatal " : "nonfatal ").
append (type == ExceptionInfo.GENERAL ? "general error" :
type == ExceptionInfo.INTERNAL ? "internal error" :
type == ExceptionInfo.STORE ? "store error" :
type == ExceptionInfo.UNSUPPORTED ? "unsupported error" :
type == ExceptionInfo.USER ? "user error" :
(type + " error")).
append(" > ");
buf.append(e.getClass().getName()).append(": ").
append(e.getMessage());
Object failed = e.getFailedObject();
if (failed != null)
buf.append(SEP).append("FailedObject: ").
append(toString(failed));
return buf.toString();
}
Stringify the given exception. |