/*
 * Copyright (C) 2007 Esmertec AG. Copyright (C) 2007 The Android Open Source
 * Project
 *
 * Licensed 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 info.guardianproject.otr.app.im.engine;

// import info.guardianproject.otr.app.im.plugin.loopback.LoopbackConnection;
import info.guardianproject.otr.app.im.plugin.xmpp.LLXmppConnection;
import info.guardianproject.otr.app.im.plugin.xmpp.XmppConnection;

import java.util.Map;

import android.content.Context;

/** The factory used to create an instance of ImConnection. */
public class ConnectionFactory {
    private static ConnectionFactory sInstance;

    private ConnectionFactory() {
    }

    /**
     * Gets the singleton instance of the factory.
     *
     * @return the singleton instance.
     */
    public synchronized static ConnectionFactory getInstance() {
        if (sInstance == null) {
            sInstance = new ConnectionFactory();
        }
        return sInstance;
    }

    /**
     * Creates a new ImConnection.
     *
     * @return the new ImConnection.
     * @throws IMException if an error occurs during creating a connection.
     */
    public synchronized ImConnection createConnection(Map<String, String> settings, Context context)
            throws ImException {
        if ("XMPP".equals(settings.get("im.protocol"))) {

            try
            {
                return new XmppConnection(context);
            }
            catch (Exception e)
            {
                throw new ImException(e.getMessage());
            }
        }
        if ("LLXMPP".equals(settings.get("im.protocol"))) {
            return new LLXmppConnection(context);
        }
        /*else if ("LOOPBACK".equals(settings.get("im.protocol"))) {
        	return new SMSConnection();
        } */
        else {
            throw new ImException("Unsupported protocol: " + settings.get("im.protocol"));
        }
    }
}

@@ -763,32 +763,93 @@
 backConnection;%0A
+import info.guardianproject.otr.app.im.plugin.ImConfigNames;%0A
 import info.guar
@@ -1823,24 +1823,97 @@
 n %7B%0A        
+String protocolName = settings.get(ImConfigNames.PROTOCOL_NAME);%0A        
 if (%22XMPP%22.e
@@ -1922,33 +1922,16 @@
 als(
-settings.get(%22im.
 protocol
 %22)))
@@ -1922,26 +1922,28 @@
 als(protocol
-%22)
+Name
 )) %7B%0A%0A      
@@ -2189,33 +2189,16 @@
 als(
-settings.get(%22im.
 protocol
 %22)))
@@ -2185,34 +2185,36 @@
 .equals(protocol
-%22)
+Name
 )) %7B%0A           
@@ -2303,33 +2303,16 @@
 als(
-settings.get(%22im.
 protocol
 %22)))
@@ -2307,18 +2307,20 @@
 protocol
-%22)
+Name
 )) %7B%0A   
@@ -2446,33 +2446,16 @@
 %22 + 
-settings.get(%22im.
 protocol
 %22));
@@ -2450,18 +2450,20 @@
 protocol
-%22)
+Name
 );%0A     

use ImConfigNames.PROTOCOL_NAME as constant in all relevant places