Polymorphic Thread Bot

package uk.me.spamer.polybot;
 
public class PolyBot {
  private java.util.Properties properties = null;
  public PolyBot(java.util.Properties properties) {
    if (properties!=null) {
      this.properties = properties;
      }
    else {
      try {
        properties.load( new java.io.FileInputStream( new java.io.File( this.getClass().getName()+".properties" ) ) ) ;
      } catch (java.io.IOException ioException ) {
        System.err.println( "Error: reading "+this.getClass().getName()+".properties file" ) ;
      }
    }
  }
 
  public java.util.Properties execute(java.util.Properties properties) {
    java.util.Enumeration keys = properties.propertyNames() ;
    while(keys.hasMoreElements()) {
      String key = (String) keys.nextElement() ;
      String value = properties.getProperty( key ) ;
      try {
        java.lang.Thread thread = (java.lang.Thread) Class.forName( value ).newInstance() ;
        thread.run() ;
      } catch (java.lang.ClassNotFoundException classNotFoundException) {
        classNotFoundException.printStackTrace( System.err ) ;
      } catch (java.lang.InstantiationException instantiationException) {
        instantiationException.printStackTrace( System.err ) ;
      } catch (java.lang.IllegalAccessException illegalAccessException) {
        illegalAccessException.printStackTrace( System.err ) ;
      }
    }
    return properties;
  }
 
  public static void main(String[] args) {
    java.util.Properties parameter = new java.util.Properties() ;
    try {    
      for(int i=0 ; i<args.length ; i++) {
        String key = args[i] ;
        String value = args[i] ;
        parameter.setProperty( key, value ) ;
      }
    } catch (java.lang.IndexOutOfBoundsException indexOutOfBoundsException) {
      /* silent consume */
      System.err.println( "Error: reading args[]" ) ;
    }
    PolyBot instance = new PolyBot( parameter ) ;
    java.util.Properties response = instance.execute( parameter ) ;
    System.out.println( response.toString() ) ;  
  }
}

oo_java_polybot.txt ยท Last modified: 2013/01/30 18:09 by Martin Spamer