checkpointing

This commit is contained in:
2026-10-31 18:24:58 +05:30
parent c0aa24bc29
commit 44a605dde2
69 changed files with 9412 additions and 1153 deletions
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>daxi.moe</groupId>
<artifactId>daxi.moe.parent</artifactId>
<version>v1-SNAPSHOT</version>
</parent>
<artifactId>daxi.moe.api</artifactId>
<packaging>jar</packaging>
</project>
@@ -0,0 +1,43 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
/**
* @author indroneel
*/
public class CodecException extends MoeException {
private final String codecName;
public CodecException(String codecName, String message) {
super(message);
this.codecName = codecName;
}
public CodecException(String codecName, String message, Throwable cause) {
super(message, cause);
this.codecName = codecName;
}
public CodecException(String codecName, Throwable cause) {
super(cause);
this.codecName = codecName;
}
public String getCodecName() {
return codecName;
}
}
@@ -0,0 +1,41 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
/**
* Signals a failure while converting data between model classes and plain Java objects.
*
* @author indroneel
*/
public class ConvertException extends MoeException {
private final String type;
private final String method;
public ConvertException(String typeName, String methodName, String message, Throwable cause) {
super(message, cause);
this.type = typeName;
this.method = methodName;
}
public String getType() {
return type;
}
public String getMethod() {
return method;
}
}
@@ -0,0 +1,41 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
import daxi.moe.model.AnyData;
import java.io.InputStream;
/**
* Context for external data sources, such as a byte array or an inputstream. The data is loaded
* from these sources, and then converted into Java entities.
*
* @author indroneel
*/
public interface External {
External from(InputStream in) throws MoeException;
External from(byte[] data) throws MoeException;
boolean hasPath(String path);
AnyData getModel();
<T> T convert(Class<T> type) throws MoeException;
<T> T convert(String path, Class<T> type) throws MoeException;
}
@@ -0,0 +1,35 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
import daxi.moe.model.AnyData;
/**
* Context for internal data sources, such as a Java object. The data is loaded from these sources,
* and then converted into a byte array.
*
* @author indroneel
*/
public interface Internal {
Internal from(Object obj) throws MoeException;
AnyData getModel();
byte[] convert() throws MoeException;
byte[] convert(boolean pretty) throws MoeException;
}
@@ -0,0 +1,34 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to specify the source field name in the data model for a method in a class. This is
* used to map data from a data model to a target object.
*
* @author indroneel
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MapFrom {
String value() default "";
}
@@ -0,0 +1,34 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotation to specify the target field name in the data model corresponding to the data from a
* method in a Java class. This is used to map data from a source object to a data model.
*
* @author indroneel
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MapTo {
String value() default "";
}
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
import java.util.Objects;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class Moe {
private static final Logger L = Logger.getLogger(Moe.class.getName());
/**
* Populates an instance of {@link Moe} with the given options.
*
* @param opts the options to set
* @return the {@link Moe} instance with the given options set
*/
protected abstract Moe options(Options... opts);
/**
* Returns an instance of {@link External} for the given format.
*
* @param format the format to use
* @return an instance of {@link External} for the given format
*/
public abstract External external(String format);
/**
* Returns an instance of {@link Internal} for the given format.
*
* @param format the format to use
* @return an instance of {@link Internal} for the given format
*/
public abstract Internal internal(String format);
/**
* Creates an instance of {@link Moe} using the ServiceLoader mechanism.
*
* @return an instance of {@link Moe} if found, otherwise null
*/
public static Moe create() {
ServiceLoader<Moe> loader = ServiceLoader.load(Moe.class);
try {
java.util.Optional<Moe> moeopt = loader.findFirst();
if (moeopt.isEmpty()) {
if(L.isLoggable(Level.SEVERE)) {
L.log(Level.SEVERE, "moe implementation NOT found");
}
return null;
}
else {
Moe moe = moeopt.get();
if(L.isLoggable(Level.CONFIG)) {
L.config(String.format("moe implementation found: %s",
moe.getClass().getName()));
}
return moe;
}
}
catch (ServiceConfigurationError err) {
if(L.isLoggable(Level.SEVERE)) {
L.log(Level.SEVERE, "moe implementation NOT found", err);
}
return null;
}
}
/**
* Creates an instance of {@link Moe} using the ServiceLoader mechanism and populates it with the
* given options.
*
* @param opts the options to set
* @return an instance of {@link Moe} with the given options set
*/
public static Moe create(Options... opts) {
return Objects.requireNonNull(Moe.create()).options(opts);
}
/**
* Defined options for {@link Moe} instances.
*/
public static enum Options {
ANYCASE,
DECODE_IGNORE_MISSING
}
}
@@ -0,0 +1,55 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.app;
/**
* The base exception class for all exceptions thrown by the Moe library.
*
* @author indroneel
*/
public class MoeException extends Exception {
/**
* Constructs a new MoeException with the specified detail message.
*
* @param message the detail message
*/
public MoeException(String message) {
super(message);
}
/**
* Constructs a new MoeException with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause of the exception
*/
public MoeException(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs a new MoeException with the specified cause.
*
* @param cause the cause of the exception
*/
public MoeException(Throwable cause) {
super(cause);
}
}
@@ -0,0 +1,49 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.codec;
/**
* Supplies the format identifier and format-specific codec components for a supported external data
* format.
*
* @author indroneel
*/
public interface MoeCodec {
/**
* Returns the identifier of the format supported by this provider (e.g., "JSON", "XML").
*
* @return the supported format identifier
*/
String getFormat();
/**
* Returns a decoder for the format supported by this provider.
*
* @return a decoder for the supported format
*/
MoeDecoder decoder();
/**
* Returns an encoder for the format supported by this provider.
*
* @return an encoder for the supported format
*/
MoeEncoder encoder();
}
@@ -0,0 +1,35 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.codec;
import daxi.moe.app.CodecException;
import daxi.moe.app.Moe;
import daxi.moe.model.AnyData;
import java.io.InputStream;
import java.util.List;
/**
* @author indroneel
*/
public interface MoeDecoder {
void setSource(byte[] data) throws CodecException;
void setSource(InputStream input) throws CodecException;
AnyData decode(List<Moe.Options> options) throws CodecException;
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.codec;
import daxi.moe.app.CodecException;
import daxi.moe.model.AnyData;
/**
* Encodes data into the byte representation of a supported format.
*
* @author indroneel
*/
public interface MoeEncoder {
/**
* Encodes the supplied data using the default formatting.
*
* @param data the data to encode
* @return the encoded data as a byte array
*/
byte[] convert(AnyData data) throws CodecException;
/**
* Encodes the supplied data, optionally formatting the output for readability.
*
* @param data the data to encode
* @param pretty whether to format the output for readability
* @return the encoded data as a byte array
*/
byte[] convert(AnyData data, boolean pretty) throws CodecException;
}
@@ -0,0 +1,60 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.model;
/**
* A class that can hold any of the three data types: {@link SimpleData}, {@link LinearData}, or
* {@link MappedData}. This class is used to represent a generic data type that can be one of those
* three types.
*
* @author indroneel
*/
public class AnyData {
private final SimpleData simple;
private final LinearData linear;
private final MappedData mapped;
public AnyData(SimpleData simple) {
this.simple = simple;
this.linear = null;
this.mapped = null;
}
public AnyData(LinearData linear) {
this.simple = null;
this.linear = linear;
this.mapped = null;
}
public AnyData(MappedData mapped) {
this.simple = null;
this.linear = null;
this.mapped = mapped;
}
public SimpleData asSimple() {
return simple;
}
public LinearData asLinear() {
return linear;
}
public MappedData asMapped() {
return mapped;
}
}
@@ -0,0 +1,45 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.model;
import java.util.LinkedList;
import java.util.List;
/**
* A simple linear data structure that stores a list of {@link AnyData} objects.
*
* @author indroneel
*/
public class LinearData {
private final List<AnyData> dataList;
public LinearData() {
dataList = new LinkedList<>();
}
public void add(AnyData value) {
dataList.add(value);
}
public AnyData get(int position) {
return dataList.get(position);
}
public int size() {
return dataList.size();
}
}
@@ -0,0 +1,50 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.model;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A simple data structure that maps string keys to {@link AnyData} values.
*
* @author indroneel
*/
public class MappedData {
private final Map<String, AnyData> dataMap;
public MappedData() {
dataMap = new HashMap<>();
}
public List<String> getKeys() {
return dataMap.keySet().stream().toList();
}
public boolean contains(String key) {
return dataMap.containsKey(key);
}
public AnyData get(String key) {
return dataMap.get(key);
}
public void put(String key, AnyData value) {
dataMap.put(key, value);
}
}
@@ -0,0 +1,71 @@
/*
* Copyright (c) DuxTechnica
*
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
* use this file except in compliance with the License. You may obtain a copy of the License by
* contacting:
*
* Dux Technica, [email protected]
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package daxi.moe.model;
/**
* A simple data type that can hold a string, number, or boolean value.
*
* @author indroneel
*/
public class SimpleData {
private final String strVal;
private final Number numVal;
private final Boolean boolVal;
public SimpleData(String value) {
strVal = value;
numVal = null;
boolVal = null;
}
public SimpleData(Number value) {
strVal = null;
numVal = value;
boolVal = null;
}
public SimpleData(Boolean value) {
strVal = null;
numVal = null;
boolVal = value;
}
public String getString() {
return strVal;
}
public Boolean getBoolean() {
return boolVal;
}
public Number getNumber() {
return numVal;
}
public String toString() {
if(strVal != null) {
return "string: " + strVal;
}
if(numVal != null) {
return "number: " + numVal.toString();
}
if(boolVal != null) {
return "boolean: " + boolVal.toString();
}
return "impossible!";
}
}