gt: 		if (bindingContainer instanceof JBinding) {
context: /*
   * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Sly Technologies, Inc.
   *
   * This file is part of jNetPcap.
   *
   * jNetPcap is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as 
   * published by the Free Software Foundation, either version 3 of 
   * the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  package org.jnetpcap.packet;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Formatter;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.jnetpcap.PcapDLT;
  import org.jnetpcap.packet.structure.AnnotatedBinding;
  import org.jnetpcap.packet.structure.AnnotatedHeader;
  import org.jnetpcap.packet.structure.AnnotatedScannerMethod;
  import org.jnetpcap.packet.structure.HeaderDefinitionError;
  import org.jnetpcap.protocol.JProtocol;
  import org.jnetpcap.util.resolver.Resolver;
  import org.jnetpcap.util.resolver.Resolver.ResolverType;
  
  // TODO: Auto-generated Javadoc
  /**
   * 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
   * @author Sly Technologies, Inc.
   */
  @SuppressWarnings("unchecked")
  public final class JRegistry {
  
  	/**
  	 * A header information entry created for every header registered. Entry class
  	 * contains various bits and pieces of information about the registred header.
  	 * 
  	 * @author Mark Bednarczyk
  	 * @author Sly Technologies, Inc.
  	 */
  	private static class Entry {
  
  		/** The annotated header. */
  		private AnnotatedHeader annotatedHeader;
  
  		/** The class name. */
  		private final String className;
  
  		/** The clazz. */
  		private Class<? extends JHeader> clazz;
  
  		/** The id. */
  		private final int id;
  
  		/**
  		 * Instantiates a new entry.
  		 * 
  		 * @param id
  		 *          the id
  		 * @param c
  		 *          the c
  		 */
  		public Entry(int id, Class<? extends JHeader> c) {
  			this.id = id;
  			this.clazz = c;
  			this.className = c.getName();
  		}
  
  		/**
  		 * Instantiates a new entry.
  		 * 
  		 * @param id
  		 *          the id
  		 * @param className
  		 *          the class name
  		 */
  		public Entry(int id, String className) {
  			this.id = id;
  			this.className = className;
  		}
  
  		/**
  		 * Gets the header class.
  		 * 
  		 * @return the header class
  		 */
  		public Class<? extends JHeader> getHeaderClass() {
  			if (clazz == null) {
  				try {
  					return (Class<? extends JHeader>) Class.forName(className);
  				} catch (ClassNotFoundException e) {
  					throw new IllegalStateException(e);
  				}
  			} else {
  				return this.clazz;
  			}
  		}
  	}
  
  	/**
  	 * A private duplicate constant for MAX_ID_COUNT who's name is prefixed with
  	 * A_ so that due to source code sorting, we don't get compiler errors. Made
  	 * private so no one outside this class knows about it. Got tired of having to
  	 * move MAX_ID_COUNT definition around after each source sort.
  	 */
  	private final static int A_MAX_ID_COUNT = 256;
  
  	/** Number of core protocols defined by jNetPcap. */
  	public static final int CORE_ID_COUNT = JProtocol.LAST_ID;
  
  	/** The Constant DLTS_TO_IDS. */
  	private final static int[] DLTS_TO_IDS;
  
  	/** The errors. */
  	private static List<HeaderDefinitionError> errors =
  			new ArrayList<HeaderDefinitionError>();
  
  	/**
  	 * A flag that allows tells that a java scanner's process bindings method has
  	 * been overriden.
  	 */
  	public final static int FLAG_HEURISTIC_BINDING = 0x00000010;
  
  	/**
  	 * A flag that allows tells that a java scanner's process bindings method has
  	 * been overriden.
  	 */
  	public final static int FLAG_HEURISTIC_PRE_BINDING = 0x00000020;
  
  	/**
  	 * A flag that allows tells that a java scanner's process bindings method has
  	 * been overriden.
  	 */
  	public final static int FLAG_OVERRIDE_BINDING = 0x00000002;
  
  	/**
  	 * A flag that allows tells that a java scanner's get length method has been
  	 * overriden.
  	 */
  	public final static int FLAG_OVERRIDE_LENGTH = 0x00000001;
  
  	/** The Constant headerFlags. */
  	private final static int headerFlags[] = new int[A_MAX_ID_COUNT];
  
  	/** The Constant IDS_TO_DLTS. */
  	private final static int[] IDS_TO_DLTS;
  
  	/** The LAS t_ id. */
  	private static int LAST_ID = JProtocol.LAST_ID;
  
  	/** The Constant MAP_BY_ID. */
  	private final static Entry[] MAP_BY_ID = new Entry[A_MAX_ID_COUNT];
  
  	/** Holds class to ID mapping - this is global accross all registries. */
  	private static Map<String, Entry> mapByClassName =
  			new HashMap<String, Entry>();
  
  	/** The map subs by class name. */
  	private static Map<String, AnnotatedHeader> mapSubsByClassName =
  			new HashMap<String, AnnotatedHeader>(50);
  
  	/** The Constant MAX_DLT_COUNT. */
  	private static final int MAX_DLT_COUNT = 512;
  
  	/**
  	 * Maximum number of protocol header entries allowed by this implementation of
  	 * JRegistry.
  	 */
  	public final static int MAX_ID_COUNT = 256;
  
  	/**
  	 * A constant if returned from {@link #mapDLTToId} or {@link #mapIdToDLT} that
  	 * no mapping exists.
  	 */
  	public static final int NO_DLT_MAPPING = -1;
  
  	/**
  	 * Allow any type of key to be used so that users can register their own
  	 * unknown type resolvers.
  	 */
  	private final static Map<Object, Resolver> resolvers =
  			new HashMap<Object, Resolver>();
  
  	/**
  	 * Header scanners for each header type and protocol. The user can override
  	 * native direct scanners by supplying a java based scanner that will override
  	 * a particular protocols entry.
  	 */
  	private final static JHeaderScanner[] scanners =
  			new JHeaderScanner[A_MAX_ID_COUNT];
  
  	/**
  	 * Initialize JRegistry with defaults
  	 * <ul>
  	 * <li>libpcap DLT mappings</li>
  	 * <li>Register CORE protocols</li>
  	 * <li>Register address resolvers</li>
  	 * </ul>
  	 */
  	static {
  		/**
  		 * Initialized DLT to ID mappings
  		 */
  		DLTS_TO_IDS = new int[MAX_DLT_COUNT];
  		IDS_TO_DLTS = new int[MAX_ID_COUNT];
  
  		Arrays.fill(JRegistry.DLTS_TO_IDS, -1);
  		Arrays.fill(JRegistry.IDS_TO_DLTS, -1);
  
  		/**
  		 * Register CORE protocols
  		 */
  		for (JProtocol p : JProtocol.values()) {
  			try {
  				register(p);
  			} catch (Exception e) {
  				System.err.println("JRegistry Error: " + e.getMessage());
  				e.printStackTrace();
  
  				System.exit(0);
  			}
  		}
  
  		/**
  		 * Bind CORE protocols. Most bindings are provided by the native scanner but
  		 * some protocols may have java bindings as well that need to be registered.
  		 * They are by default registered in addition to the native bindings.
  		 */
  		for (JProtocol p : JProtocol.values()) {
  
  			try {
  				JBinding[] bindings =
  						AnnotatedBinding.inspectJHeaderClass(p.getHeaderClass(), errors);
  				if (bindings != null && bindings.length != 0) {
  					addBindings(bindings);
  				}
  			} catch (Exception e) {
  				System.err.println("JRegistry Error: " + e.getMessage());
  				e.printStackTrace();
  
  				System.exit(0);
  			}
  		}
  
  		/**
  		 * Register default resolvers for address to name mappings
  		 */
  		for (ResolverType t : ResolverType.values()) {
  			if (t.getResolver() != null) {
  				try {
  					registerResolver(t, t.getResolver());
  				} catch (Exception e) {
  					System.err.println("JRegistry Error: " + e.getMessage());
  					e.printStackTrace();
  
  					System.exit(0);
  				}
  			}
  		}
  
  		/**
  		 * Enable heuristics by default for TCP and UDP protocols
  		 */
  		setFlags(JProtocol.TCP_ID, FLAG_HEURISTIC_BINDING);
  		setFlags(JProtocol.UDP_ID, FLAG_HEURISTIC_BINDING);
  
  	}
  
  	/**
  	 * Adds bindings found in the container class. Any static methods that have
  	 * the <code>Bind</code> annotation defined will be extracted and wrapped as
  	 * <code>JBinding</code> interface objects, suitable to be registered with for
  	 * a target header. Bindings contained in any class that does not extend
  	 * <code>JHeader</code> is required to provide both "to" and "from" parameters
  	 * to <code>Bind</code> annotation.
  	 * 
  	 * @param container
  	 *          container that has static bind methods
  	 */
  	public static void addBindings(Class<?> container) {
  		clearErrors();
  
  		if (JHeader.class.isAssignableFrom(container)) {
  			addBindings(AnnotatedBinding
  					.inspectJHeaderClass((Class<? extends JHeader>) container, errors));
  
  		} else {
  			addBindings(AnnotatedBinding.inspectClass(container, errors));
  		}
  	}
  
  	/**
  	 * Adds additional bindings to a particular protocol.
  	 * 
  	 * @param bindings
  	 *          the bindings
  	 */
  	public static void addBindings(JBinding... bindings) {
  
  		for (JBinding b : bindings) {
  			scanners[b.getTargetId()].addBindings(b);
  		}
  
  	}
  
  	/**
  	 * Adds all of the bindings found in the bindinsContainer object supplied. The
  	 * methods that have the <code>Bind</code> 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.
  	 * 
  	 * @param bindingContainer
  	 *          container object that contains binding instance methods
  	 */
  	public static void addBindings(Object bindingContainer) {
  