src/org/jnetpcap/packet/structure/AnnotatedHeader.java
private static AnnotatedHeader inspectHeaderAnnotation(
	    Class<? extends JHeader> c,
	    List<HeaderDefinitionError> errors) {

		AnnotatedHeader header = new AnnotatedHeader(c);

		if (c.isAnnotationPresent(Header.class)) {
			Header a = c.getAnnotation(Header.class);

			if (JHeader.class.isAssignableFrom(c) == false) {
				/*
				 * All headers must subclass JHeader.class, no exceptions.
				 */

				errors.add(new HeaderDefinitionError(c,
				    "header must subclass 'JHeader'"));
			}

			if (a.name().length() != 0) {
				header.name = a.name();
			} else {
				header.name = c.getSimpleName();
			}

			if (a.nicname().length() != 0) {
				header.nicname = a.nicname();
			} else {
				header.nicname = header.name;
			}

			if (a.description().length() != 0) {
				header.description = a.description();
			} else if (a.dlt().length != 0) {
				/*
				 * Description comes from libpcap itself :)
				 */
				header.description = a.dlt()[0].getDescription();

			} else {
				header.description = null;
			}

			if (a.id() != -1) {
				a.id();
			}

			if (a.parent() != JHeader.class) {
				header.parentClass = a.parent();
			}

			if (header.parentClass == null && c.getEnclosingClass() != null) {
				for (Class<?> p = c.getEnclosingClass(); p != null; p =
				    p.getEnclosingClass()) {

					if (p.isAnnotationPresent(Header.class)) {
						if (JHeader.class.isAssignableFrom(p) == false) {
							errors.add(new HeaderDefinitionError(c, "parentClass header '"
							    + p.getSimpleName() + "' must subclass 'JHeader'"));
							break;
						}

						header.parentClass = p.asSubclass(JHeader.class);
						break;
					}
				}
			}

		} else {
			errors.add(new HeaderDefinitionError(c,
			    "header missing @Header annotation"));
		}

		return header;
	}
/**
	 * Inspect header annotation.
	 * 
	 * @param c
	 *          the c
	 * @param errors
	 *          the errors
	 * @return the annotated header
	 * @Header is optional on top level header. It defaults to class name as
	 *         header name
	 */
Inspect header annotation.

@param c
the c
@param errors
the errors
@return the annotated header
@Header is optional on top level header. It defaults to class name as
header name
Inspect header annotation . @param c the c @param errors the errors @return the annotated header @Header is optional on top level header . It defaults to class name as header name
private static AnnotatedHeader inspectHeaderAnnotation(
	    Class<? extends JHeader> c,
	    List<HeaderDefinitionError> errors) {
		AnnotatedHeader header = new AnnotatedHeader(c);
		if (c.isAnnotationPresent(Header.class)) {
			Header a = c.getAnnotation(Header.class);
			if (JHeader.class.isAssignableFrom(c) == false) {
				/*
				 * All headers must subclass JHeader.class, no exceptions.
				 */
				errors.add(new HeaderDefinitionError(c,
				    "header must subclass 'JHeader'"));
			}
			if (a.name().length() != 0) {
				header.name = a.name();
			} else {
				header.name = c.getSimpleName();
			}
			if (a.nicname().length() != 0) {
				header.nicname = a.nicname();
			} else {
				header.nicname = header.name;
			}
			if (a.description().length() != 0) {
				header.description = a.description();
			} else if (a.dlt().length != 0) {
				/*
				 * Description comes from libpcap itself :)
				 */
				header.description = a.dlt()[0].getDescription();
			} else {
				header.description = null;
			}
			if (a.id() != -1) {
				a.id();
			}
			if (a.parent() != JHeader.class) {
				header.parentClass = a.parent();
			}
			if (header.parentClass == null && c.getEnclosingClass() != null) {
				for (Class<?> p = c.getEnclosingClass(); p != null; p =
				    p.getEnclosingClass()) {
					if (p.isAnnotationPresent(Header.class)) {
						if (JHeader.class.isAssignableFrom(p) == false) {
							errors.add(new HeaderDefinitionError(c, "parentClass header '"
							    + p.getSimpleName() + "' must subclass 'JHeader'"));
							break;
						}
						header.parentClass = p.asSubclass(JHeader.class);
						break;
					}
				}
			}
		} else {
			errors.add(new HeaderDefinitionError(c,
			    "header missing @Header annotation"));
		}
		return header;
	}
private static AnnotatedHeader inspectHeaderAnnotation ( Class < ? extends JHeader > c , List < HeaderDefinitionError > errors ) { AnnotatedHeader header = new AnnotatedHeader ( c ) ; if ( c . isAnnotationPresent ( Header . class ) ) { Header a = c . getAnnotation ( Header . class ) ; if ( JHeader . class . isAssignableFrom ( c ) == false ) { /*
				 * All headers must subclass JHeader.class, no exceptions.
				 */ errors . add ( new HeaderDefinitionError ( c , "header must subclass 'JHeader'" ) ) ; } if ( a . name ( ) . length ( ) != 0 ) { header . name = a . name ( ) ; } else { header . name = c . getSimpleName ( ) ; } if ( a . nicname ( ) . length ( ) != 0 ) { header . nicname = a . nicname ( ) ; } else { header . nicname = header . name ; } if ( a . description ( ) . length ( ) != 0 ) { header . description = a . description ( ) ; } else if ( a . dlt ( ) . length != 0 ) { /*
				 * Description comes from libpcap itself :)
				 */ header . description = a . dlt ( ) [ 0 ] . getDescription ( ) ; } else { header . description = null ; } if ( a . id ( ) != - 1 ) { a . id ( ) ; } if ( a . parent ( ) != JHeader . class ) { header . parentClass = a . parent ( ) ; } if ( header . parentClass == null && c . getEnclosingClass ( ) != null ) { for ( Class < ? > p = c . getEnclosingClass ( ) ; p != null ; p = p . getEnclosingClass ( ) ) { if ( p . isAnnotationPresent ( Header . class ) ) { if ( JHeader . class . isAssignableFrom ( p ) == false ) { errors . add ( new HeaderDefinitionError ( c , "parentClass header '" + p . getSimpleName ( ) + "' must subclass 'JHeader'" ) ) ; break ; } header . parentClass = p . asSubclass ( JHeader . class ) ; break ; } } } } else { errors . add ( new HeaderDefinitionError ( c , "header missing @Header annotation" ) ) ; } return header ; }
Inspect header annotation.
Inspect header annotation .