public void init(final Map attributes) throws SaslException {
      if (state != -1) {
         throw new IllegalMechanismStateException("init()");
      }

      if (properties == null) {
         properties = new HashMap();
      } else {
         properties.clear();
      }
      if (attributes != null) {
         protocol = (String) attributes.get(Registry.SASL_PROTOCOL);
         serverName = (String) attributes.get(Registry.SASL_SERVER_NAME);
         handler = (CallbackHandler) attributes.get(Registry.SASL_CALLBACK_HANDLER);
         channelBinding = (byte[]) attributes.get(Registry.SASL_CHANNEL_BINDING);
         properties.putAll(attributes);
      } else {
         handler = null;
      }

      if (protocol == null) {
         protocol = "";
      }
      if (serverName == null) {
         serverName = "";
      }
      if (authenticator != null) {
         authenticator.activate(properties);
      }
      if (channelBinding == null) {
         channelBinding = new byte[0];
      }
      initMechanism();
      complete = false;
      state = 0;
   }