
import com.apple.dnssd.DNSSD;
import com.apple.dnssd.DNSSDException;

import java.lang.reflect.InvocationTargetException;

public class Main {

  public static void main(String[] args) {

    String name = null;
    try{
      Object student =
        Class.forName("Student").newInstance();
		name = (String) (Class.forName("Student").getMethod("name",null).invoke(student,null));
    }  catch (ClassNotFoundException e) {
      System.out.println("You need to provide a class named Student " +
        "in a file named Student.java.");
      System.exit(0);
    } catch (NoSuchMethodException e) {
      System.out.println("The Student class must contain a method that " +
        "is called 'name' and which returns a String.");
      System.exit(0);
    } catch (IllegalAccessException e) {
      System.out.println("The method 'name()' can not be private.");
      System.exit(0);
    } catch (InvocationTargetException e) {
      // no way this gets called
    } catch (InstantiationException e) {
      System.out.println("Check that Student has no constructor.");
      System.exit(0);
    }



      try {
      DNSSD.register(name, "_example-rolecall._tcp", 9093, new RegistrationMonitor() );
      } catch (DNSSDException e){
        System.err.println("Could not register service.");
      }
    }


}
