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