All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hadoopz.pluginBoss.utils.DefaultPluginLoader Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2019 jw362j.
 *
 * 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 com.hadoopz.pluginBoss.utils;

import com.hadoopz.pluginBoss.boss.ClzzProcessor;
import com.hadoopz.pluginBoss.boss.PluginLoadListener;
import com.hadoopz.pluginBoss.boss.PluginLoader;
import com.mycomm.IProtocol.log.UniversalLogHolder;
import com.mycomm.itool.SystemUtil;
import java.lang.reflect.Modifier;
import java.util.Set;

/**
 *
 * @author jw362j
 */
class DefaultPluginLoader implements PluginLoader {

    private final ClzzProcessor[] clzzProcessors;

    public DefaultPluginLoader(ClzzProcessor[] clzzProcessors) {
        this.clzzProcessors = clzzProcessors;
    }

    public void discoverPlugin(String pkgName, Object context, PluginLoadListener pluginLoadListener) {
        if (SystemUtil.isTxtEmpty(pkgName)) {
            UniversalLogHolder.d("", "pkgName is empty in DefaultPluginLoader.discoverPlugin...");
            return;
        }
        Set> clzs = null;
        if (SystemUtil.isAndroidEnvironment()) {
            clzs = SystemUtil.loadAndroidClasses(context, pkgName);
            if (clzs == null || clzs.isEmpty()) {
                UniversalLogHolder.d("", "Please use PluginBoss class properly,just pass android.content.Context to the second parameter:public static PluginBossAPI getBossInstance(String pkgName, Context androidContext)");
            }
        } else {
            clzs = SystemUtil.getClassSet(pkgName);
        }
        if (clzs == null || clzs.isEmpty()) {
            UniversalLogHolder.d("", "clzs is empty in DefaultPluginLoader.discoverPlugin...");
            return;
        }

        for (Class clz : clzs) {
            UniversalLogHolder.d("", "" + clz.getName());
            boolean isAbs = Modifier.isAbstract(clz.getModifiers());
            if (isAbs) {
                UniversalLogHolder.d(getClass().getSimpleName(), clz.getName() + " is Abstract.....!");
                continue;
            }
            if (clz.getName().contains("$")) {
                continue;
            }

            if (clzzProcessors != null && clzzProcessors.length > 0) {
                for (ClzzProcessor clzProcessor : clzzProcessors) {
                    if (clzProcessor != null) {
                        clzProcessor.processClazz(clz, pluginLoadListener);
                    }
                }
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy