net.happyonroad.component.classworld.PomStrategy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-component-framework Show documentation
Show all versions of spring-component-framework Show documentation
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-9-22
*/
package net.happyonroad.component.classworld;
import org.codehaus.plexus.classworlds.strategy.AbstractStrategy;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
/**
* 参考 SelfFirstStrategy 实现的 类/资源加载策略
*/
public class PomStrategy extends AbstractStrategy {
protected PomClassRealm pomRealm;
public PomStrategy(PomClassRealm realm) {
super(realm);
this.pomRealm = realm;
}
@Override
public Class loadClass(String name) throws ClassNotFoundException {
//pom realm refer to component itself
Class clazz = pomRealm.loadClassFromSelf(name);
if ( clazz == null )
{
//depended pom realms refer to depended components
clazz = pomRealm.loadClassFromDepends( name );
if ( clazz == null )
{
//refer to 3rd libraries which can be accessed by current class
clazz = pomRealm.loadClassFromParent( name );
if ( clazz == null )
{
throw new ClassNotFoundException( name );
}
}
}
return clazz;
}
@Override
public URL getResource(String name) {
URL resource = pomRealm.loadResourceFromDepends(name);
if ( resource == null )
{
resource = pomRealm.loadResourceFromSelf( name );
if ( resource == null )
{
resource = pomRealm.loadResourceFromParent( name );
}
}
return resource;
}
@Override
public Enumeration getResources(String name) throws IOException {
Enumeration depends = pomRealm.loadResourcesFromDepends(name);
Enumeration self = pomRealm.loadResourcesFromSelf( name );
Enumeration parent = pomRealm.loadResourcesFromParent( name );
return combineResources( depends, self, parent );
}
}