package application;

public aspect ExchangeClassAspect {
	public pointcut exhangedClassConstructor() : 
		call(SMTPServer.new(..)) 			// pointcut catches all constructor calls
		&& !within(ExchangeClassAspect);    // not within this aspect

	SMTPServer around( ) : exhangedClassConstructor( ) {//executed instead of original constructor
		return getExchangeObject(proceed()); // exchange logic must return object which class inherits directly from original class    
	}

	SMTPServer getExchangeObject(SMTPServer server) {
	  if (server.isConnected()) {    // was connection succesful?
	    return server;             // return original object
	  } else {
	    return new SMTPServer("OK", "exhanged", "pwd");  // return alternative object
	  }
	}
}
