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

net.happyonroad.component.container.feature.StaticFeatureResolver Maven / Gradle / Ivy

Go to download

The spring component framework is used to setup a plugin based, micro-kernel, standalone application (today, we will support webapp in later releases) which is based on SpringFramework. It can help you decouple your application into several components clearly with zero invasion and keep your application consistent between develop time and runtime.

The newest version!
/**
 * @author XiongJie, Date: 13-11-11
 */
package net.happyonroad.component.container.feature;

import net.happyonroad.component.classworld.PomClassWorld;
import net.happyonroad.component.core.Component;
import net.happyonroad.component.core.Features;
import net.happyonroad.component.core.support.DefaultComponent;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.classworlds.realm.DuplicateRealmException;

/** 静态特性解析 */
public class StaticFeatureResolver extends AbstractFeatureResolver{

    public StaticFeatureResolver() {
        super(100);
    }

    @Override
    public String getName() {
        return Features.STATIC_FEATURE;
    }

    @Override
    public boolean hasFeature(Component component) {
        return component.getResource().exists("META-INF/pom.xml");
    }

    @Override
    public void resolve(Component component) {
        logger.debug("Resolving {} {} feature", component, getName());
        if(component.isPlain()) return;
        ClassRealm realm = resolveContext.getClassRealm(component.getId());
        if(realm == null){
            PomClassWorld world = (PomClassWorld) resolveContext.getMainClassLoader().getWorld();
            try {
                realm = world.newRealm(component);
            } catch (DuplicateRealmException e) {
                logger.error(e.getMessage(), e);
            }
        }
        if(component instanceof DefaultComponent){
            ((DefaultComponent)component).setClassLoader(realm);
        }
        resolveContext.registerFeature(component, getName(), realm);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy