Mapper improved x3
This commit is contained in:
parent
87f2c12bea
commit
afafe62cf6
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.alterdekim.game</groupId>
|
<groupId>com.alterdekim.game</groupId>
|
||||||
<artifactId>actionScriptDecompiler</artifactId>
|
<artifactId>actionScriptDecompiler</artifactId>
|
||||||
<version>0.0.5</version>
|
<version>0.0.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>SWFDissect</name>
|
<name>SWFDissect</name>
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.alterdekim.flash.decompiler.mapper;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.TYPE)
|
||||||
|
public @interface FlashClass {
|
||||||
|
String name() default "";
|
||||||
|
}
|
@ -1,12 +1,16 @@
|
|||||||
package com.alterdekim.flash.decompiler.mapper;
|
package com.alterdekim.flash.decompiler.mapper;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class FlashMapper {
|
public class FlashMapper {
|
||||||
@ -38,4 +42,58 @@ public class FlashMapper {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void mapToObj(Map<String, Object> o, List<OutputObject> objs) {
|
||||||
|
for( OutputObject object : objs ) {
|
||||||
|
String entryName = object.getObjectClass().getAnnotation(FlashClass.class).name();
|
||||||
|
Map<String, Object> m = (Map<String, Object>) o.get(entryName);
|
||||||
|
if( object.getIsSimple() ) {
|
||||||
|
m.keySet().forEach(k -> {
|
||||||
|
try {
|
||||||
|
Object entry = object.getObjectClass().getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
Arrays.stream(object.getObjectClass().getDeclaredFields())
|
||||||
|
.filter(f -> f.isAnnotationPresent(FlashValue.class))
|
||||||
|
.forEach(f -> {
|
||||||
|
try {
|
||||||
|
f.setAccessible(true);
|
||||||
|
switch (f.getAnnotation(FlashValue.class).type()) {
|
||||||
|
case Id -> f.set(entry, Long.parseLong(k));
|
||||||
|
case Value -> f.set(entry, m.get(k));
|
||||||
|
}
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
log.error("FlashMapper valueSet error: {}", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
object.getCallback().onOutputObjectReady(entry);
|
||||||
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
|
||||||
|
NoSuchMethodException e) {
|
||||||
|
log.error("FlashMapper class error: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
m.keySet().forEach(k -> {
|
||||||
|
Long id = Long.parseLong(k);
|
||||||
|
Map<String, Object> obj = (Map<String, Object>) m.get(k);
|
||||||
|
Object entity = FlashMapper.mapToObj(obj, object.getObjectClass());
|
||||||
|
Optional<Field> f1 = Arrays.stream(object.getObjectClass().getDeclaredFields())
|
||||||
|
.filter(f -> f.isAnnotationPresent(FlashValue.class) && f.getAnnotation(FlashValue.class).type() == FlashValueType.Id)
|
||||||
|
.findFirst();
|
||||||
|
if( f1.isEmpty() ) {
|
||||||
|
log.error("FlashMapper valueSet error; can't find Id field for object.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
f1.get().setAccessible(true);
|
||||||
|
try {
|
||||||
|
f1.get().set(entity, id);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
log.error("FlashMapper valueSet error: {}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
object.getCallback().onOutputObjectReady(entity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.alterdekim.flash.decompiler.mapper;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
public @interface FlashValue {
|
||||||
|
FlashValueType type() default FlashValueType.Value;
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package com.alterdekim.flash.decompiler.mapper;
|
||||||
|
|
||||||
|
public enum FlashValueType {
|
||||||
|
Id,
|
||||||
|
Value;
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.alterdekim.flash.decompiler.mapper;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class OutputObject {
|
||||||
|
private final Class<?> objectClass;
|
||||||
|
private final Boolean isSimple;
|
||||||
|
private final OutputObjectCallback callback;
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.alterdekim.flash.decompiler.mapper;
|
||||||
|
|
||||||
|
public interface OutputObjectCallback {
|
||||||
|
void onOutputObjectReady(Object entity);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user