mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-13 00:15:24 +00:00
feat[storage]: Resource类增加配置writeable属性,这样类的属性就可以为public和set方法
This commit is contained in:
1 parent
6b9ae203a1
commit
bbe0579982
6 files changed
+35
-13
No files matched your search
@@ -17,6 +17,7 @@ import com.zfoo.protocol.util.IOUtils;
|
||||
import com.zfoo.protocol.util.JsonUtils;
|
||||
import com.zfoo.protocol.util.ReflectionUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
import com.zfoo.storage.StorageContext;
|
||||
import com.zfoo.storage.model.anno.Id;
|
||||
import com.zfoo.storage.model.resource.ResourceData;
|
||||
import com.zfoo.storage.model.resource.ResourceEnum;
|
||||
@@ -123,18 +124,20 @@ public class ResourceReader implements IResourceReader {
|
||||
}
|
||||
}
|
||||
|
||||
if (Modifier.isPublic(field.getModifiers())) {
|
||||
throw new RunException("因为静态资源类是不能被修改的,所以资源类[class:{}]的属性[filed:{}]不能被public修饰,请改为private修饰", clazz, field.getName());
|
||||
}
|
||||
if (!StorageContext.getStorageManager().storageConfig().isWriteable()) {
|
||||
if (Modifier.isPublic(field.getModifiers())) {
|
||||
throw new RunException("因为静态资源类是不能被修改的,资源类[class:{}]的属性[filed:{}]不能被public修饰,用private修饰或者开启配置writeable属性", clazz, field.getName());
|
||||
}
|
||||
|
||||
var setMethodName = StringUtils.EMPTY;
|
||||
try {
|
||||
setMethodName = ReflectionUtils.fieldToSetMethod(clazz, field);
|
||||
} catch (Exception e) {
|
||||
// 没有setMethod是正确的
|
||||
}
|
||||
if (StringUtils.isNotBlank(setMethodName)) {
|
||||
throw new RunException("因为静态资源类是不能被修改的,所以资源类[class:{}]的属性[filed:{}]不能含有set方法[{}]", clazz, field.getName(), setMethodName);
|
||||
var setMethodName = StringUtils.EMPTY;
|
||||
try {
|
||||
setMethodName = ReflectionUtils.fieldToSetMethod(clazz, field);
|
||||
} catch (Exception e) {
|
||||
// 没有setMethod是正确的
|
||||
}
|
||||
if (StringUtils.isNotBlank(setMethodName)) {
|
||||
throw new RunException("因为静态资源类是不能被修改的,资源类[class:{}]的属性[filed:{}]不能含有set方法[{}],删除set方法或者开启配置writeable属性", clazz, field.getName(), setMethodName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
package com.zfoo.storage.manager;
|
||||
|
||||
import com.zfoo.storage.model.config.StorageConfig;
|
||||
import com.zfoo.storage.model.vo.Storage;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
@@ -48,4 +49,5 @@ public interface IStorageManager {
|
||||
|
||||
void updateStorage(Class<?> clazz, Storage<?, ?> storage);
|
||||
|
||||
StorageConfig storageConfig();
|
||||
}
|
||||
@@ -196,6 +196,11 @@ public class StorageManager implements IStorageManager {
|
||||
storageMap.put(clazz, storage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StorageConfig storageConfig() {
|
||||
return getStorageConfig();
|
||||
}
|
||||
|
||||
private Set<String> scanResourceAnno(String scanLocation) {
|
||||
var resourcePatternResolver = new PathMatchingResourcePatternResolver();
|
||||
var metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
|
||||
|
||||
@@ -25,6 +25,9 @@ public class StorageConfig {
|
||||
|
||||
private String resourceLocation;
|
||||
|
||||
// 类的属性是否可写,如果为false则类的属性必须为private并且不能有set方法
|
||||
private boolean writeable;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -48,4 +51,12 @@ public class StorageConfig {
|
||||
public void setResourceLocation(String resourceLocation) {
|
||||
this.resourceLocation = resourceLocation;
|
||||
}
|
||||
|
||||
public boolean isWriteable() {
|
||||
return writeable;
|
||||
}
|
||||
|
||||
public void setWriteable(boolean writeable) {
|
||||
this.writeable = writeable;
|
||||
}
|
||||
}
|
||||
@@ -68,10 +68,10 @@ public class StorageDefinitionParser implements BeanDefinitionParser {
|
||||
|
||||
resolvePlaceholder("id", "id", builder, element, parserContext);
|
||||
resolvePlaceholder("package", "scanPackage", builder, scanElement, parserContext);
|
||||
resolvePlaceholder("writeable", "writeable", builder, scanElement, parserContext);
|
||||
resolvePlaceholder("location", "resourceLocation", builder, resourceElement, parserContext);
|
||||
|
||||
parserContext.getRegistry().registerBeanDefinition(clazz.getCanonicalName(), builder.getBeanDefinition());
|
||||
|
||||
}
|
||||
|
||||
private void registerBeanDefinition(ParserContext parserContext) {
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<!-- package声明类型 -->
|
||||
<xsd:complexType name="scan">
|
||||
<xsd:attribute name="package" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="writeable" type="xsd:boolean" default="false"/>
|
||||
</xsd:complexType>
|
||||
|
||||
|
||||
@@ -59,4 +60,4 @@
|
||||
<xsd:element name="storage" type="configType"/>
|
||||
|
||||
|
||||
</xsd:schema>
|
||||
</xsd:schema>
|
||||
Reference in new issue
Block a user