Skip to content

Commit

Permalink
Merge pull request #21 from ClearXs/1.1.x
Browse files Browse the repository at this point in the history
feat: 1.[uno-core]: update uno-core pom.xml. 2.[uno-core]: add mvel a…
  • Loading branch information
ClearXs authored May 23, 2024
2 parents ea2f3e2 + bec01c1 commit 2aa1934
Show file tree
Hide file tree
Showing 53 changed files with 355 additions and 226 deletions.
6 changes: 6 additions & 0 deletions uno-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<neo4j.version>5.17.0</neo4j.version>
<!-- redisson -->
<redisson.version>3.27.1</redisson.version>
<mvel.version>2.5.0.Final</mvel.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -396,6 +397,11 @@
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>${mvel.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
22 changes: 17 additions & 5 deletions uno-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>uno-core</artifactId>
<description>uno pivotal is the core library.</description>

<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
Expand Down Expand Up @@ -40,6 +47,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</dependency>
<!-- 代理相关依赖包 -->
<dependency>
<groupId>cglib</groupId>
Expand Down Expand Up @@ -82,12 +93,14 @@
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
</dependency>
<!-- test -->
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -100,5 +113,4 @@
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,12 @@ default boolean match(Class<?> type) {
.stream()
.anyMatch(p -> {
Class<?> leftHand = p.getClass();
Class<?> rightHand = type;
if (leftHand.isInterface()) {
return ClassUtils.isAssignable(leftHand, rightHand);
} else if (rightHand.isInterface()) {
return ClassUtils.isAssignable(rightHand, leftHand);
return ClassUtils.isAssignable(leftHand, type);
} else if (type.isInterface()) {
return ClassUtils.isAssignable(type, leftHand);
}
return leftHand.isNestmateOf(rightHand);
return leftHand.isNestmateOf(type);
});
}

Expand Down Expand Up @@ -280,9 +279,6 @@ static ImmutableOptionalContext immutable(OptionalContext other, Map<String, Obj
return new ImmutableOptionalContext(other, values);
}

/**
* 不可变的{@link OptionalContext}
*/
class ImmutableOptionalContext implements OptionalContext {

private final Map<String, Object> context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cc.allio.uno.core.bean;

import cc.allio.uno.core.exception.Exceptions;
import cc.allio.uno.core.type.Types;
import cc.allio.uno.core.util.CollectionUtils;
import com.google.common.collect.Maps;
import reactor.core.publisher.Flux;
Expand All @@ -19,27 +20,28 @@
* @date 2022/5/21 10:17
* @since 1.0
*/
public class ObjectWrapper implements ValueWrapper {
public class BeanWrapper implements ValueWrapper {

/**
* 解析的目标对象
*/
private final Object instance;
private final BeanInfoWrapper<Object> wrapper;

public ObjectWrapper(Object instance) {
public BeanWrapper(Object instance) {
if (Objects.isNull(instance)) {
throw new NullPointerException("Instance Must not null");
}
Class<Object> beanClass = (Class<Object>) instance.getClass();
try {
this.wrapper = new BeanInfoWrapper<>((Class<Object>) instance.getClass());
this.wrapper = new BeanInfoWrapper<>(beanClass);
this.instance = instance;
} catch (IntrospectionException ex) {
throw Exceptions.unchecked(ex);
}
}

public ObjectWrapper(Class<Object> instanceClass) {
public BeanWrapper(Class<Object> instanceClass) {
if (Objects.isNull(instanceClass)) {
throw new NullPointerException("InstanceClass Must not null");
}
Expand Down Expand Up @@ -170,7 +172,7 @@ public Object getTarget() {
* @param value value
*/
public static void setValue(Object instance, String name, Object... value) {
ObjectWrapper wrapper = new ObjectWrapper(instance);
BeanWrapper wrapper = new BeanWrapper(instance);
if (Boolean.TRUE.equals(wrapper.contains(name))) {
wrapper.setForce(name, value);
}
Expand All @@ -184,7 +186,7 @@ public static void setValue(Object instance, String name, Object... value) {
* @return value or null
*/
public static Object getValue(Object instance, String name) {
ObjectWrapper wrapper = new ObjectWrapper(instance);
BeanWrapper wrapper = new BeanWrapper(instance);
if (Boolean.TRUE.equals(wrapper.contains(name))) {
return wrapper.getForce(name);
}
Expand All @@ -199,10 +201,41 @@ public static Object getValue(Object instance, String name) {
* @return value or null
*/
public static <T> T getValue(Object instance, String name, Class<T> fieldType) {
ObjectWrapper wrapper = new ObjectWrapper(instance);
BeanWrapper wrapper = new BeanWrapper(instance);
if (Boolean.TRUE.equals(wrapper.contains(name))) {
return wrapper.getForce(name, fieldType);
}
return null;
}

/**
* create a new {@link BeanWrapper} from bean instance
*
* @param beanInstance the bean instance
* @return {@link BeanWrapper} instance
* @throws NullPointerException if bean instance is null
*/
public static BeanWrapper of(Object beanInstance) {
if (beanInstance == null) {
throw Exceptions.unNull("bean instance is not null");
}
Class<?> beanClass = beanInstance.getClass();
if (!Types.isBean(beanClass)) {
throw Exceptions.unOperate("bean must be a bean");
}
return new BeanWrapper(beanInstance);
}

/**
* create a new {@link BeanWrapper} from bean class
*
* @param beanClass the bean class
* @return {@link BeanWrapper} instance
*/
public static BeanWrapper of(Class<?> beanClass) {
if (!Types.isBean(beanClass)) {
throw Exceptions.unOperate("bean must be a bean");
}
return new BeanWrapper(beanClass);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author j.x
* @date 2023/4/17 18:39
* @see BeanInfoWrapper 根据{@link BeanInfo}提取bean对象的属性进而实现值提取动作
* @see ObjectWrapper 接收某个具体的对象(一般为pojo)
* @see BeanWrapper 接收某个具体的对象(一般为pojo)
* @see MapWrapper 基于{@link Map}实现
* @since 1.1.4
*/
Expand Down Expand Up @@ -294,7 +294,7 @@ static Object restore(Object ori) {
*/
static ValueWrapper get(Object o) {
if (Types.isBean(o.getClass())) {
return new ObjectWrapper(o);
return new BeanWrapper(o);
} else if (Types.isMap(o.getClass())) {
return new MapWrapper((Map<String, Object>) o);
}
Expand Down
4 changes: 2 additions & 2 deletions uno-core/src/main/java/cc/allio/uno/core/bus/TopicKey.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cc.allio.uno.core.bus;

import cc.allio.uno.core.StringPool;
import cc.allio.uno.core.bean.ObjectWrapper;
import cc.allio.uno.core.bean.BeanWrapper;
import cc.allio.uno.core.util.ObjectUtils;
import cc.allio.uno.core.util.StringUtils;
import lombok.Getter;
Expand Down Expand Up @@ -70,7 +70,7 @@ static TopicKey create(Class<?> clazz, String[] appends) {
* @return TopicKey
*/
static TopicKey create(String prefix, Object pojo) {
ObjectWrapper wrapper = new ObjectWrapper(pojo);
BeanWrapper wrapper = new BeanWrapper(pojo);
return create(prefix, wrapper.findMapValuesForce().values().stream().map(Object::toString).toArray(String[]::new));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,21 @@ public String getFieldName() {
* @return SerializedLambda实例
*/
public static SerializedLambda of(Object lambda) {
return cache.computeIfAbsent(lambda.getClass(), clazz -> {
Method writeReplace = ClassUtils.getMethod(clazz, "writeReplace");
SerializedLambda serializedLambda;
try {
ClassUtils.setAccessible(writeReplace);
serializedLambda = new SerializedLambda((java.lang.invoke.SerializedLambda) writeReplace.invoke(lambda));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new UnsupportedOperationException(e);
}
if (serializedLambda.getMethodName().startsWith("lambda$")) {
throw new UnsupportedOperationException("请使用方法引用,例如: UserEntity::getName");
}
return serializedLambda;
});
return cache.computeIfAbsent(
lambda.getClass(),
clazz -> {
Method writeReplace = ClassUtils.getMethod(clazz, "writeReplace");
SerializedLambda serializedLambda;
try {
ClassUtils.setAccessible(writeReplace);
serializedLambda = new SerializedLambda((java.lang.invoke.SerializedLambda) writeReplace.invoke(lambda));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new UnsupportedOperationException(e);
}
if (serializedLambda.getMethodName().startsWith("lambda$")) {
throw new UnsupportedOperationException("请使用方法引用,例如: UserEntity::getName");
}
return serializedLambda;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cc.allio.uno.core.metadata.convert;

import cc.allio.uno.core.bean.ObjectWrapper;
import cc.allio.uno.core.bean.BeanWrapper;
import cc.allio.uno.core.metadata.mapping.MappingMetadata;
import cc.allio.uno.core.serializer.JsonNodeEnhancer;
import cc.allio.uno.core.util.JsonUtils;
Expand Down Expand Up @@ -96,7 +96,7 @@ public T execute(JsonNode root, T metadata) throws Throwable {
* @param excludeNotNecessaryFilter 排除必要过滤数据
*/
protected void executeAssignmentAction(JsonNode root, T metadata, boolean excludeNotNecessaryFilter) {
ObjectWrapper wrapper = new ObjectWrapper(metadata);
BeanWrapper wrapper = new BeanWrapper(metadata);
JsonNodeEnhancer jsonEnhancer = new JsonNodeEnhancer(root);
MappingMetadata mappingMetadata = metadata.getMapping();
Flux.fromStream(mappingMetadata.entrySet().stream())
Expand All @@ -117,6 +117,6 @@ protected void executeAssignmentAction(JsonNode root, T metadata, boolean exclud
* @param metadata 元数据
* @param wrapper sequential对象包装器
*/
protected abstract Mono<Void> executeAssignmentDefaultAction(T metadata, ObjectWrapper wrapper);
protected abstract Mono<Void> executeAssignmentDefaultAction(T metadata, BeanWrapper wrapper);

}
Loading

0 comments on commit 2aa1934

Please sign in to comment.