关于ofbiz-component.xml文件中的resource-loader

寻找文件的方式最后是通过ComponentConfig.java的getURL方法来解析的
public URL getURL(String resourceLoaderName, String location) throws ComponentException {
ResourceLoaderInfo resourceLoaderInfo = resourceLoaderInfos.get(resourceLoaderName);
if (resourceLoaderInfo == null) {
throw new ComponentException("Could not find resource-loader named: " + resourceLoaderName);
}

if ("component".equals(resourceLoaderInfo.type) || "file".equals(resourceLoaderInfo.type)) {
//如果是<resource-loader name="main" type="component" />
String fullLocation = getFullLocation(resourceLoaderName, location);
URL fileUrl = UtilURL.fromFilename(fullLocation);
if (fileUrl == null) {
throw new ComponentException("File Resource not found: " + fullLocation);
}
return fileUrl;
} else if ("classpath".equals(resourceLoaderInfo.type)) {
String fullLocation = getFullLocation(resourceLoaderName, location);
URL url = UtilURL.fromResource(fullLocation);
if (url == null) {
throw new ComponentException("Classpath Resource not found: " + fullLocation);
}
return url;
} else if ("url".equals(resourceLoaderInfo.type)) {
String fullLocation = getFullLocation(resourceLoaderName, location);
URL url = null;
try {
url = FlexibleLocation.resolveLocation(location);
} catch (java.net.MalformedURLException e) {
throw new ComponentException("Error with malformed URL while trying to load URL resource at location [" + fullLocation + "]", e);
}
if (url == null) {
throw new ComponentException("URL Resource not found: " + fullLocation);
}
return url;
} else {
throw new ComponentException("The resource-loader type is not recognized: " + resourceLoaderInfo.type);
}
}

其中主要是看
就是用getFullLocation(resourceLoaderName, location);方法
它做的事是判断如果类型是component,就进行rootLocation+location。而rootLocation就是组建所在路径,而location就是我们的entity-resource或者service-resource等等设置的location。
另外这个方法还有几个操作,判断是否要使用prependEnv,如果使用,会添加上prependEnv

if (UtilValidate.isNotEmpty(resourceLoaderInfo.prependEnv)) {
String propValue = System.getProperty(resourceLoaderInfo.prependEnv);
if (propValue == null) {
String errMsg = "The Java environment (-Dxxx=yyy) variable with name " + resourceLoaderInfo.prependEnv + " is not set, cannot load resource.";
Debug.logError(errMsg, module);
throw new IllegalArgumentException(errMsg);
}
buf.append(propValue);
}

//判断是否要添加prefix
if (UtilValidate.isNotEmpty(resourceLoaderInfo.prefix)) {
buf.append(resourceLoaderInfo.prefix);
}
由此可以得出,resource-loader元素的完整配置是
<resource-loader name="main" type="component" prepend-env="" prefix=""/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值