package com.perforce.client.api; class P4Error { //================================// // // PACKAGE // //================================// long instance = 0; // the native peer instance of the error int id() { return nId(this.instance); } String fmt() { return nFmt(this.instance); } /** * Test to see if there was an error made. * * @return if there is an error or not. * **/ boolean test() { return nTest(this.instance); } P4Error() { this.instance = nNewInstance(); javaCreatedTheInstance = true; } /** * Make a new P4Error that will just bind to an already * existing native Error. * * @param instance a native peer to bind this to. * @return the java interface. * **/ static P4Error makeJavaPeer(long instance) { return new P4Error(instance); } /** * Take a P4ClientException, and make sure that the * error on the native side is set. * * <p> You would call this when you've caught a P4ClientException * and want to convey that to the native side. * * @param err the exception that we use to see what to set. * **/ void convertException(P4ClientException err) { int id = err.getErrorId(); if (id != 0) nSetErrorId(this.instance, id); else nSetMessage(this.instance, err.toString()); } /** * Given a P4Error, see if there was an exception on the native side. * If so, throw the corresponding P4ClientException. * * <p> You would use this if you wanted to convert from P4's Error * handling system to a more java-like exception mechanism. * * @throws the corresponding P4ClientException that matches the Error * but only if one needs to be thrown. * **/ void checkException() throws P4ClientException { // Check to see if there was an error. if (!test()) return; // There was, so get the native one and, as best we // can, throw the corresponding exception. P4ClientException exp = new P4ClientException(id(), fmt()); if (exp != null) throw exp; } //================================// // // PROTECTED // //================================// protected void finalize() { // If this instance was create to pass to the native side, // then a native pointer was allocated and we need to clean // that up, otherwise, this was created as a face to an // Error that was created outside of Java and we do not want // to clean that up. if (javaCreatedTheInstance) nDeleteInstance(this.instance); } //================================// // // PRIVATE // //================================// // to track if we created this or the native side did // private boolean javaCreatedTheInstance; // // methods to create and dispose of native Error pointers. // private static native long nNewInstance(); private static native void nDeleteInstance(long instance); /** * Make a P4Error to use as a "face" to an actual, pre-existing * native Error instance. * * @param instance the pre-existing native instance. * **/ private P4Error(long instance) { this.instance = instance; javaCreatedTheInstance = false; } //================================// // // NATIVE // //================================// private static native void nSetErrorId(long errInstance, int id); private static native void nSetMessage(long errInstance, String message); private static native boolean nTest(long instance); private static native String nFmt(long instance); private static native int nId(long instance); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#9 | 4181 | Paul Krause |
Rename //guest/paul_krause/perforce/api/java/wcvm/com/... //guest/paul_krause/perforce/api/java/wcvm/javax/... To //guest/paul_krause/perforce/api/java/wcvm/src-15/... |
||
#8 | 4177 | Paul Krause | parameterize container types - requires tiger or pizza | ||
#7 | 4173 | Paul Krause | add serialVersionUID | ||
#6 | 4129 | Paul Krause | use msgclient.h in place of old errclient.h | ||
#5 | 4107 | Paul Krause | fix JNI sigs for ErrorId | ||
#4 | 4103 | Paul Krause | ditch clienterror.h | ||
#3 | 4100 | Paul Krause | fix type problems | ||
#2 | 4097 | Paul Krause | remove support for unimplemented abort() function | ||
#1 | 4073 | Paul Krause | branch com.perforce.api package from michael_bishop | ||
//guest/michael_bishop/P4APIForJava/java/com/perforce/client/api/P4Error.java | |||||
#1 | 430 | Michael Bishop |
Initial checkin. Seems to work. Not very much testing. Not very much documentation. Some more commenting needs to take place. But, it's there to experiment with. |