CoreConfigServiceImpl.java 5.87 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.aemds.settings.AemDsSettingsService
 *  javax.transaction.TransactionManager
 *  org.apache.commons.io.FileUtils
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Deactivate
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.settings.SlingSettingsService
 *  org.osgi.framework.BundleContext
 *  org.osgi.service.component.ComponentContext
 */
package com.adobe.aemds.bedrock.internal;

import com.adobe.aemds.bedrock.CoreConfigService;
import com.adobe.aemds.bedrock.internal.OSGiUtils;
import com.adobe.aemds.settings.AemDsSettingsService;
import java.io.File;
import java.io.IOException;
import javax.transaction.TransactionManager;
import org.apache.commons.io.FileUtils;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.settings.SlingSettingsService;
import org.omg.CORBA.ORB;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;

@Component
@Service(value={CoreConfigService.class})
public class CoreConfigServiceImpl
implements CoreConfigService {
    private String serverNativeDirPath;
    private String serverConfigDirPath;
    private String serverDataDirPath;
    private String serverCommonDirPath;
    private String serverTempDirPath;
    @Reference
    private SlingSettingsService settingsService;
    @Reference
    private AemDsSettingsService aemDsSettingsService;
    @Reference
    private TransactionManager transactionManager;
    @Reference(referenceInterface=ORB.class)
    private ORB orb;

    @Activate
    private void activate(ComponentContext componentContext) throws IOException {
        File slingHome = new File(this.settingsService.getSlingHomePath());
        File rootDir = new File(slingHome, "bedrock");
        FileUtils.forceMkdir((File)rootDir);
        File tempDir = new File(this.aemDsSettingsService.getTempFolderPath());
        File serverNativeDir = new File(rootDir, "svcnative");
        File serverConfigDir = new File(rootDir, "svcconfig");
        File serverCommonDir = new File(rootDir, "svccommon");
        File serverDataDir = new File(rootDir, "svcdata");
        File serverTempDir = new File(tempDir, "datamanager");
        FileUtils.forceMkdir((File)serverNativeDir);
        FileUtils.forceMkdir((File)serverConfigDir);
        FileUtils.forceMkdir((File)serverCommonDir);
        FileUtils.forceMkdir((File)serverDataDir);
        FileUtils.forceMkdir((File)serverTempDir);
        this.serverNativeDirPath = serverNativeDir.getCanonicalPath();
        this.serverConfigDirPath = serverConfigDir.getCanonicalPath();
        this.serverDataDirPath = serverDataDir.getCanonicalPath();
        this.serverCommonDirPath = serverCommonDir.getCanonicalPath();
        this.serverTempDirPath = serverTempDir.getCanonicalPath();
        OSGiUtils.setCoreConfigService(this);
        OSGiUtils.setBundleContext(componentContext.getBundleContext());
        OSGiUtils.setTransactionManager(this.transactionManager);
        OSGiUtils.setOrb(this.orb);
        this.exportServerProperties();
    }

    @Deactivate
    private void deactivate() {
        OSGiUtils.setCoreConfigService(null);
        OSGiUtils.setBundleContext(null);
        OSGiUtils.setTransactionManager(null);
        OSGiUtils.setOrb(null);
    }

    public String getServerConfigHomeDir() {
        return this.serverConfigDirPath;
    }

    public String getServerDataDir() {
        return this.serverDataDirPath;
    }

    public String getServerNativeDir() {
        return this.serverNativeDirPath;
    }

    public String getServerCommonDir() {
        return this.serverCommonDirPath;
    }

    public String getServerTempDir() {
        return this.serverTempDirPath;
    }

    public void exportServerProperties() {
        System.setProperty("com.adobe.aemds.bedrock.serverConfigDirPath", this.serverConfigDirPath);
        System.setProperty("com.adobe.aemds.bedrock.serverDataDirPath", this.serverDataDirPath);
        System.setProperty("com.adobe.aemds.bedrock.serverNativeDirPath", this.serverNativeDirPath);
        System.setProperty("com.adobe.aemds.bedrock.serverCommonDirPath", this.serverCommonDirPath);
        System.setProperty("com.adobe.aemds.bedrock.serverTempDirPath", this.serverTempDirPath);
        System.setProperty("com.adobe.tempDirectory", this.serverTempDirPath);
    }

    protected void bindSettingsService(SlingSettingsService slingSettingsService) {
        this.settingsService = slingSettingsService;
    }

    protected void unbindSettingsService(SlingSettingsService slingSettingsService) {
        if (this.settingsService == slingSettingsService) {
            this.settingsService = null;
        }
    }

    protected void bindAemDsSettingsService(AemDsSettingsService aemDsSettingsService) {
        this.aemDsSettingsService = aemDsSettingsService;
    }

    protected void unbindAemDsSettingsService(AemDsSettingsService aemDsSettingsService) {
        if (this.aemDsSettingsService == aemDsSettingsService) {
            this.aemDsSettingsService = null;
        }
    }

    protected void bindTransactionManager(TransactionManager transactionManager) {
        this.transactionManager = transactionManager;
    }

    protected void unbindTransactionManager(TransactionManager transactionManager) {
        if (this.transactionManager == transactionManager) {
            this.transactionManager = null;
        }
    }

    protected void bindOrb(ORB oRB) {
        this.orb = oRB;
    }

    protected void unbindOrb(ORB oRB) {
        if (this.orb == oRB) {
            this.orb = null;
        }
    }
}