package com.autonomy.abc.selenium.application;

import com.autonomy.abc.selenium.keywords.KeywordService;
import com.autonomy.abc.selenium.promotions.PromotionService;
import com.autonomy.abc.selenium.search.SearchService;
import com.autonomy.abc.selenium.users.UserService;
import com.hp.autonomy.frontend.selenium.application.Application;
import com.hp.autonomy.frontend.selenium.application.ApplicationType;
import com.hp.autonomy.frontend.selenium.application.LoginService;
import com.hp.autonomy.frontend.selenium.control.Window;
import com.hp.autonomy.frontend.selenium.util.AppPage;
import com.hp.autonomy.frontend.selenium.util.Factory;
import com.hp.autonomy.frontend.selenium.util.SafeClassLoader;

import java.util.EnumMap;
import java.util.Map;

public abstract class IsoApplication<T extends IsoElementFactory> implements Application<T> {
    private final static Map<ApplicationType, Factory<? extends IsoApplication>> FACTORY_MAP = new EnumMap<>(ApplicationType.class);
    private LoginService loginService;

    static {
        FACTORY_MAP.put(ApplicationType.HOSTED, new SafeClassLoader<>(IsoApplication.class, "com.autonomy.abc.selenium.hsod.HSODApplication"));
        FACTORY_MAP.put(ApplicationType.ON_PREM, new SafeClassLoader<>(IsoApplication.class, "com.autonomy.abc.selenium.iso.IdolIsoApplication"));
    }

    public abstract PromotionService promotionService();

    public abstract UserService<?> userService();

    public KeywordService keywordService() {
        return new KeywordService(this);
    }

    public SearchService searchService() {
        return new SearchService(this);
    }

    @Override
    public LoginService loginService() {
        if (loginService == null) {
            loginService = new LoginService(this);
        }
        return loginService;
    }

    public <S extends AppPage> S switchTo(Class<S> pageType) {
        elementFactory().handleSwitch(pageType);
        return elementFactory().loadPage(pageType);
    }

    @Override
    public String getName() {
        return "Search";
    }

    public static IsoApplication<?> ofType(ApplicationType type) {
        return FACTORY_MAP.get(type).create();
    }

    @Override
    public abstract IsoApplication<T> inWindow(Window window);
}

@@ -41,16 +41,131 @@
 ation;%0A%0A
+import com.autonomy.abc.selenium.hsod.IsoHsodApplication;%0Aimport com.autonomy.abc.selenium.iso.IdolIsoApplication;%0A
 import c
@@ -702,752 +702,141 @@
 ge;%0A
-import com.hp.autonomy.frontend.selenium.util.Factory;%0Aimport com.hp.autonomy.frontend.selenium.util.SafeClassLoader;%0A%0Aimport java.util.EnumMap;%0Aimport java.util.Map;%0A%0Apublic abstract class IsoApplication%3CT extends IsoElementFactory%3E implements Application%3CT%3E %7B%0A    private final static Map%3CApplicationType, Factory%3C? extends IsoApplication%3E%3E FACTORY_MAP = new EnumMap%3C%3E(ApplicationType.class);%0A    private LoginService loginService;%0A%0A    static %7B%0A        FACTORY_MAP.put(ApplicationType.HOSTED, new SafeClassLoader%3C%3E(IsoApplication.class, %22com.autonomy.abc.selenium.hsod.HSODApplication%22));%0A        FACTORY_MAP.put(ApplicationType.ON_PREM, new SafeClassLoader%3C%3E(IsoApplication.class, %22com.autonomy.abc.selenium.iso.IdolIsoApplication%22));%0A    %7D
+%0Apublic abstract class IsoApplication%3CT extends IsoElementFactory%3E implements Application%3CT%3E %7B%0A    private LoginService loginService;
 %0A%0A  
@@ -1639,46 +1639,285 @@
     
-return FACTORY_MAP.get(type).create();
+switch (type) %7B%0A            case HOSTED:%0A                return new IsoHsodApplication();%0A            case ON_PREM:%0A                return new IdolIsoApplication();%0A            default:%0A                throw new IllegalStateException(%22Unsupported app type: %22 + type);%0A        %7D
 %0A   

Fix application factory