| Home >> All |
Source code: Freenet/ConnectionFactory.java
1 package Freenet; 2 3 import java.lang.reflect.*; 4 5 public class ConnectionFactory 6 { 7 static public Connection connect(Address address) throws ConnectTimedOutException 8 { 9 try 10 { 11 Class c=Class.forName("Freenet."+address.protocol+"Connection"); 12 Class[] carr={Class.forName("Freenet."+address.protocol+"Address")}; 13 Constructor con=c.getConstructor(carr); 14 Object[] aar={address.address}; 15 return (Connection)con.newInstance(aar); 16 } 17 catch(InvocationTargetException e) 18 { 19 Throwable f=e.getTargetException(); 20 if(f instanceof ConnectTimedOutException) 21 throw new ConnectTimedOutException(); 22 else 23 f.printStackTrace(); 24 return null; 25 } 26 catch(Exception e) 27 { 28 e.printStackTrace(); 29 return null; 30 } 31 } 32 } 33 34 35 36