Home >> All |
Source code: Freenet/HandshakeFactory.java
1 package Freenet; 2 3 import java.lang.reflect.*; 4 import Freenet.support.*; 5 6 /* 7 This code is part of the Java Adaptive Network Client by Ian Clarke. 8 It is distributed under the GNU Public Licence (GPL) version 2. See 9 http://www.gnu.org/ for further details of the GPL. 10 */ 11 12 /** 13 * HandshakeFactory.java 14 * 15 * This object takes a RawMessage and converts it to the appropriate 16 * subclass of the Handshake class depending on the handshake. 17 * 18 * @author Brandon Wiley (blanu@uts.cc.utexas.edu) 19 * @author Ian Clarke (I.Clarke@strs.co.uk) 20 **/ 21 22 public class HandshakeFactory 23 { 24 public static Handshake toHandshake(RawMessage r) 25 { 26 try 27 { 28 Class c=Class.forName("Freenet.handshake."+r.messageType); 29 Class[] carr={Freenet.RawMessage.class}; 30 Object[] oarr={r}; 31 Constructor con=c.getConstructor(carr); 32 Handshake m=(Handshake)con.newInstance(oarr); 33 return m; 34 } 35 catch(InvocationTargetException e) 36 { 37 Logger.log("HandshakeFactory.java","Handshake constructor threw exception:",Logger.ERROR); 38 e.getTargetException().printStackTrace(Logger.Lout); 39 } 40 catch(ClassNotFoundException e) { 41 Logger.log("HandshakeFactory.java","Unknown messagetype.",Logger.NORMAL); 42 } 43 catch(Exception e) 44 { 45 e.printStackTrace(Logger.Lout); 46 } 47 return null; 48 } 49 } 50 51 52 53 54 55 56