package gov.hhs.fha.nhinc.orchestration;

import gov.hhs.fha.nhinc.admindistribution.entity.EntityAdminDistributionFactory;
import gov.hhs.fha.nhinc.common.nhinccommon.HomeCommunityType;
import gov.hhs.fha.nhinc.connectmgr.ConnectionManagerCache;
import gov.hhs.fha.nhinc.nhinclib.NhincConstants;

public class OrchestrationContextFactory {

    private static OrchestrationContextFactory INSTANCE = new OrchestrationContextFactory();

    private OrchestrationContextFactory() {
    }

    public static OrchestrationContextFactory getInstance() {
        return INSTANCE;
    }

    public OrchestrationContextBuilder getBuilder(HomeCommunityType homeCommunityType, String serviceName) {
        NhincConstants.GATEWAY_API_LEVEL apiLevel = ConnectionManagerCache.getApiVersionForNhinTarget(
                    homeCommunityType.getHomeCommunityId(), serviceName);
        if (NhincConstants.DOC_RETRIEVE_SERVICE_NAME.equals(serviceName)) {
            return EntityAdminDistributionFactory.getInstance().createOrchestrationContextBuilder(apiLevel);
        } else if (NhincConstants.ADMIN_DIST_SERVICE_NAME.equals(serviceName)) {
            return EntityAdminDistributionFactory.getInstance().createOrchestrationContextBuilder(apiLevel);
        }

        return null;
    }
}

@@ -240,16 +240,86 @@
 rCache;%0A
+import gov.hhs.fha.nhinc.docretrieve.entity.EntityDocRetrieveFactory;%0A
 import g
@@ -930,16 +930,206 @@
 eName);%0A
+        return getBuilder(apiLevel, serviceName);%0A    %7D%0A    %0A    private OrchestrationContextBuilder getBuilder(%0A            NhincConstants.GATEWAY_API_LEVEL apiLevel, String serviceName) %7B%0A
         
@@ -1221,33 +1221,27 @@
 n Entity
-AdminDistribution
+DocRetrieve
 Factory.

Refactor a bit.