/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 ****************************************************************/

package org.apache.james.protocols.api;

import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.Map;


import org.apache.james.protocols.api.ProtocolTransport;
import org.slf4j.Logger;

/**
 * Basic implementation of {@link ProtocolSession}
 * 
 * 
 */
public class ProtocolSessionImpl implements ProtocolSession {

    private final SessionLog pLog;
    private final ProtocolTransport transport;
    private final Map<String, Object> connectionState;
    private final Map<String, Object> sessionState;
    private String user;

    public ProtocolSessionImpl(Logger logger, ProtocolTransport transport) {
        this.transport = transport;
        this.pLog = new SessionLog(getSessionID(), logger);;
        this.connectionState = new HashMap<String, Object>();
        this.sessionState = new HashMap<String, Object>();

    }

    @Override
	public InetSocketAddress getLocalAddress() {
		return transport.getLocalAddress();
	}

	@Override
	public InetSocketAddress getRemoteAddress() {
		return transport.getRemoteAddress();
	}

	/**
     * @see org.apache.james.protocols.api.ProtocolSession#getRemoteHost()
     */
    public String getRemoteHost() {
        return getRemoteAddress().getHostName();
    }

    /**
     * @see org.apache.james.protocols.api.ProtocolSession#getRemoteIPAddress()
     */
    public String getRemoteIPAddress() {
        return getRemoteAddress().getAddress().getHostAddress();
    }

    /**
     * @see org.apache.james.protocols.api.ProtocolSession#getUser()
     */
    public String getUser() {
        return user;
    }

    /**
     * @see org.apache.james.protocols.api.ProtocolSession#setUser(java.lang.String)
     */
    public void setUser(String user) {
        this.user = user;
    }

    /*
     * 
     */
    public ProtocolTransport getProtocolTransport() {
        return transport;
    }

    /**
     * @see org.apache.james.protocols.api.ProtocolSession#isStartTLSSupported()
     */
    public boolean isStartTLSSupported() {
        return transport.isStartTLSSupported();
    }

    /**
     * @see org.apache.james.protocols.api.ProtocolSession#isTLSStarted()
     */
    public boolean isTLSStarted() {
        return transport.isTLSStarted();
    }


    /**
     * @see org.apache.james.protocols.api.ProtocolSession#getLogger()
     */
    public Logger getLogger() {
        return pLog;
    }
    

    /**
     * @see org.apache.james.protocols.api.ProtocolSession#getSessionID()
     */
    public String getSessionID() {
        return transport.getId();
    }
    
    
    /**
     * @see org.apache.james.protocols.api.ProtocolSession#getConnectionState()
     */
    public Map<String, Object> getConnectionState() {
        return connectionState;
    }

    /**
     * @see org.apache.james.protocols.api.ProtocolSession#getState()
     */
    public Map<String, Object> getState() {
        return sessionState;
    }

    /**
     * This implementation just returns <code>null</code>. Sub-classes should overwrite this if needed
     */
	@Override
	public Response newLineTooLongResponse() {
		return null;
	}

    /**
     * This implementation just returns <code>null</code>. Sub-classes should overwrite this if needed
     */
	@Override
	public Response newFatalErrorResponse() {
		return null;
	}

	/**
	 * This implementation just clears the sessions state. Sub-classes should overwrite this if needed
	 */
	@Override
	public void resetState() {
		sessionState.clear();
	}

}

@@ -2046,33 +2046,36 @@
 %0A%0A    @Override%0A
-%09
+    
 public InetSocke
@@ -2095,34 +2095,40 @@
 ocalAddress() %7B%0A
-%09%09
+        
 return transport
@@ -2147,21 +2147,27 @@
 ress();%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 @Overrid
@@ -2164,25 +2164,28 @@
   @Override%0A
-%09
+    
 public InetS
@@ -2214,26 +2214,32 @@
 Address() %7B%0A
-%09%09
+        
 return trans
@@ -2263,21 +2263,27 @@
 ress();%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 /**%0A    
@@ -4217,32 +4217,39 @@
 b-classes should
+%0A     *
  overwrite this 
@@ -4258,33 +4258,36 @@
  needed%0A     */%0A
-%09
+    
 @Override%0A%09publi
@@ -4272,33 +4272,36 @@
 /%0A    @Override%0A
-%09
+    
 public Response 
@@ -4319,34 +4319,40 @@
 ongResponse() %7B%0A
-%09%09
+        
 return null;%0A%09%7D%0A
@@ -4348,17 +4348,20 @@
 n null;%0A
-%09
+    
 %7D%0A%0A    /
@@ -4432,32 +4432,39 @@
 b-classes should
+%0A     *
  overwrite this 
@@ -4477,25 +4477,28 @@
 ded%0A     */%0A
-%09
+    
 @Override%0A%09p
@@ -4491,25 +4491,28 @@
   @Override%0A
-%09
+    
 public Respo
@@ -4541,18 +4541,24 @@
 nse() %7B%0A
-%09%09
+        
 return n
@@ -4566,18 +4566,27 @@
 ll;%0A
-%09%7D%0A%0A%09/**%0A%09
+    %7D%0A%0A    /**%0A    
  * T
@@ -4654,16 +4654,23 @@
 s should
+%0A     *
  overwri
@@ -4691,14 +4691,20 @@
 ded%0A
-%09 */%0A%09
+     */%0A    
 @Ove
@@ -4709,17 +4709,20 @@
 verride%0A
-%09
+    
 public v
@@ -4744,10 +4744,16 @@
 ) %7B%0A
-%09%09
+        
 sess
@@ -4774,9 +4774,12 @@
 ();%0A
-%09
+    
 %7D%0A%0A%7D

Replace tabs by spaces