|
Weaver 3.1.0a1-D1 | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.oldlight.weaver.clientbinding.WeaverAttributeAssertion
The WeaverAttributeAssertion class checks values supplied to W-Beans. This class provides a convenient mechanism to check that the values needed by your W-Beans exist and are of the correct type. If values are not as expected then a WeaverClientException containing a suitable error message is automatically thrown. You may verify any of the following:
... private static final WeaverAttributeAssertion[] assertions = new WeaverAttributeAssertion[] { new WeaverAttributeAssertion("var", WeaverAttributeUtil.SCOPE_BEAN, java.lang.String.class, true), new WeaverAttributeAssertion("colour", WeaverAttributeUtil.SCOPE_BEAN, java.lang.String.class, true, new String[] { "red", "green" } ), }; ... public void handle(WeaverExecutionContext context) throws WeaverClientException { WeaverAttributeAssertion.assertAttributes(null, context, assertions); ...The first assertion declares that a value called var must be found in the Bean scope (that is must have been supplied via the param tag in the WAD file) and that it must be a String. The second assertion is similar to the first but insists that the value of colour attribute is take from the values red and green. Attribute assertions can be a great help during development but can be an overhead in a production deployment.
Field Summary | |
private Class |
attrClass
|
private static boolean |
checking
|
private boolean |
mandatory
|
private String |
name
|
private String |
scope
|
private String[] |
values
|
Constructor Summary | |
WeaverAttributeAssertion(String name,
String scope,
Class attrClass,
boolean mandatory)
Create an attribute assertion. |
|
WeaverAttributeAssertion(String name,
String scope,
Class attrClass,
boolean mandatory,
String[] values)
Create an attribute assertion. |
Method Summary | |
private void |
append(String toAppend,
StringBuffer buffer)
|
static void |
assertAttributes(String id,
WeaverExecutionContext context,
WeaverAttributeAssertion[] assertions)
Check the current execution context against the supplied assertions. |
private boolean |
check(WeaverExecutionContext context,
StringBuffer message)
|
private static boolean |
isA(Class valueClass,
Class attrClass)
|
static void |
setChecking(boolean doChecking)
Enable or disable checking attribute assertions. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private Class attrClass
private boolean mandatory
private String scope
private String name
private String[] values
private static boolean checking
Constructor Detail |
public WeaverAttributeAssertion(String name, String scope, Class attrClass, boolean mandatory, String[] values)
name
- The name of the attribute to check.scope
- The scope of the attribute to check - or null to check all scopes via WeaverExecutionContext.findAttribute.attrClass
- The class the attribute must be compatible with - or null to not check.mandatory
- Whether existance of the value is mandatory.values
- A set of String values from which the attribute value must be taken.public WeaverAttributeAssertion(String name, String scope, Class attrClass, boolean mandatory)
name
- The name of the attribute to check.scope
- The scope of the attribute to check - or null to check all scopes via WeaverExecutionContext.findAttribute.attrClass
- The class the attribute must be compatible with - or null to not check.mandatory
- Whether existance of the value is mandatory.Method Detail |
public static void setChecking(boolean doChecking)
doChecking
- Whether to enable or disable attribute assertions.private static boolean isA(Class valueClass, Class attrClass)
private void append(String toAppend, StringBuffer buffer)
private boolean check(WeaverExecutionContext context, StringBuffer message)
public static void assertAttributes(String id, WeaverExecutionContext context, WeaverAttributeAssertion[] assertions) throws WeaverClientException
id
- The id parameter to pass to any WeaverClientException that may be thrown (may be null).context
- The execution context against which to check the assertions.assertions
- The assertions themselves.
WeaverClientException
- Thrown if any of the assertions are not satisfied.
|
Copyright ©Paul Harvey | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |