org.jnetpcap.packet
Class JRegistry

java.lang.Object
  extended by org.jnetpcap.packet.JRegistry

public final class JRegistry
extends java.lang.Object

A registry of protocols, their classes, runtime IDs and bindings. This is a global registry that all of jnetpcap's packet framework accesses. The registry matains tables of bindings, header scanners and numerical IDs for each header. The registry also performs various lookup and cross reference infomatation such as mapping a header class to a numerical ID.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Field Summary
static int CORE_ID_COUNT
          Number of core protocols defined by jNetPcap
static int FLAG_OVERRIDE_BINDING
          A flag that allows tells that a java scanner's process bindings method has been overriden
static int FLAG_OVERRIDE_LENGTH
          A flag that allows tells that a java scanner's get length method has been overriden
static int MAX_ID_COUNT
          Maximum number of protocol header entries allowed by this implementation of JRegistry
static int NO_DLT_MAPPING
          A constant if returned from #mapDltToId or mapIdToDLT(int) that no mapping exists.
 
Method Summary
static
<T extends JAnalyzer>
void
addAnalyzer(T analyzer)
           
static void addBindings(java.lang.Class<?> container)
          Adds bindings found in the container class.
static void addBindings(JBinding... bindings)
          Adds additional bindings to a particular protocol
static void addBindings(java.lang.Object bindingContainer)
          Adds all of the bindings found in the bindinsContainer object supplied.
static void clearErrors()
          Clears any existing registery errors
static void clearFlags(int id, int flags)
          Clears the supplied bits within the flag's bitmap
static void clearScanners(java.lang.Class<? extends JHeader>... classes)
          Clears java scanners for supplied list of headers
static void clearScanners(int... ids)
          Clears java scanners for supplied list of headers
static void clearScanners(java.lang.Object container)
          Removes previously registered scanners that are defined in the supplied object container.
static
<T extends JAnalyzer>
T
getAnalyzer(java.lang.Class<T> c)
           
static JBinding[] getBindings(int id)
          Retrieves all current bindings bound to a protocol
static HeaderDefinitionError[] getErrors()
          Retrieves the recent errors that were generated by registry operations
static int getFlags(int id)
          Gets the current flags for a specified protocol
static JHeaderScanner[] getHeaderScanners()
          Retrieves the entire list of scanners for all registered protocols
static Resolver getResolver(java.lang.Object customType)
          Retrieves a registered instance of any resolver.
static Resolver getResolver(Resolver.ResolverType type)
          Retrieves a registered instance of a resolver.
static boolean hasDltMapping(int dlt)
          Checks if a mapping for libpcap dlt value is defined
static boolean hasErrors()
          Checks if there are any registry errors that were recently generated
static boolean hasResolver(java.lang.Object type)
          Checks if resolver of specific type is currently registered
static boolean hasResolver(Resolver.ResolverType type)
          Checks if resolver of specific type is currently registered
static AnnotatedHeader inspect(java.lang.Class<? extends JHeader> c, java.util.List<HeaderDefinitionError> errors)
           
static java.lang.Object[] listResolvers()
          Returns a complete list of currently active resolvers types.
static AnnotatedHeader lookupAnnotatedHeader(java.lang.Class<? extends JHeader> c)
           
static AnnotatedHeader lookupAnnotatedHeader(int id)
           
static AnnotatedHeader lookupAnnotatedHeader(JProtocol protocol)
           
static java.lang.Class<? extends JHeader> lookupClass(int id)
          Looks up the class of a header based on its ID.
static int lookupId(java.lang.Class<? extends JHeader> c)
          Look's up the protocol header ID using a class name
static int lookupId(JProtocol p)
          Look's up the protocol header ID using a protocol constant.
static JHeaderScanner lookupScanner(int id)
          Looks up a header scanner.
static int mapDLTToId(int dlt)
           
static int mapIdToDLT(int id)
           
static PcapDLT mapIdToPcapDLT(int id)
           
static int register(java.lang.Class<? extends JHeader> c)
           
static int register(java.lang.Class<? extends JHeader> c, java.util.List<HeaderDefinitionError> errors)
          Registeres a new protocol header.
static void registerDLT(int dlt, int id)
           
static void registerDLT(PcapDLT dlt, int id)
           
static void registerResolver(java.lang.Object customType, Resolver custom)
          Registers a new resolver of any type, replacing the previous resolver.
static void registerResolver(Resolver.ResolverType type, Resolver custom)
          Registers a new resolver of specific type, replacing the previous resolver.
static void resetBindings(int id)
          Clears any existing java bindings for the specified protocol
static void setFlags(int id, int flags)
          Sets the current flag for a specified protocol
static void setScanners(AnnotatedScannerMethod... scanners)
           
static void setScanners(java.lang.Class<?> c)
           
static void setScanners(java.lang.Object container)
           
static void shutdown()
          Prepares the registry for shutdown.
static java.lang.String toDebugString()
          Dumps various tables JRegistry maintains as debug information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CORE_ID_COUNT

public static final int CORE_ID_COUNT
Number of core protocols defined by jNetPcap


FLAG_OVERRIDE_BINDING

public static final int FLAG_OVERRIDE_BINDING
A flag that allows tells that a java scanner's process bindings method has been overriden

See Also:
Constant Field Values

FLAG_OVERRIDE_LENGTH

public static final int FLAG_OVERRIDE_LENGTH
A flag that allows tells that a java scanner's get length method has been overriden

See Also:
Constant Field Values

MAX_ID_COUNT

public static final int MAX_ID_COUNT
Maximum number of protocol header entries allowed by this implementation of JRegistry

See Also:
Constant Field Values

NO_DLT_MAPPING

public static final int NO_DLT_MAPPING
A constant if returned from #mapDltToId or mapIdToDLT(int) that no mapping exists.

See Also:
Constant Field Values
Method Detail

addBindings

public static void addBindings(java.lang.Class<?> container)
Adds bindings found in the container class. Any static methods that have the Bind annotation defined will be extracted and wrapped as JBinding interface objects, suitable to be registered with for a target header. Bindings contained in any class that does not extend JHeader is required to provide both "to" and "from" parameters to Bind annotation.

Parameters:
container - container that has static bind methods

addBindings

public static void addBindings(JBinding... bindings)
Adds additional bindings to a particular protocol

Parameters:
id -
bindings -

addBindings

public static void addBindings(java.lang.Object bindingContainer)
Adds all of the bindings found in the bindinsContainer object supplied. The methods that have the Bind annotation, will be extracted and converted to JBinding objects that will call on those methods as a binding. The "this" pointer in the instance methods will be set to null, therefore do not rely on any super methods and "this" operator. The bind annotation inspector check and ensure that only "Object" class is extended for the container class.

Parameters:
bindingContainer - container object that contains binding instance methods

clearErrors

public static void clearErrors()
Clears any existing registery errors


clearFlags

public static void clearFlags(int id,
                              int flags)
Clears the supplied bits within the flag's bitmap

Parameters:
id - protocol ID
flags - flags to clear

clearScanners

public static void clearScanners(java.lang.Class<? extends JHeader>... classes)
Clears java scanners for supplied list of headers

Parameters:
classes - classes of all the headers that java scanner will be cleared if previously registered

clearScanners

public static void clearScanners(int... ids)
Clears java scanners for supplied list of headers

Parameters:
ids - ids of all the headers that java scanner will be cleared if previously registered

clearScanners

public static void clearScanners(java.lang.Object container)
Removes previously registered scanners that are defined in the supplied object container. Any scanners within the supplied container are retrieved and all the currently registered java scanner for the headers that the retrieved scanners target, are cleared.

Parameters:
container - container object containing scanner methods which target headers that will be cleared of java scanners

getBindings

public static JBinding[] getBindings(int id)
Retrieves all current bindings bound to a protocol

Parameters:
id - protocol id
Returns:
array of bindings for this protocol

getErrors

public static HeaderDefinitionError[] getErrors()
Retrieves the recent errors that were generated by registry operations

Returns:
array of errors

getFlags

public static int getFlags(int id)
Gets the current flags for a specified protocol

Parameters:
id - numerical id of the protocol header
Returns:
current flags as a bit mask

getHeaderScanners

public static JHeaderScanner[] getHeaderScanners()
Retrieves the entire list of scanners for all registered protocols

Returns:
array of header scanners

getResolver

public static Resolver getResolver(java.lang.Object customType)
Retrieves a registered instance of any resolver.

Parameters:
customType - resolver type
Returns:
currently registered resolver

getAnalyzer

public static <T extends JAnalyzer> T getAnalyzer(java.lang.Class<T> c)

addAnalyzer

public static <T extends JAnalyzer> void addAnalyzer(T analyzer)

getResolver

public static Resolver getResolver(Resolver.ResolverType type)
Retrieves a registered instance of a resolver.

Parameters:
type - resolver type
Returns:
currently registered resolver

hasDltMapping

public static boolean hasDltMapping(int dlt)
Checks if a mapping for libpcap dlt value is defined

Parameters:
dlt - value to check for
Returns:
true if dlt mapping exists, otherwise false

hasErrors

public static boolean hasErrors()
Checks if there are any registry errors that were recently generated

Returns:
true if error queue is not empty

hasResolver

public static boolean hasResolver(java.lang.Object type)
Checks if resolver of specific type is currently registered

Parameters:
type - type of resolver to check for
Returns:
true if resolver is registered, otherwise false

hasResolver

public static boolean hasResolver(Resolver.ResolverType type)
Checks if resolver of specific type is currently registered

Parameters:
type - type of resolver to check for
Returns:
true if resolver is registered, otherwise false

inspect

public static AnnotatedHeader inspect(java.lang.Class<? extends JHeader> c,
                                      java.util.List<HeaderDefinitionError> errors)

listResolvers

public static java.lang.Object[] listResolvers()
Returns a complete list of currently active resolvers types.

Returns:

lookupAnnotatedHeader

public static AnnotatedHeader lookupAnnotatedHeader(java.lang.Class<? extends JHeader> c)
                                             throws UnregisteredHeaderException
Throws:
UnregisteredHeaderException

lookupAnnotatedHeader

public static AnnotatedHeader lookupAnnotatedHeader(int id)
                                             throws UnregisteredHeaderException
Throws:
UnregisteredHeaderException

lookupAnnotatedHeader

public static AnnotatedHeader lookupAnnotatedHeader(JProtocol protocol)
Parameters:
protocol -
Returns:

lookupClass

public static java.lang.Class<? extends JHeader> lookupClass(int id)
                                                      throws UnregisteredHeaderException
Looks up the class of a header based on its ID.

Parameters:
id - protocol id
Returns:
class for this protocol
Throws:
UnregisteredHeaderException
UnregisteredHeaderException - thrown if protocol not found, invalid ID

lookupId

public static int lookupId(java.lang.Class<? extends JHeader> c)
Look's up the protocol header ID using a class name

Parameters:
c - class of the header
Returns:
numerical ID of the protocol header
Throws:
UnregisteredHeaderException - if header class is not registered

lookupId

public static int lookupId(JProtocol p)
Look's up the protocol header ID using a protocol constant. This method does not throw any exception since all core protocols defined on Jprotocol table are guarrantted to be registered.

Parameters:
p - protocol constant
Returns:
numerical ID of the protocol header

lookupScanner

public static JHeaderScanner lookupScanner(int id)
Looks up a header scanner.

Parameters:
id - id of the scanner to lookup
Returns:
header scanner for this ID

mapDLTToId

public static int mapDLTToId(int dlt)

mapIdToDLT

public static int mapIdToDLT(int id)

mapIdToPcapDLT

public static PcapDLT mapIdToPcapDLT(int id)

register

public static int register(java.lang.Class<? extends JHeader> c)
                    throws RegistryHeaderErrors
Throws:
RegistryHeaderErrors

register

public static int register(java.lang.Class<? extends JHeader> c,
                           java.util.List<HeaderDefinitionError> errors)
Registeres a new protocol header. A new numerical ID is assigned to the protocol and various mappings are recorded for this protocol.

Type Parameters:
T - header class type
Parameters:
c - class of the header
scan - header scanner that will perform header scans and check bindings
bindings - protocol to protocol bindings for this protocol
Returns:
numerical id assigned to this new protocol
Throws:
RegistryHeaderErrors

registerDLT

public static void registerDLT(int dlt,
                               int id)

registerDLT

public static void registerDLT(PcapDLT dlt,
                               int id)

registerResolver

public static void registerResolver(java.lang.Object customType,
                                    Resolver custom)
Registers a new resolver of any type, replacing the previous resolver.

Parameters:
customType - type of resolver to replace
custom - new resolver to register

registerResolver

public static void registerResolver(Resolver.ResolverType type,
                                    Resolver custom)
Registers a new resolver of specific type, replacing the previous resolver.

Parameters:
type - type of resolver to replace
custom - new resolver to register

resetBindings

public static void resetBindings(int id)
Clears any existing java bindings for the specified protocol

Parameters:
id - numerical id of the protocol header

setFlags

public static void setFlags(int id,
                            int flags)
Sets the current flag for a specified protocol

Parameters:
id - numerical id of the protocol header
flags - flags to set (bitwise OR) with the existing flags

setScanners

public static void setScanners(AnnotatedScannerMethod... scanners)

setScanners

public static void setScanners(java.lang.Class<?> c)

setScanners

public static void setScanners(java.lang.Object container)
Parameters:
container -

shutdown

public static void shutdown()
                     throws java.io.IOException
Prepares the registry for shutdown. The registry will save caches and release resources other that may be held.

Throws:
java.io.IOException

toDebugString

public static java.lang.String toDebugString()
Dumps various tables JRegistry maintains as debug information.

Returns:
multi-line string containing various debug information about JRegistry