AppInstanceProviderFactory.java 3.94 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.felix.scr.annotations.Activate
 *  org.apache.felix.scr.annotations.Component
 *  org.apache.felix.scr.annotations.Properties
 *  org.apache.felix.scr.annotations.Property
 *  org.apache.felix.scr.annotations.PropertyUnbounded
 *  org.apache.felix.scr.annotations.Reference
 *  org.apache.felix.scr.annotations.Service
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.commons.osgi.PropertiesUtil
 *  org.osgi.service.component.ComponentContext
 */
package com.adobe.cq.mobile.phonegap.impl;

import com.adobe.cq.mobile.appcache.impl.AppCacheManagerAdapterFactory;
import com.adobe.cq.mobile.phonegap.impl.AppInstanceProviderImpl;
import com.adobe.cq.mobile.platform.MobileResourceType;
import com.adobe.cq.mobile.platform.impl.AbstractMobileAppProviderFactory;
import com.adobe.cq.mobile.platform.impl.MobileAppProvider;
import com.adobe.cq.mobile.platform.impl.MobileAppProviderFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Dictionary;
import java.util.List;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.PropertyUnbounded;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.osgi.service.component.ComponentContext;

@Component(metatype=1, label="%cq.mobile.phonegap.AppInstanceProviderFactory.name", description="%cq.mobile.phonegap.AppInstanceProviderFactory.description")
@Service
@Properties(value={@Property(name="service.ranking", intValue={100}, propertyPrivate=1)})
public class AppInstanceProviderFactory
extends AbstractMobileAppProviderFactory
implements MobileAppProviderFactory {
    private static List<String> appPlatforms = new ArrayList<String>();
    @Property(label="%cq.mobile.phonegap.AppInstanceProviderFactory.defaultPlatforms.label", description="%cq.mobile.phonegap.AppInstanceProviderFactory.defaultPlatforms.description", value={"android", "ios"}, unbounded=PropertyUnbounded.ARRAY)
    private static final String DEFAULT_PLATFORM_NAMES = "cq.mobile.phonegap.instance.defaultPlatforms";
    private List<String> defaultPlatforms = new ArrayList<String>();
    @Reference
    private AppCacheManagerAdapterFactory appCacheManagerAdapterFactory;
    private final String[] acceptableTypes = new String[]{MobileResourceType.INSTANCE.getType(), "mobileapps/phonegap/components/instance"};

    @Override
    public MobileAppProvider getMobileAppProvider(Resource res) {
        if (this.accepts(res)) {
            AppInstanceProviderImpl provider = new AppInstanceProviderImpl(res, this.appCacheManagerAdapterFactory, this.defaultPlatforms);
            return provider;
        }
        return null;
    }

    @Override
    protected String[] getAcceptableTypes() {
        return this.acceptableTypes;
    }

    @Activate
    protected void activate(ComponentContext ctx) {
        Dictionary props = ctx.getProperties();
        this.defaultPlatforms.clear();
        if (props.get("cq.mobile.phonegap.instance.defaultPlatforms") != null) {
            this.defaultPlatforms.addAll(Arrays.asList(PropertiesUtil.toStringArray(props.get("cq.mobile.phonegap.instance.defaultPlatforms"))));
        }
    }

    protected void bindAppCacheManagerAdapterFactory(AppCacheManagerAdapterFactory appCacheManagerAdapterFactory) {
        this.appCacheManagerAdapterFactory = appCacheManagerAdapterFactory;
    }

    protected void unbindAppCacheManagerAdapterFactory(AppCacheManagerAdapterFactory appCacheManagerAdapterFactory) {
        if (this.appCacheManagerAdapterFactory == appCacheManagerAdapterFactory) {
            this.appCacheManagerAdapterFactory = null;
        }
    }
}