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

com.alogic.xscript.Namespace Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.alogic.xscript;

import com.alogic.xscript.plugins.Segment;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;

/**
 * Namespace基类
 *
 * @since 1.6.12.42 [20190911]
 */
public class Namespace extends Segment {
    protected Map scripts = new HashMap();

    public Namespace(String tag, Logiclet p) {
        super(tag, p);
    }

    public void registerModule(String xmltag,Class clazz,String src) {
        super.registerModule(xmltag, clazz);
        scripts.put(xmltag,src);
    }

    protected Logiclet createLogiclet(Class clazz,String xmlTag,Logiclet parent){
        try {
            if (ExtensionTag.class.isAssignableFrom(clazz)){
                String src = scripts.get(xmlTag);
                if (StringUtils.isNotEmpty(src)){
                    Constructor constructor = clazz.getConstructor(String.class, Logiclet.class,String.class);
                    return constructor.newInstance(new Object[]{xmlTag, parent,src});
                }else{
                    Constructor constructor = clazz.getConstructor(String.class, Logiclet.class);
                    return constructor.newInstance(new Object[]{xmlTag,parent});
                }
            }else {
                Constructor constructor = clazz.getConstructor(String.class, Logiclet.class);
                return constructor.newInstance(new Object[]{xmlTag, parent});
            }
        } catch (Exception e) {
            logger.error("Can not create segment instance:" + clazz.getName(),e);
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy