title: How to search a class which can handle specific data in Java?
body: <p>I have multiple classes in my current project like <code>HTMLRequest</code>, <code>SPDYRequest</code>, <code>BHIVERequest</code>. I get data from a network stream and I want to find out, which of the classes can handle this data. For this I read the header of the Stream packet (All protocols are in the same form, so I can read until I get empty line (\r\n) ) and then pass this header to a static function in the request classes which returns a boolean which tells whether it is a header for this kind of request or not. Now I want to be able to load specific Protocols at runtime (from plug-ins). What is the best way to be able to check whether I have a Protocol for a header or not.</p>
  
  <p>My thoughts were:</p>
  
  <ul>
  <li><p>An extra class <code>Protocol</code> as a singleton, which then is registered in a <code>RequestFactory</code>, that then has to find out which Protocol can create a request for this kind of header and calls Protocol.assemble()</p></li>
  <li><p>A static List of <code>Class&lt;? extends Request&gt;</code> so I can call the static methods through reflection or by <code>Class.newInstance()</code></p></li>
  </ul>
  
  <p>I don't like both that ideas, so what is the right way to dynamically do this stuff in Java?</p>