|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.oclc.da.gdfr.registryprototype.exceptions.Assertor
public class Assertor
This class implements pre/post-condition checking. There are two types of conditions: Validating and Testing. Validating pre/post-conditions cannot be turned off, whereas Testing pre/post-conditions can.
| Nested Class Summary | |
|---|---|
static interface |
Assertor.DeferredCondition
This interface is used to defer execution of the pre/post-condition expression until the TESTING boolean can be checked. |
| Field Summary | |
|---|---|
static int |
POST
Static variable identifying the condition as post-condition. |
static int |
PRE
Static variable identifying the condition as pre-condition. |
boolean |
TESTING
Instance variable determining whether or not Testing Pre/Post-conditions are turned on or off. |
| Constructor Summary | |
|---|---|
Assertor()
Public constructor. |
|
| Method Summary | |
|---|---|
void |
post(boolean valid,
int type,
java.lang.String[] msgArgs)
This method enforces Validating Post-Conditions, which cannot be turned off and cannot be resolved by the client, but by the support staff. |
void |
pre(boolean valid,
int type,
java.lang.String[] msgArgs)
This method enforces Validating Pre-Conditions, which cannot be turned off and must be resolved by the client. |
void |
test(int cond,
Assertor.DeferredCondition valid,
int type,
java.lang.String[] msgArgs)
This method is a deferred version of test. |
void |
test(int cond,
boolean valid,
int type,
java.lang.String[] msgArgs)
This method enforces Testing Pre/Post-Conditions, which may be turned off. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int PRE
public static final int POST
public boolean TESTING
| Constructor Detail |
|---|
public Assertor()
org.oclc.da.gdfr.registryprototype.exceptions.Assertor.TESTING to determine if
testing pre/post-conditions should be turned on or off.
| Method Detail |
|---|
public void pre(boolean valid,
int type,
java.lang.String[] msgArgs)
throws RegistryException
RegistryException in the throws
clause.
valid - The boolean condition to be checked.type - The condition identifier (see
org.oclc.da.gdfr.registryprototype.exceptions.RegistryExceptionCodes).msgArgs - A string array of arguments to be substituted into the
assertion exception, if needed.
RegistryException - Validation exception if condition is
false.
public void post(boolean valid,
int type,
java.lang.String[] msgArgs)
RegistrySystemException
and does not need to be declared in the throws
clause.
valid - The boolean condition to be checked.type - The condition identifier (see
org.oclc.da.gdfr.registryprototype.exceptions.RegistryExceptionCodes).msgArgs - A string array of arguments to be substituted into the
assertion exception, if needed.
RegistrySystemException - Validation exception if condition
is false.
public void test(int cond,
boolean valid,
int type,
java.lang.String[] msgArgs)
org.oclc.da.gdfr.registryprototype.exceptions.Assertor.TESTING.
cond - The condition type: PRE or POST.valid - The boolean condition to be checked.type - The condition identifier (see
org.oclc.da.gdfr.registryprototype.exceptions.RegistryExceptionCodes).msgArgs - A string array of arguments to be substituted into the
assertion exception, if needed.
RegistrySystemException - Validation exception if condition
is false.
public void test(int cond,
Assertor.DeferredCondition valid,
int type,
java.lang.String[] msgArgs)
test.
This method enforces Testing Pre/Post-Conditions, which may be
turned off. Default is ON, but can be turned off by specifying the
environment variable
org.oclc.da.gdfr.registryprototype.exceptions.Assertor.TESTING.
How to use the inner class DeferredCondition is shown in
the example below. This example shows how to check that the new thread
was started properly, but the verification conditional is deferred to
ensure that testing post-conditions are turned on.
// the final qualifier is required in order for the inner class
// to call methods on this variable
String threadName = this.toString()+"::Runner";
final Thread t = new Thread(new Runnable()
{
public void run()
{
l.load();
}
}, threadName);
t.start();
// post-conditions
// 1. in this format, the expression is executed before the
// TESTING system variable is checked, and so, it may execute
// unnecessarily.
tester.test(Assertor.POST, t.isAlive(), DAExceptionCodes.MUST_EXIST,
new String[] { "THREAD", threadName });
// 2. in this second format, the expression is executed after the
// TESTING system variable is checked, inside the test() method
// itself.
tester.test(Assertor.POST,
new Assertor.DeferredCondition()
{
public boolean test()
{
return t.isAlive();
}
},
DAExceptionCodes.MUST_EXIST,
new String[] {"THREAD", threadName});
return true;
see test(int, boolean, int, java.lang.String[]);
cond - The condition type: PRE or POST.valid - The expression condition to be checked.type - The condition identifier (see
org.oclc.da.gdfr.registryprototype.exceptions.RegistryExceptionCodes).msgArgs - A string array of arguments to be substituted into the
assertion exception, if needed.
RegistrySystemException - Validation exception if
valid.check() evaluates to false.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||