|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Target(value=METHOD) @Documented @Retention(value=RUNTIME) public @interface Validate
Defines a binding method. Any method annotated with Bind must
be of specific java method signature and must supply annotation's 'to'
parameter. In addition, bindings that are defined in non JHeader
based classes, must also provide the 'from' parameter.
The required method signature varies depending how it is declared. Here are the possible binding method declarations and their required Bind annotation parameters.
JHeader based class -
only requires the 'to' parameter. The 'from' paramter is optional and the
default value is the class of the parent header definition that the binding
is defined in.JHeader based class -
requires both 'to' and 'from' parameters to be defined.Object.class - requires both 'to' and 'from'
parameters to be defined.Static signature: public static boolean bindSourceClassToDestinationClass(JPacket packet, <? extends JHeader> header); Instance signature: public boolean bindSourceClassToDestinationClass(JPacket packet, <? extends JHeader> header);The method names are irrelevant and are provided in the above only as an example. It is recommended that implementors of binding methods, follow the following method naming convention to be consistent with other implementors and implementations. Here is the recommended naming convention:
methodName := "bind" fromClass "To" toClass fromClass := HEADER_NAME toClass := HEADER_NAMEThe naming convention is not enforced.
Here is an example of a complete binding method in a code fragment:
public class TestBindings {
@Bind(from = Ip4.class, to = Ethernet.class)
public static boolean bindIp4ToEthernet(JPacket packet, Ethernet eth) {
return eth.type() == 0x800;
}
@Bind(from = Ip4.class, to = IEEESnap.class)
public static boolean bindIp4ToIEEESnap(JPacket packet, IEEESnap snap) {
return snap.pid() == 0x800;
}
}
Here is an example of a single instance method.
Object o = new Object() {
@SuppressWarnings("unused")
@Bind(from = Ip4.class, to = Ethernet.class)
public boolean bindIp4ToMyHeader(JPacket packet, Ethernet eth) {
return eth.type() == 0x800;
}
The second parameter to the method must match the 'to' annotation parameter
type. The types are verified at runtime and errors generated if those
parameters do not match.
The Bind annotation also takes an optional "intValue"
parameter. This parameter is used for making bindings that matches up with a
BindValue marked field. Any field or method that is marked
with BindValue annotation within the "to" class, can be used
to make a match with "intValue" parameter. Since this is completely optional
operation, that may or may not be implemented or utilized, it is also
neccessary to provide the complete binding method with its logic as well. The
"intValue" parameter is used to optimize bindings that use constant value for
linking one protocol to the other.
| Optional Element Summary | |
|---|---|
java.lang.Class<? extends JHeader>[] |
hueristics
Binds this validation method as a heuristic discovery method for each protocol listed. |
int |
max
Maximum header length in bytes. |
int |
min
Minimum header length that is allowed by this protocol. |
public abstract java.lang.Class<? extends JHeader>[] hueristics
public abstract int max
public abstract int min
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||