Compare commits

...

63 Commits
main ... dev

Author SHA1 Message Date
Edouard DUPIN
20ca8fb072 [FIX] arbo 2025-05-24 00:24:25 +02:00
6f6f756886 [FEAT] continue maven integration 2024-06-09 09:57:21 +02:00
5f7dad27b2 [FEAT] use Maven a build system root tool 2024-06-07 09:26:18 +02:00
e2637aecfc [DEV] refactor 2023-08-24 18:11:07 +02:00
1b51e75970 [DEV] update from aknot 2022-11-01 23:46:49 +01:00
d310c2cda8 [DEV] remove dependency with scenarium 2022-10-03 23:44:48 +02:00
e6ec6674e8 ---No commit message--- 2022-10-03 00:08:28 +02:00
5b287e107c ---No commit message--- 2022-10-03 00:08:20 +02:00
695220ad11 ---No commit message--- 2022-10-01 15:45:33 +02:00
382b6744c4 [DEV] continue rework (big one) 2022-09-03 21:05:02 +02:00
4db045751d [DEV] update to the mapper concept to simplify interface and set it common 2022-05-13 23:42:31 +02:00
e268e655a4 [DEV] externalize the introspection in aknot
# Conflicts:
#	src/org/atriasoft/exml/builder/BuilderIntrospection.java
#	src/org/atriasoft/exml/builder/IntrospectionModelComplex.java
2022-05-11 00:49:00 +02:00
80a9db1f25 [DEV] remove unneeded logs 2022-05-08 17:56:59 +02:00
1812bfccf1 [DEV] update new aknot 2022-05-03 15:07:12 +02:00
9069a26622 [DEV] set case sensitive tag availlable for enum 2022-04-26 00:04:11 +02:00
6adc3b3897 [DEV] add Text interface for injection (concept of pack text and factory Model 2022-04-24 08:01:52 +02:00
25f149357b [DEV] update log interface 2022-04-01 00:58:05 +02:00
1201bf804a add gitignore 2022-03-20 23:52:31 +01:00
139a01063c [DEV] commit all with new insland 2022-03-20 23:39:28 +01:00
f5f6d34135 dcc 2022-02-21 18:19:51 +01:00
24d9099a85 [DEV] continue integration properties 2021-12-22 00:41:12 +01:00
ce7b909cb0 [DEV] add ignoring missing and default null in record constructor 2021-10-09 08:27:34 +02:00
4a32ec0b15 [DOC] correct the the doc 2021-08-23 11:15:54 +02:00
1b69ba649a [DEV] start full test of decorators... 2021-07-15 22:13:01 +02:00
a2d37bb241 [DEV] lib is worling 2021-07-15 01:38:22 +02:00
0a0ee42b4b integration of contructor properties 2021-07-14 20:20:48 +02:00
095a705d4b [DEV] rework bean register model 2021-07-09 23:51:58 +02:00
b9fcbc6780 [DEV] need rework to manage hybride bean 2021-07-11 23:05:04 +02:00
77dd42e499 [DEV] rework parameter management 2021-07-09 23:51:58 +02:00
e57b77c466 [DEV] correct bug 2021-07-09 21:21:18 +02:00
e875791c27 [DEV] missing String 2021-07-09 00:08:58 +02:00
e86cd23abf [DEV] remove deprecated code, but already used ==> bug... 2021-07-09 00:05:19 +02:00
3ad74f0fb1 [DEV] set it work for imutable and basic records 2021-07-09 00:04:54 +02:00
c8ff65615f [DEV] remove deprecated API 2021-07-08 14:20:35 +02:00
70dae9d861 [DEV] add simple record test 2021-07-08 14:19:28 +02:00
99b846be25 [DEV] add object not empty constructor 2021-07-08 14:19:17 +02:00
e5db63a06b [DEV] add object test 2021-07-08 14:18:46 +02:00
a6c90e5515 [DEV] detect empty constructor (one) 2021-07-08 14:18:29 +02:00
6bd92d1a57 [DEV] reaname create model 2021-07-08 14:11:34 +02:00
c3e4b287e4 [DEV] add test for validate the structured list 2021-07-08 14:11:03 +02:00
1c8ad846a3 [DEV] remove toStringList 2021-07-08 14:09:58 +02:00
a9b4d39fc0 [DEV] hirarchic tree 2021-07-07 22:12:01 +02:00
bc83c265b8 [DEV] add enums, correct test bugs and better model ==> need to clean deprecated code ... 2021-07-07 00:24:06 +02:00
a7bdce291d [DEV] continue rework 2021-07-05 23:16:03 +02:00
cb4d58c32f [DEV] integrate new model model... 2021-07-05 00:53:33 +02:00
c7297bd106 [DEV] update list 2021-07-03 16:51:40 +02:00
d4b528eedf [DEV] update real separation between the node and the properties 2021-07-03 00:12:50 +02:00
956f78642b [DEV] continue integration 2021-07-02 23:41:02 +02:00
7ef59f2f7e [DEV] work on introspection generation 2021-07-02 10:40:27 +02:00
e68802010b [DEV] start thing of xml introspection generation 2021-06-29 23:39:03 +02:00
cd25863ed9 [DEV] better introspection add node parsing, list mode and base for enums 2021-06-29 00:02:19 +02:00
7017468e46 [DEV] continue integration of generated object 2021-06-24 21:48:10 +02:00
48fb2da890 [DEV] start add element in nodes 2021-06-22 07:51:46 +02:00
2e6f7c3a5f [DEV] load from java generic PAth 2021-06-17 22:33:25 +02:00
8a32b34593 [DEV] add test of lutin builder 2021-06-14 13:41:05 +02:00
2f0da010c2 [DEV] set game working 2021-05-27 00:17:48 +02:00
ad744e3d75 [DEV] better parser XML 2021-05-03 16:57:33 +02:00
c1ef21754d [DEV] correct somes bugs 2021-03-29 00:17:00 +02:00
f81392846a [DEV] contiue rework 2021-03-16 00:30:49 +01:00
240b71805e [DEV] add basic annitation and first introspection with attribute works. 2021-02-27 01:29:38 +01:00
f610c366ba [DEV] refacto separate serializer, parser and model is OK ==> sax reader is OK not the sax generator (API not open) 2021-02-26 00:13:25 +01:00
d16f4c95e3 [DEV] start dev of a new parsing model to support sax and big file in stream 2021-02-25 01:42:08 +01:00
e906b9a089 [DOC] remove @brief (noit compatible with javadoc 2021-02-24 21:22:28 +01:00
95 changed files with 15910 additions and 2558 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false"> <fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="ewol" local="false"> <fileset name="all" enabled="true" check-config-name="Google Checks" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/> <file-match-pattern match-pattern="." include-pattern="true"/>
</fileset> </fileset>
</fileset-config> </fileset-config>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="out/eclipse/classes-test" path="test/src">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/scenarium-logger">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/atriasoft-etk">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="out/eclipse/classes"/>
</classpath>

5
.gitignore vendored
View File

@ -1,3 +1,5 @@
/__pycache__/
/bin/ /bin/
/Operator/ /Operator/
/DrawerProperties/ /DrawerProperties/
@ -15,3 +17,6 @@ build.number
/.settings/ /.settings/
/junit/ /junit/
/target/ /target/
/*.log

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>atriasoft-exml</name>
<comment></comment>
<projects>
<project>atriasoft-exml</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
</natures>
</projectDescription>

View File

@ -4,5 +4,23 @@ Atria-soft Exml
[MPL-2] Mozilla public licence (V 2.0) [MPL-2] Mozilla public licence (V 2.0)
Ewol xml tool. Implementation a a XML parser and generator. I create this one, because jackson API is done for JSON and not XML.
The main base of the parser is a simple SAX parser (not streamable right now...)
A DOM parser is available (based on SAX)
A POJO parse is in progress (based on SAX too)
POJO need to implement (TODO list):
- Immutable reader/writer
- Record reader/writer
The model of the Pojo reader is based on reading all sub element and create the object at the end (leaf first and parent node after). This is needed to manage the record and the immutable.
We do not manage the constructor properties. Then right now, the constructor MUST be empty
need to check if the class is an abstract or not...

View File

@ -0,0 +1,91 @@
#!/usr/bin/python
import realog.debug as debug
import lutin.tools as tools
import realog.debug as debug
import lutin.image as image
import os
import lutin.multiprocess as lutinMultiprocess
def get_type():
return "LIBRARY_DYNAMIC"
def get_desc():
return "Ewol Tool Kit"
def get_licence():
return "MPL-2"
def get_compagny_type():
return "org"
def get_compagny_name():
return "atria-soft"
#def get_maintainer():
# return "authors.txt"
#def get_version():
# return "version.txt"
def configure(target, my_module):
my_module.add_src_file([
'src/module-info.java',
'src/org/atriasoft/exml/model/XmlNode.java',
'src/org/atriasoft/exml/model/XmlText.java',
'src/org/atriasoft/exml/model/XmlAttributeList.java',
'src/org/atriasoft/exml/model/XmlElement.java',
'src/org/atriasoft/exml/model/XmlAttribute.java',
'src/org/atriasoft/exml/model/XmlNodeType.java',
'src/org/atriasoft/exml/model/XmlDeclaration.java',
'src/org/atriasoft/exml/model/XmlComment.java',
'src/org/atriasoft/exml/annotation/ExmlAnnotation.java',
'src/org/atriasoft/exml/annotation/XmlDefaultManaged.java',
'src/org/atriasoft/exml/annotation/XmlDefaultOptional.java',
'src/org/atriasoft/exml/annotation/XmlDefaultAttibute.java',
'src/org/atriasoft/exml/annotation/XmlProperty.java',
'src/org/atriasoft/exml/annotation/XmlOptional.java',
'src/org/atriasoft/exml/annotation/XmlDefaultCaseSensitive.java',
'src/org/atriasoft/exml/annotation/XmlCaseSensitive.java',
'src/org/atriasoft/exml/annotation/XmlName.java',
'src/org/atriasoft/exml/annotation/XmlManaged.java',
'src/org/atriasoft/exml/serializer/SerializerXml.java',
'src/org/atriasoft/exml/builder/BuilderIntrospection.java',
'src/org/atriasoft/exml/builder/IntrospectionPropertyMethod.java',
'src/org/atriasoft/exml/builder/BuilderGeneric.java',
'src/org/atriasoft/exml/builder/IntrospectionProperty.java',
'src/org/atriasoft/exml/builder/IntrospectionObject.java',
'src/org/atriasoft/exml/builder/Builder.java',
'src/org/atriasoft/exml/builder/IntrospectionData.java',
'src/org/atriasoft/exml/builder/IntrospectionPropertyField.java',
'src/org/atriasoft/exml/exception/ExmlParserError.java',
'src/org/atriasoft/exml/exception/ExmlNodeDoesNotExist.java',
'src/org/atriasoft/exml/exception/ExmlAttributeDoesNotExist.java',
'src/org/atriasoft/exml/exception/ExmlException.java',
'src/org/atriasoft/exml/exception/ExmlParserErrorMulti.java',
'src/org/atriasoft/exml/exception/ExmlBuilderException.java',
'src/org/atriasoft/exml/parser/ParseXml.java',
'src/org/atriasoft/exml/parser/StoreMode.java',
'src/org/atriasoft/exml/parser/ParsingProperty.java',
'src/org/atriasoft/exml/parser/Tools.java',
'src/org/atriasoft/exml/parser/PositionParsing.java',
'src/org/atriasoft/exml/parser/FilePos.java',
'src/org/atriasoft/exml/Exml.java',
])
my_module.add_path('src/', type='java')
my_module.add_depend([
'org-atriasoft-etk'
])
#my_module.add_path([
# 'lib/spotbugs-annotations-4.2.2.jar'
# ],
# type='java',
# export=True
#);
my_module.add_flag('java', "RELEASE_15_PREVIEW");
return True

144
pom.xml Normal file
View File

@ -0,0 +1,144 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.atriasoft</groupId>
<artifactId>exml</artifactId>
<version>0.1.0</version>
<licenses>
<license>
<name>Mozilla Public License 2.0</name>
<url>https://opensource.org/licenses/MPL-2.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>dev1</id>
<name>Edouard DUPIN</name>
<email>edouard.dupin@proton.me</email>
<roles>
<role>Lead Developer</role>
</roles>
</developer>
</developers>
<repositories>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
<snapshotRepository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.atriasoft</groupId>
<artifactId>etk</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.atriasoft</groupId>
<artifactId>aknot</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.1.0-alpha1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>
<testResources>
<testResource>
<directory>${basedir}/src/testResources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<!-- Create the source bundle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- junit results -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Java-doc generation for stand-alone site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</plugin>
</plugins>
</build>
<!-- Generate Java-docs As Part Of Project Reports -->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<show>public</show>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -0,0 +1,97 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.etk.Uri;
import org.atriasoft.exml.builder.Builder;
import org.atriasoft.exml.builder.BuilderGeneric;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.exception.ExmlParserErrorMulti;
import org.atriasoft.exml.generator.GeneratorGeneric;
import org.atriasoft.exml.model.XmlElement;
import org.atriasoft.exml.model.XmlNode;
import org.atriasoft.exml.parser.ParseXml;
import org.atriasoft.exml.parser.ParsingProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Exml {
final static Logger LOGGER = LoggerFactory.getLogger(Exml.class);
/**
* Display the Document on console
*/
public static void display(final XmlElement node) {
final StringBuilder tmpp = new StringBuilder();
Exml.generate(node, tmpp);
LOGGER.info("Generated XML : \n" + tmpp.toString());
}
/**
* Generate a string that contain the created XML
*
* @param data Data where the xml is stored
*/
public static void generate(final XmlNode root, final StringBuilder data) {
if (!root.isElement() || (((XmlElement) root).getValue() != null && !((XmlElement) root).getValue().isEmpty())) {
GeneratorGeneric.serialize(root, data, 0);
} else {
GeneratorGeneric.serializeRoot((XmlElement) root, data);
}
// return iGenerate(_data, 0);
}
public static XmlElement parse(final Path data) throws ExmlException, ExmlParserErrorMulti, AknotException {
final Builder builder = new BuilderGeneric();
final ParseXml parser = new ParseXml(builder);
final ParsingProperty property = new ParsingProperty();
property.setDisplayError(true);
byte[] elemData = null;
try {
elemData = Files.readAllBytes(data);
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (elemData == null) {
LOGGER.error("Can not read the Stream : " + data);
return null;
}
final String dataToParse = new String(elemData);
return (XmlElement) parser.parse(dataToParse, property);
}
public static XmlElement parse(final String data) throws ExmlException, ExmlParserErrorMulti, AknotException {
final Builder builder = new BuilderGeneric();
final ParseXml parser = new ParseXml(builder);
final ParsingProperty property = new ParsingProperty();
property.setDisplayError(true);
return (XmlElement) parser.parse(data, property);
}
public static XmlElement parse(final Uri data) throws ExmlException, AknotException {
final Builder builder = new BuilderGeneric();
final ParseXml parser = new ParseXml(builder);
final ParsingProperty property = new ParsingProperty();
property.setDisplayError(true);
final byte[] elemData = Uri.getAllData(data);
if (elemData == null) {
LOGGER.error("Can not read the Stream : " + data);
return null;
}
final String dataToParse = new String(elemData);
return (XmlElement) parser.parse(dataToParse, property);
}
private Exml() {}
}

View File

@ -0,0 +1,138 @@
package org.atriasoft.exml;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.aknot.model.ModelType;
import org.atriasoft.etk.Uri;
import org.atriasoft.exml.builder.Builder;
import org.atriasoft.exml.builder.BuilderIntrospection;
import org.atriasoft.exml.builder.IntrospectionObject;
import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.atriasoft.exml.generator.GeneratorIntrospection;
import org.atriasoft.exml.parser.ParseXml;
import org.atriasoft.exml.parser.ParsingProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class XmlMapper {
final static Logger LOGGER = LoggerFactory.getLogger(XmlMapper.class);
private static String readFile(final Path path, final Charset encoding) throws IOException {
final byte[] encoded = Files.readAllBytes(path);
return new String(encoded, encoding);
}
public XmlMapper() {
}
public void generate(final Object root, final StringBuilder data) throws ExmlException, AknotException {
GeneratorIntrospection generator;
try {
generator = new GeneratorIntrospection(ModelType.NORMAL, root.getClass());
generator.generate(root, data);
} catch (final ExmlBuilderException ex) {
throw ex;
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public <T> T parse(final Path path, final Class<T> classType) throws ExmlException, ExmlNodeDoesNotExist, AknotException {
byte[] elemData = null;
try {
elemData = Files.readAllBytes(path);
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (elemData == null) {
LOGGER.error("Can not read the Stream : " + path);
return null;
}
final String dataToParse = new String(elemData);
return parse(dataToParse, classType);
}
/**
* Parse a single root node that have the name of the Class Parsed:
* <pre>
* &gt;ClassName a="kk" ... &lt;
* ...
* &gt;/ClassName&lt;
* </pre>
* @param <T> Object type to parse
* @param data Data String to Parse
* @param classType Object Class to introspect data (POJO)
* @return The Object parsed or null
*/
@SuppressWarnings("unchecked")
public <T> T parse(final String data, final Class<T> classType) throws ExmlException, ExmlNodeDoesNotExist, AknotException {
Builder builder;
try {
builder = new BuilderIntrospection(ModelType.NORMAL, classType);
final ParseXml parser = new ParseXml(builder);
final ParsingProperty property = new ParsingProperty();
property.setDisplayError(true);
final IntrospectionObject introspectionObject = (IntrospectionObject) parser.parse(data, property);
introspectionObject.generateTheObject();
final Object listRet = introspectionObject.getData();
if (listRet != null && !listRet.getClass().isArray() && listRet.getClass() == classType) {
return (T) listRet;
} else if (listRet != null && listRet.getClass().isArray() && listRet.getClass().componentType() == classType) {
final T[] tmp = (T[]) listRet;
if (tmp.length >= 1) {
return tmp[0];
}
}
return null;
} catch (final ExmlException ex) {
ex.printStackTrace();
throw ex;
}
}
public <T> T read(final Class<T> classType, final Path path) throws ExmlException, AknotException, IOException {
String content = null;
try {
content = readFile(path, StandardCharsets.UTF_8);
} catch (final IOException e) {
e.printStackTrace();
}
return parse(content, classType);
}
public <T> T read(final Class<T> classType, final Uri uri) throws ExmlException, AknotException, IOException {
final byte[] elemData = Uri.getAllData(uri);
if (elemData == null) {
LOGGER.error("Can not read the Stream : " + uri);
return null;
}
final String content = new String(elemData);
return parse(content, classType);
}
public void store(final Object root, final Path path) throws ExmlException, AknotException, IOException {
final StringBuilder builder = new StringBuilder();
generate(root, builder);
Files.writeString(path, builder.toString());
}
public void store(final Object root, final Uri uri) throws ExmlException, AknotException, IOException {
final StringBuilder builder = new StringBuilder();
generate(root, builder);
Uri.writeAll(uri, builder.toString());
}
}

View File

@ -0,0 +1,91 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.builder;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.exml.Exml;
import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.exception.ExmlException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public interface Builder {
final static Logger LOGGER = LoggerFactory.getLogger(Builder.class);
/**
* Detect the end of the element : {@code<ELEMENT>}
* @param element Element that is finished
* @throws ExmlBuilderException
*/
void endElement(Object element) throws ExmlException, AknotException;
/**
* This is called before a text adding, in some case the subData must not be parsed, then all the subData is pack as a single string without managing the XML properties.
* @param parent Parent node of the element that is created
* @return true if the data must be packed.
* @throws ExmlException
*/
boolean isPackText(Object parent) throws ExmlException, AknotException;
/**
* New comment added on this Element
* @param element Element representing the node of the Comment is added
* @param comment Comment value
* @throws ExmlBuilderException Error with this node or element.
*/
void newComment(Object element, String comment) throws ExmlException, AknotException;
/**
* New comment added on this Element
* @param parent Element representing the node of the Declaration is added
* @param text Name of the declaration
* @return Declaration object value
* @throws ExmlBuilderException Error with this node or element.
*/
Object newDeclaration(Object parent, String text) throws ExmlException, AknotException;
/**
* Add a new sub-element on the current parent element: {@code<ELEMENT>}
* @param parent Element representing the node of the Element is added
* @param nodeName New element name.
* @return the object representing the Element.
* @throws ExmlBuilderException Error with this node or element.
*/
Object newElement(Object parent, String nodeName) throws ExmlException, AknotException;
/**
* The sub-element is finish (creation done)
* @param parent Parent node of the element that is created
* @param tmpname Name of the node
* @param element Element builder that has been created
*/
void newElementFinished(Object parent, String tmpname, Object element) throws ExmlException, AknotException;
/**
* Add a property on the Element.
* @param element Element representing the node of the property is added
* @param propertyName Name of the property
* @param propertyValue Value of the property
* @throws ExmlBuilderException Error with this node or element.
*/
void newProperty(Object element, String propertyName, String propertyValue) throws ExmlException, AknotException;
/**
* Create or get the root element of the document
* @return An object that id a root element.
* @throws ExmlBuilderException Error with this node or element.
*/
Object newRoot() throws ExmlBuilderException, AknotException;
/**
* Add a text value on the current Element
* @param parent Parent element where the Text is added
* @param text Test to add.
* @throws ExmlBuilderException Error with this node or element.
*/
void newText(Object parent, String text) throws ExmlException, AknotException;
}

View File

@ -0,0 +1,89 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.builder;
import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.model.XmlAttribute;
import org.atriasoft.exml.model.XmlAttributeList;
import org.atriasoft.exml.model.XmlComment;
import org.atriasoft.exml.model.XmlDeclaration;
import org.atriasoft.exml.model.XmlElement;
import org.atriasoft.exml.model.XmlText;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BuilderGeneric implements Builder {
final static Logger LOGGER = LoggerFactory.getLogger(BuilderGeneric.class);
@Override
public void endElement(final Object element) {
// Nothing to do...
}
@Override
public boolean isPackText(final Object parent) throws ExmlException {
return false;
}
@Override
public void newComment(final Object element, final String comment) throws ExmlBuilderException {
if (element instanceof final XmlElement elem) {
elem.append(new XmlComment(comment));
return;
}
throw new ExmlBuilderException("can not add Comment on something else than Element");
}
@Override
public Object newDeclaration(final Object parent, final String text) throws ExmlBuilderException {
if (parent instanceof final XmlElement elem) {
final XmlDeclaration dec = new XmlDeclaration(text);
elem.append(dec);
return dec;
}
throw new ExmlBuilderException("can not add Declaration on something else than Element");
}
@Override
public Object newElement(final Object parent, final String nodeName) throws ExmlBuilderException {
if (parent instanceof final XmlElement elem) {
final XmlElement eee = new XmlElement(nodeName);
elem.append(eee);
return eee;
}
throw new ExmlBuilderException("can not add Element on something else than Element");
}
@Override
public void newElementFinished(final Object parent, final String tmpname, final Object element) {
// Nothing to do...
}
@Override
public void newProperty(final Object element, final String propertyName, final String propertyValue) throws ExmlBuilderException {
if (element instanceof final XmlAttributeList attr) {
attr.appendAttribute(new XmlAttribute(propertyName, propertyValue));
return;
}
throw new ExmlBuilderException("can not add Attribute on something else than Element or Declaration");
}
@Override
public Object newRoot() throws ExmlBuilderException {
return new XmlElement();
}
@Override
public void newText(final Object parent, final String text) throws ExmlBuilderException {
if (parent instanceof final XmlElement attr) {
attr.append(new XmlText(text));
return;
}
throw new ExmlBuilderException("can not add Text on something else than Element or Declaration");
}
}

View File

@ -0,0 +1,328 @@
package org.atriasoft.exml.builder;
import java.util.ArrayList;
import java.util.List;
import org.atriasoft.aknot.StringSerializer;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.aknot.model.InterfaceFactoryAccess;
import org.atriasoft.aknot.model.IntrospectionModel;
import org.atriasoft.aknot.model.ModelType;
import org.atriasoft.aknot.pojo.CacheIntrospectionModel;
import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist;
import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BuilderIntrospection implements Builder {
final static Logger LOGGER = LoggerFactory.getLogger(BuilderIntrospection.class);
// Keep in cach all the object alredy parsed ==> optimize CPU
CacheIntrospectionModel cacheModel = new CacheIntrospectionModel();
// The root class (need to keep it if we use 2 time the builder, the root class is no more accessible).
final Class<?> rootClassType;
final String rootNodeName;
final InterfaceFactoryAccess factory;
public BuilderIntrospection(final InterfaceFactoryAccess factory) throws ExmlException, AknotException {
LOGGER.error("[CRITICAL] is it used ????");
System.exit(-50);
this.factory = factory;
this.rootNodeName = null;
this.rootClassType = null;
for (final String it : this.factory.getConversionMap().keySet()) {
this.cacheModel.findOrCreate(ModelType.NORMAL, it, this.factory.getConversionMap().get(it));
}
}
public BuilderIntrospection(final ModelType model, final Class<?> classType) throws ExmlException, AknotException {
this.factory = null;
this.rootClassType = classType;
final IntrospectionModel typeModel = this.cacheModel.findOrCreate(model, null, classType);
this.rootNodeName = typeModel.getNames()[0];
}
public BuilderIntrospection(final ModelType model, final Class<?> classType, final String rootNodeName) throws ExmlException, AknotException {
LOGGER.error("is it used ????");
System.exit(-50);
this.factory = null;
this.rootNodeName = rootNodeName;
this.rootClassType = classType;
this.cacheModel.findOrCreate(model, null, classType);
}
@Override
public void endElement(final Object element) throws ExmlBuilderException, AknotException {
LOGGER.trace("End of Element: {}", element);
if (element == null) {
return;
}
final IntrospectionObject introspectionObject = (IntrospectionObject) element;
if (introspectionObject.getModelIntrospection() == null) {
// property on nothing ???
return;
}
introspectionObject.generateTheObject();
}
@Override
public boolean isPackText(final Object parent) throws ExmlException {
if (parent == null) {
return false;
}
final IntrospectionObject introspectionObject = (IntrospectionObject) parent;
final IntrospectionModel model = introspectionObject.getModelIntrospection();
if (model.hasTextModel()) {
return true;
}
return false;
}
@Override
public void newComment(final Object element, final String comment) {}
@Override
public Object newDeclaration(final Object parent, final String text) {
// we drop all declaration, no need of it too.
return null;
}
@Override
public Object newElement(final Object parent, final String nodeName) throws ExmlException, AknotException {
if (parent == null) {
return null;
}
LOGGER.trace("new element on NodeName=" + nodeName);
final IntrospectionObject introspectionObject = (IntrospectionObject) parent;
final IntrospectionModel model = introspectionObject.getModelIntrospection();
Class<?> typeClass = null;
String listTreeName = null;
if (model.isArray() || model.isList()) {
final List<String> nodesAvaillable = model.getNodeAvaillable();
if (nodesAvaillable == null || nodesAvaillable.size() == 0) {
throw new ExmlBuilderException("Model can not have subNode with name: '" + nodeName + "'");
}
if (!nodesAvaillable.get(0).equals(nodeName)) {
throw new ExmlBuilderException("Model can not have subNode with name: '" + nodeName + "'. Must be " + nodesAvaillable.get(0));
}
typeClass = model.getClassType();
} else {
if (!introspectionObject.isSubNodeOrPropertyExist(nodeName) && model.isIgnoreUnknown()) {
LOGGER.debug("Ignore node: '" + nodeName + "' Does not exist...");
return null;
}
try {
typeClass = introspectionObject.getTypeOfSubNode(nodeName);
listTreeName = introspectionObject.getTreeNameOfSubNode(nodeName);
} catch (final AknotException e) {
throw new ExmlNodeDoesNotExist("Node does not exist: " + e.getMessage());
}
}
if (typeClass != null) {
// specific case for List ==> need to get the subType in introspection ...
if (typeClass.isArray()) {
final Class<?> subTypeClass = typeClass.getComponentType();
LOGGER.trace("Create array new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'");
IntrospectionModel inferData = null;
if (listTreeName == null) {
inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
} else {
// when we request a list elements, we need to add the element in a list, then we need the return is LIST and not ARRAY
inferData = this.cacheModel.findOrCreate(ModelType.LIST, listTreeName, subTypeClass);
}
// Create the data when object is ended created...
return new IntrospectionObject(inferData);
}
if (List.class.isAssignableFrom(typeClass)) {
Class<?> subTypeClass = null;
try {
subTypeClass = introspectionObject.getTypeOfSubNodeSubType(nodeName);
} catch (final AknotException e) {
throw new ExmlNodeDoesNotExist("Node does not exist: " + e.getMessage());
}
LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'");
IntrospectionModel inferData = null;
if (listTreeName == null) {
inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
} else {
inferData = this.cacheModel.findOrCreate(ModelType.LIST, listTreeName, subTypeClass);
}
// Create the data when object is ended created...
return new IntrospectionObject(inferData);
}
LOGGER.trace("Create new class: '" + typeClass.getCanonicalName() + "' for node '" + nodeName + "'");
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, listTreeName, typeClass);
// Create the data when object is ended created...
return new IntrospectionObject(inferData);
}
return null;
}
@Override
public void newElementFinished(final Object parent, final String tmpName, final Object element) throws ExmlException, AknotException {
LOGGER.debug("new element fionished : ==> " + tmpName);
if (parent == null || element == null) {
return;
}
final IntrospectionObject introspectionElementObject = (IntrospectionObject) element;
if (introspectionElementObject.getModelIntrospection() == null) {
// property on nothing ???
return;
}
final IntrospectionObject introspectionParentObject = (IntrospectionObject) parent;
if (introspectionParentObject.getModelIntrospection() == null) {
if (tmpName.equals(this.rootNodeName)) {
// this is the root node ...
final Object tmpp = introspectionParentObject.getData();
if (tmpp instanceof List) {
@SuppressWarnings("unchecked")
final List<Object> elementsOut = (List<Object>) tmpp;
elementsOut.add(introspectionElementObject.getData());
}
}
return;
}
introspectionParentObject.addObject(tmpName, introspectionElementObject.getData());
}
@Override
public void newProperty(final Object element, final String propertyName, final String propertyValue) throws ExmlException, AknotException {
if (element == null) {
return;
}
final IntrospectionObject introspectionObject = (IntrospectionObject) element;
final IntrospectionModel model = introspectionObject.getModelIntrospection();
if (model.isArray() || model.isList()) {
throw new ExmlBuilderException("Model (List/Array) can not have property with name '" + propertyName + "'");
}
final String beanName = model.getBeanName(propertyName);
if (beanName == null) {
if (model.isIgnoreUnknown()) {
LOGGER.debug("Ignore node : '" + propertyName + "'");
return;
}
throw new ExmlAttributeDoesNotExist("The node '" + propertyName + "' Does not exist...");
}
// T O D O: check why we do not use the been name to get the type ..... !!!!!!!!!!!
final Class<?> typeClass = model.getTypeOfProperty(propertyName);
if (typeClass != null) {
// specific case for List ==> need to get the subType in introspection ...
if (typeClass.isPrimitive()) {
final Object out = StringSerializer.valueOf(typeClass, propertyValue);
introspectionObject.putProperty(propertyName, out);
} else if (typeClass.isArray()) {
final String[] elems = propertyValue.split(";");
final Class<?> subTypeClass = typeClass.getComponentType();
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
final List<Object> out = new ArrayList<>();
for (int iii = 0; iii < elems.length; iii++) {
final Object tmp = inferData.getValueFromText(elems[iii]);
out.add(tmp);
}
introspectionObject.putProperty(propertyName, out);
} else if (List.class.isAssignableFrom(typeClass)) {
final String[] elems = propertyValue.split(";");
final Class<?> subTypeClass = introspectionObject.getTypeOfSubProperty(propertyName);
LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + propertyName + "'");
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
final List<Object> out = new ArrayList<>();
for (int iii = 0; iii < elems.length; iii++) {
final Object tmp = inferData.getValueFromText(elems[iii]);
out.add(tmp);
}
introspectionObject.putProperty(propertyName, out);
} else {
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, typeClass);
final Object out = inferData.getValueFromText(propertyValue);
introspectionObject.putProperty(propertyName, out);
}
}
}
@Override
public Object newRoot() throws ExmlBuilderException, AknotException {
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.ARRAY, this.rootNodeName, this.rootClassType);
return new IntrospectionObject(inferData);
}
@Override
public void newText(final Object parent, final String text) throws ExmlException, AknotException {
if (parent == null) {
return;
}
final IntrospectionObject introspectionObject = (IntrospectionObject) parent;
final IntrospectionModel model = introspectionObject.getModelIntrospection();
if (model.isArray() || model.isList()) {
final List<String> nodesAvaillable = model.getNodeAvaillable();
if (nodesAvaillable != null && nodesAvaillable.size() != 0) {
throw new ExmlBuilderException("Model can not have direct text with model data= '" + text + "'");
}
final Class<?> arrayType = model.getClassType();
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, arrayType);
// Create the data when object is ended created...
final IntrospectionObject tmpp = new IntrospectionObject(inferData);
newText(tmpp, text);
final Object dataLocal = tmpp.getData();
introspectionObject.addObject(IntrospectionModel.STUPID_TOCKEN, dataLocal);
return;
}
if (model.hasTextModel()) {
final String beanName = model.getTextBeanName();
if (beanName == null) {
if (model.isIgnoreUnknown()) {
LOGGER.debug("Ignore node : **TEXT**");
return;
}
throw new ExmlAttributeDoesNotExist("The node **TEXT** Does not exist...");
}
final Class<?> typeClass = model.getTypeOfText();
if (typeClass != null) {
// specific case for List ==> need to get the subType in introspection ...
if (typeClass.isPrimitive()) {
final Object out = StringSerializer.valueOf(typeClass, text);
introspectionObject.putProperty(beanName, out);
} else if (typeClass.isArray()) {
LOGGER.error("Not managed !!! ");
/*
final String[] elems = propertyValue.split(";");
final Class<?> subTypeClass = typeClass.getComponentType();
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
final List<Object> out = new ArrayList<>();
for (int iii = 0; iii < elems.length; iii++) {
final Object tmp = inferData.getValueFromText(elems[iii]);
out.add(tmp);
}
introspectionObject.putProperty(propertyName, out);
*/
} else if (List.class.isAssignableFrom(typeClass)) {
LOGGER.error("Not managed !!! ");
/*
final String[] elems = propertyValue.split(";");
final Class<?> subTypeClass = introspectionObject.getTypeOfSubProperty(propertyName);
LOGGER.trace("Create List new 'SUB' class: '" + typeClass.getCanonicalName() + "' for property '" + propertyName + "'");
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, subTypeClass);
final List<Object> out = new ArrayList<>();
for (int iii = 0; iii < elems.length; iii++) {
final Object tmp = inferData.getValueFromText(elems[iii]);
out.add(tmp);
}
introspectionObject.putProperty(propertyName, out);
*/
} else {
//LOGGER.error("Not managed !!! ");
final IntrospectionModel inferData = this.cacheModel.findOrCreate(ModelType.NORMAL, null, typeClass);
final Object out = inferData.getValueFromText(text);
introspectionObject.putProperty(IntrospectionObject.PUBLIC_TEXT_NAME, out);
}
}
} else {
introspectionObject.setText(text);
}
}
}

View File

@ -0,0 +1,172 @@
package org.atriasoft.exml.builder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.aknot.model.IntrospectionModel;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class IntrospectionObject {
final static Logger LOGGER = LoggerFactory.getLogger(IntrospectionObject.class);
public static final String PUBLIC_TEXT_NAME = "##<< ** TEXT-ZONE ** >>##";
private final IntrospectionModel modelInterface;
private Object data = null;
private final Map<String, Object> properties = new HashMap<>();
private final Map<String, List<Object>> nodes = new HashMap<>();
public IntrospectionObject(final IntrospectionModel dataInterface) {
this.modelInterface = dataInterface;
}
@SuppressWarnings("unchecked")
public void addObject(final String nodeName, final Object value) throws ExmlException {
if (value == null) {
// specific case when a List is empty <links></links> but define for a specific list ==> need no action
return;
}
final String beanName = this.modelInterface.getBeanName(nodeName);
if (beanName == null) {
throw new ExmlNodeDoesNotExist("The node '" + nodeName + "' Does not exist...");
}
List<Object> node = this.nodes.get(beanName);
if (node == null) {
if (List.class.isAssignableFrom(value.getClass())) {
node = (List<Object>) value;
} else if (value.getClass().isArray()) {
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
} else {
node = new ArrayList<>();
node.add(value);
}
this.nodes.put(beanName, node);
} else if (value.getClass().isArray()) {
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
LOGGER.error("this is a big problem ...");
} else if (List.class.isAssignableFrom(value.getClass())) {
final List<Object> nodeIn = (List<Object>) value;
node.addAll(nodeIn);
} else {
node.add(value);
}
}
public void generateTheObject() throws AknotException {
if (this.data != null) {
// nothing to do ... ==> element already created
return;
}
LOGGER.warn("Create the element for the Specific node ... type = " + this.modelInterface.getClassType().getCanonicalName() + (this.modelInterface.isArray() ? "[array]" : "")
+ (this.modelInterface.isList() ? "[List]" : ""));
LOGGER.warn(" Properties : " + this.properties.keySet());
LOGGER.warn(" Nodes : " + this.nodes.keySet());
this.data = this.modelInterface.createObject(this.properties, this.nodes, false);
}
public Object getData() {
return this.data;
}
public IntrospectionModel getModelIntrospection() {
return this.modelInterface;
}
public String getTreeNameOfSubNode(final String nodeName) throws AknotException, ExmlNodeDoesNotExist {
final String beanName = this.modelInterface.getBeanName(nodeName);
if (beanName == null) {
throw new ExmlNodeDoesNotExist("The node '" + nodeName + "' Does not exist...");
}
return this.modelInterface.getTreeNameOfSubNode(beanName, false);
}
public Class<?> getTypeOfProperty(final String nodeName) throws AknotException, ExmlNodeDoesNotExist {
final String beanName = this.modelInterface.getBeanName(nodeName);
if (beanName == null) {
throw new ExmlNodeDoesNotExist("The node '" + nodeName + "' Does not exist...");
}
return this.modelInterface.getTypeOfProperty(beanName);
}
/**
* Detect a subNode, and ask the type of the node at the parent Class
* @param nodeName Name of the node
* @return Class of the node to create
*/
public Class<?> getTypeOfSubNode(final String nodeName) throws AknotException, ExmlNodeDoesNotExist {
final String beanName = this.modelInterface.getBeanNameModel(nodeName);
if (beanName == null) {
throw new ExmlNodeDoesNotExist("The node '" + nodeName + "' Does not exist...");
}
return this.modelInterface.getTypeOfSubNode(beanName, false);
}
public Class<?> getTypeOfSubNodeSubType(final String nodeName) throws AknotException, ExmlNodeDoesNotExist {
final String beanName = this.modelInterface.getBeanNameModel(nodeName);
if (beanName == null) {
throw new ExmlNodeDoesNotExist("The node '" + nodeName + "' Does not exist...");
}
return this.modelInterface.getTypeOfSubNodeList(beanName, false);
}
public Class<?> getTypeOfSubProperty(final String nodeName) throws AknotException, ExmlNodeDoesNotExist {
final String beanName = this.modelInterface.getBeanName(nodeName);
if (beanName == null) {
throw new ExmlNodeDoesNotExist("The node '" + nodeName + "' Does not exist...");
}
return this.modelInterface.getTypeOfSubProperty(beanName);
}
public boolean isSubNodeOrPropertyExist(final String nodeName) {
final String beanName = this.modelInterface.getBeanName(nodeName);
if (beanName == null) {
return false;
}
return true;
}
public void putProperty(final String propertyName, final Object propertyValue) throws AknotException, ExmlException {
String beanName = null;
if (propertyName == PUBLIC_TEXT_NAME) {
beanName = this.modelInterface.getTextBeanName();
} else {
beanName = this.modelInterface.getBeanName(propertyName);
}
if (this.properties.containsKey(beanName)) {
throw new ExmlException("Property have multiple values ==> impossible case; A Node must contain only 1 attibutes");
}
this.properties.put(beanName, propertyValue);
}
public void setText(final String text) throws AknotException, ExmlException {
if (this.data != null) {
throw new ExmlException("Can not set multiple text value in a single NODE ...");
}
this.data = this.modelInterface.getValueFromText(text);
}
}

View File

@ -5,7 +5,11 @@
*/ */
package org.atriasoft.exml.exception; package org.atriasoft.exml.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlAttributeDoesNotExist extends ExmlException { public class ExmlAttributeDoesNotExist extends ExmlException {
final static Logger LOGGER = LoggerFactory.getLogger(ExmlAttributeDoesNotExist.class);
/** /**
* Generate Unique ID for serialization * Generate Unique ID for serialization
*/ */

View File

@ -0,0 +1,22 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlBuilderException extends ExmlException {
final static Logger LOGGER = LoggerFactory.getLogger(ExmlBuilderException.class);
/**
* Generate Unique ID for serialization
*/
private static final long serialVersionUID = 1L;
public ExmlBuilderException(final String data) {
super(data);
}
}

View File

@ -5,7 +5,11 @@
*/ */
package org.atriasoft.exml.exception; package org.atriasoft.exml.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlException extends Exception { public class ExmlException extends Exception {
final static Logger LOGGER = LoggerFactory.getLogger(ExmlException.class);
/** /**
* Generate Unique ID for serialization * Generate Unique ID for serialization
*/ */

View File

@ -5,7 +5,11 @@
*/ */
package org.atriasoft.exml.exception; package org.atriasoft.exml.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlNodeDoesNotExist extends ExmlException { public class ExmlNodeDoesNotExist extends ExmlException {
final static Logger LOGGER = LoggerFactory.getLogger(ExmlNodeDoesNotExist.class);
/** /**
* Generate Unique ID for serialization * Generate Unique ID for serialization
*/ */

View File

@ -0,0 +1,28 @@
package org.atriasoft.exml.exception;
import org.atriasoft.etk.util.FilePos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlParserError extends ExmlBuilderException {
final static Logger LOGGER = LoggerFactory.getLogger(ExmlParserError.class);
private static final long serialVersionUID = 1L;
private final String dataLine; //!< Parse line error (copy);
private final FilePos filePos; //!< position of the error
public ExmlParserError(final String dataLine, final FilePos filePos, final String comment) {
super(comment);
this.dataLine = dataLine;
this.filePos = filePos.clone();
}
public String getDataLine() {
return this.dataLine;
}
public FilePos getFilePos() {
return this.filePos;
}
}

View File

@ -0,0 +1,22 @@
package org.atriasoft.exml.exception;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlParserErrorMulti extends ExmlBuilderException {
final static Logger LOGGER = LoggerFactory.getLogger(ExmlParserErrorMulti.class);
private static final long serialVersionUID = 1L;
private final List<ExmlParserError> errors; // list of errors
public ExmlParserErrorMulti(final String message, final List<ExmlParserError> errors) {
super(message);
this.errors = errors;
}
public List<ExmlParserError> getErrors() {
return this.errors;
}
}

View File

@ -0,0 +1,9 @@
package org.atriasoft.exml.generator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public interface Generator {
final static Logger LOGGER = LoggerFactory.getLogger(Generator.class);
}

View File

@ -0,0 +1,119 @@
package org.atriasoft.exml.generator;
import java.util.List;
import org.atriasoft.etk.Tools;
import org.atriasoft.exml.model.XmlAttribute;
import org.atriasoft.exml.model.XmlAttributeList;
import org.atriasoft.exml.model.XmlComment;
import org.atriasoft.exml.model.XmlDeclaration;
import org.atriasoft.exml.model.XmlElement;
import org.atriasoft.exml.model.XmlNode;
import org.atriasoft.exml.model.XmlNodeType;
import org.atriasoft.exml.model.XmlText;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GeneratorGeneric {
final static Logger LOGGER = LoggerFactory.getLogger(GeneratorGeneric.class);
public static void serialize(final XmlNode node, final StringBuilder data, final int indent) {
if (node instanceof XmlElement) {
GeneratorGeneric.serializeElement((XmlElement) node, data, indent);
} else if (node instanceof XmlText) {
GeneratorGeneric.serializeText((XmlText) node, data, indent);
} else if (node instanceof XmlDeclaration) {
GeneratorGeneric.serializeDeclaration((XmlDeclaration) node, data, indent);
} else if (node instanceof XmlComment) {
GeneratorGeneric.serializeComment((XmlComment) node, data, indent);
} else {
// TODO throw an error ...
}
}
private static void serializeAttribute(final XmlAttribute attribute, final StringBuilder data, final int indent) {
data.append(" ");
data.append(attribute.getName());
data.append("=\"");
data.append(attribute.getValue());
data.append("\"");
}
private static void serializeAttributeList(final XmlAttributeList list, final StringBuilder data, final int indent) {
for (int iii = 0; iii < list.getAttributes().size(); iii++) {
GeneratorGeneric.serializeAttribute(list.getAttributes().get(iii), data, indent);
}
}
private static void serializeComment(final XmlComment comment, final StringBuilder data, final int indent) {
Tools.addIndent(data, indent);
data.append("<!--");
final String commentData = comment.getValue();
if (commentData != null) {
data.append(comment.getValue());
}
data.append("-->");
}
private static void serializeDeclaration(final XmlDeclaration declaration, final StringBuilder data, final int indent) {
Tools.addIndent(data, indent);
data.append("<?");
data.append(declaration.getValue());
GeneratorGeneric.serializeAttributeList(declaration, data, indent);
data.append("?>");
}
private static void serializeElement(final XmlElement element, final StringBuilder data, final int indent) {
Tools.addIndent(data, indent);
data.append("<");
data.append(element.getValue());
GeneratorGeneric.serializeAttributeList(element, data, indent);
final List<XmlNode> nodes = element.getNodes();
if (nodes.size() > 0) {
if (nodes.size() == 1 && nodes.get(0) != null && nodes.get(0).getType() == XmlNodeType.TEXT && ((XmlText) nodes.get(0)).countLines() == 1) {
data.append(">");
GeneratorGeneric.serialize(nodes.get(0), data, 0);
LOGGER.trace(" generate : '" + data + "'");
} else {
data.append(">");
for (final XmlNode node : nodes) {
if (node != null) {
GeneratorGeneric.serialize(node, data, indent + 1);
}
}
Tools.addIndent(data, indent);
}
data.append("</");
data.append(element.getValue());
data.append(">");
} else {
data.append("/>");
}
}
public static void serializeRoot(final XmlElement root, final StringBuilder data) {
for (int iii = 0; iii < root.getNodes().size(); iii++) {
final XmlNode node = root.getNodes().get(iii);
GeneratorGeneric.serialize(node, data, 0);
}
}
private static void serializeText(final XmlText text, final StringBuilder data, final int indent) {
data.append(Tools.replaceSpecialCharOut(text.getValue()));
}
/* CDATA generation ... maybe to add later ...
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
_data.append("<![CDATA[");
_data.append(this.value);
_data.append("]]>");
return true;
}
*/
private GeneratorGeneric() {}
}

View File

@ -0,0 +1,288 @@
package org.atriasoft.exml.generator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.aknot.model.IntrospectionModel;
import org.atriasoft.aknot.model.MapKey;
import org.atriasoft.aknot.model.ModelType;
import org.atriasoft.aknot.pojo.IntrospectionModelFactory;
import org.atriasoft.aknot.pojo.IntrospectionProperty;
import org.atriasoft.etk.Tools;
import org.atriasoft.etk.util.ArraysTools;
import org.atriasoft.exml.exception.ExmlBuilderException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class GeneratorIntrospection implements Generator {
final static Logger LOGGER = LoggerFactory.getLogger(GeneratorIntrospection.class);
// Keep in cache all the object already parsed ==> optimize CPU
final Map<MapKey, IntrospectionModel> elements = new HashMap<>();
// The root class (need to keep it if we use 2 time the builder, the root class is no more accessible).
final Class<?> rootClassType;
final String rootNodeName;
public GeneratorIntrospection(final ModelType model, final Class<?> classType) throws Exception {
this.rootClassType = classType;
final MapKey key = new MapKey(model, classType);
// TODO pb if it is a List or an Array ...
final IntrospectionModel typeModel = IntrospectionModelFactory.createModel(key);
this.elements.put(key, typeModel);
this.rootNodeName = typeModel.getNames()[0];
}
private <T> String autoArrayToString(final Class<T> clazz, final Object inData, final IntrospectionModel model) throws ExmlBuilderException, AknotException {
@SuppressWarnings("unchecked")
final T[] datas = (T[]) inData;
final StringBuilder out = new StringBuilder();
for (int iii = 0; iii < datas.length; iii++) {
if (!out.isEmpty()) {
out.append(";");
}
out.append(model.toString(datas[iii]));
}
return out.toString();
}
private <T> String autoListToString(final Class<T> clazz, final Object inData, final IntrospectionModel model) throws ExmlBuilderException, AknotException {
@SuppressWarnings("unchecked")
final List<T> elements1 = (List<T>) inData;
final StringBuilder out = new StringBuilder();
for (final Object elem1 : elements1) {
if (!out.isEmpty()) {
out.append(";");
}
out.append(model.toString(elem1));
}
return out.toString();
}
IntrospectionModel findOrCreate(final ModelType model, final String name, final Class<?> classType) throws ExmlBuilderException, AknotException {
final MapKey key = new MapKey(model, name, classType);
IntrospectionModel out = this.elements.get(key);
if (out != null) {
return out;
}
if (model == ModelType.ARRAY) {
out = IntrospectionModelFactory.createModelArray(key.nodeName(), key);
} else if (model == ModelType.LIST) {
out = IntrospectionModelFactory.createModelList(key.nodeName(), key);
} else {
out = IntrospectionModelFactory.createModel(key);
}
this.elements.put(key, out);
return out;
}
public void generate(final Object root, final StringBuilder tmpp) throws ExmlBuilderException, AknotException {
final IntrospectionModel introspection = findOrCreate(ModelType.NORMAL, null, root.getClass());
generateNode(root, introspection, this.rootNodeName, tmpp, 0);
}
public <T> void generateArrayNode(final Class<T> clazz, final Object data, final IntrospectionModel model, final String nodeName, final StringBuilder tmpp, final int indent)
throws ExmlBuilderException, AknotException {
//Class<?> clazzData = data.getClass();
if (clazz.isPrimitive()) {
if (clazz == byte.class) {
final byte[] datas = (byte[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
} else if (clazz == boolean.class) {
final boolean[] datas = (boolean[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
} else if (clazz == short.class) {
final short[] datas = (short[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
} else if (clazz == int.class) {
final int[] datas = (int[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
} else if (clazz == long.class) {
final long[] datas = (long[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
} else if (clazz == float.class) {
final float[] datas = (float[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
} else if (clazz == double.class) {
final double[] datas = (double[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
}
return;
}
@SuppressWarnings("unchecked")
final T[] datas = (T[]) data;
for (int iii = 0; iii < datas.length; iii++) {
generateNode(datas[iii], model, nodeName, tmpp, indent);
}
}
public void generateNode(final Object data, final IntrospectionModel model, final String nodeName, final StringBuilder tmpp, final int indent) throws ExmlBuilderException, AknotException {
if (model.isNative()) {
Tools.addIndent(tmpp, indent);
tmpp.append("<");
tmpp.append(nodeName);
tmpp.append(">");
tmpp.append(model.toString(data));
tmpp.append("</");
tmpp.append(nodeName);
tmpp.append(">");
} else if (model.isArray()) {
final List<String> baseName = model.getNodeAvaillable();
final IntrospectionModel introspectionSub = findOrCreate(ModelType.NORMAL, null, model.getClassType());
if (baseName == null || baseName.size() == 0) {
// mode render : <nodeName>aaa</nodeName><nodeName>bbb</nodeName>
generateArrayNode(model.getClassType(), data, introspectionSub, nodeName, tmpp, indent);
} else {
// mode render : <nodeName><val>aaa</val><val>bbb</val></nodeName>
Tools.addIndent(tmpp, indent);
tmpp.append("<");
tmpp.append(nodeName);
tmpp.append(">");
generateArrayNode(model.getClassType(), data, introspectionSub, baseName.get(0), tmpp, indent + 1);
Tools.addIndent(tmpp, indent);
tmpp.append("</");
tmpp.append(nodeName);
tmpp.append(">");
}
LOGGER.error("lkjlk");
} else if (model.isList()) {
final List<String> baseName = model.getNodeAvaillable();
@SuppressWarnings("unchecked")
final List<Object> datas = (List<Object>) data;
if (baseName == null || baseName.size() == 0) {
// mode render : <nodeName>aaa</nodeName><nodeName>bbb</nodeName>
for (final Object elem : datas) {
// note the type can change in List ...
final IntrospectionModel introspectionSub = findOrCreate(ModelType.NORMAL, null, elem.getClass());
generateNode(elem, introspectionSub, nodeName, tmpp, indent);
}
} else {
// mode render : <nodeName><val>aaa</val><val>bbb</val></nodeName>
Tools.addIndent(tmpp, indent);
tmpp.append("<");
tmpp.append(nodeName);
tmpp.append(">");
for (final Object elem : datas) {
// note the type can change in List ...
final IntrospectionModel introspectionSub = findOrCreate(ModelType.NORMAL, null, elem.getClass());
generateNode(elem, introspectionSub, baseName.get(0), tmpp, indent + 1);
}
//tmpp.append(model.toString(data));
Tools.addIndent(tmpp, indent);
tmpp.append("</");
tmpp.append(nodeName);
tmpp.append(">");
}
} else if (model.isEnum()) {
Tools.addIndent(tmpp, indent);
tmpp.append("<");
tmpp.append(nodeName);
tmpp.append(">");
tmpp.append(model.toString(data));
tmpp.append("</");
tmpp.append(nodeName);
tmpp.append(">");
} else {
Tools.addIndent(tmpp, indent);
tmpp.append("<");
tmpp.append(nodeName);
generateProperties(data, model, tmpp);
if (model.getNodes().size() != 0) {
tmpp.append(">");
generateSubNodes(data, model, tmpp, indent + 1);
Tools.addIndent(tmpp, indent);
tmpp.append("</");
tmpp.append(nodeName);
tmpp.append(">");
} else {
tmpp.append("/>");
}
}
}
public void generateProperties(final Object data, final IntrospectionModel introspection, final StringBuilder tmpp) throws ExmlBuilderException, AknotException {
final List<IntrospectionProperty> elements = introspection.getAttributes();
if (elements == null) {
return;
}
for (final IntrospectionProperty elem : elements) {
if (!elem.canGetValue()) {
continue;
}
final Object dataObj = elem.getValue(data);
if (dataObj == null) {
continue;
}
final String name = elem.getNames()[0];
final Class<?> type = elem.getType();
String dataString = null;
if (type.isArray()) {
final Class<?> typeClass = elem.getType().componentType();
if (typeClass.isPrimitive()) {
dataString = ArraysTools.primitivaArrayToSting(dataObj);
} else {
final IntrospectionModel introspectionSub = findOrCreate(ModelType.NORMAL, null, typeClass);
dataString = autoArrayToString(typeClass, dataObj, introspectionSub);
}
} else if (List.class.isAssignableFrom(type)) {
final Class<?> typeClass = elem.getSubType();
final IntrospectionModel introspectionSub = findOrCreate(ModelType.NORMAL, null, typeClass);
dataString = autoListToString(typeClass, dataObj, introspectionSub);
} else {
final IntrospectionModel introspectionSub = findOrCreate(ModelType.NORMAL, null, dataObj.getClass());
dataString = introspectionSub.toString(dataObj);
}
if (dataString != null) {
tmpp.append(" ");
tmpp.append(name);
tmpp.append("=\"");
tmpp.append(dataString);
tmpp.append("\"");
}
}
}
public void generateSubNodes(final Object data, final IntrospectionModel introspection, final StringBuilder tmpp, final int indent) throws ExmlBuilderException, AknotException {
final List<IntrospectionProperty> elements = introspection.getNodes();
for (final IntrospectionProperty elem : elements) {
if (!elem.canGetValue()) {
continue;
}
final Object dataObj = elem.getValue(data);
if (dataObj == null) {
continue;
}
final String name = elem.getNames()[0];
final Class<?> type = elem.getType();
IntrospectionModel introspectionSub = null;
if (type.isArray()) {
final Class<?> typeClass = elem.getType().componentType();
final String listTreeName = elem.getListName();
introspectionSub = findOrCreate(ModelType.ARRAY, listTreeName, typeClass);
} else if (List.class.isAssignableFrom(type)) {
final Class<?> typeClass = elem.getSubType();
final String listTreeName = elem.getListName();
introspectionSub = findOrCreate(ModelType.LIST, listTreeName, typeClass);
} else {
introspectionSub = findOrCreate(ModelType.NORMAL, null, dataObj.getClass());
}
generateNode(dataObj, introspectionSub, name, tmpp, indent);
}
}
}

View File

@ -0,0 +1,89 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.model;
import org.atriasoft.etk.util.FilePos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Single attribute element
*/
public class XmlAttribute {
final static Logger LOGGER = LoggerFactory.getLogger(XmlAttribute.class);
protected String name; //!< Name of the attribute
protected FilePos pos; //!< position in the read file (null if the file is not parsed);
protected String value; //!< value of the node (for element this is the name, for text it is the inside text ...);
public XmlAttribute() {
this.pos = null;
this.value = "";
this.name = "";
}
public XmlAttribute(final String name) {
this.name = name;
this.value = "";
}
/**
* Constructor
* @param _name Name of the attribute.
* @param _value Value of the attribute.
*/
public XmlAttribute(final String name, final String value) {
this.name = name;
this.value = value;
}
public XmlAttribute(final XmlAttribute obj) {
this.pos = null;
this.value = obj.value;
this.name = obj.name;
}
public void clear() {
this.value = "";
}
@Override
public XmlAttribute clone() {
return new XmlAttribute(this.name, this.value);
}
/**
* get the current name of the Attribute
* @return String of the attribute
*/
public String getName() {
return this.name;
}
/**
* get the current element Value.
* @return the reference of the string value.
*/
public String getValue() {
return this.value;
}
/**
* set the name of the attribute
* @param _name New name of the attribute
*/
public void setName(final String name) {
this.name = name;
}
/**
* set the value of the node.
* @param _value New value of the node.
*/
public final void setValue(final String value) {
this.value = value;
}
}

View File

@ -0,0 +1,188 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import org.atriasoft.etk.util.Pair;
import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* List of all attribute element in a node
*/
public abstract class XmlAttributeList extends XmlNode {
final static Logger LOGGER = LoggerFactory.getLogger(XmlAttributeList.class);
protected List<XmlAttribute> listAttribute = new ArrayList<>(); //!< list of all attribute;
public XmlAttributeList() {}
/**
* Constructor
* @param value Node value;
*/
public XmlAttributeList(final String value) {
super(value);
}
/**
* Add attribute on the List
* @param attr Pointer on the attribute
*/
public void appendAttribute(final XmlAttribute attr) {
if (attr == null) {
LOGGER.error("Try to set an empty node");
return;
}
for (int iii = 0; iii < this.listAttribute.size(); iii++) {
if (this.listAttribute.get(iii) == attr) {
LOGGER.error("Try to add a node that is already added before !!!");
return;
}
if (this.listAttribute.get(iii).getName().contentEquals(attr.getName())) {
LOGGER.error("Try to add a node that is already added before (same name)");
return;
}
}
this.listAttribute.add(attr);
}
@Override
public void clear() {
super.clear();
this.listAttribute.clear();
}
/**
* Check if an attribute exist or not with his name.
* @param name Attribute Name.
* @return true if the attribute exist or False
*/
public boolean existAttribute(final String name) {
if (name.length() == 0) {
return false;
}
for (int iii = 0; iii < this.listAttribute.size(); ++iii) {
if (this.listAttribute.get(iii) != null && this.listAttribute.get(iii).getName().contentEquals(name)) {
return true;
}
}
return false;
}
/**
* Get attribute whith his ID
* @param id Identifier of the attribute 0<= id < sizeAttribute()
* @return Pointer on the attribute or NULL
* @throws ExmlAttributeDoesNotExist The attribute does not exist.
*/
public XmlAttribute getAttr(final int id) throws ExmlAttributeDoesNotExist {
if (id < 0 || id >= this.listAttribute.size()) {
throw new ExmlAttributeDoesNotExist("Attribute does not exist: " + id + "/" + this.listAttribute.size());
}
return this.listAttribute.get(id);
}
/**
* get the attribute value with searching in the List with his name
* @param name Attribute Name.
* @return Value of the attribute or no data in the string
* @throws ExmlAttributeDoesNotExist The attribute does not exist.
*/
public String getAttribute(final String name) throws ExmlAttributeDoesNotExist {
if (name.length() == 0) {
throw new ExmlAttributeDoesNotExist("Attribute can not have empty name");
}
for (final XmlAttribute xmlAttribute : this.listAttribute) {
if (xmlAttribute != null && xmlAttribute.getName().contentEquals(name)) {
return xmlAttribute.getValue();
}
}
throw new ExmlAttributeDoesNotExist("Attribute does not exist: " + name + " in " + this.listAttribute.size() + " attributes");
}
public String getAttribute(final String name, final String defaultValue) {
if (name.length() == 0) {
return defaultValue;
}
for (final XmlAttribute xmlAttribute : this.listAttribute) {
if (xmlAttribute != null && xmlAttribute.getName().contentEquals(name)) {
return xmlAttribute.getValue();
}
}
return defaultValue;
}
public List<XmlAttribute> getAttributes() {
return Collections.unmodifiableList(this.listAttribute);
}
/**
* get attribute whith his ID
* @param id Identifier of the attribute 0<= id < sizeAttribute()
* @return Name and value of the attribute
* @throws ExmlAttributeDoesNotExist The attribute does not exist.
*/
public Pair<String, String> getAttrPair(final int id) throws ExmlAttributeDoesNotExist {
final XmlAttribute att = getAttr(id);
return new Pair<String, String>(att.getName(), att.getValue());
}
/**
* Remove an attribute form the list
* @param name Name of the attribute
* @return true The attribute has been removed
* @return false An error occured.
*/
public boolean removeAttribute(final String name) {
if (name.length() == 0) {
return false;
}
for (final ListIterator<XmlAttribute> iter = this.listAttribute.listIterator(); iter.hasNext();) {
final XmlAttribute element = iter.next();
if (element == null) {
iter.remove();
continue;
}
if (element.getName().contentEquals(name)) {
iter.remove();
return true;
}
}
return false;
}
/**
* Set A new attribute or replace data of the previous one
* @param name Name of the attribute
* @param value Value of the attribute
*/
public void setAttribute(final String name, final String value) {
// check if attribute already det :
for (int iii = 0; iii < this.listAttribute.size(); ++iii) {
if (this.listAttribute.get(iii) != null && this.listAttribute.get(iii).getName().contentEquals(name)) {
// update the value :
this.listAttribute.get(iii).setValue(value);
return;
}
}
final XmlAttribute attr = new XmlAttribute(name, value);
this.listAttribute.add(attr);
}
/**
* get the number of attribute in the Node
* @return Nulber of attribute >=0
*/
public int sizeAttribute() {
return this.listAttribute.size();
}
}

View File

@ -0,0 +1,42 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Comment node: lt;!-- ... --gt;
*/
public class XmlComment extends XmlNode {
final static Logger LOGGER = LoggerFactory.getLogger(XmlComment.class);
public XmlComment() {
}
/**
* Constructor
* @param _value comment value
*/
public XmlComment(final String value) {
super(value);
}
public XmlComment(final XmlComment obj) {
super(obj.value);
}
@Override
public XmlComment clone() {
return new XmlComment(this);
}
@Override
public XmlNodeType getType() {
return XmlNodeType.COMMENT;
}
}

View File

@ -0,0 +1,63 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Declaration node: lt;?XXXXXX ... gt;
*/
public class XmlDeclaration extends XmlAttributeList {
final static Logger LOGGER = LoggerFactory.getLogger(XmlDeclaration.class);
public XmlDeclaration() {
super("");
}
/**
* Constructor
* @param name name of the declaration (xml, xml:xxxx ...)
*/
public XmlDeclaration(final String name) {
super(name);
}
public XmlDeclaration(final String version, final String format, final boolean standalone) {
super("xml");
if (!version.isEmpty()) {
setAttribute("version", version);
}
if (format.contentEquals("UTF-8")) {
setAttribute("encoding", "UTF-8");
} else {
LOGGER.error("Actually does not supported other charset than UTF8");
setAttribute("encoding", "UTF-8");
}
if (standalone) {
setAttribute("standalone", "true");
} else {
setAttribute("standalone", "true");
}
}
public XmlDeclaration(final XmlDeclaration obj) {
super(obj.value);
for (final XmlAttribute elem : obj.listAttribute) {
this.listAttribute.add(elem.clone());
}
}
@Override
public XmlDeclaration clone() {
return new XmlDeclaration(this);
}
@Override
public XmlNodeType getType() {
return XmlNodeType.DECLARATION;
}
}

View File

@ -0,0 +1,235 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.atriasoft.exml.generator.GeneratorGeneric;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* Basic element Node of an XML document lt;YYYYYgt;
*/
public class XmlElement extends XmlAttributeList {
final static Logger LOGGER = LoggerFactory.getLogger(XmlElement.class);
protected List<XmlNode> listSub = new ArrayList<>(); //!< List of subNodes;
/**
* Constructor
*/
public XmlElement() {}
/**
* Constructor
* @param value Element name;
*/
public XmlElement(final String value) {
super(value);
}
public XmlElement(final XmlElement obj) throws CloneNotSupportedException {
super(obj.value);
for (final XmlAttribute elem : obj.listAttribute) {
this.listAttribute.add(elem.clone());
}
for (final XmlNode elem : obj.listSub) {
this.listSub.add(elem.clone());
}
}
/**
* add a node at the element (not Attribute (move in the attribute automaticly).
* @param node Pointer of the node to add.
*/
public void append(final XmlNode node) {
if (node == null) {
LOGGER.error("Try to set an empty node");
return;
}
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) == node) {
LOGGER.error("Try to add a node that is already added before !!!");
return;
}
}
this.listSub.add(node);
}
@Override
public void clear() {
super.clear();
this.listSub.clear();
}
@Override
public XmlElement clone() throws CloneNotSupportedException {
return new XmlElement(this);
}
/**
* get the Node pointer of the element id.
* @param id Id of the element.
* @return true if the Node exist.
*/
public boolean existNode(final int id) {
if (id < 0 || id >= this.listSub.size()) {
return false;
}
return true;
}
/**
* get an element with his name (work only with Element)
* @param name Name of the element that is requested
* @return true if the Node exist.
*/
public boolean existNode(final String name) {
if (name.isEmpty()) {
return false;
}
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null && this.listSub.get(iii).getValue().contentEquals(name)) {
if (this.listSub.get(iii) == null) {
return false;
}
return true;
}
}
return false;
}
/**
* get the Node pointer of the element id.
* @param id Id of the element.
* @return Pointer on node.
* @throws ExmlNodeDoesNotExist The Node does not exist
*/
public XmlNode getNode(final int id) throws ExmlNodeDoesNotExist {
if (id < 0 || id >= this.listSub.size()) {
throw new ExmlNodeDoesNotExist("Node does not exist: " + id + "/" + this.listSub.size());
}
return this.listSub.get(id);
}
/**
* get an element with his name (work only with Element)
* @param name Name of the element that is requested
* @return Pointer on the node.
* @throws ExmlNodeDoesNotExist The Node does not exist
*/
public XmlNode getNode(final String name) throws ExmlNodeDoesNotExist {
if (name.isEmpty()) {
throw new ExmlNodeDoesNotExist("Node can not have empty name in " + this.listAttribute.size() + " nodes");
}
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null && this.listSub.get(iii).getValue().contentEquals(name)) {
return this.listSub.get(iii);
}
}
throw new ExmlNodeDoesNotExist("Node does not exist: '" + name + "' in " + this.listAttribute.size());
}
public XmlNode getNodeNoExcept(final String name) {
if (name.isEmpty()) {
return null;
}
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null && this.listSub.get(iii).getValue().contentEquals(name)) {
return this.listSub.get(iii);
}
}
return null;
}
/**
* Get the list of the sub-nodes.
* @return List of current nodes.
*/
public List<XmlNode> getNodes() {
return Collections.unmodifiableList(this.listSub);
}
/**
* Get the internal data of the element (if the element has some sub node they are converted in xml string == > like this it is not needed to use <![CDATA[...]]>
* @return the current data string. if Only one text node, then we get the parsed data (no amp; ...) if more than one node, then we transform ,",',<,> in xml normal text...
*/
public String getText() {
final StringBuilder res = new StringBuilder();
if (this.listSub.size() == 1) {
if (this.listSub.get(0).getType() == XmlNodeType.TEXT) {
res.append(this.listSub.get(0).getValue());
} else {
GeneratorGeneric.serialize(this.listSub.get(0), res, 0);
}
} else {
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null) {
GeneratorGeneric.serialize(this.listSub.get(iii), res, 0);
}
}
}
return res.toString();
}
@Override
public XmlNodeType getType() {
return XmlNodeType.ELEMENT;
}
/**
* get the type of the element id.
* @param id Id of the element.
* @return the Current type of the element or typeUnknow.
* @throws ExmlNodeDoesNotExist The Node does not exist
*/
public XmlNodeType getType(final int id) throws ExmlNodeDoesNotExist {
if (id < 0 || id >= this.listSub.size()) {
throw new ExmlNodeDoesNotExist("Node does not exist: " + id + "/" + this.listSub.size());
}
return this.listSub.get(id).getType();
}
/**
* Remove all element with this name
* @param nodeName Name of nodes to remove.
*/
public void remove(final String nodeName) {
if (nodeName.isEmpty()) {
return;
}
for (final ListIterator<XmlNode> iter = this.listSub.listIterator(); iter.hasNext();) {
final XmlNode element = iter.next();
if (element == null) {
iter.remove();
continue;
}
if (element.getValue().contentEquals(nodeName)) {
iter.remove();
}
}
}
/**
* get the number of sub element in the node (can be Comment ; Element ; Text :Declaration).
* @return a number >=0.
*/
public int size() {
return this.listSub.size();
}
}

View File

@ -0,0 +1,134 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Basic main object of all xml elements.
*/
public abstract class XmlNode {
final static Logger LOGGER = LoggerFactory.getLogger(XmlNode.class);
/// Value of the node (for element this is the name, for text it is the inside text ...)(null for the root element);
protected String value = null;
/**
* basic element of a xml structure
*/
public XmlNode() {}
/**
* Basic element of a xml structure
* @param value value of the node
*/
public XmlNode(final String value) {
setValue(value);
}
/**
* Clear the Node
*/
public void clear() {
this.value = null;
}
@Override
protected XmlNode clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("Can not clone an abs ctract class ...");
}
/**
* Get the node type.
* @return the type of the Node.
*/
public abstract XmlNodeType getType();
/**
* Get the current element Value (value in the XML tag &gt;VALUE ... &lt; &gt;/VALUE&lt;.
* @return the reference of the string value.
*/
public String getValue() {
return this.value;
}
/**
* Check if the node is a Comment
* @return true if the node is a Comment
*/
public final boolean isComment() {
return this instanceof XmlComment;
}
/**
* check if the node is a Declaration
* @return true if the node is a Declaration
*/
public final boolean isDeclaration() {
return this instanceof XmlDeclaration;
}
/**
* check if the node is a Element
* @return true if the node is a Element
*/
public final boolean isElement() {
return this instanceof XmlElement;
}
/**
* check if the node is a Text
* @return true if the node is a Text
*/
public final boolean isText() {
return this instanceof XmlText;
}
/**
* set the value of the node.
* @param value New value of the node.
*/
public final void setValue(final String value) {
if (value.isEmpty() || value.isBlank()) {
this.value = null;
} else {
this.value = value;
}
}
/**
* Cast the element in a Comment if it is possible.
* @return pointer on the class or null.
*/
public final XmlComment toComment() {
return (XmlComment) this;
}
/**
* Cast the element in a Declaration if it is possible.
* @return pointer on the class or null.
*/
public final XmlDeclaration toDeclaration() {
return (XmlDeclaration) this;
}
/**
* Cast the element in a Element if it is possible.
* @return pointer on the class or null.
*/
public final XmlElement toElement() {
return (XmlElement) this;
}
/**
* Cast the element in a Text if it is possible.
* @return pointer on the class or null.
*/
public final XmlText toText() {
return (XmlText) this;
}
}

View File

@ -3,13 +3,12 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package org.atriasoft.exml; package org.atriasoft.exml.model;
/** /**
* @brief Type of the XML elements. * Type of the XML elements.
*/ */
public enum NodeType { public enum XmlNodeType {
DOCUMENT, //!< all the file main access
DECLARATION, //!< &lt;?xml ... ?&gt; DECLARATION, //!< &lt;?xml ... ?&gt;
ELEMENT, //!< the &lt;XXX&gt; ... &lt;/XXX&gt; ELEMENT, //!< the &lt;XXX&gt; ... &lt;/XXX&gt;
COMMENT, //!< comment node : &lt;!-- --&gt; COMMENT, //!< comment node : &lt;!-- --&gt;

View File

@ -0,0 +1,49 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Text node interface (internal data between two Marker: &lt;XXX&gt; ALL here &lt;/XXX&gt;
*/
public class XmlText extends XmlNode {
final static Logger LOGGER = LoggerFactory.getLogger(XmlText.class);
/**
* Constructor
*/
public XmlText() {}
/**
* Constructor
* @param data String data of the current Text
*/
public XmlText(final String data) {
super(data);
}
/**
* count the number of line in the current text
* @return The number of lines
*/
public int countLines() {
int count = 1;
for (int iii = 0; iii < this.value.length(); iii++) {
if (this.value.charAt(iii) == '\n') {
count++;
}
}
return count;
}
@Override
public XmlNodeType getType() {
return XmlNodeType.TEXT;
}
}

View File

@ -0,0 +1,651 @@
package org.atriasoft.exml.parser;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.etk.Tools;
import org.atriasoft.etk.util.FilePos;
import org.atriasoft.exml.builder.Builder;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.exception.ExmlParserError;
import org.atriasoft.exml.exception.ExmlParserErrorMulti;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ParseXml {
final static Logger LOGGER = LoggerFactory.getLogger(ParseXml.class);
// global builder that is generate the final Tree
private final Builder builder;
public ParseXml(final Builder builder) {
this.builder = builder;
}
protected boolean iParseAttribute(final Object parent, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty)
throws ExmlException, AknotException {
LOGGER.trace("start parse : 'attribute'");
// search end of the comment :
int lastElementName = pos.value;
for (int iii = pos.value; iii < data.length(); iii++) {
filePos.check(data.charAt(iii));
Tools.drawElementParsed(data.charAt(iii), filePos);
if (!Tools.checkAvaillable(data.charAt(iii), false)) {
break;
}
lastElementName = iii;
}
final String name = data.substring(pos.value, lastElementName + 1);
// TODO check if in the current list of attribute one is not currently set with this value...
String value = "";
// count white space :
final FilePos tmpPos = new FilePos();
int white = Tools.countWhiteChar(data, lastElementName + 1, tmpPos);
filePos.add(tmpPos);
if (lastElementName + white + 1 >= data.length()) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, lastElementName + white + 1), filePos, " parse an xml end with an attribute parsing..."));
return false;
}
if (data.charAt(lastElementName + white + 1) != '=') {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, lastElementName + white + 1), filePos, " error attribute parsing == > missing '=' ..."));
return false;
}
white += Tools.countWhiteChar(data, lastElementName + white + 2, tmpPos);
filePos.add(tmpPos);
if (lastElementName + white + 2 >= data.length()) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, lastElementName + white + 2), filePos, " parse an xml end with an attribute parsing..."));
return false;
}
boolean simpleQuoteCase = false;
if (data.charAt(lastElementName + white + 2) == '\'') { // '
simpleQuoteCase = true;
}
if (data.charAt(lastElementName + white + 2) != '"' && data.charAt(lastElementName + white + 2) != '\'') { // '
// parse with no element " == > direct value separate with space ...
filePos.increment();
int lastAttributePos = lastElementName + white + 2;
for (int iii = lastElementName + white + 2; iii < data.length(); iii++) {
Tools.drawElementParsed(data.charAt(iii), filePos);
if (filePos.check(data.charAt(iii))) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, iii), filePos, "unexpected '\\n' in an attribute parsing"));
return false;
}
if ((data.charAt(iii) == ' ') || (data.charAt(iii) == '/') || (data.charAt(iii) == '?') || (data.charAt(iii) == '>')) {
break;
}
lastAttributePos = iii + 1;
}
value = data.substring(lastElementName + white + 2, lastAttributePos);
//EXMLPARSEATTRIBUTE(pos << " attribute : " << name << "=\"" << value << "\"");
pos.value = lastAttributePos - 1;
try {
this.builder.newProperty(parent, name, value);
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
int lastAttributePos = lastElementName + white + 3;
for (int iii = lastElementName + white + 3; iii < data.length(); iii++) {
Tools.drawElementParsed(data.charAt(iii), filePos);
filePos.check(data.charAt(iii));
if (((data.charAt(iii) == '"') || simpleQuoteCase) && ((data.charAt(iii) == '\'') || !simpleQuoteCase)) {
break;
}
lastAttributePos = iii + 1;
}
value = data.substring(lastElementName + white + 3, lastAttributePos);
//EXMLPARSEATTRIBUTE(pos << " attribute : " << name << "=\"" << value << "\"");
pos.value = lastAttributePos;
this.builder.newProperty(parent, name, value);
return true;
}
protected boolean iParseCDATA(final Object parent, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty)
throws ExmlException, AknotException {
LOGGER.trace("start parse : 'text::CDATA'");
// search end of the comment :
for (int iii = pos.value; iii + 2 < data.length(); iii++) {
Tools.drawElementParsed(data.charAt(iii), filePos);
if (filePos.check(data.charAt(iii))) {
continue;
}
if (data.charAt(iii) == ']' && data.charAt(iii + 1) == ']' && data.charAt(iii + 2) == '>') {
// find end of value:
filePos.add(2);
final String valueCData = data.substring(pos.value, iii);
LOGGER.trace(" find text CDATA '" + valueCData + "'");
pos.value = iii + 2;
this.builder.newText(parent, valueCData);
return true;
}
}
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "text CDATA got end of file without finding end node"));
pos.value = data.length();
return false;
}
protected boolean iParseComment(final Object parent, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty)
throws ExmlException, AknotException {
LOGGER.trace("start parse : 'comment'");
final FilePos tmpPos = new FilePos();
final int white = Tools.countWhiteChar(data, pos.value, tmpPos);
filePos.add(tmpPos);
// search end of the comment :
for (int iii = pos.value + white; iii + 2 < data.length(); iii++) {
Tools.drawElementParsed(data.charAt(iii), filePos);
if (filePos.check(data.charAt(iii))) {
continue;
}
if (data.charAt(iii) == '-' && data.charAt(iii + 1) == '-' && data.charAt(iii + 2) == '>') {
filePos.add(2);
// search whitespace :
int newEnd = iii;
for (int jjj = iii - 1; jjj > pos.value; jjj--) {
if (!Tools.isWhiteChar(data.charAt(jjj))) {
break;
}
newEnd = jjj;
}
// find end of value:
final String value2 = data.substring(pos.value + white, newEnd);
LOGGER.trace(" find comment '" + value2 + "'");
this.builder.newComment(parent, value2);
pos.value = iii + 2;
return true;
}
}
pos.value = data.length();
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "comment got end of file without finding end node"));
return false;
}
protected boolean iParseDeclaration(final Object parent, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty)
throws ExmlException, AknotException {
// search end of the comment :
for (int iii = pos.value; iii + 1 < data.length(); iii++) {
Tools.drawElementParsed(data.charAt(iii), filePos);
if (filePos.check(data.charAt(iii))) {
continue;
}
if (data.charAt(iii) == '>' || data.charAt(iii) == '<') {
// an error occured :
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, " find '>' or '<' instead of '?>'"));
return false;
}
if (data.charAt(iii) == '?' && data.charAt(iii + 1) == '>') {
filePos.increment();
// find end of declaration:
pos.value = iii + 1;
return true;
}
if (Tools.checkAvaillable(data.charAt(iii), true)) {
// we find an attibute ==> parse it:
pos.value = iii;
if (!iParseAttribute(parent, data, pos, filePos, parsingProperty)) {
return false;
}
iii = pos.value;
continue;
}
}
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Text got end of file without finding end node"));
pos.value = data.length();
return false;
}
protected boolean iParseDOCTYPE(final Object parent, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty) throws ExmlException {
LOGGER.trace("start parse : 'DOCTYPE'");
final FilePos tmpPos = new FilePos();
final int white = Tools.countWhiteChar(data, pos.value, tmpPos);
filePos.add(tmpPos);
// search end of the comment :
for (int iii = pos.value + white; iii < data.length(); iii++) {
Tools.drawElementParsed(data.charAt(iii), filePos);
if (filePos.check(data.charAt(iii))) {
continue;
}
if (data.charAt(iii) == '>') {
pos.value = iii;
return true;
}
}
pos.value = data.length();
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "DOTYPE got end of file without finding end node"));
return false;
}
protected boolean iParseElement(final Object parent, final String nameElement, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty)
throws ExmlException, AknotException {
// note : When start parsing the upper element must have set the value of the element and set the position after this one
// find a normal node ...
for (int iii = pos.value; iii < data.length(); iii++) {
filePos.check(data.charAt(iii));
Tools.drawElementParsed(data.charAt(iii), filePos);
if (data.charAt(iii) == '>') {
// we find the end ...
pos.value = iii + 1;
return subParseElement(parent, nameElement, data, pos, filePos, parsingProperty);
}
if (data.charAt(iii) == '/') {
// standalone node or error...
if (iii + 1 >= data.length()) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Find end of files ... == > bad case"));
return false;
}
// TODO : Can have white spaces ....
if (data.charAt(iii + 1) == '>') {
pos.value = iii + 1;
// end of parsing element in auto end close &lt;/&gt;
this.builder.endElement(parent);
return true;
}
// error
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Find / without > char ..."));
return false;
}
if (Tools.checkAvaillable(data.charAt(iii), true)) {
// we find an attibute ==> parse it:
pos.value = iii;
if (!iParseAttribute(parent, data, pos, filePos, parsingProperty)) {
return false;
}
iii = pos.value;
continue;
}
if (!Tools.isWhiteChar(data.charAt(iii))) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, iii), filePos, "Find an unknow element : '" + data.charAt(iii) + "'"));
return false;
}
}
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos,
"Unexpecting end of parsing exml::internal::Element : '" + nameElement + "' == > check if the '/>' is set or the end of element"));
return false;
}
protected int iParseFindEndComment(final String data, final int position) {
for (int iii = position; iii + 2 < data.length(); iii++) {
LOGGER.trace("iParseFindEndComment : '{}{}{}'", data.charAt(iii), data.charAt(iii + 1), data.charAt(iii + 2));
if (data.charAt(iii) == '-' && data.charAt(iii + 1) == '-' && data.charAt(iii + 2) == '>') {
return iii + 2;
}
}
return data.length();
}
protected int iParseFindEndDeclaration(final String data, final int position) {
for (int iii = position; iii + 1 < data.length(); iii++) {
LOGGER.trace("iParseFindEndDeclaration : '{}{}'", data.charAt(iii), data.charAt(iii + 1));
if (data.charAt(iii) == '?' && data.charAt(iii + 1) == '>') {
return iii + 1;
}
}
return data.length();
}
protected int iParseFindEndNode(final String data, final int position) {
LOGGER.trace("iParseFindEndNode : {}", data.charAt(position));
if (position + 3 < data.length() && data.charAt(position) == '!' && data.charAt(position + 1) == '-' && data.charAt(position + 2) == '-') {
// fond comment
return iParseFindEndComment(data, position + 3);
}
if (position < data.length() && data.charAt(position) == '?') {
// simple declaration Node
return iParseFindEndDeclaration(data, position + 1);
}
int newPos = iParseFindEndSingleNode(data, position);
// check <..../>
if (data.charAt(newPos - 1) == '/') {
return newPos;
}
// normal Node
newPos = iParseFindTextPackEnd(data, newPos) + 1;
if (data.charAt(newPos) != '<' || data.charAt(newPos + 1) != '/') {
LOGGER.error("iParseFindEndNode : {}{} ==> wrong end node !!! ", data.charAt(newPos), data.charAt(newPos + 1));
}
newPos = iParseFindEndSingleNode(data, newPos + 1);
return newPos;
}
protected int iParseFindEndSingleNode(final String data, final int position) {
for (int iii = position; iii < data.length(); iii++) {
LOGGER.trace("iParseFindEndSingleNode : '{}'", data.charAt(iii));
if (data.charAt(iii) == '>') {
return iii;
}
}
return data.length();
}
protected int iParseFindTextPackEnd(final String data, final int position) {
for (int iii = position; iii < data.length(); iii++) {
LOGGER.trace("iParseFindTextPackEnd : {}", data.charAt(iii));
if (data.charAt(iii) == '<' && data.charAt(iii + 1) == '/') {
LOGGER.trace("iParseFindTextPackEnd ==> find end of text !!!");
return iii - 1;
}
if (data.charAt(iii) == '<') {
LOGGER.trace("iParseFindTextPackEnd ==> find new node !!!");
final int endNode = iParseFindEndNode(data, iii + 1);
iii = endNode;
continue;
}
}
return data.length();
}
protected boolean iParseText(final Object parent, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty) throws ExmlException, AknotException {
LOGGER.trace("start parse : 'text'");
if (this.builder.isPackText(parent)) {
final int endOfText = iParseFindTextPackEnd(data, pos.value);
final String valueText = data.substring(pos.value, endOfText + 1);
LOGGER.trace("find text '{}' ==> new Pos='{}'", valueText, data.charAt(endOfText + 1));
pos.value = endOfText;
this.builder.newText(parent, valueText);
return true;
} else {
// search end of the comment :
for (int iii = pos.value; iii < data.length(); iii++) {
Tools.drawElementParsed(data.charAt(iii), filePos);
if (filePos.check(data.charAt(iii))) {
continue;
}
if (data.charAt(iii) == '>' || data.charAt(iii) == '<') {
// search whitespace :
int newEnd = iii;
for (int jjj = iii - 1; jjj > pos.value; --jjj) {
if (!Tools.isWhiteChar(data.charAt(jjj))) {
break;
}
newEnd = jjj;
}
// find end of value:
String valueText = data.substring(pos.value, newEnd);
LOGGER.trace("find text '" + valueText + "'");
pos.value = iii - 1;
valueText = Tools.replaceSpecialChar(valueText);
this.builder.newText(parent, valueText);
return true;
}
}
}
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Text got end of file without finding end node"));
pos.value = data.length();
return false;
}
public Object parse(final String data, final ParsingProperty property) throws ExmlException, AknotException {
LOGGER.trace("Start parsing document (type: string) size=" + data.length());
// came from char == > force in utf8 ...
final FilePos pos = new FilePos(1, 0);
final PositionParsing parsePos = new PositionParsing();
final Object rootNode = this.builder.newRoot();
subParseElement(rootNode, null, data, parsePos, pos, property);
if (property.isErrorDetected()) {
if (property.isThrowOnError()) {
throw new ExmlParserErrorMulti("Parsing error multiple error detected", property.getErrors());
}
return null;
}
return rootNode;
}
/**
* Parse sub node string
* @param data all file string data
* @param pos Position to start parsing in the file and return the end of parsing
* @param caseSensitive Case sensitive parsing (usefull for html)
* @param filePos Current File position of the parsing
* @param doc Document base reference
* @param mainNode if true, this is the first root node
* @return true parsing is done OK
* @return false An error appear in the parsing
* @throws ExmlException
*/
protected boolean subParseElement(final Object parent, final String nameElement, final String data, final PositionParsing pos, final FilePos filePos, final ParsingProperty parsingProperty)
throws ExmlException, AknotException {
//EXMLPARSEELEMENT(" start subParse ... " << pos << " " << filePos);
for (int iii = pos.value; iii < data.length(); iii++) {
filePos.check(data.charAt(iii));
Tools.drawElementParsed(data.charAt(iii), filePos);
final FilePos tmpPos = new FilePos();
if (data.charAt(iii) == '<') {
final int white = Tools.countWhiteChar(data, iii + 1, tmpPos);
if (iii + white + 1 >= data.length()) {
filePos.add(tmpPos);
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "End file with '<' char == > invalide XML"));
pos.value = iii + white;
return false;
}
// Detect type of the element:
if (data.charAt(iii + white + 1) == '>') {
filePos.add(tmpPos);
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Find '>' with no element in the element..."));
pos.value = iii + white + 1;
return false;
}
if (data.charAt(iii + white + 1) == '?') {
tmpPos.increment();
// TODO : white space ...
if (!Tools.checkAvaillable(data.charAt(iii + white + 2), true)) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Find unavaillable name in the Declaration node..."));
pos.value = iii + white + 1;
return false;
}
//EXMLDEBUG("Generate node name : '" << data[iii+1] << "'");
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < data.length(); jjj++) {
if (!Tools.checkAvaillable(data.charAt(jjj), false)) {
break;
}
// we find the end ...
endPosName = jjj;
tmpPos.check(data.charAt(jjj));
}
final String tmpname = data.substring(iii + white + 2, endPosName + 1);
// Find declaration marker
final Object declaration = this.builder.newDeclaration(parent, tmpname);
filePos.add(tmpPos);
pos.value = endPosName + 1;
LOGGER.trace("start parse : 'declaration' : '" + tmpname + "'");
if (!iParseDeclaration(declaration, data, pos, filePos, parsingProperty)) {
return false;
}
iii = pos.value;
continue;
}
if (data.charAt(iii + white + 1) == '!') {
tmpPos.increment();
// Find special block element
if (iii + white + 2 >= data.length()) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "End file with '<!' chars == > invalide XML"));
return false;
}
if (data.charAt(iii + white + 2) == '-') {
tmpPos.increment();
if (iii + white + 3 >= data.length()) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "End file with '<!-' chars == > invalide XML"));
return false;
}
if (data.charAt(iii + white + 3) != '-') {
parsingProperty
.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Element parse with '<!-" + data.charAt(iii + 3) + "' chars == > invalide XML"));
return false;
}
tmpPos.increment();
// find comment:
pos.value = iii + white + 4;
filePos.add(tmpPos);
if (!iParseComment(parent, data, pos, filePos, parsingProperty)) {
return false;
}
iii = pos.value;
} else if (data.charAt(iii + white + 2) == '[') {
tmpPos.increment();
if (iii + white + 8 >= data.length()) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "End file with '<![' chars == > invalide XML"));
return false;
}
if (data.charAt(iii + white + 3) != 'C' || data.charAt(iii + white + 4) != 'D' || data.charAt(iii + white + 5) != 'A' || data.charAt(iii + white + 6) != 'T'
|| data.charAt(iii + white + 7) != 'A' || data.charAt(iii + white + 8) != '[') {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos,
"Element parse with '<![" + data.charAt(iii + white + 3) + data.charAt(iii + white + 4) + data.charAt(iii + white + 5) + data.charAt(iii + white + 6)
+ data.charAt(iii + white + 7) + data.charAt(iii + white + 8) + "' chars == > invalide XML"));
return false;
}
tmpPos.add(6);
// find text:
pos.value = iii + 9 + white;
filePos.add(tmpPos);
if (!iParseCDATA(parent, data, pos, filePos, parsingProperty)) {
return false;
}
iii = pos.value;
} else if (data.charAt(iii + white + 2) == 'D' && iii + white + 9 < data.length() && data.charAt(iii + white + 3) == 'O' && data.charAt(iii + white + 4) == 'C'
&& data.charAt(iii + white + 5) == 'T' && data.charAt(iii + white + 6) == 'Y' && data.charAt(iii + white + 7) == 'P' && data.charAt(iii + white + 8) == 'E') {
tmpPos.increment();
tmpPos.increment();
tmpPos.increment();
tmpPos.increment();
tmpPos.increment();
tmpPos.increment();
tmpPos.increment();
tmpPos.increment();
// find comment:
pos.value = iii + white + 4;
filePos.add(tmpPos);
if (!iParseDOCTYPE(parent, data, pos, filePos, parsingProperty)) {
return false;
}
iii = pos.value;
} else {
parsingProperty
.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "End file with '<!" + data.charAt(iii + white + 2) + "' chars == > invalide XML"));
return false;
}
continue;
}
if (data.charAt(iii + white + 1) == '/') {
tmpPos.increment();
LOGGER.debug("Detect END of Node name : '" + nameElement + "'");
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < data.length(); jjj++) {
if (!Tools.checkAvaillable(data.charAt(jjj), false)) {
break;
}
// we find the end ...
endPosName = jjj;
tmpPos.check(data.charAt(jjj));
}
final String tmpname = data.substring(iii + white + 2, endPosName + 1);
String tmpNameCheck = tmpname;
String nameElementCheck = nameElement;
if (parsingProperty.getCaseSensitive()) {
tmpNameCheck = tmpname.toLowerCase();
nameElementCheck = nameElement.toLowerCase();
}
if (!tmpNameCheck.contentEquals(nameElementCheck)) {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "End node error : '" + tmpname + "' != '" + nameElement + "'"));
return false;
}
// find end of node :
// find > element ...
for (int jjj = endPosName + 1; jjj < data.length(); jjj++) {
Tools.drawElementParsed(data.charAt(jjj), filePos);
if (tmpPos.check(data.charAt(jjj))) {
continue;
}
if (data.charAt(jjj) == '>') {
pos.value = jjj;
filePos.add(tmpPos);
this.builder.endElement(parent);
return true;
}
if (data.charAt(jjj) != '\r' && data.charAt(jjj) != ' ' && data.charAt(jjj) != '\t') {
filePos.add(tmpPos);
parsingProperty
.createError(new ExmlParserError(Tools.extractLine(data, jjj), filePos, "End node error : have data inside end node other than [ \\n\\t\\r] " + nameElement + "'"));
return false;
}
}
}
if (data.charAt(iii + white + 1) == '>') {
// end of something == > this is really bad
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Find '>' chars == > invalide XML"));
return false;
}
if (Tools.checkAvaillable(data.charAt(iii + white + 1), true)) {
tmpPos.increment();
LOGGER.debug("Generate node name : '" + data.charAt(iii + 1) + "...'");
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < data.length(); jjj++) {
if (!Tools.checkAvaillable(data.charAt(jjj), false)) {
break;
}
// we find the end ...
endPosName = jjj;
tmpPos.check(data.charAt(jjj));
}
final String tmpname = data.substring(iii + white + 1, endPosName + 1);
final String tmpnameOriginal = tmpname;
LOGGER.debug("find node named : '" + tmpname + "'");
// find text:
Object element = null;
//try {
element = this.builder.newElement(parent, tmpname);
//} catch (final Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
//}
pos.value = endPosName + 1;
filePos.add(tmpPos);
LOGGER.trace("start parse : 'element' named='" + tmpname + "'");
if (!iParseElement(element, tmpnameOriginal, data, pos, filePos, parsingProperty)) {
return false;
}
// TODO : Add the element in the parent ...
this.builder.newElementFinished(parent, tmpname, element);
iii = pos.value;
continue;
}
filePos.add(tmpPos);
// here we have an error :
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Find an ununderstanding element : '" + data.charAt(iii + white + 1) + "'"));
return false;
}
if (data.charAt(iii) == '>') {
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Find elemement '>' == > no reason to be here ..."));
return false;
}
// might to be data text ...
if (data.charAt(iii) == '\n' || data.charAt(iii) == ' ' || data.charAt(iii) == '\t' || data.charAt(iii) == '\r') {
// empty spaces == > nothing to do ....
} else {
// find data == > parse it...
pos.value = iii;
filePos.add(tmpPos);
if (!iParseText(parent, data, pos, filePos, parsingProperty)) {
return false;
}
iii = pos.value;
}
}
if (nameElement == null) {
return true;
}
parsingProperty.createError(new ExmlParserError(Tools.extractLine(data, pos.value), filePos, "Did not find end of the Element : '" + nameElement + "'"));
return false;
}
}

View File

@ -0,0 +1,159 @@
package org.atriasoft.exml.parser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.atriasoft.etk.Tools;
import org.atriasoft.exml.exception.ExmlParserError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ParsingProperty {
final static Logger LOGGER = LoggerFactory.getLogger(ParsingProperty.class);
/// check the case sensitive of the nodes (end marker) and attribute (duplicates)
private boolean caseSensitive = true;
// List of all error detected
private final List<ExmlParserError> errors = new ArrayList<>();
/// Permissive XML parsing (allows some errors must not be critical).
private boolean permisiveXML = false;
/// throw when an error when it is detected (if permissive XML it throw only at the end of parsing).
private boolean throwOnError = true;
/// write error when not throw on error.
private boolean writeError = false;
/**
* Constructor
*/
public ParsingProperty() {}
/**
* Constructor
* @param caseSensitive set the parsing of value is case sensitive.
* @param writeError Write all error when detected.
* @param throwOnError throw an error when parsing fail (if permissiveXml, it throw only at the end).
* @param permisiveXML Allow error and try to continue the parsing it is possible.
*/
public ParsingProperty(final boolean caseSensitive, final boolean writeError, final boolean throwOnError, final boolean permisiveXML) {
this.caseSensitive = caseSensitive;
this.writeError = writeError;
this.throwOnError = throwOnError;
this.permisiveXML = permisiveXML;
}
/**
* Add an error in the parsing of the XML (the function will select if we need to throw, print or ...)
* @param error the error to throw or keep.
* @return true if the parsing will stop
* @throws ExmlParserError the error injected if user request it.
*/
public boolean createError(final ExmlParserError error) throws ExmlParserError {
// need display the error
if (this.writeError) {
displayError(error);
}
// need throw the error
if (this.throwOnError && !this.permisiveXML) {
throw error;
}
// Keep it in case
this.errors.add(error);
return !this.permisiveXML;
}
/**
* Request Display in log all the errors.
*/
public void displayError() {
this.errors.forEach(this::displayError);
}
/**
* Request display in log of the error
* @param error The error to display.
*/
public void displayError(final ExmlParserError error) {
LOGGER.error(error.getFilePos() + " " + error.getMessage() + "\n" + error.getDataLine() + "\n" + Tools.createPosPointer(error.getDataLine(), error.getFilePos().getCol()));
}
/**
* get the status of case sensitive mode.
* @return true if case sensitive is active
*/
public boolean getCaseSensitive() {
return this.caseSensitive;
}
/**
* Get the display of the error status.
* @return true Display error
* @return false Does not display error (get it at end)
*/
public boolean getDisplayError() {
return this.writeError;
}
/**
* Get all error detected in the XML
* @return Immutable list of error (order by arrival)
*/
public List<ExmlParserError> getErrors() {
return Collections.unmodifiableList(this.errors);
}
/**
* Check is error has been detected
* @return true if some error are stored.
*/
public boolean isErrorDetected() {
return !this.errors.isEmpty();
}
/**
* Get the permissive value
* @return true if permissive mode is enable
*/
public boolean isPermisiveXML() {
return this.permisiveXML;
}
/**
* Check if throw on error
* @return true if it throw on error
*/
public boolean isThrowOnError() {
return this.throwOnError;
}
/**
* Enable or diasable the case sensitive (must be done before the call of parsing)
* @param val true if enable; false else.
*/
public void setCaseSensitive(final boolean val) {
this.caseSensitive = val;
}
/**
* Set the display of the error when detected.
* @param value true: display error, false not display error (get it at end)
*/
public void setDisplayError(final boolean value) {
this.writeError = value;
}
/**
* Set the permissive value.
* @param permisiveXML new value of permissive parsing.
*/
public void setPermisiveXML(final boolean permisiveXML) {
this.permisiveXML = permisiveXML;
}
/**
* Set throwing on error (if permissive, it throw at the end of parsing)
* @param throwOnError true if it throw on error.
*/
public void setThrowOnError(final boolean throwOnError) {
this.throwOnError = throwOnError;
}
}

View File

@ -1,6 +1,5 @@
package org.atriasoft.exml.internal; package org.atriasoft.exml.parser;
public class PositionParsing { public class PositionParsing {
public int value = 0; public int value = 0;
} }

View File

@ -1,12 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
open module org.atriasoft.exml {
exports org.atriasoft.exml;
requires transitive org.atriasoft.etk;
requires transitive io.scenarium.logger;
}

View File

@ -1,179 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/**
* @brief Single attribute element
*/
public class Attribute {
protected FilePos pos; //!< position in the read file (null if the file is not parsed);
protected String value; //!< value of the node (for element this is the name, for text it is the inside text ...);
protected String name; //!< Name of the attribute
public Attribute() {
this.pos = null;
this.value = "";
this.name = "";
}
public Attribute(final Attribute _obj) {
this.pos = null;
this.value = _obj.value;
this.name = _obj.name;
}
public Attribute(final String _name) {
this.name = _name;
this.value = "";
}
/**
* @brief Constructor
* @param[in] _name Name of the attribute.
* @param[in] _value Value of the attribute.
*/
public Attribute(final String _name, final String _value) {
this.name = _name;
this.value = _value;
}
public void clear() {
this.value = "";
}
@Override
public Attribute clone() {
return new Attribute(this);
}
/**
* @brief get the current name of the Attribute
* @return String of the attribute
*/
public String getName() {
return this.name;
};
/**
* @brief get the current element Value.
* @return the reference of the string value.
*/
public String getValue() {
return this.value;
};
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
_data.append(" ");
_data.append(this.name);
_data.append("=\"");
_data.append(this.value);
_data.append("\"");
return true;
};
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'attribute'");
this.pos = _filePos.clone();
// search end of the comment :
int lastElementName = _pos.value;
for (int iii = _pos.value; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (Tools.checkAvaillable(_data.charAt(iii), false) == true) {
lastElementName = iii;
} else {
break;
}
}
this.name = _data.substring(_pos.value, lastElementName + 1);
if (_caseSensitive == true) {
this.name = this.name.toLowerCase();
}
// count white space :
final FilePos tmpPos = new FilePos();
int white = Tools.countWhiteChar(_data, lastElementName + 1, tmpPos);
_filePos.add(tmpPos);
if (lastElementName + white + 1 >= _data.length()) {
_doc.createError(_data, lastElementName + white + 1, _filePos, " parse an xml end with an attribute parsing...");
return false;
}
if (_data.charAt(lastElementName + white + 1) != '=') {
_doc.createError(_data, lastElementName + white + 1, _filePos, " error attribute parsing == > missing '=' ...");
return false;
}
white += Tools.countWhiteChar(_data, lastElementName + white + 2, tmpPos);
_filePos.add(tmpPos);
if (lastElementName + white + 2 >= _data.length()) {
_doc.createError(_data, lastElementName + white + 2, _filePos, " parse an xml end with an attribute parsing...");
return false;
}
boolean simpleQuoteCase = false;
if (_data.charAt(lastElementName + white + 2) == '\'') { // '
simpleQuoteCase = true;
}
if (_data.charAt(lastElementName + white + 2) != '"' && _data.charAt(lastElementName + white + 2) != '\'') { // '
// parse with no element " == > direct value separate with space ...
_filePos.increment();
int lastAttributePos = lastElementName + white + 2;
for (int iii = lastElementName + white + 2; iii < _data.length(); iii++) {
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
_doc.createError(_data, iii, _filePos, "unexpected '\\n' in an attribute parsing");
return false;
}
if (_data.charAt(iii) != ' ' && _data.charAt(iii) != '/' && _data.charAt(iii) != '?' && _data.charAt(iii) != '>') {
lastAttributePos = iii + 1;
} else {
break;
}
}
this.value = _data.substring(lastElementName + white + 2, lastAttributePos);
//EXML_PARSE_ATTRIBUTE(pos << " attribute : " << name << "=\"" << value << "\"");
_pos.value = lastAttributePos - 1;
return true;
}
int lastAttributePos = lastElementName + white + 3;
for (int iii = lastElementName + white + 3; iii < _data.length(); iii++) {
Tools.drawElementParsed(_data.charAt(iii), _filePos);
_filePos.check(_data.charAt(iii));
if ((_data.charAt(iii) != '"' && simpleQuoteCase == false) || (_data.charAt(iii) != '\'' && simpleQuoteCase == true)) { // '
lastAttributePos = iii + 1;
} else {
break;
}
}
this.value = _data.substring(lastElementName + white + 3, lastAttributePos);
//EXML_PARSE_ATTRIBUTE(pos << " attribute : " << name << "=\"" << value << "\"");
_pos.value = lastAttributePos;
return true;
}
/**
* @brief set the name of the attribute
* @param[in] _name New name of the attribute
*/
public void setName(final String _name) {
this.name = _name;
}
/**
* @brief set the value of the node.
* @param[in] _value New value of the node.
*/
public final void setValue(final String _value) {
this.value = _value;
}
};

View File

@ -1,184 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.atriasoft.etk.util.Pair;
import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist;
import org.atriasoft.exml.internal.Log;
/**
* @brief List of all attribute element in a node
*/
public abstract class AttributeList extends Node {
protected List<Attribute> listAttribute = new ArrayList<>(); //!< list of all attribute;
public AttributeList() {
super();
};
/**
* @brief Constructor
* @param[in] _value Node value;
*/
public AttributeList(final String _value) {
super(_value);
}
/**
* @brief add attribute on the List
* @param[in] _attr Pointer on the attribute
*/
public void appendAttribute(final Attribute _attr) {
if (_attr == null) {
Log.error("Try to set an empty node");
return;
}
for (int iii = 0; iii < this.listAttribute.size(); iii++) {
if (this.listAttribute.get(iii) == _attr) {
Log.error("Try to add a node that is already added before !!!");
return;
}
if (this.listAttribute.get(iii).getName().contentEquals(_attr.getName()) == true) {
Log.error("Try to add a node that is already added before (same name)");
return;
}
}
this.listAttribute.add(_attr);
}
@Override
public void clear() {
super.clear();
this.listAttribute.clear();
};
/**
* @brief check if an attribute exist or not with his name.
* @param[in] _name Attribute Name.
* @return true if the attribute exist or False
*/
public boolean existAttribute(final String _name) {
if (_name.length() == 0) {
return false;
}
for (int iii = 0; iii < this.listAttribute.size(); ++iii) {
if (this.listAttribute.get(iii) != null && this.listAttribute.get(iii).getName().contentEquals(_name) == true) {
return true;
}
}
return false;
}
/**
* @brief get attribute whith his ID
* @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute()
* @return Pointer on the attribute or NULL
* @throws ExmlAttributeDoesNotExist The attribute does not exist.
*/
public Attribute getAttr(final int _id) throws ExmlAttributeDoesNotExist {
if (_id < 0 || _id >= this.listAttribute.size()) {
throw new ExmlAttributeDoesNotExist("Attribute does not exist: " + _id + "/" + this.listAttribute.size());
}
return this.listAttribute.get(_id);
}
/**
* @brief get the attribute value with searching in the List with his name
* @param[in] _name Attribute Name.
* @return Value of the attribute or no data in the string
* @throws ExmlAttributeDoesNotExist The attribute does not exist.
*/
public String getAttribute(final String _name) throws ExmlAttributeDoesNotExist {
if (_name.length() == 0) {
throw new ExmlAttributeDoesNotExist("Attribute can not have empty name");
}
for (int iii = 0; iii < this.listAttribute.size(); iii++) {
if (this.listAttribute.get(iii) != null && this.listAttribute.get(iii).getName().contentEquals(_name) == true) {
return this.listAttribute.get(iii).getValue();
}
}
throw new ExmlAttributeDoesNotExist("Attribute does not exist: " + _name + " in " + this.listAttribute.size() + " attributes");
}
public List<Attribute> getAttributes() {
return this.listAttribute;
}
/**
* @brief get attribute whith his ID
* @param[in] _id Identifier of the attribute 0<= _id < sizeAttribute()
* @return Name and value of the attribute
* @throws ExmlAttributeDoesNotExist The attribute does not exist.
*/
public Pair<String, String> getAttrPair(final int _id) throws ExmlAttributeDoesNotExist {
final Attribute att = getAttr(_id);
return new Pair<String, String>(att.getName(), att.getValue());
}
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
for (int iii = 0; iii < this.listAttribute.size(); iii++) {
if (this.listAttribute.get(iii) != null) {
this.listAttribute.get(iii).iGenerate(_data, _indent);
}
}
return true;
}
/**
* @brief Remove an attribute form the list
* @param[in] _name Name of the attribute
* @return true The attribute has been removed
* @return false An error occured.
*/
public boolean removeAttribute(final String _name) {
if (_name.length() == 0) {
return false;
}
for (final ListIterator<Attribute> iter = this.listAttribute.listIterator(); iter.hasNext();) {
final Attribute element = iter.next();
if (element == null) {
iter.remove();
continue;
}
if (element.getName().contentEquals(_name) == true) {
iter.remove();
return true;
}
}
return false;
}
/**
* @brief Set A new attribute or replace data of the previous one
* @param[in] _name Name of the attribute
* @param[in] _value Value of the attribute
*/
public void setAttribute(final String _name, final String _value) {
// check if attribute already det :
for (int iii = 0; iii < this.listAttribute.size(); ++iii) {
if (this.listAttribute.get(iii) != null && this.listAttribute.get(iii).getName().contentEquals(_name) == true) {
// update the value :
this.listAttribute.get(iii).setValue(_value);
return;
}
}
final Attribute attr = new Attribute(_name, _value);
this.listAttribute.add(attr);
}
/**
* @brief get the number of attribute in the Node
* @return Nulber of attribute >=0
*/
public int sizeAttribute() {
return this.listAttribute.size();
}
}

View File

@ -1,87 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/**
* @brief Comment node: lt;!-- ... --gt;
*/
public class Comment extends Node {
public Comment() {
super();
}
public Comment(final Comment obj) {
super(obj.value);
}
/**
* @brief Constructor
* @param[in] _value comment value
*/
public Comment(final String _value) {
super(_value);
}
@Override
public Comment clone() {
return new Comment(this);
}
@Override
public NodeType getType() {
return NodeType.COMMENT;
}
@Override
public boolean iGenerate(final StringBuilder _data, final int _indent) {
Tools.addIndent(_data, _indent);
_data.append("<!--");
_data.append(this.value);
_data.append("-->\n");
return true;
}
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'comment'");
this.pos = _filePos;
final FilePos tmpPos = new FilePos();
final int white = Tools.countWhiteChar(_data, _pos.value, tmpPos);
_filePos.add(tmpPos);
// search end of the comment :
for (int iii = _pos.value + white; iii + 2 < _data.length(); iii++) {
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}
if (_data.charAt(iii) == '-' && _data.charAt(iii + 1) == '-' && _data.charAt(iii + 2) == '>') {
_filePos.add(2);
// search whitespace :
int newEnd = iii;
for (int jjj = iii - 1; jjj > _pos.value; jjj--) {
if (Tools.isWhiteChar(_data.charAt(jjj)) == true) {
newEnd = jjj;
} else {
break;
}
}
// find end of value:
this.value = _data.substring(_pos.value + white, newEnd);
Log.verbose(" find comment '" + this.value + "'");
_pos.value = iii + 2;
return true;
}
}
_pos.value = _data.length();
_doc.createError(_data, _pos.value, _filePos, "comment got end of file without finding end node");
return false;
}
};

View File

@ -1,93 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/**
* @brief Declaration node: lt;?XXXXXX ... gt;
*/
public class Declaration extends AttributeList {
public Declaration() {
super("");
};
public Declaration(final Declaration obj) {
super(obj.value);
for (final Attribute elem : obj.listAttribute) {
this.listAttribute.add(elem.clone());
}
};
/**
* @brief Constructor
* @param[in] _name name of the declaration (xml, xml:xxxx ...)
*/
public Declaration(final String _name) {
super(_name);
}
@Override
public Declaration clone() {
return new Declaration(this);
}
@Override
public NodeType getType() {
return NodeType.DECLARATION;
};
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
Tools.addIndent(_data, _indent);
_data.append("<?");
_data.append(this.value);
super.iGenerate(_data, _indent);
_data.append("?>\n");
return true;
}
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'declaration' : '" + this.value + "'");
this.pos = _filePos;
// search end of the comment :
for (int iii = _pos.value; iii + 1 < _data.length(); iii++) {
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}
if (_data.charAt(iii) == '>' || _data.charAt(iii) == '<') {
// an error occured :
_doc.createError(_data, _pos.value, _filePos, " find '>' or '<' instead of '?>'");
return false;
}
if (_data.charAt(iii) == '?' && _data.charAt(iii + 1) == '>') {
_filePos.increment();
// find end of declaration:
_pos.value = iii + 1;
return true;
}
if (Tools.checkAvaillable(_data.charAt(iii), true) == true) {
// we find an attibute == > create an element and parse it:
final Attribute attribute = new Attribute();
_pos.value = iii;
if (attribute.iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
return false;
}
iii = _pos.value;
this.listAttribute.add(attribute);
continue;
}
}
_doc.createError(_data, _pos.value, _filePos, "Text got end of file without finding end node");
_pos.value = _data.length();
return false;
}
}

View File

@ -1,41 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
public class DeclarationXML extends Declaration {
public DeclarationXML(final DeclarationXML obj) {
super(obj.value);
for (final Attribute elem : obj.listAttribute) {
this.listAttribute.add(elem.clone());
}
}
public DeclarationXML(final String _version, final String _format, final boolean _standalone) {
super("xml");
if (_version.isEmpty() != true) {
setAttribute("version", _version);
}
if (_format.contentEquals("UTF-8")) {
setAttribute("encoding", "UTF-8");
} else {
Log.error("Actually does not supported other charset than UTF8");
setAttribute("encoding", "UTF-8");
}
if (_standalone == true) {
setAttribute("standalone", "true");
} else {
setAttribute("standalone", "true");
}
}
@Override
public DeclarationXML clone() {
return new DeclarationXML(this);
}
}

View File

@ -1,243 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* @brief Basic document element of a document
*/
public class Document extends Element {
private boolean caseSensitive; //!< check the case sensitive of the nodes and attribute
private boolean writeErrorWhenDetexted; //!< Request print error in parsing just when detected
private String comment; //!< Comment on the error;
private String Line; //!< Parse line error (copy);
private FilePos filePos; //!< position of the error
/**
* @brief Constructor
*/
public Document() {
this.caseSensitive = false;
this.writeErrorWhenDetexted = true;
this.comment = "";
this.Line = "";
this.filePos = new FilePos(0, 0);
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
/**
* @brief Create an error in the parsing (call by the syetm for error management)
* @param[in] _data string of chat is wrong
* @param[in] _pos Position in the file
* @param[in] _filePos human position of the error
* @param[in] _comment Error string to display
*/
public void createError(final String _data, final int _pos, final FilePos _filePos, final String _comment) {
this.comment = _comment;
this.Line = extract_line(_data, _pos);
this.filePos = _filePos;
if (this.writeErrorWhenDetexted == true) {
displayError();
}
}
/**
* @brief Display the Document on console
*/
public void display() {
final StringBuilder tmpp = new StringBuilder();
iGenerate(tmpp, 0);
Log.info("Generated XML : \n" + tmpp.toString());
}
/**
* @brief Request display in log of the error
*/
public void displayError() {
if (this.comment.length() == 0) {
Log.error("No error detected ???");
return;
}
Log.error(this.filePos + " " + this.comment + "\n" + this.Line + "\n" + Tools.createPosPointer(this.Line, this.filePos.getCol()));
//Log.critical("detect error");
}
String extract_line(final String data, final int _pos) {
// search back : '\n'
int startPos = data.lastIndexOf('\n', _pos);
if (startPos == _pos) {
startPos = 0;
} else {
startPos++;
}
// search forward : '\n'
int stopPos = _pos;
if (data.length() == _pos) {
stopPos = _pos;
} else if (data.charAt(_pos) != '\n') {
stopPos = data.indexOf('\n', _pos);
if (stopPos == _pos) {
stopPos = data.length();
}
}
if (startPos == -1) {
startPos = 0;
} else if (startPos >= data.length()) {
return "";
}
if (stopPos == -1) {
return "";
} else if (stopPos >= data.length()) {
stopPos = data.length();
}
return data.substring(startPos, stopPos);
}
/**
* @brief generate a string that contain the created XML
* @param[out] _data Data where the xml is stored
* @return false : An error occured
* @return true : Parsing is OK
*/
public boolean generate(final StringBuilder _data) {
return iGenerate(_data, 0);
}
/**
* @brief Load the file that might contain the xml
* @param[in] _uri URI of the xml
* @return false : An error occured
* @return true : Parsing is OK
*/
/*
public boolean load( Uri _uri){
// Start loading the XML :
EXML_VERBOSE("open file (xml) " + _uri);
clear();
auto fileIo = uri::get(_uri);
if (fileIo == null) {
Log.error("File Does not exist : " + _uri);
return false;
}
if (fileIo->open(io::OpenMode::Read) == false) {
Log.error("Can not open (r) the file : " + _uri);
return false;
}
// load data from the file:
String tmpDataUnicode = fileIo->readAllString();
// close the file:
fileIo->close();
// parse the data:
boolean ret = parse(tmpDataUnicode);
//Display();
return ret;
}
*/
/**
* @brief Store the Xml in the file
* @param[in] _uri URI of the xml
* @return false : An error occured
* @return true : Parsing is OK
*/
/*
public boolean store( Uri _uri){
String createData;
if (generate(createData) == false) {
Log.error("Error while creating the XML: " + _uri);
return false;
}
auto fileIo = uri::get(_uri);
if (fileIo == null) {
Log.error("Can not create the uri: " + _uri);
return false;
}
if (fileIo->open(io::OpenMode::Write) == false) {
Log.error("Can not open (r) the file : " + _uri);
return false;
}
fileIo->writeAll(createData);
fileIo->close();
return true;
}
*/
/**
* @brief get the status of case sensitive mode.
* @return true if case sensitive is active
*/
public boolean getCaseSensitive() {
return this.caseSensitive;
}
/**
* @brief Get the display of the error status.
* @return true Display error
* @return false Does not display error (get it at end)
*/
public boolean getDisplayError() {
return this.writeErrorWhenDetexted;
}
@Override
public NodeType getType() {
return NodeType.DOCUMENT;
}
@Override
public boolean iGenerate(final StringBuilder _data, final int _indent) {
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null) {
this.listSub.get(iii).iGenerate(_data, _indent);
}
}
return true;
}
/**
* @brief parse a string that contain an XML
* @param[in] _data Data to parse
* @return false : An error occured
* @return true : Parsing is OK
*/
public boolean parse(final String _data) {
Log.verbose("Start parsing document (type: string) size=" + _data.length());
clear();
// came from char == > force in utf8 ...
this.pos = new FilePos(1, 0);
final PositionParsing parsePos = new PositionParsing();
return subParse(_data, parsePos, this.caseSensitive, this.pos, this, true);
}
/**
* @brief Enable or diasable the case sensitive (must be done before the call of parsing)
* @param[in] _val true if enable; false else.
*/
// TODO: Naming error, it is insensitive ...
public void setCaseSensitive(final boolean _val) {
this.caseSensitive = _val;
}
/**
* @brief Set the display of the error when detected.
* @param[in] _value true: display error, false not display error (get it at end)
*/
public void setDisplayError(final boolean _value) {
this.writeErrorWhenDetexted = _value;
}
}

View File

@ -1,536 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* @brief Basic element Node of an XML document lt;YYYYYgt;
*/
public class Element extends AttributeList {
protected List<Node> listSub = new ArrayList<>(); //!< List of subNodes;
/**
* @brief Constructor
*/
public Element() {
super();
};
public Element(final Element obj) throws CloneNotSupportedException {
super(obj.value);
for (final Attribute elem : obj.listAttribute) {
this.listAttribute.add(elem.clone());
}
for (final Node elem : obj.listSub) {
this.listSub.add(elem.clone());
}
}
/**
* @brief Constructor
* @param[in] _value Element name;
*/
public Element(final String _value) {
super(_value);
};
/**
* @brief add a node at the element (not Attribute (move in the attribute automaticly).
* @param[in] _node Pointer of the node to add.
*/
public void append(final Node _node) {
if (_node == null) {
Log.error("Try to set an empty node");
return;
}
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) == _node) {
Log.error("Try to add a node that is already added before !!!");
return;
}
}
this.listSub.add(_node);
}
@Override
public void clear() {
super.clear();
this.listSub.clear();
};
@Override
public Element clone() throws CloneNotSupportedException {
return new Element(this);
}
/**
* @brief get the Node pointer of the element id.
* @param[in] _id Id of the element.
* @return true if the Node exist.
*/
public boolean existNode(final int _id) {
if (_id < 0 || _id >= this.listSub.size()) {
return false;
}
return true;
}
/**
* @brief get an element with his name (work only with Element)
* @param[in] _name Name of the element that is requested
* @return true if the Node exist.
*/
public boolean existNode(final String _name) {
if (_name.isEmpty() == true) {
return false;
}
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null && this.listSub.get(iii).getValue().contentEquals(_name) == true) {
if (this.listSub.get(iii) == null) {
return false;
}
return true;
}
}
return false;
}
/**
* @brief get the Node pointer of the element id.
* @param[in] _id Id of the element.
* @return Pointer on node.
* @throws ExmlNodeDoesNotExist The Node does not exist
*/
public Node getNode(final int _id) throws ExmlNodeDoesNotExist {
if (_id < 0 || _id >= this.listSub.size()) {
throw new ExmlNodeDoesNotExist("Node does not exist: " + _id + "/" + this.listSub.size());
}
return this.listSub.get(_id);
}
/**
* @brief get an element with his name (work only with Element)
* @param[in] _name Name of the element that is requested
* @return Pointer on the node.
* @throws ExmlNodeDoesNotExist The Node does not exist
*/
public Node getNode(final String _name) throws ExmlNodeDoesNotExist {
if (_name.isEmpty() == true) {
throw new ExmlNodeDoesNotExist("Node can not have empty name in " + this.listAttribute.size() + " nodes");
}
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null && this.listSub.get(iii).getValue().contentEquals(_name) == true) {
return this.listSub.get(iii);
}
}
throw new ExmlNodeDoesNotExist("Node does not exist: '" + _name + "' in " + this.listAttribute.size());
}
/**
* @brief Get the list of the sub-nodes.
* @return List of current nodes.
*/
public List<Node> getNodes() {
return this.listSub;
}
/**
* @brief get the internal data of the element (if the element has some sub node they are converted in xml string == > like this it is not needed to use <![CDATA[...]]>
* @return the curent data string. if Only one text node, then we get the parssed data (no amp; ...) if more than one node, then we transform ,",',<,> in xml normal text...
*/
public String getText() {
final StringBuilder res = new StringBuilder();
if (this.listSub.size() == 1) {
if (this.listSub.get(0).getType() == NodeType.TEXT) {
res.append(this.listSub.get(0).getValue());
} else {
this.listSub.get(0).iGenerate(res, 0);
}
} else {
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null) {
this.listSub.get(iii).iGenerate(res, 0);
}
}
}
return res.toString();
}
@Override
public NodeType getType() {
return NodeType.ELEMENT;
}
/**
* @brief get the type of the element id.
* @param[in] _id Id of the element.
* @return the Current type of the element or typeUnknow.
* @throws ExmlNodeDoesNotExist The Node does not exist
*/
public NodeType getType(final int _id) throws ExmlNodeDoesNotExist {
if (_id < 0 || _id >= this.listSub.size()) {
throw new ExmlNodeDoesNotExist("Node does not exist: " + _id + "/" + this.listSub.size());
}
return this.listSub.get(_id).getType();
}
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
Tools.addIndent(_data, _indent);
_data.append("<");
_data.append(this.value);
super.iGenerate(_data, _indent);
if (this.listSub.size() > 0) {
if (this.listSub.size() == 1 && this.listSub.get(0) != null && this.listSub.get(0).getType() == NodeType.TEXT && ((Text) this.listSub.get(0)).countLines() == 1) {
_data.append(">");
this.listSub.get(0).iGenerate(_data, 0);
Log.verbose(" generate : '" + _data + "'");
} else {
_data.append(">\n");
for (int iii = 0; iii < this.listSub.size(); iii++) {
if (this.listSub.get(iii) != null) {
this.listSub.get(iii).iGenerate(_data, _indent + 1);
}
}
Tools.addIndent(_data, _indent);
}
_data.append("</");
_data.append(this.value);
_data.append(">\n");
} else {
_data.append("/>\n");
}
return true;
}
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
//EXML_PARSE_ELEMENT("start parse : 'element' named='" + value + "'");
// note : When start parsing the upper element must have set the value of the element and set the position after this one
this.pos = _filePos.clone();
// find a normal node ...
for (int iii = _pos.value; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_data.charAt(iii) == '>') {
// we find the end ...
_pos.value = iii + 1;
return subParse(_data, _pos, _caseSensitive, _filePos, _doc, false);
}
if (_data.charAt(iii) == '/') {
// standalone node or error...
if (iii + 1 >= _data.length()) {
_doc.createError(_data, _pos.value, _filePos, "Find end of files ... == > bad case");
return false;
}
// TODO : Can have white spaces ....
if (_data.charAt(iii + 1) == '>') {
_pos.value = iii + 1;
return true;
}
// error
_doc.createError(_data, _pos.value, _filePos, "Find / without > char ...");
return false;
}
if (Tools.checkAvaillable(_data.charAt(iii), true) == true) {
// we find an attibute == > create an element and parse it:
final Attribute attribute = new Attribute();
_pos.value = iii;
if (attribute.iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
return false;
}
iii = _pos.value;
this.listAttribute.add(attribute);
continue;
}
if (Tools.isWhiteChar(_data.charAt(iii)) == false) {
_doc.createError(_data, iii, _filePos, "Find an unknow element : '" + _data.charAt(iii) + "'");
return false;
}
}
_doc.createError(_data, _pos.value, _filePos, "Unexpecting end of parsing exml::internal::Element : '" + this.value + "' == > check if the '/>' is set or the end of element");
return false;
}
/**
* @brief Remove all element with this name
* @param[in] _nodeName Name of nodes to remove.
*/
public void remove(final String _nodeName) {
if (_nodeName == "") {
return;
}
for (final ListIterator<Node> iter = this.listSub.listIterator(); iter.hasNext();) {
final Node element = iter.next();
if (element == null) {
iter.remove();
continue;
}
if (element.getValue().contentEquals(_nodeName) == true) {
iter.remove();
}
}
}
/**
* @brief get the number of sub element in the node (can be Comment ; Element ; Text :Declaration).
* @return a number >=0.
*/
public int size() {
return this.listSub.size();
}
/**
* @brief Parse sub node string
* @param[in] _data all file string data
* @param[in,out] _pos Position to start parsing in the file and return the end of parsing
* @param[in] _caseSensitive Case sensitive parsing (usefull for html)
* @param[in] _filePos Current File position of the parsing
* @param[in] _doc Document base reference
* @param[in] _mainNode if true, this is the first root node
* @return true parsing is done OK
* @return false An error appear in the parsing
*/
protected boolean subParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
return subParse(_data, _pos, _caseSensitive, _filePos, _doc, false);
}
protected boolean subParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc, final boolean _mainNode) {
//EXML_PARSE_ELEMENT(" start subParse ... " << _pos << " " << _filePos);
for (int iii = _pos.value; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
Tools.drawElementParsed(_data.charAt(iii), _filePos);
final FilePos tmpPos = new FilePos();
if (_data.charAt(iii) == '<') {
final int white = Tools.countWhiteChar(_data, iii + 1, tmpPos);
if (iii + white + 1 >= _data.length()) {
_filePos.add(tmpPos);
_doc.createError(_data, _pos.value, _filePos, "End file with '<' char == > invalide XML");
_pos.value = iii + white;
return false;
}
// Detect type of the element:
if (_data.charAt(iii + white + 1) == '>') {
_filePos.add(tmpPos);
_doc.createError(_data, _pos.value, _filePos, "Find '>' with no element in the element...");
_pos.value = iii + white + 1;
return false;
}
if (_data.charAt(iii + white + 1) == '?') {
tmpPos.increment();
// TODO : white space ...
if (Tools.checkAvaillable(_data.charAt(iii + white + 2), true) == false) {
_doc.createError(_data, _pos.value, _filePos, "Find unavaillable name in the Declaration node...");
_pos.value = iii + white + 1;
return false;
}
//EXML_DEBUG("Generate node name : '" << _data[iii+1] << "'");
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < _data.length(); jjj++) {
if (Tools.checkAvaillable(_data.charAt(jjj), false) == true) {
// we find the end ...
endPosName = jjj;
} else {
break;
}
tmpPos.check(_data.charAt(jjj));
}
String tmpname = _data.substring(iii + white + 2, endPosName + 1);
if (_caseSensitive == true) {
tmpname = tmpname.toLowerCase();
}
// Find declaration marker
final Declaration declaration = new Declaration(tmpname);
_filePos.add(tmpPos);
_pos.value = endPosName + 1;
if (declaration.iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
return false;
}
iii = _pos.value;
this.listSub.add(declaration);
continue;
}
if (_data.charAt(iii + white + 1) == '!') {
tmpPos.increment();
// Find special block element
if (iii + white + 2 >= _data.length()) {
_doc.createError(_data, _pos.value, _filePos, "End file with '<!' chars == > invalide XML");
return false;
}
if (_data.charAt(iii + white + 2) == '-') {
tmpPos.increment();
if (iii + white + 3 >= _data.length()) {
_doc.createError(_data, _pos.value, _filePos, "End file with '<!-' chars == > invalide XML");
return false;
}
if (_data.charAt(iii + white + 3) != '-') {
_doc.createError(_data, _pos.value, _filePos, "Element parse with '<!-" + _data.charAt(iii + 3) + "' chars == > invalide XML");
return false;
}
tmpPos.increment();
// find comment:
final Comment comment = new Comment();
_pos.value = iii + white + 4;
_filePos.add(tmpPos);
if (comment.iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
return false;
}
iii = _pos.value;
this.listSub.add(comment);
} else if (_data.charAt(iii + white + 2) == '[') {
tmpPos.increment();
if (iii + white + 8 >= _data.length()) {
_doc.createError(_data, _pos.value, _filePos, "End file with '<![' chars == > invalide XML");
return false;
}
if (_data.charAt(iii + white + 3) != 'C' || _data.charAt(iii + white + 4) != 'D' || _data.charAt(iii + white + 5) != 'A' || _data.charAt(iii + white + 6) != 'T'
|| _data.charAt(iii + white + 7) != 'A' || _data.charAt(iii + white + 8) != '[') {
_doc.createError(_data, _pos.value, _filePos, "Element parse with '<![" + _data.charAt(iii + white + 3) + _data.charAt(iii + white + 4) + _data.charAt(iii + white + 5)
+ _data.charAt(iii + white + 6) + _data.charAt(iii + white + 7) + _data.charAt(iii + white + 8) + "' chars == > invalide XML");
return false;
}
tmpPos.add(6);
// find text:
final TextCDATA text = new TextCDATA();
_pos.value = iii + 9 + white;
_filePos.add(tmpPos);
if (text.iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
return false;
}
iii = _pos.value;
this.listSub.add(text);
} else {
_doc.createError(_data, _pos.value, _filePos, "End file with '<!" + _data.charAt(iii + white + 2) + "' chars == > invalide XML");
return false;
}
continue;
}
if (_data.charAt(iii + white + 1) == '/') {
tmpPos.increment();
//EXML_DEBUG("Generate node name : '" << _data[iii+1] << "'");
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < _data.length(); jjj++) {
if (Tools.checkAvaillable(_data.charAt(jjj), false) == true) {
// we find the end ...
endPosName = jjj;
} else {
break;
}
tmpPos.check(_data.charAt(jjj));
}
String tmpname = _data.substring(iii + white + 2, endPosName + 1);
if (_caseSensitive == true) {
tmpname = tmpname.toLowerCase();
}
if (tmpname.contentEquals(this.value) == true) {
// find end of node :
// find > element ...
for (int jjj = endPosName + 1; jjj < _data.length(); jjj++) {
Tools.drawElementParsed(_data.charAt(jjj), _filePos);
if (tmpPos.check(_data.charAt(jjj)) == true) {
continue;
}
if (_data.charAt(jjj) == '>') {
_pos.value = jjj;
_filePos.add(tmpPos);
return true;
} else if (_data.charAt(jjj) != '\r' && _data.charAt(jjj) != ' ' && _data.charAt(jjj) != '\t') {
_filePos.add(tmpPos);
_doc.createError(_data, jjj, _filePos, "End node error : have data inside end node other than [ \\n\\t\\r] " + this.value + "'");
return false;
}
}
} else {
_doc.createError(_data, _pos.value, _filePos, "End node error : '" + tmpname + "' != '" + this.value + "'");
return false;
}
}
if (_data.charAt(iii + white + 1) == '>') {
// end of something == > this is really bad
_doc.createError(_data, _pos.value, _filePos, "Find '>' chars == > invalide XML");
return false;
}
if (Tools.checkAvaillable(_data.charAt(iii + white + 1), true) == true) {
tmpPos.increment();
Log.debug("Generate node name : '" + _data.charAt(iii + 1) + "'");
int endPosName = iii + white + 1;
// generate element name ...
for (int jjj = iii + white + 2; jjj < _data.length(); jjj++) {
if (Tools.checkAvaillable(_data.charAt(jjj), false) == true) {
// we find the end ...
endPosName = jjj;
} else {
break;
}
tmpPos.check(_data.charAt(jjj));
}
String tmpname = _data.substring(iii + white + 1, endPosName + 1);
if (_caseSensitive == true) {
tmpname = tmpname.toLowerCase();
}
Log.debug("find node named : '" + tmpname + "'");
// find text:
final Element element = new Element(tmpname);
_pos.value = endPosName + 1;
_filePos.add(tmpPos);
if (element.iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
return false;
}
iii = _pos.value;
this.listSub.add(element);
continue;
}
_filePos.add(tmpPos);
// here we have an error :
_doc.createError(_data, _pos.value, _filePos, "Find an ununderstanding element : '" + _data.charAt(iii + white + 1) + "'");
return false;
} else {
if (_data.charAt(iii) == '>') {
_doc.createError(_data, _pos.value, _filePos, "Find elemement '>' == > no reason to be here ...");
return false;
}
// might to be data text ...
if (_data.charAt(iii) == '\n' || _data.charAt(iii) == ' ' || _data.charAt(iii) == '\t' || _data.charAt(iii) == '\r') {
// empty spaces == > nothing to do ....
} else {
// find data == > parse it...
final Text text = new Text();
_pos.value = iii;
_filePos.add(tmpPos);
if (text.iParse(_data, _pos, _caseSensitive, _filePos, _doc) == false) {
return false;
}
iii = _pos.value;
this.listSub.add(text);
}
}
}
if (_mainNode == true) {
return true;
}
_doc.createError(_data, _pos.value, _filePos, "Did not find end of the exml::internal::Element : '" + this.value + "'");
return false;
}
};

View File

@ -1,185 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
/**
* @brief Position in the file of the original data.
*/
public class FilePos {
private int col; //!< source text colomn
private int line; //!< source Line colomn
/**
* @brief default contructor (set line and col at 0)
*/
public FilePos() {
this.col = 0;
this.line = 0;
}
/**
* @brief initialize constructor
* @param[in] _line Line in the file
* @param[in] _col Colomn in the file
*/
public FilePos(final int _line, final int _col) {
this.col = _col;
this.line = _line;
}
/**
* @brief Addition operator
* @param[in] _obj Addition object..
* @return Reference on this
*/
public FilePos add(final FilePos _obj) {
if (_obj.line == 0) {
this.col += _obj.col;
} else {
this.col = _obj.col;
this.line += _obj.line;
}
return this;
}
/**
* @brief Colomn addition operator
* @param[in] _col Number of colomn to add
* @return Reference on this
*/
public FilePos add(final int _col) {
this.col += _col;
return this;
}
/**
* @brief Check if the value is a new line and update internal property
* @param[in] _val Char value to check
* @return true We find a new line
* @return false We NOT find a new line
*/
public boolean check(final Character _val) {
this.col++;
if (_val == '\n') {
newLine();
return true;
}
return false;
}
/**
* @brief Reset position at 0,0
*/
public void clear() {
this.col = 0;
this.line = 0;
}
@Override
public FilePos clone() {
final FilePos out = new FilePos();
out.col = this.col;
out.line = this.line;
return out;
}
/**
* @brief Decrement the colomn position
* @return Reference on this
*/
public FilePos decrement() {
this.col--;
return this;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof FilePos)) {
return false;
}
final FilePos other = (FilePos) obj;
return this.col == other.col && this.line == other.line;
}
/**
* @brief Get the colomn position
* @return Colomn in number of utf8-char
*/
public int getCol() {
return this.col;
}
/**
* @brief Get the line number position
* @return line ID (start at 0)
*/
public int getLine() {
return this.line;
}
@Override
public int hashCode() {
return super.hashCode() + this.line + this.col;
}
/**
* @brief Increment the colomn position
* @return Reference on this
*/
public FilePos increment() {
this.col++;
return this;
}
/**
* @brief Find a new line & reset colomn at 0
*/
public void newLine() {
this.col = 0;
this.line++;
}
/**
* @brief Asignment operator
* @param[in] _obj Object to copy
* @return Reference on this
*/
public FilePos set(final FilePos _obj) {
this.col = _obj.col;
this.line = _obj.line;
return this;
}
/**
* @brief Setter of specific data
* @param[in] _line Line in the file
* @param[in] _col Colomn in the file
*/
public void set(final int _line, final int _col) {
this.col = _col;
this.line = _line;
}
@Override
public String toString() {
String out = "(l=";
out += this.line;
out += ",c=";
out += this.col;
out += ")";
return out;
}
};

View File

@ -1,177 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.PositionParsing;
/**
* @brief Basic main object of all xml elements.
*/
public abstract class Node {
protected FilePos pos; //!< position in the read file (null if the file is not parsed)
protected String value; //!< value of the node (for element this is the name, for text it is the inside text ...);
/**
* @brief basic element of a xml structure
*/
public Node() {
this.pos = null;
}
/**
* @brief basic element of a xml structure
* @param[in] _value value of the node
*/
public Node(final String _value) {
this.pos = null;
this.value = _value;
}
/**
* @brief clear the Node
*/
public void clear() {
this.value = "";
this.pos = null;
}
@Override
protected Node clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("Can not clone an abstract class ...");
}
/**
* @brief get the current position where the element is in the file
* @return The file position reference
*/
public FilePos getPos() {
return this.pos;
}
/**
* @brief get the node type.
* @return the type of the Node.
*/
public abstract NodeType getType();
/**
* @brief get the current element Value.
* @return the reference of the string value.
*/
public String getValue() {
return this.value;
}
/**
* @brief generate a string with the tree of the xml
* @param[in,out] _data string where to add the elements
* @param[in] _indent current indentation of the file
* @return false if an error occured.
*/
protected abstract boolean iGenerate(final StringBuilder _data, final int _indent);
/**
* @brief parse the Current node [pure VIRUAL]
* @param[in] _data data string to parse.
* @param[in,out] _pos position in the string to start parse, return the position end of parsing.
* @param[in] _caseSensitive Request a parsion of element that is not case sensitive (all element is in low case)
* @param[in,out] _filePos file parsing position (line x col x)
* @param[in,out] _doc Base document reference
* @return false if an error occured.
*/
protected abstract boolean iParse(String _data, PositionParsing _pos, boolean _caseSensitive, FilePos _filePos, Document _doc);
/**
* @brief check if the node is a Comment
* @return true if the node is a Comment
*/
public final boolean isComment() {
return this instanceof Comment;
}
/**
* @brief check if the node is a Declaration
* @return true if the node is a Declaration
*/
public final boolean isDeclaration() {
return this instanceof Declaration;
}
/**
* @brief check if the node is a Document
* @return true if the node is a Document
*/
public final boolean isDocument() {
return this instanceof Document;
}
/**
* @brief check if the node is a Element
* @return true if the node is a Element
*/
public final boolean isElement() {
return this instanceof Element;
}
/**
* @brief check if the node is a Text
* @return true if the node is a Text
*/
public final boolean isText() {
return this instanceof Text;
}
/**
* @brief set the value of the node.
* @param[in] _value New value of the node.
*/
public final void setValue(final String _value) {
this.value = _value;
}
/**
* @brief Cast the element in a Comment if it is possible.
* @return pointer on the class or null.
*/
public final Comment toComment() {
return (Comment) this;
}
/**
* @brief Cast the element in a Declaration if it is possible.
* @return pointer on the class or null.
*/
public final Declaration toDeclaration() {
return (Declaration) this;
}
/**
* @brief Cast the element in a Document if it is possible.
* @return pointer on the class or null.
*/
public final Document toDocument() {
return (Document) this;
}
/**
* @brief Cast the element in a Element if it is possible.
* @return pointer on the class or null.
*/
public final Element toElement() {
return (Element) this;
}
/**
* @brief Cast the element in a Text if it is possible.
* @return pointer on the class or null.
*/
public final Text toText() {
return (Text) this;
}
}

View File

@ -1,116 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
/**
* @brief Text node interface (internal data between two Marker: &lt;XXX&gt; ALL here &lt;/XXX&gt;
*/
public class Text extends Node {
// transform the Text with :
// "&lt;" == "<"
// "&gt;" == ">"
// "&amp;" == "&"
// "&apos;" == "'"
// "&quot;" == """
private static String replaceSpecialChar(final String _inval) {
final String out = _inval;
out.replace("&lt;", "<");
out.replace("&gt;", ">");
out.replace("&apos;", "'");
out.replace("&quot;", "\"");
out.replace("&amp;", "&");
//EXML_ERROR("INNN '"<< _inval << "' => '" << out << "'");
return out;
}
private static String replaceSpecialCharOut(final String _inval) {
final String out = _inval;
out.replace("<", "&lt;");
out.replace(">", "&gt;");
out.replace("'", "&apos;");
out.replace("\"", "&quot;");
out.replace("&", "&amp;");
//EXML_ERROR("OUTTT '"<< _inval << "' => '" << out << "'");
return out;
}
/**
* @brief Constructor
*/
public Text() {};
/**
* @brief Constructor
* @param[in] _data String data of the current Text
*/
public Text(final String _data) {
super(_data);
}
/**
* @brief count the number of line in the current text
* @return The number of lines
*/
protected int countLines() {
int count = 1;
for (int iii = 0; iii < this.value.length(); iii++) {
if (this.value.charAt(iii) == '\n') {
count++;
}
}
return count;
}
@Override
public NodeType getType() {
return NodeType.TEXT;
};
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
_data.append(replaceSpecialCharOut(this.value));
return true;
}
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'text'");
this.pos = _filePos.clone();
// search end of the comment :
for (int iii = _pos.value; iii < _data.length(); iii++) {
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}
if (_data.charAt(iii) == '>' || _data.charAt(iii) == '<') {
// search whitespace :
int newEnd = iii;
for (int jjj = iii - 1; jjj > _pos.value; --jjj) {
if (Tools.isWhiteChar(_data.charAt(jjj)) == true) {
newEnd = jjj;
} else {
break;
}
}
// find end of value:
this.value = _data.substring(_pos.value, newEnd);
Log.verbose(" find text '" + this.value + "'");
_pos.value = iii - 1;
this.value = replaceSpecialChar(this.value);
return true;
}
}
_doc.createError(_data, _pos.value, _filePos, "Text got end of file without finding end node");
_pos.value = _data.length();
return false;
}
};

View File

@ -1,52 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml;
import org.atriasoft.exml.internal.Log;
import org.atriasoft.exml.internal.PositionParsing;
import org.atriasoft.exml.internal.Tools;
public class TextCDATA extends Text {
public TextCDATA() {
super();
}
public TextCDATA(final String data) {
super(data);
}
@Override
protected boolean iGenerate(final StringBuilder _data, final int _indent) {
_data.append("<![CDATA[");
_data.append(this.value);
_data.append("]]>");
return true;
}
@Override
protected boolean iParse(final String _data, final PositionParsing _pos, final boolean _caseSensitive, final FilePos _filePos, final Document _doc) {
Log.verbose("start parse : 'text::CDATA'");
this.pos = _filePos.clone();
// search end of the comment :
for (int iii = _pos.value; iii + 2 < _data.length(); iii++) {
Tools.drawElementParsed(_data.charAt(iii), _filePos);
if (_filePos.check(_data.charAt(iii)) == true) {
continue;
}
if (_data.charAt(iii) == ']' && _data.charAt(iii + 1) == ']' && _data.charAt(iii + 2) == '>') {
// find end of value:
_filePos.add(2);
this.value = _data.substring(_pos.value, iii);
Log.verbose(" find text CDATA '" + this.value + "'");
_pos.value = iii + 2;
return true;
}
}
_doc.createError(_data, _pos.value, _filePos, "text CDATA got end of file without finding end node");
_pos.value = _data.length();
return false;
}
}

View File

@ -1,73 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.exml.internal;
import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
public class Log {
private static final String LIB_NAME = "exml";
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
public static void critical(final String data) {
if (PRINT_CRITICAL) {
Logger.critical(LIB_NAME_DRAW, data);
}
}
public static void debug(final String data) {
if (PRINT_DEBUG) {
Logger.debug(LIB_NAME_DRAW, data);
}
}
public static void error(final String data) {
if (PRINT_ERROR) {
Logger.error(LIB_NAME_DRAW, data);
}
}
public static void info(final String data) {
if (PRINT_INFO) {
Logger.info(LIB_NAME_DRAW, data);
}
}
public static void print(final String data) {
if (PRINT_PRINT) {
Logger.print(LIB_NAME_DRAW, data);
}
}
public static void todo(final String data) {
if (PRINT_TODO) {
Logger.todo(LIB_NAME_DRAW, data);
}
}
public static void verbose(final String data) {
if (PRINT_VERBOSE) {
Logger.verbose(LIB_NAME_DRAW, data);
}
}
public static void warning(final String data) {
if (PRINT_WARNING) {
Logger.warning(LIB_NAME_DRAW, data);
}
}
private Log() {}
}

View File

@ -1,101 +0,0 @@
package org.atriasoft.exml.internal;
import org.atriasoft.exml.FilePos;
public class Tools {
/**
* @brief add indentation of the string input.
* @param[in,out] _data String where the indentation is done.
* @param[in] _indent Number of tab to add at the string.
*/
public static void addIndent(final StringBuilder _data, final int _indent) {
for (int iii = 0; iii < _indent; iii++) {
_data.append("\t");
}
}
/**
* @brief check if an element or attribute is availlable (not : !"#$%&'()*+,/;<=>?@[\]^`{|}~ \\n\\t\\r and for first char : not -.0123456789).
* @param[in] _val Value to check the conformity.
* @param[in] _firstChar True if the element check is the first char.
* @return true The value can be a part of attribute name
* @return false The value can NOT be a part of attribute name
*/
public static boolean checkAvaillable(final Character _val, final boolean _firstChar) {
if (_val == '!' || _val == '"' || _val == '#' || _val == '$' || _val == '%' || _val == '&' || _val == '\'' // '
|| _val == '(' || _val == ')' || _val == '*' || _val == '+' || _val == ',' || _val == '/' || _val == ';' || _val == '<' || _val == '=' || _val == '>' || _val == '?' || _val == '@'
|| _val == '[' || _val == '\\' || _val == ']' || _val == '^' || _val == '`' || _val == '{' || _val == '|' || _val == '}' || _val == '~' || _val == ' ' || _val == '\n' || _val == '\t'
|| _val == '\r') {
return false;
}
if (_firstChar == true) {
if (_val == '-' || _val == '.' || (_val >= '0' && _val <= '9')) {
return false;
}
}
return true;
}
/**
* @brief count the number of white char in the string from the specify position (stop at the first element that is not a white char)
* @param[in] _data Data to parse.
* @param[in] _pos Start position in the string.
* @param[out] _filePos new poistion of te file to add.
* @return number of white element.
*/
public static int countWhiteChar(final String _data, final int _pos, final FilePos _filePos) {
_filePos.clear();
int white = 0;
for (int iii = _pos; iii < _data.length(); iii++) {
_filePos.check(_data.charAt(iii));
if (Tools.isWhiteChar(_data.charAt(iii)) == true) {
white++;
} else {
break;
}
}
_filePos.decrement();
return white;
}
public static String createPosPointer(final String _line, final int _pos) {
String out = "";
int iii;
for (iii = 0; iii < _pos && iii < _line.length(); iii++) {
if (_line.charAt(iii) == '\t') {
out += "\t";
} else {
out += " ";
}
}
for (; iii < _pos; iii++) {
out += " ";
}
out += "^";
return out;
}
/**
* @brief Display the cuurent element that is curently parse.
* @param[in] _val Char that is parsed.
* @param[in] _filePos Position of the char in the file.
*/
public static void drawElementParsed(final Character _val, final FilePos _filePos) {
if (_val == '\n') {
Log.debug(_filePos + " parse '\\n'");
} else if (_val == '\t') {
Log.debug(_filePos + " parse '\\t'");
} else {
Log.debug(_filePos + " parse '" + _val + "'");
}
}
public static boolean isWhiteChar(final Character _val) {
if (_val == ' ' || _val == '\t' || _val == '\n' || _val == '\r') {
return true;
}
return false;
}
private Tools() {}
}

View File

@ -0,0 +1,55 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.generic;
import org.atriasoft.aknot.exception.AknotException;
import org.atriasoft.exml.Exml;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.model.XmlNode;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class ExmlLocal {
final static Logger LOGGER = LoggerFactory.getLogger(ExmlLocal.class);
// errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
public static void test(final String ref, final String input, final int errorPos) {
ExmlLocal.test(ref, input, errorPos, false);
}
public static void test(final String ref, final String input, final int errorPos, final boolean caseInSensitive) {
//doc.setCaseSensitive(!caseInSensitive);
LOGGER.trace("parse : \n" + input);
XmlNode root = null;
try {
root = Exml.parse(input);
if (errorPos == 1) {
Assertions.fail("Must have detected an error");
}
} catch (final AknotException e) {
if (errorPos == 1) {
return;
}
Assertions.fail("Must have NOT detected an AknotException error");
} catch (final ExmlException e) {
if (errorPos == 1) {
return;
}
Assertions.fail("Must have NOT detected an ExmlException error");
}
final StringBuilder out = new StringBuilder();
// TODO 2 is for failing in generate ...
Exml.generate(root, out);
final String data = out.toString();
if (errorPos == 3) {
Assertions.assertNotEquals(ref, data);
}
Assertions.assertEquals(ref, data);
}
private ExmlLocal() {}
}

View File

@ -3,15 +3,19 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package test.atriasoft.exml; package test.atriasoft.exml.generic;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlTestAll {
public class TestExmlAll {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlAll.class);
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
Log.verbose("----------------------------------------------------------------"); LOGGER.trace("----------------------------------------------------------------");
} }
@Test @Test
@ -21,14 +25,14 @@ public class ExmlTestAll {
+ " <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n" + " <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n"
+ " <exlkjl-_dsfg./>\n" + " <exlkjl-_dsfg./>\n"
+ " <ex2>Text example ...</ex2>\n" + " <ex2>Text example ...</ex2>\n"
+ "</exemple>\n", + "</exemple>",
"< exemple\n >\n" "< exemple\n >\n"
+ " <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n" + " <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"
+ " <exlkjl-_dsfg./>\n" + " <exlkjl-_dsfg./>\n"
+ " <ex2>\n" + " <ex2>\n"
+ " Text example ...\n" + " Text example ...\n"
+ " </ex2>\n" + " </ex2>\n"
+ "</exemple>\n", + "</exemple>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -40,14 +44,14 @@ public class ExmlTestAll {
+" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n" +" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=\"456321\"/>\n"
+" <exlkjl-_dsfg./>\n" +" <exlkjl-_dsfg./>\n"
+" <ex2>Text example ...</ex2>\n" +" <ex2>Text example ...</ex2>\n"
+"</exemple>\n", +"</exemple>",
"< exemple\n >\n" "< exemple\n >\n"
+" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n" +" <ex2 ploppp-plpl:erer=\"dfsdfsdfsdf\" lkmjmlk=\"156235\" sdfsdf=456321 />\n"
+" <exlkjl-_dsfg./>\n" +" <exlkjl-_dsfg./>\n"
+" <ex2>\n" +" <ex2>\n"
+" Text example ...\n" +" Text example ...\n"
+" </ex2>\n" +" </ex2>\n"
+"</exemple>\n", +"</exemple>",
-1, -1,
false); false);
//@formatter:on //@formatter:on
@ -63,7 +67,7 @@ public class ExmlTestAll {
+" <ex2>\n" +" <ex2>\n"
+" Text example ...\n" +" Text example ...\n"
+" </ex2>\n" +" </ex2>\n"
+"</exemple>\n", +"</exemple>",
1); 1);
//@formatter:on //@formatter:on
} }

View File

@ -3,56 +3,57 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package test.atriasoft.exml; package test.atriasoft.exml.generic;
import org.atriasoft.exml.Attribute; import org.atriasoft.exml.Exml;
import org.atriasoft.exml.Document;
import org.atriasoft.exml.Element;
import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist; import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist; import org.atriasoft.exml.model.XmlAttribute;
import org.atriasoft.exml.model.XmlElement;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlTestAttribute {
public class TestExmlAttribute {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlAttribute.class);
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
Log.verbose("----------------------------------------------------------------"); LOGGER.trace("----------------------------------------------------------------");
} }
@Test @Test
public void AttributeElementNotExist() { public void attributeElementNotExist() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> myElement.getAttr(65465465)); Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> myElement.getAttr(65465465));
} }
@Test @Test
public void clear() { public void clear() {
final XmlAttribute myAttribute = new XmlAttribute("nameAttribute", "valueAttribute");
final Attribute myAttribute = new Attribute("nameAttribute", "valueAttribute");
myAttribute.clear(); myAttribute.clear();
} }
@Test @Test
public void createAssignement() { public void createAssignement() {
final Attribute myAttribute = new Attribute("nameAttribute", "valueAttribute"); final XmlAttribute myAttribute = new XmlAttribute("nameAttribute", "valueAttribute");
final Attribute myOtherAttribute = myAttribute.clone(); final XmlAttribute myOtherAttribute = myAttribute.clone();
Assertions.assertEquals(myAttribute.getValue(), myOtherAttribute.getValue()); Assertions.assertEquals(myAttribute.getValue(), myOtherAttribute.getValue());
Assertions.assertEquals(myAttribute.getName(), myOtherAttribute.getName()); Assertions.assertEquals(myAttribute.getName(), myOtherAttribute.getName());
} }
@Test @Test
public void createCopy() { public void createCopy() {
final Attribute myAttribute = new Attribute("nameAttribute", "valueAttribute"); final XmlAttribute myAttribute = new XmlAttribute("nameAttribute", "valueAttribute");
final Attribute myOtherAttribute = new Attribute(myAttribute); final XmlAttribute myOtherAttribute = new XmlAttribute(myAttribute);
Assertions.assertEquals(myAttribute.getValue(), myOtherAttribute.getValue()); Assertions.assertEquals(myAttribute.getValue(), myOtherAttribute.getValue());
Assertions.assertEquals(myAttribute.getName(), myOtherAttribute.getName()); Assertions.assertEquals(myAttribute.getName(), myOtherAttribute.getName());
} }
@Test @Test
public void exist() { public void exist() {
final XmlElement elem = new XmlElement("elem");
final Element elem = new Element("elem");
elem.setAttribute("valA", "plop"); elem.setAttribute("valA", "plop");
Assertions.assertEquals(elem.existAttribute("valA"), true); Assertions.assertEquals(elem.existAttribute("valA"), true);
Assertions.assertEquals(elem.existAttribute("qsdfsdf"), false); Assertions.assertEquals(elem.existAttribute("qsdfsdf"), false);
@ -60,44 +61,30 @@ public class ExmlTestAttribute {
@Test @Test
public void get() { public void get() {
final XmlElement elem = new XmlElement("elem");
final Element elem = new Element("elem");
elem.setAttribute("valA", "plop"); elem.setAttribute("valA", "plop");
try { final String attributeValue = Assertions.assertDoesNotThrow(() -> elem.getAttribute("valA"));
Assertions.assertEquals(elem.getAttribute("valA"), "plop"); Assertions.assertEquals(attributeValue, "plop");
} catch (final ExmlAttributeDoesNotExist e) {
Assertions.fail("Should Not have thrown an exception");
}
Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> elem.getAttribute("qsdfsdf")); Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> elem.getAttribute("qsdfsdf"));
} }
@Test @Test
public void getpair() { public void getpair() {
final XmlElement elem = new XmlElement("elem");
final Element elem = new Element("elem");
elem.setAttribute("valA", "coucou"); elem.setAttribute("valA", "coucou");
try { final String first = Assertions.assertDoesNotThrow(() -> elem.getAttrPair(0).first);
Assertions.assertEquals(elem.getAttrPair(0).first, "valA"); Assertions.assertEquals(first, "valA");
Assertions.assertEquals(elem.getAttrPair(0).second, "coucou"); final String second = Assertions.assertDoesNotThrow(() -> elem.getAttrPair(0).second);
} catch (final ExmlAttributeDoesNotExist e) { Assertions.assertEquals(second, "coucou");
Assertions.fail("Should Not have thrown an exception");
}
Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> elem.getAttrPair(1)); Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> elem.getAttrPair(1));
Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> elem.getAttrPair(-1)); Assertions.assertThrows(ExmlAttributeDoesNotExist.class, () -> elem.getAttrPair(-1));
} }
@Test @Test
public void moveInAllElement() { public void moveInAllElement() {
final Document doc = new Document(); final XmlElement root = Assertions.assertDoesNotThrow(() -> Exml.parse("<elem valA=\"plop\"/>"));
doc.parse("<elem valA=\"plop\"/>"); final XmlElement elem = Assertions.assertDoesNotThrow(() -> (XmlElement) root.getNode("elem"));
Element elem; for (final XmlAttribute it : elem.getAttributes()) {
try {
elem = (Element) doc.getNode("elem");
} catch (final ExmlNodeDoesNotExist e) {
Assertions.fail("Should Not have thrown an exception");
return;
}
for (final Attribute it : elem.getAttributes()) {
Assertions.assertEquals(it.getName(), "valA"); Assertions.assertEquals(it.getName(), "valA");
Assertions.assertEquals(it.getValue(), "plop"); Assertions.assertEquals(it.getValue(), "plop");
} }
@ -105,7 +92,7 @@ public class ExmlTestAttribute {
@Test @Test
public void remove() { public void remove() {
final Element elem = new Element("elem"); final XmlElement elem = new XmlElement("elem");
elem.setAttribute("valA", "plop"); elem.setAttribute("valA", "plop");
Assertions.assertEquals(elem.existAttribute("valA"), true); Assertions.assertEquals(elem.existAttribute("valA"), true);
elem.removeAttribute("valA"); elem.removeAttribute("valA");
@ -114,8 +101,7 @@ public class ExmlTestAttribute {
@Test @Test
public void setGetName() { public void setGetName() {
final XmlAttribute myAttribute = new XmlAttribute("nameAttribute", "valueAttribute");
final Attribute myAttribute = new Attribute("nameAttribute", "valueAttribute");
Assertions.assertEquals(myAttribute.getName(), "nameAttribute"); Assertions.assertEquals(myAttribute.getName(), "nameAttribute");
myAttribute.setName("newName"); myAttribute.setName("newName");
Assertions.assertEquals(myAttribute.getName(), "newName"); Assertions.assertEquals(myAttribute.getName(), "newName");
@ -123,8 +109,7 @@ public class ExmlTestAttribute {
@Test @Test
public void setGetValue() { public void setGetValue() {
final XmlAttribute myAttribute = new XmlAttribute("nameAttribute", "valueAttribute");
final Attribute myAttribute = new Attribute("nameAttribute", "valueAttribute");
Assertions.assertEquals(myAttribute.getValue(), "valueAttribute"); Assertions.assertEquals(myAttribute.getValue(), "valueAttribute");
myAttribute.setValue("new value"); myAttribute.setValue("new value");
Assertions.assertEquals(myAttribute.getValue(), "new value"); Assertions.assertEquals(myAttribute.getValue(), "new value");
@ -132,31 +117,20 @@ public class ExmlTestAttribute {
@Test @Test
public void setterNew() { public void setterNew() {
final XmlElement elem = new XmlElement("elem");
final Element elem = new Element("elem");
elem.setAttribute("valA", "coucou"); elem.setAttribute("valA", "coucou");
try { final String attributeValue = Assertions.assertDoesNotThrow(() -> elem.getAttribute("valA"));
Assertions.assertEquals(elem.getAttribute("valA"), "coucou"); Assertions.assertEquals(attributeValue, "coucou");
} catch (final ExmlAttributeDoesNotExist e) {
Assertions.fail("Should Not have thrown an exception");
}
} }
@Test @Test
public void setterRewrite() { public void setterRewrite() {
final XmlElement elem = new XmlElement("elem");
final Element elem = new Element("elem");
elem.setAttribute("valA", "coucou"); elem.setAttribute("valA", "coucou");
try { String attributeValue = Assertions.assertDoesNotThrow(() -> elem.getAttribute("valA"));
Assertions.assertEquals(elem.getAttribute("valA"), "coucou"); Assertions.assertEquals(attributeValue, "coucou");
} catch (final ExmlAttributeDoesNotExist e) {
Assertions.fail("Should Not have thrown an exception");
}
elem.setAttribute("valA", "coucou2"); elem.setAttribute("valA", "coucou2");
try { attributeValue = Assertions.assertDoesNotThrow(() -> elem.getAttribute("valA"));
Assertions.assertEquals(elem.getAttribute("valA"), "coucou2"); Assertions.assertEquals(attributeValue, "coucou2");
} catch (final ExmlAttributeDoesNotExist e) {
Assertions.fail("Should Not have thrown an exception");
}
} }
} }

View File

@ -0,0 +1,30 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.generic;
import org.atriasoft.exml.Exml;
import org.atriasoft.exml.model.XmlElement;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlCData {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlCData.class);
@BeforeAll
public static void beforeClass() {
LOGGER.trace("----------------------------------------------------------------");
}
@Test
public void parseCDATA() {
final XmlElement root = Assertions.assertDoesNotThrow(() -> Exml.parse("<elem><![CDATA[Text &é<>examp]le]] ...]]></elem>"));
final XmlElement elem = Assertions.assertDoesNotThrow(() -> (XmlElement) root.getNode("elem"));
Assertions.assertEquals("Text &é<>examp]le]] ...", elem.getText());
}
}

View File

@ -0,0 +1,53 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.generic;
import org.atriasoft.exml.model.XmlComment;
import org.atriasoft.exml.model.XmlNode;
import org.atriasoft.exml.model.XmlNodeType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlComment {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlComment.class);
@BeforeAll
public static void beforeClass() {
LOGGER.trace("----------------------------------------------------------------");
}
@Test
public void create() {
final XmlComment myComment = new XmlComment("my Comment");
Assertions.assertEquals(myComment.getType(), XmlNodeType.COMMENT);
}
@Test
public void createAssignement() {
final XmlComment myComment = new XmlComment("my comment");
final XmlComment myOtherComment = myComment.clone();
Assertions.assertEquals(myComment.getValue(), myOtherComment.getValue());
}
@Test
public void createCopy() {
final XmlComment myComment = new XmlComment("my Comment");
final XmlComment myOtherComment = new XmlComment(myComment);
Assertions.assertEquals(myComment.getValue(), myOtherComment.getValue());
}
@Test
public void transform() {
XmlComment myComment = new XmlComment("my comment");
final XmlNode myNode = myComment;
myComment = myNode.toComment();
Assertions.assertEquals(myComment.getValue(), "my comment");
}
}

View File

@ -3,25 +3,30 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package test.atriasoft.exml; package test.atriasoft.exml.generic;
import org.atriasoft.exml.DeclarationXML;
import org.atriasoft.exml.NodeType;
import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist; import org.atriasoft.exml.exception.ExmlAttributeDoesNotExist;
import org.atriasoft.exml.model.XmlDeclaration;
import org.atriasoft.exml.model.XmlNodeType;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlTestDeclarationXML {
public class TestExmlDeclarationXML {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlDeclarationXML.class);
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
Log.verbose("----------------------------------------------------------------"); LOGGER.trace("----------------------------------------------------------------");
} }
@Test @Test
public void create() { public void create() {
final DeclarationXML myDeclarationXML = new DeclarationXML("1.0", "UTF-8", true); final XmlDeclaration myDeclarationXML = new XmlDeclaration("1.0", "UTF-8", true);
Assertions.assertEquals(myDeclarationXML.getType(), NodeType.DECLARATION); Assertions.assertEquals(myDeclarationXML.getType(), XmlNodeType.DECLARATION);
try { try {
Assertions.assertEquals(myDeclarationXML.getAttribute("version"), "1.0"); Assertions.assertEquals(myDeclarationXML.getAttribute("version"), "1.0");
Assertions.assertEquals(myDeclarationXML.getAttribute("encoding"), "UTF-8"); Assertions.assertEquals(myDeclarationXML.getAttribute("encoding"), "UTF-8");
@ -34,8 +39,8 @@ public class ExmlTestDeclarationXML {
@Test @Test
public void createAssignement() { public void createAssignement() {
final DeclarationXML myDeclarationXML = new DeclarationXML("1.0", "UTF-8", true); final XmlDeclaration myDeclarationXML = new XmlDeclaration("1.0", "UTF-8", true);
final DeclarationXML myOtherDeclarationXML = myDeclarationXML.clone(); final XmlDeclaration myOtherDeclarationXML = myDeclarationXML.clone();
Assertions.assertEquals(myDeclarationXML.getValue(), myOtherDeclarationXML.getValue()); Assertions.assertEquals(myDeclarationXML.getValue(), myOtherDeclarationXML.getValue());
try { try {
Assertions.assertEquals(myDeclarationXML.getAttribute("version"), myOtherDeclarationXML.getAttribute("version")); Assertions.assertEquals(myDeclarationXML.getAttribute("version"), myOtherDeclarationXML.getAttribute("version"));
@ -48,8 +53,8 @@ public class ExmlTestDeclarationXML {
@Test @Test
public void createCopy() { public void createCopy() {
final DeclarationXML myDeclarationXML = new DeclarationXML("1.0", "UTF-8", true); final XmlDeclaration myDeclarationXML = new XmlDeclaration("1.0", "UTF-8", true);
final DeclarationXML myOtherDeclarationXML = new DeclarationXML(myDeclarationXML); final XmlDeclaration myOtherDeclarationXML = new XmlDeclaration(myDeclarationXML);
Assertions.assertEquals(myDeclarationXML.getValue(), myOtherDeclarationXML.getValue()); Assertions.assertEquals(myDeclarationXML.getValue(), myOtherDeclarationXML.getValue());
try { try {
Assertions.assertEquals(myDeclarationXML.getAttribute("version"), myOtherDeclarationXML.getAttribute("version")); Assertions.assertEquals(myDeclarationXML.getAttribute("version"), myOtherDeclarationXML.getAttribute("version"));

View File

@ -3,28 +3,33 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package test.atriasoft.exml; package test.atriasoft.exml.generic;
import org.atriasoft.exml.Document; import org.atriasoft.exml.Exml;
import org.atriasoft.exml.Element;
import org.atriasoft.exml.Node;
import org.atriasoft.exml.NodeType;
import org.atriasoft.exml.exception.ExmlNodeDoesNotExist; import org.atriasoft.exml.exception.ExmlNodeDoesNotExist;
import org.atriasoft.exml.model.XmlElement;
import org.atriasoft.exml.model.XmlNode;
import org.atriasoft.exml.model.XmlNodeType;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlTestElement {
public class TestExmlElement {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlElement.class);
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
Log.verbose("----------------------------------------------------------------"); LOGGER.trace("----------------------------------------------------------------");
} }
@Test @Test
public void append() { public void append() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertEquals(myElement.getNodes().size(), 0); Assertions.assertEquals(myElement.getNodes().size(), 0);
myElement.append(new Element("jkjhkjhkh")); myElement.append(new XmlElement("jkjhkjhkh"));
Assertions.assertEquals(myElement.getNodes().size(), 1); Assertions.assertEquals(myElement.getNodes().size(), 1);
try { try {
myElement.getNode("jkjhkjhkh"); myElement.getNode("jkjhkjhkh");
@ -36,9 +41,9 @@ public class ExmlTestElement {
@Test @Test
public void clear() { public void clear() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertEquals(myElement.getNodes().size(), 0); Assertions.assertEquals(myElement.getNodes().size(), 0);
myElement.append(new Element("jkjhkjhkh")); myElement.append(new XmlElement("jkjhkjhkh"));
Assertions.assertEquals(myElement.getNodes().size(), 1); Assertions.assertEquals(myElement.getNodes().size(), 1);
try { try {
myElement.getNode("jkjhkjhkh"); myElement.getNode("jkjhkjhkh");
@ -52,15 +57,15 @@ public class ExmlTestElement {
@Test @Test
public void create() { public void create() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertEquals(myElement.getType(), NodeType.ELEMENT); Assertions.assertEquals(myElement.getType(), XmlNodeType.ELEMENT);
} }
@Test @Test
public void createAssignement() { public void createAssignement() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
try { try {
final Element myOtherElement = myElement.clone(); final XmlElement myOtherElement = myElement.clone();
Assertions.assertEquals(myElement.getValue(), myOtherElement.getValue()); Assertions.assertEquals(myElement.getValue(), myOtherElement.getValue());
} catch (final CloneNotSupportedException e) { } catch (final CloneNotSupportedException e) {
Assertions.fail("Should Not have thrown an exception"); Assertions.fail("Should Not have thrown an exception");
@ -69,9 +74,9 @@ public class ExmlTestElement {
@Test @Test
public void createCopy() { public void createCopy() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
try { try {
final Element myOtherElement = new Element(myElement); final XmlElement myOtherElement = new XmlElement(myElement);
Assertions.assertEquals(myElement.getValue(), myOtherElement.getValue()); Assertions.assertEquals(myElement.getValue(), myOtherElement.getValue());
} catch (final CloneNotSupportedException e) { } catch (final CloneNotSupportedException e) {
Assertions.fail("Should Not have thrown an exception"); Assertions.fail("Should Not have thrown an exception");
@ -81,43 +86,42 @@ public class ExmlTestElement {
@Test @Test
public void getNamed() { public void getNamed() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertEquals(myElement.existNode("jkjhkjhkh"), false); Assertions.assertEquals(myElement.existNode("jkjhkjhkh"), false);
} }
@Test @Test
public void getNodeId() { public void getNodeId() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertEquals(false, myElement.existNode(465)); Assertions.assertEquals(false, myElement.existNode(465));
} }
@Test @Test
public void getText1() { public void getText1() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertEquals("", myElement.getText()); Assertions.assertEquals("", myElement.getText());
} }
@Test @Test
public void getText2() { public void getText2() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
myElement.append(new Element("jkjhkjhkh")); myElement.append(new XmlElement("jkjhkjhkh"));
Assertions.assertEquals("<jkjhkjhkh/>\n", myElement.getText()); Assertions.assertEquals("<jkjhkjhkh/>", myElement.getText());
} }
@Test @Test
public void getTypeId() { public void getTypeId() {
final Element myElement = new Element("NodeName"); final XmlElement myElement = new XmlElement("NodeName");
Assertions.assertThrows(ExmlNodeDoesNotExist.class, () -> myElement.getType(1)); Assertions.assertThrows(ExmlNodeDoesNotExist.class, () -> myElement.getType(1));
} }
@Test @Test
public void moveInAllElement() { public void moveInAllElement() {
final Document doc = new Document(); final XmlElement root = Assertions.assertDoesNotThrow(() -> Exml.parse("<elem><elem1/><elem2/></elem>"));
doc.parse("<elem><elem1/><elem2/></elem>"); for (final XmlNode it : root.getNodes()) {
for (final Node it : doc.getNodes()) { final XmlElement elem = (XmlElement) it;
final Element elem = (Element) it;
Assertions.assertEquals("elem", elem.getValue()); Assertions.assertEquals("elem", elem.getValue());
Assertions.assertEquals(2, elem.getNodes().size()); Assertions.assertEquals(2, elem.getNodes().size());
Assertions.assertEquals(2, elem.size()); Assertions.assertEquals(2, elem.size());

View File

@ -3,22 +3,27 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package test.atriasoft.exml; package test.atriasoft.exml.generic;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlTestParseAttribute {
public class TestExmlParseAttribute {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlParseAttribute.class);
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
Log.verbose("----------------------------------------------------------------"); LOGGER.trace("----------------------------------------------------------------");
} }
@Test @Test
public void testBase() { public void testBase() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"plop\"/>\n", ExmlLocal.test("<elementtt attr=\"plop\"/>",
"<elementtt attr=\"plop\"/>\n", "<elementtt attr=\"plop\"/>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -26,8 +31,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testEmptyAttribute() { public void testEmptyAttribute() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"\"/>\n", ExmlLocal.test("<elementtt attr=\"\"/>",
"<elementtt attr=\"\"/>\n", "<elementtt attr=\"\"/>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -35,8 +40,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testEmptyAttributeNoQuote() { public void testEmptyAttributeNoQuote() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"\"/>\n", ExmlLocal.test("<elementtt attr=\"\"/>",
"<elementtt attr=/>\n", "<elementtt attr=/>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -54,7 +59,7 @@ public class ExmlTestParseAttribute {
public void testEndAttributeErrorMissingEqual() { public void testEndAttributeErrorMissingEqual() {
//@formatter:off //@formatter:off
ExmlLocal.test("", ExmlLocal.test("",
"<elementtt attr \"kjlkj\"/>\n", "<elementtt attr \"kjlkj\"/>",
1); 1);
//@formatter:on //@formatter:on
} }
@ -62,8 +67,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testMultiline() { public void testMultiline() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"plop\"/>\n", ExmlLocal.test("<elementtt attr=\"plop\"/>",
"<elementtt attr\n=\n\"plop\"/>\n", "<elementtt attr\n=\n\"plop\"/>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -71,8 +76,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testMultilineNoQuote() { public void testMultilineNoQuote() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"plop\"/>\n", ExmlLocal.test("<elementtt attr=\"plop\"/>",
"<elementtt attr \n = \n\t plop/>\n", "<elementtt attr \n = \n\t plop/>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -80,8 +85,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testNoQuote() { public void testNoQuote() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"plop\"/>\n", ExmlLocal.test("<elementtt attr=\"plop\"/>",
"<elementtt attr=plop/>\n", "<elementtt attr=plop/>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -89,8 +94,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testNoQuoteNumber() { public void testNoQuoteNumber() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"234345@3452345_.'\"/>\n", ExmlLocal.test("<elementtt attr=\"234345@3452345_.'\"/>",
"<elementtt attr=234345@3452345_.' />\n", "<elementtt attr=234345@3452345_.' />",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -98,8 +103,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testSpace1() { public void testSpace1() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"plop\"/>\n", ExmlLocal.test("<elementtt attr=\"plop\"/>",
"<elementtt attr =\"plop\"/>\n", "<elementtt attr =\"plop\"/>",
-1); -1);
//@formatter:on //@formatter:on
} }
@ -107,8 +112,8 @@ public class ExmlTestParseAttribute {
@Test @Test
public void testSpace2() { public void testSpace2() {
//@formatter:off //@formatter:off
ExmlLocal.test("<elementtt attr=\"plop\"/>\n", ExmlLocal.test("<elementtt attr=\"plop\"/>",
"<elementtt attr= \"plop\"/>\n", "<elementtt attr= \"plop\"/>",
-1); -1);
//@formatter:on //@formatter:on
} }

View File

@ -3,58 +3,63 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package test.atriasoft.exml; package test.atriasoft.exml.generic;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlTestParseComment {
public class TestExmlParseComment {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlParseComment.class);
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
Log.verbose("----------------------------------------------------------------"); LOGGER.trace("----------------------------------------------------------------");
} }
@Test @Test
public void testAll() { public void testAll() {
//@formatter:off //@formatter:off
ExmlLocal.test("<!--<.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris>-->\n", ExmlLocal.test("<!--<.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris>-->",
"<!-- <.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris> -->\n", "<!-- <.:!*%^$0945- '(- &<<< >>> '& ( '( '-' <elementPouris> -->",
-1); -1);
//@formatter:on //@formatter:on
} }
@Test @Test
public void testBase() { public void testBase() {
ExmlLocal.test("<!--exemple-->\n", "<!--exemple-->\n", -1); ExmlLocal.test("<!--exemple-->", "<!--exemple-->\n", -1);
} }
@Test @Test
public void testEndError() { public void testEndError() {
ExmlLocal.test("<!--exemple-->\n", "<!-- ssdfgdfg >\n", 1); ExmlLocal.test("<!--exemple-->", "<!-- ssdfgdfg >\n", 1);
} }
@Test @Test
public void testMultiline() { public void testMultiline() {
ExmlLocal.test("<!--exemple-->\n", "<!-- \t \t\t exemple \n\n\n\t-->\n", -1); ExmlLocal.test("<!--exemple-->", "<!-- \t \t\t exemple \n\n\n\t-->\n", -1);
} }
@Test @Test
public void testMultipleEnd() { public void testMultipleEnd() {
ExmlLocal.test("<!--exemple-->\n", "<!-- ---> exemple -->\n", 1); ExmlLocal.test("<!--exemple-->", "<!-- ---> exemple -->\n", 1);
} }
@Test @Test
public void testNoCharInComment() { public void testNoCharInComment() {
ExmlLocal.test("<!---->\n", "<!---->\n", -1); ExmlLocal.test("<!---->", "<!---->\n", -1);
} }
@Test @Test
public void testTiretInComment() { public void testTiretInComment() {
ExmlLocal.test("<!---- exemple-->\n", "<!-- -- exemple -->\n", -1); ExmlLocal.test("<!---- exemple-->", "<!-- -- exemple -->\n", -1);
} }
@Test @Test
public void testWrongEndParsing() { public void testWrongEndParsing() {
ExmlLocal.test("<!--> exemple-->\n", "<!--> exemple -->\n", -1); ExmlLocal.test("<!--> exemple-->", "<!--> exemple -->\n", -1);
} }
} }

View File

@ -0,0 +1,66 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.generic;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlParseDeclaration {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlParseDeclaration.class);
@BeforeAll
public static void beforeClass() {
LOGGER.trace("----------------------------------------------------------------");
}
@Test
public void testAll() {
ExmlLocal.test("<?xml attr=\"p65421lop\"?>", "<?xml attr \n = \n\t p65421lop?>", -1);
}
@Test
public void testAttribute() {
ExmlLocal.test("<?xml attr=\"plop\"?>", "<?xml attr=\"plop\"?>", -1);
}
@Test
public void testBase() {
ExmlLocal.test("<?testDeclaration?>", "<?testDeclaration?>", -1);
}
@Test
public void testCaseSensitiveBalise() {
ExmlLocal.test("<Elem/>", "<Elem></elem>", -1);
}
@Test
public void testMultiline() {
ExmlLocal.test("<?xml attr=\"plop\"?>", "<?xml attr\n=\n\"plop\"?>", -1);
}
@Test
public void testNoQuote() {
ExmlLocal.test("<?xml attr=\"plop\"?>", "<?xml attr=plop?>", -1);
}
@Test
public void testNumberNoQuote() {
ExmlLocal.test("<?xml attr=\"234345@3452345_.'\"?>", "<?xml attr=234345@3452345_.' ?>", -1);
}
@Test
public void testSpace1() {
ExmlLocal.test("<?xml attr=\"plop\"?>", "<?xml attr =\"plop\"?>", -1);
}
@Test
public void testSpace2() {
ExmlLocal.test("<?xml attr=\"plop\"?>", "<?xml attr= \"plop\"?>", -1);
}
}

View File

@ -3,17 +3,22 @@
* @copyright 2021, Edouard DUPIN, all right reserved * @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
package test.atriasoft.exml; package test.atriasoft.exml.generic;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExmlTestParseElement {
static String refOutputElement = "<exemple/>\n";
public class TestExmlParseElement {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlParseElement.class);
static String refOutputElement = "<exemple/>";
@BeforeAll @BeforeAll
public static void beforeClass() { public static void beforeClass() {
Log.verbose("----------------------------------------------------------------"); LOGGER.trace("----------------------------------------------------------------");
} }
@Test @Test

View File

@ -0,0 +1,394 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.Arrays;
import org.atriasoft.exml.XmlMapper;
import org.atriasoft.exml.exception.ExmlBuilderException;
import org.atriasoft.exml.exception.ExmlParserErrorMulti;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import test.atriasoft.exml.generic.TestExmlAttribute;
import test.atriasoft.exml.introspection.model.ClassMethodEnum;
import test.atriasoft.exml.introspection.model.ClassPublicMemberOnly;
import test.atriasoft.exml.introspection.model.ClassPublicMethodOnly;
import test.atriasoft.exml.introspection.model.ClassPublicMethodeNode;
import test.atriasoft.exml.introspection.model.ClassPublicMethodeStructured;
import test.atriasoft.exml.introspection.model.SimpleEnum;
public class TestExmlIntrospection {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospection.class);
@BeforeAll
public static void beforeClass() {
LOGGER.trace("----------------------------------------------------------------");
}
@Test
public void test1() throws ExmlParserErrorMulti, ExmlBuilderException {
//@formatter:off
final String dataToParse = """
<elem
memberByte="12"
memberShort="1223"
memberInteger="4541542"
memberLong = "4564654654"
memberBoolean = "true"\s
memberByteClass = "55"\s
memberShortClass = "1523"\s
memberIntegerClass = "4654654"\s
memberLongClass = "545645645454"
memberBooleanClass = "true"\s
memberStringClass = "sdfgsdkjfglksqjéé"
memberArrayByte="12; 15;123; 100; 2"
memberArrayByteClass="
\n 12;1; 100;122"
memberArrayShort="1245;1894; -100;-12542"
memberArrayShortClass="-1245;-1894; 0;2542;15615"
memberArrayInteger="123456;-654987"
memberArrayIntegerClass="1567845;45621354;-5646544"
memberArrayLong="1651324654;65421351685;-5"
memberArrayLongClass="6746541351;546546546;564654654;654654654654;-45546"
memberArrayBoolean="true; true; false"
memberArrayBooleanClass="false; false; true; true"
/>
""";
//@formatter:on
final ClassPublicMemberOnly elem = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataToParse, ClassPublicMemberOnly.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) 12, elem.memberByte);
Assertions.assertEquals((short) 1223, elem.memberShort);
Assertions.assertEquals(4541542, elem.memberInteger);
Assertions.assertEquals(4564654654L, elem.memberLong);
Assertions.assertEquals(true, elem.memberBoolean);
Assertions.assertEquals((byte) 55, elem.memberByteClass);
Assertions.assertEquals((short) 1523, elem.memberShortClass);
Assertions.assertEquals(4654654, elem.memberIntegerClass);
Assertions.assertEquals(545645645454L, elem.memberLongClass);
Assertions.assertEquals(true, elem.memberBooleanClass);
Assertions.assertEquals("sdfgsdkjfglksqjéé", elem.memberStringClass);
Assertions.assertEquals(5, elem.memberArrayByte.length);
Assertions.assertEquals((byte) 12, elem.memberArrayByte[0]);
Assertions.assertEquals((byte) 15, elem.memberArrayByte[1]);
Assertions.assertEquals((byte) 123, elem.memberArrayByte[2]);
Assertions.assertEquals((byte) 100, elem.memberArrayByte[3]);
Assertions.assertEquals(2, elem.memberArrayByte[4]);
Assertions.assertEquals(4, elem.memberArrayByteClass.length);
Assertions.assertEquals((byte) 12, elem.memberArrayByteClass[0]);
Assertions.assertEquals((byte) 1, elem.memberArrayByteClass[1]);
Assertions.assertEquals((byte) 100, elem.memberArrayByteClass[2]);
Assertions.assertEquals((byte) 122, elem.memberArrayByteClass[3]);
Assertions.assertEquals(4, elem.memberArrayShort.length);
Assertions.assertEquals((short) 1245, elem.memberArrayShort[0]);
Assertions.assertEquals((short) 1894, elem.memberArrayShort[1]);
Assertions.assertEquals((short) -100, elem.memberArrayShort[2]);
Assertions.assertEquals((short) -12542, elem.memberArrayShort[3]);
Assertions.assertEquals(5, elem.memberArrayShortClass.length);
Assertions.assertEquals((short) -1245, elem.memberArrayShortClass[0]);
Assertions.assertEquals((short) -1894, elem.memberArrayShortClass[1]);
Assertions.assertEquals((short) 0, elem.memberArrayShortClass[2]);
Assertions.assertEquals((short) 2542, elem.memberArrayShortClass[3]);
Assertions.assertEquals((short) 15615, elem.memberArrayShortClass[4]);
Assertions.assertEquals(2, elem.memberArrayInteger.length);
//Assertions.assertArrayEquals(Arrays.asList(123456, -654987).toArray(), elem.memberArrayInteger);
Assertions.assertEquals(3, elem.memberArrayIntegerClass.length);
Assertions.assertArrayEquals(Arrays.asList(1567845, 45621354, -5646544).toArray(), elem.memberArrayIntegerClass);
Assertions.assertEquals(3, elem.memberArrayLong.length);
//Assertions.assertArrayEquals(Arrays.asList(1651324654L, 65421351685L, -5L).toArray(), elem.memberArrayLong);
Assertions.assertEquals(5, elem.memberArrayLongClass.length);
Assertions.assertArrayEquals(Arrays.asList(6746541351L, 546546546L, 564654654L, 654654654654L, -45546L).toArray(), elem.memberArrayLongClass);
Assertions.assertEquals(3, elem.memberArrayBoolean.length);
//Assertions.assertArrayEquals(Arrays.asList(true, true, false).toArray(), elem.memberArrayBoolean);
Assertions.assertEquals(4, elem.memberArrayBooleanClass.length);
Assertions.assertArrayEquals(Arrays.asList(false, false, true, true).toArray(), elem.memberArrayBooleanClass);
}
@Test
public void test2() {
//@formatter:off
final String dataToParse = """
<elem
memberByte="12"
memberShort="1223"
memberInteger="4541542"
memberLong = "4564654654"
memberBoolean = "true"\s
memberByteClass = "55"\s
memberShortClass = "1523"\s
memberIntegerClass = "4654654"\s
memberLongClass = "545645645454"
memberBooleanClass = "true"\s
memberStringClass = "sdfgsdkjfglksqjéé"
memberArrayByte="12; 15;123; 100; 2"
memberArrayByteClass="
\n 12;1; 100;122"
memberArrayShort="1245;1894; -100;-12542"
memberArrayShortClass="-1245;-1894; 0;2542;15615"
memberArrayInteger="123456;-654987"
memberArrayIntegerClass="1567845;45621354;-5646544"
memberArrayLong="1651324654;65421351685;-5"
memberArrayLongClass="6746541351;546546546;564654654;654654654654;-45546"
memberArrayBoolean="true; true; false"
memberArrayBooleanClass="false; false; true; true"
/>
""";
//@formatter:on
final ClassPublicMethodOnly elem = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataToParse, ClassPublicMethodOnly.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) 12, elem.getMemberByte());
Assertions.assertEquals((short) 1223, elem.getMemberShort());
Assertions.assertEquals(4541542, elem.getMemberInteger());
Assertions.assertEquals(4564654654L, elem.getMemberLong());
Assertions.assertEquals(true, elem.isMemberBoolean());
Assertions.assertEquals((byte) 55, elem.getMemberByteClass());
Assertions.assertEquals((short) 1523, elem.getMemberShortClass());
Assertions.assertEquals(4654654, elem.getMemberIntegerClass());
Assertions.assertEquals(545645645454L, elem.getMemberLongClass());
Assertions.assertEquals(true, elem.isMemberBooleanClass());
Assertions.assertEquals("sdfgsdkjfglksqjéé", elem.getMemberStringClass());
Assertions.assertEquals(5, elem.getMemberArrayByte().length);
Assertions.assertEquals((byte) 12, elem.getMemberArrayByte()[0]);
Assertions.assertEquals((byte) 15, elem.getMemberArrayByte()[1]);
Assertions.assertEquals((byte) 123, elem.getMemberArrayByte()[2]);
Assertions.assertEquals((byte) 100, elem.getMemberArrayByte()[3]);
Assertions.assertEquals(2, elem.getMemberArrayByte()[4]);
Assertions.assertEquals(4, elem.getMemberArrayByteClass().length);
Assertions.assertEquals((byte) 12, elem.getMemberArrayByteClass()[0]);
Assertions.assertEquals((byte) 1, elem.getMemberArrayByteClass()[1]);
Assertions.assertEquals((byte) 100, elem.getMemberArrayByteClass()[2]);
Assertions.assertEquals((byte) 122, elem.getMemberArrayByteClass()[3]);
Assertions.assertEquals(4, elem.getMemberArrayShort().length);
Assertions.assertEquals((short) 1245, elem.getMemberArrayShort()[0]);
Assertions.assertEquals((short) 1894, elem.getMemberArrayShort()[1]);
Assertions.assertEquals((short) -100, elem.getMemberArrayShort()[2]);
Assertions.assertEquals((short) -12542, elem.getMemberArrayShort()[3]);
Assertions.assertEquals(5, elem.getMemberArrayShortClass().length);
Assertions.assertEquals((short) -1245, elem.getMemberArrayShortClass()[0]);
Assertions.assertEquals((short) -1894, elem.getMemberArrayShortClass()[1]);
Assertions.assertEquals((short) 0, elem.getMemberArrayShortClass()[2]);
Assertions.assertEquals((short) 2542, elem.getMemberArrayShortClass()[3]);
Assertions.assertEquals((short) 15615, elem.getMemberArrayShortClass()[4]);
Assertions.assertEquals(2, elem.getMemberArrayInteger().length);
//Assertions.assertArrayEquals(Arrays.asList(123456, -654987).toArray(), elem.getMemberArrayInteger());
Assertions.assertEquals(3, elem.getMemberArrayIntegerClass().length);
Assertions.assertArrayEquals(Arrays.asList(1567845, 45621354, -5646544).toArray(), elem.getMemberArrayIntegerClass());
Assertions.assertEquals(3, elem.getMemberArrayLong().length);
//Assertions.assertArrayEquals(Arrays.asList(1651324654L, 65421351685L, -5L).toArray(), elem.getMemberArrayLong());
Assertions.assertEquals(5, elem.getMemberArrayLongClass().length);
Assertions.assertArrayEquals(Arrays.asList(6746541351L, 546546546L, 564654654L, 654654654654L, -45546L).toArray(), elem.getMemberArrayLongClass());
Assertions.assertEquals(3, elem.getMemberArrayBoolean().length);
//Assertions.assertArrayEquals(Arrays.asList(true, true, false).toArray(), elem.getMemberArrayBoolean());
Assertions.assertEquals(4, elem.getMemberArrayBooleanClass().length);
Assertions.assertArrayEquals(Arrays.asList(false, false, true, true).toArray(), elem.getMemberArrayBooleanClass());
}
@Test
public void test3() {
//@formatter:off
final String dataToParse = """
<elem>
<memberByte>12</memberByte>
<memberShort>1223</memberShort>
<memberInteger>4541542</memberInteger>
<memberLong>4564654654</memberLong>
<memberBoolean>true</memberBoolean>
<memberByteClass>55</memberByteClass>
<memberShortClass>1523</memberShortClass>
<memberIntegerClass>4654654</memberIntegerClass>
<memberLongClass>545645645454</memberLongClass>
<memberBooleanClass>true</memberBooleanClass>
<memberStringClass>sdfgsdkjfglksqjéé</memberStringClass>
<memberArrayByte>12</memberArrayByte>
<memberArrayByte>15</memberArrayByte>
<memberArrayByte>123</memberArrayByte>
<memberArrayByte>100</memberArrayByte>
<memberArrayByte>2</memberArrayByte>
<memberArrayByteClass>
\n 12</memberArrayByteClass>
<memberArrayByteClass>1</memberArrayByteClass>
<memberArrayByteClass> 100</memberArrayByteClass>
<memberArrayByteClass>122</memberArrayByteClass>
<memberArrayShort>1245</memberArrayShort>
<memberArrayShort>1894</memberArrayShort>
<memberArrayShort> -100</memberArrayShort>
<memberArrayShort>-12542</memberArrayShort>
<memberArrayShortClass>-1245</memberArrayShortClass>
<memberArrayShortClass>-1894</memberArrayShortClass>
<memberArrayShortClass> 0</memberArrayShortClass>
<memberArrayShortClass>2542</memberArrayShortClass>
<memberArrayShortClass>15615</memberArrayShortClass>
<memberArrayInteger>123456</memberArrayInteger>
<memberArrayInteger>-654987</memberArrayInteger>
<memberArrayIntegerClass>1567845</memberArrayIntegerClass>
<memberArrayIntegerClass>45621354</memberArrayIntegerClass>
<memberArrayIntegerClass>-5646544</memberArrayIntegerClass>
<memberArrayLong>1651324654</memberArrayLong>
<memberArrayLong>65421351685</memberArrayLong>
<memberArrayLong>-5</memberArrayLong>
<memberArrayLongClass>6746541351</memberArrayLongClass>
<memberArrayLongClass>546546546</memberArrayLongClass>
<memberArrayLongClass>564654654</memberArrayLongClass>
<memberArrayLongClass>654654654654</memberArrayLongClass>
<memberArrayLongClass>-45546</memberArrayLongClass>
<memberArrayBoolean>true</memberArrayBoolean>
<memberArrayBoolean> true</memberArrayBoolean>
<memberArrayBoolean>false</memberArrayBoolean>
<memberArrayBooleanClass>false</memberArrayBooleanClass>
<memberArrayBooleanClass> false</memberArrayBooleanClass>
<memberArrayBooleanClass>true</memberArrayBooleanClass>
<memberArrayBooleanClass> true</memberArrayBooleanClass>
<memberListByteClass>55 </memberListByteClass>
<memberListByteClass> -53 </memberListByteClass>
<memberListShortClass> 31632</memberListShortClass>
<memberListShortClass>-32100 </memberListShortClass>
<memberListIntegerClass>15612 </memberListIntegerClass>
<memberListIntegerClass> 542 </memberListIntegerClass>
<memberListLongClass>16521 </memberListLongClass>
<memberListLongClass> 4654 </memberListLongClass>
<memberListLongClass>9875546 </memberListLongClass>
<memberListBooleanClass> true</memberListBooleanClass>
<memberListBooleanClass>false </memberListBooleanClass>
</elem>
""";
//@formatter:on
final ClassPublicMethodeNode elem = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataToParse, ClassPublicMethodeNode.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) 12, elem.getMemberByte());
Assertions.assertEquals((short) 1223, elem.getMemberShort());
Assertions.assertEquals(4541542, elem.getMemberInteger());
Assertions.assertEquals(4564654654L, elem.getMemberLong());
Assertions.assertEquals(true, elem.isMemberBoolean());
Assertions.assertEquals((byte) 55, elem.getMemberByteClass());
Assertions.assertEquals((short) 1523, elem.getMemberShortClass());
Assertions.assertEquals(4654654, elem.getMemberIntegerClass());
Assertions.assertEquals(545645645454L, elem.getMemberLongClass());
Assertions.assertEquals(true, elem.isMemberBooleanClass());
Assertions.assertEquals("sdfgsdkjfglksqjéé", elem.getMemberStringClass());
Assertions.assertEquals(5, elem.getMemberArrayByte().length);
Assertions.assertEquals((byte) 12, elem.getMemberArrayByte()[0]);
Assertions.assertEquals((byte) 15, elem.getMemberArrayByte()[1]);
Assertions.assertEquals((byte) 123, elem.getMemberArrayByte()[2]);
Assertions.assertEquals((byte) 100, elem.getMemberArrayByte()[3]);
Assertions.assertEquals(2, elem.getMemberArrayByte()[4]);
Assertions.assertEquals(4, elem.getMemberArrayByteClass().length);
Assertions.assertEquals((byte) 12, elem.getMemberArrayByteClass()[0]);
Assertions.assertEquals((byte) 1, elem.getMemberArrayByteClass()[1]);
Assertions.assertEquals((byte) 100, elem.getMemberArrayByteClass()[2]);
Assertions.assertEquals((byte) 122, elem.getMemberArrayByteClass()[3]);
Assertions.assertEquals(4, elem.getMemberArrayShort().length);
Assertions.assertEquals((short) 1245, elem.getMemberArrayShort()[0]);
Assertions.assertEquals((short) 1894, elem.getMemberArrayShort()[1]);
Assertions.assertEquals((short) -100, elem.getMemberArrayShort()[2]);
Assertions.assertEquals((short) -12542, elem.getMemberArrayShort()[3]);
Assertions.assertEquals(5, elem.getMemberArrayShortClass().length);
Assertions.assertEquals((short) -1245, elem.getMemberArrayShortClass()[0]);
Assertions.assertEquals((short) -1894, elem.getMemberArrayShortClass()[1]);
Assertions.assertEquals((short) 0, elem.getMemberArrayShortClass()[2]);
Assertions.assertEquals((short) 2542, elem.getMemberArrayShortClass()[3]);
Assertions.assertEquals((short) 15615, elem.getMemberArrayShortClass()[4]);
Assertions.assertEquals(2, elem.getMemberArrayInteger().length);
//Assertions.assertArrayEquals(Arrays.asList(123456, -654987).toArray(), elem.getMemberArrayInteger());
Assertions.assertEquals(3, elem.getMemberArrayIntegerClass().length);
Assertions.assertArrayEquals(Arrays.asList(1567845, 45621354, -5646544).toArray(), elem.getMemberArrayIntegerClass());
Assertions.assertEquals(3, elem.getMemberArrayLong().length);
//Assertions.assertArrayEquals(Arrays.asList(1651324654L, 65421351685L, -5L).toArray(), elem.getMemberArrayLong());
Assertions.assertEquals(5, elem.getMemberArrayLongClass().length);
Assertions.assertArrayEquals(Arrays.asList(6746541351L, 546546546L, 564654654L, 654654654654L, -45546L).toArray(), elem.getMemberArrayLongClass());
Assertions.assertEquals(3, elem.getMemberArrayBoolean().length);
//Assertions.assertArrayEquals(Arrays.asList(true, true, false).toArray(), elem.getMemberArrayBoolean());
Assertions.assertEquals(4, elem.getMemberArrayBooleanClass().length);
Assertions.assertArrayEquals(Arrays.asList(false, false, true, true).toArray(), elem.getMemberArrayBooleanClass());
}
@Test
public void test4() {
//@formatter:off
final String dataToParse = """
<elem>
<memberArrayByte>
<value>12</value>
<value>15</value>
<value>123</value>
<value>100</value>
<value>2</value>
</memberArrayByte>
<memberListByte>
<elem>-12</elem>
<elem>-15</elem>
<elem>-123</elem>
<elem>-100</elem>
<elem>-2</elem>
</memberListByte>
</elem>
""";
//@formatter:on
final ClassPublicMethodeStructured elem = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataToParse, ClassPublicMethodeStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, elem.getMemberArrayByte().length);
Assertions.assertEquals((byte) 12, elem.getMemberArrayByte()[0]);
Assertions.assertEquals((byte) 15, elem.getMemberArrayByte()[1]);
Assertions.assertEquals((byte) 123, elem.getMemberArrayByte()[2]);
Assertions.assertEquals((byte) 100, elem.getMemberArrayByte()[3]);
Assertions.assertEquals((byte) 2, elem.getMemberArrayByte()[4]);
Assertions.assertEquals(5, elem.getMemberListByte().size());
Assertions.assertEquals((byte) -12, elem.getMemberListByte().get(0));
Assertions.assertEquals((byte) -15, elem.getMemberListByte().get(1));
Assertions.assertEquals((byte) -123, elem.getMemberListByte().get(2));
Assertions.assertEquals((byte) -100, elem.getMemberListByte().get(3));
Assertions.assertEquals((byte) -2, elem.getMemberListByte().get(4));
}
@Test
public void test5() {
//@formatter:off
final String dataToParse = """
<elem>
<data>PLIF</data>
</elem>
""";
//@formatter:on
final ClassMethodEnum elem = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataToParse, ClassMethodEnum.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(SimpleEnum.PLIF, elem.getData());
}
}

View File

@ -0,0 +1,570 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionBoolean {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionBoolean.class);
@AknotDefaultAttribute
public class TestArrayBoolean {
public Boolean[] values;
}
@AknotDefaultAttribute
public class TestArrayBooleanFunc {
private Boolean[] values;
public Boolean[] getValues() {
return this.values;
}
public void setValues(final Boolean[] values) {
this.values = values;
}
}
public class TestArrayNodeBoolean {
public Boolean[] values;
}
public class TestArrayNodeBooleanFunc {
private Boolean[] values;
public Boolean[] getValues() {
return this.values;
}
public void setValues(final Boolean[] values) {
this.values = values;
}
}
public class TestArrayNodeBooleanStructured {
@AknotList(value = "elem")
public Boolean[] values;
}
@AknotDefaultAttribute
public class TestBoolean {
public Boolean valueA;
public Boolean valueB;
public Boolean valueNull;
}
@AknotDefaultAttribute
public class TestBooleanFunc {
private Boolean valueA;
private Boolean valueB;
private Boolean valueNull;
public Boolean isValueA() {
return this.valueA;
}
public Boolean isValueB() {
return this.valueB;
}
public Boolean isValueNull() {
return this.valueNull;
}
public void setValueA(final Boolean valueA) {
this.valueA = valueA;
}
public void setValueB(final Boolean valueB) {
this.valueB = valueB;
}
public void setValueNull(final Boolean valueNull) {
this.valueNull = valueNull;
}
}
@AknotDefaultAttribute
public class TestListBoolean {
public List<Boolean> values;
}
@AknotDefaultAttribute
public class TestListBooleanFunc {
private List<Boolean> values;
public List<Boolean> getValues() {
return this.values;
}
public void setValues(final List<Boolean> values) {
this.values = values;
}
}
public class TestListNodeBoolean {
public List<Boolean> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeBooleanFunc {
private List<Boolean> values;
public List<Boolean> getValues() {
return this.values;
}
public void setValues(final List<Boolean> values) {
this.values = values;
}
}
public class TestListNodeBooleanStructured {
@AknotList(value = "elem")
public List<Boolean> values;
}
public class TestNodeBoolean {
public Boolean valueA;
public Boolean valueB;
public Boolean valueNull;
}
public class TestNodeBooleanFunc {
private Boolean valueA;
private Boolean valueB;
private Boolean valueNull;
public Boolean isValueA() {
return this.valueA;
}
public Boolean isValueB() {
return this.valueB;
}
public Boolean isValueNull() {
return this.valueNull;
}
public void setValueA(final Boolean valueA) {
this.valueA = valueA;
}
public void setValueB(final Boolean valueB) {
this.valueB = valueB;
}
public void setValueNull(final Boolean valueNull) {
this.valueNull = valueNull;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeBooleanStructured() {
final TestArrayNodeBooleanStructured elem = new TestArrayNodeBooleanStructured();
elem.values = new Boolean[] { false, false, true, false, true };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeBooleanStructured>
<values>
<elem>false</elem>
<elem>false</elem>
<elem>true</elem>
<elem>false</elem>
<elem>true</elem>
</values>
</TestArrayNodeBooleanStructured>""", dataTest);
final TestArrayNodeBooleanStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeBooleanStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(false, root.values[0]);
Assertions.assertEquals(false, root.values[1]);
Assertions.assertEquals(true, root.values[2]);
Assertions.assertEquals(false, root.values[3]);
Assertions.assertEquals(true, root.values[4]);
}
@Test
public void testListNodeBooleanStructured() {
final TestListNodeBooleanStructured elem = new TestListNodeBooleanStructured();
elem.values = List.of(false, false, true, false, true);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeBooleanStructured>
<values>
<elem>false</elem>
<elem>false</elem>
<elem>true</elem>
<elem>false</elem>
<elem>true</elem>
</values>
</TestListNodeBooleanStructured>""", dataTest);
final TestListNodeBooleanStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeBooleanStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(false, root.values.get(0));
Assertions.assertEquals(false, root.values.get(1));
Assertions.assertEquals(true, root.values.get(2));
Assertions.assertEquals(false, root.values.get(3));
Assertions.assertEquals(true, root.values.get(4));
}
@Test
public void testModelArrayBoolean() {
final TestArrayBoolean elem = new TestArrayBoolean();
elem.values = new Boolean[] { false, false, true, false, true };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayBoolean values=\"false;false;true;false;true\"/>", dataTest);
final TestArrayBoolean root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayBoolean.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(false, root.values[0]);
Assertions.assertEquals(false, root.values[1]);
Assertions.assertEquals(true, root.values[2]);
Assertions.assertEquals(false, root.values[3]);
Assertions.assertEquals(true, root.values[4]);
}
@Test
public void testModelArrayBooleanFunc() {
final TestArrayBooleanFunc elem = new TestArrayBooleanFunc();
elem.setValues(new Boolean[] { false, false, true, false, true });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayBooleanFunc values=\"false;false;true;false;true\"/>", dataTest);
final TestArrayBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(false, root.getValues()[0]);
Assertions.assertEquals(false, root.getValues()[1]);
Assertions.assertEquals(true, root.getValues()[2]);
Assertions.assertEquals(false, root.getValues()[3]);
Assertions.assertEquals(true, root.getValues()[4]);
}
@Test
public void testModelArrayNodeBoolean() {
final TestArrayNodeBoolean elem = new TestArrayNodeBoolean();
elem.values = new Boolean[] { false, false, true, false, true };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeBoolean>
<values>false</values>
<values>false</values>
<values>true</values>
<values>false</values>
<values>true</values>
</TestArrayNodeBoolean>""", dataTest);
final TestArrayNodeBoolean root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeBoolean.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(false, root.values[0]);
Assertions.assertEquals(false, root.values[1]);
Assertions.assertEquals(true, root.values[2]);
Assertions.assertEquals(false, root.values[3]);
Assertions.assertEquals(true, root.values[4]);
}
@Test
public void testModelArrayNodeBooleanFunc() {
final TestArrayNodeBooleanFunc elem = new TestArrayNodeBooleanFunc();
elem.setValues(new Boolean[] { false, false, true, false, true });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeBooleanFunc>
<values>false</values>
<values>false</values>
<values>true</values>
<values>false</values>
<values>true</values>
</TestArrayNodeBooleanFunc>""", dataTest);
final TestArrayNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(false, root.getValues()[0]);
Assertions.assertEquals(false, root.getValues()[1]);
Assertions.assertEquals(true, root.getValues()[2]);
Assertions.assertEquals(false, root.getValues()[3]);
Assertions.assertEquals(true, root.getValues()[4]);
}
@Test
public void testModelBoolean() {
final TestBoolean elem = new TestBoolean();
elem.valueA = false;
elem.valueB = true;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestBoolean valueA=\"false\" valueB=\"true\"/>", dataTest);
final TestBoolean root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestBoolean.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(false, root.valueA);
Assertions.assertEquals(true, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelBooleanFunc() {
final TestBooleanFunc elem = new TestBooleanFunc();
elem.setValueA(false);
elem.setValueB(true);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestBooleanFunc valueA=\"false\" valueB=\"true\"/>", dataTest);
final TestBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(false, root.isValueA());
Assertions.assertEquals(true, root.isValueB());
Assertions.assertEquals(null, root.isValueNull());
}
@Test
public void testModelListBoolean() {
final TestListBoolean elem = new TestListBoolean();
elem.values = List.of(false, false, true, false, true);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListBoolean values=\"false;false;true;false;true\"/>", dataTest);
final TestListBoolean root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListBoolean.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(false, root.values.get(0));
Assertions.assertEquals(false, root.values.get(1));
Assertions.assertEquals(true, root.values.get(2));
Assertions.assertEquals(false, root.values.get(3));
Assertions.assertEquals(true, root.values.get(4));
}
@Test
public void testModelListBooleanFunc() {
final TestListBooleanFunc elem = new TestListBooleanFunc();
elem.setValues(List.of(false, false, true, false, true));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListBooleanFunc values=\"false;false;true;false;true\"/>", dataTest);
final TestListBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(false, root.getValues().get(0));
Assertions.assertEquals(false, root.getValues().get(1));
Assertions.assertEquals(true, root.getValues().get(2));
Assertions.assertEquals(false, root.getValues().get(3));
Assertions.assertEquals(true, root.getValues().get(4));
}
@Test
public void testModelListNodeBoolean() {
final TestListNodeBoolean elem = new TestListNodeBoolean();
elem.values = List.of(false, false, true, false, true);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeBoolean>
<values>false</values>
<values>false</values>
<values>true</values>
<values>false</values>
<values>true</values>
</TestListNodeBoolean>""", dataTest);
final TestListNodeBoolean root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeBoolean.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(false, root.values.get(0));
Assertions.assertEquals(false, root.values.get(1));
Assertions.assertEquals(true, root.values.get(2));
Assertions.assertEquals(false, root.values.get(3));
Assertions.assertEquals(true, root.values.get(4));
}
@Test
public void testModelListNodeBooleanFunc() {
final TestListNodeBooleanFunc elem = new TestListNodeBooleanFunc();
elem.setValues(List.of(false, false, true, false, true));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeBooleanFunc>
<values>false</values>
<values>false</values>
<values>true</values>
<values>false</values>
<values>true</values>
</TestListNodeBooleanFunc>""", dataTest);
final TestListNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(false, root.getValues().get(0));
Assertions.assertEquals(false, root.getValues().get(1));
Assertions.assertEquals(true, root.getValues().get(2));
Assertions.assertEquals(false, root.getValues().get(3));
Assertions.assertEquals(true, root.getValues().get(4));
}
@Test
public void testModelNodeBoolean() {
final TestNodeBoolean elem = new TestNodeBoolean();
elem.valueA = false;
elem.valueB = true;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeBoolean>
<valueA>false</valueA>
<valueB>true</valueB>
</TestNodeBoolean>""", dataTest);
final TestNodeBoolean root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeBoolean.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(false, root.valueA);
Assertions.assertEquals(true, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelNodeBooleanFunc() {
final TestNodeBooleanFunc elem = new TestNodeBooleanFunc();
elem.setValueA(false);
elem.setValueB(true);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeBooleanFunc>
<valueA>false</valueA>
<valueB>true</valueB>
</TestNodeBooleanFunc>""", dataTest);
final TestNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(false, root.isValueA());
Assertions.assertEquals(true, root.isValueB());
Assertions.assertEquals(null, root.isValueNull());
}
}

View File

@ -0,0 +1,359 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionBooleanNative {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionBooleanNative.class);
@AknotDefaultAttribute
public class TestArrayBooleanFunc {
private boolean[] values;
public boolean[] getValues() {
return this.values;
}
public void setValues(final boolean[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestArrayBooleanNative {
public boolean[] values;
}
public class TestArrayNodeBooleanFunc {
private boolean[] values;
public boolean[] getValues() {
return this.values;
}
public void setValues(final boolean[] values) {
this.values = values;
}
}
public class TestArrayNodeBooleanNative {
public boolean[] values;
}
public class TestArrayNodeBooleanNativeStructured {
@AknotList(value = "elem")
public boolean[] values;
}
@AknotDefaultAttribute
public class TestBooleanFunc {
private boolean valueA;
private boolean valueB;
public boolean isValueA() {
return this.valueA;
}
public boolean isValueB() {
return this.valueB;
}
public void setValueA(final boolean valueA) {
this.valueA = valueA;
}
public void setValueB(final boolean valueB) {
this.valueB = valueB;
}
}
@AknotDefaultAttribute
public class TestBooleanNative {
public boolean valueA;
public boolean valueB;
}
public class TestNodeBooleanFunc {
private boolean valueA;
private boolean valueB;
public boolean isValueA() {
return this.valueA;
}
public boolean isValueB() {
return this.valueB;
}
public void setValueA(final boolean valueA) {
this.valueA = valueA;
}
public void setValueB(final boolean valueB) {
this.valueB = valueB;
}
}
public class TestNodeBooleanNative {
public boolean valueA;
public boolean valueB;
}
public static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.trace("----------------------------------------------------------------");
}
@Test
public void testArrayNodeBooleanNativeStructured() {
final TestArrayNodeBooleanNativeStructured elem = new TestArrayNodeBooleanNativeStructured();
elem.values = new boolean[] { false, false, true, false, true };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeBooleanNativeStructured>
<values>
<elem>false</elem>
<elem>false</elem>
<elem>true</elem>
<elem>false</elem>
<elem>true</elem>
</values>
</TestArrayNodeBooleanNativeStructured>""", dataTest);
final TestArrayNodeBooleanNativeStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeBooleanNativeStructured.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(false, root.values[0]);
Assertions.assertEquals(false, root.values[1]);
Assertions.assertEquals(true, root.values[2]);
Assertions.assertEquals(false, root.values[3]);
Assertions.assertEquals(true, root.values[4]);
}
@Test
public void testModelArrayBooleanFunc() {
final TestArrayBooleanFunc elem = new TestArrayBooleanFunc();
elem.setValues(new boolean[] { false, false, true, false, true });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayBooleanFunc values=\"false;false;true;false;true\"/>", dataTest);
final TestArrayBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(false, root.getValues()[0]);
Assertions.assertEquals(false, root.getValues()[1]);
Assertions.assertEquals(true, root.getValues()[2]);
Assertions.assertEquals(false, root.getValues()[3]);
Assertions.assertEquals(true, root.getValues()[4]);
}
@Test
public void testModelArrayBooleanNative() {
final TestArrayBooleanNative elem = new TestArrayBooleanNative();
elem.values = new boolean[] { false, false, true, false, true };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayBooleanNative values=\"false;false;true;false;true\"/>", dataTest);
final TestArrayBooleanNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayBooleanNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(false, root.values[0]);
Assertions.assertEquals(false, root.values[1]);
Assertions.assertEquals(true, root.values[2]);
Assertions.assertEquals(false, root.values[3]);
Assertions.assertEquals(true, root.values[4]);
}
@Test
public void testModelArrayNodeBooleanFunc() {
final TestArrayNodeBooleanFunc elem = new TestArrayNodeBooleanFunc();
elem.setValues(new boolean[] { false, false, true, false, true });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeBooleanFunc>
<values>false</values>
<values>false</values>
<values>true</values>
<values>false</values>
<values>true</values>
</TestArrayNodeBooleanFunc>""", dataTest);
final TestArrayNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(false, root.getValues()[0]);
Assertions.assertEquals(false, root.getValues()[1]);
Assertions.assertEquals(true, root.getValues()[2]);
Assertions.assertEquals(false, root.getValues()[3]);
Assertions.assertEquals(true, root.getValues()[4]);
}
@Test
public void testModelArrayNodeBooleanNative() {
final TestArrayNodeBooleanNative elem = new TestArrayNodeBooleanNative();
elem.values = new boolean[] { false, false, true, false, true };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeBooleanNative>
<values>false</values>
<values>false</values>
<values>true</values>
<values>false</values>
<values>true</values>
</TestArrayNodeBooleanNative>""", dataTest);
final TestArrayNodeBooleanNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeBooleanNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(false, root.values[0]);
Assertions.assertEquals(false, root.values[1]);
Assertions.assertEquals(true, root.values[2]);
Assertions.assertEquals(false, root.values[3]);
Assertions.assertEquals(true, root.values[4]);
}
@Test
public void testModelBooleanFunc() {
final TestBooleanFunc elem = new TestBooleanFunc();
elem.setValueA(false);
elem.setValueB(true);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestBooleanFunc valueA=\"false\" valueB=\"true\"/>", dataTest);
final TestBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(false, root.isValueA());
Assertions.assertEquals(true, root.isValueB());
}
@Test
public void testModelBooleanNative() {
final TestBooleanNative elem = new TestBooleanNative();
elem.valueA = false;
elem.valueB = true;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestBooleanNative valueA=\"false\" valueB=\"true\"/>", dataTest);
final TestBooleanNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestBooleanNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(false, root.valueA);
Assertions.assertEquals(true, root.valueB);
}
@Test
public void testModelNodeBooleanFunc() {
final TestNodeBooleanFunc elem = new TestNodeBooleanFunc();
elem.setValueA(false);
elem.setValueB(true);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeBooleanFunc>
<valueA>false</valueA>
<valueB>true</valueB>
</TestNodeBooleanFunc>""", dataTest);
final TestNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeBooleanFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(false, root.isValueA());
Assertions.assertEquals(true, root.isValueB());
}
@Test
public void testModelNodeBooleanNative() {
final TestNodeBooleanNative elem = new TestNodeBooleanNative();
elem.valueA = false;
elem.valueB = true;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeBooleanNative>
<valueA>false</valueA>
<valueB>true</valueB>
</TestNodeBooleanNative>""", dataTest);
final TestNodeBooleanNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeBooleanNative.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(false, root.valueA);
Assertions.assertEquals(true, root.valueB);
}
}

View File

@ -0,0 +1,664 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionByte {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionByte.class);
@AknotDefaultAttribute
public class TestArrayByte {
public Byte[] values;
}
@AknotDefaultAttribute
public class TestArrayByteFunc {
private Byte[] values;
public Byte[] getValues() {
return this.values;
}
public void setValues(final Byte[] values) {
this.values = values;
}
}
public class TestArrayNodeByte {
public Byte[] values;
}
public class TestArrayNodeByteFunc {
private Byte[] values;
public Byte[] getValues() {
return this.values;
}
public void setValues(final Byte[] values) {
this.values = values;
}
}
public class TestArrayNodeByteStructured {
@AknotList(value = "elem")
public Byte[] values;
}
public class TestArrayNodeByteStructuredFunc {
private Byte[] values;
@AknotList(value = "elem")
public Byte[] getValues() {
return this.values;
}
public void setValues(final Byte[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestByte {
public Byte valueA;
public Byte valueB;
public Byte valueNull;
}
@AknotDefaultAttribute
public class TestByteFunc {
private Byte valueA;
private Byte valueB;
private Byte valueNull;
public Byte getValueA() {
return this.valueA;
}
public Byte getValueB() {
return this.valueB;
}
public Byte getValueNull() {
return this.valueNull;
}
public void setValueA(final Byte valueA) {
this.valueA = valueA;
}
public void setValueB(final Byte valueB) {
this.valueB = valueB;
}
public void setValueNull(final Byte valueNull) {
this.valueNull = valueNull;
}
}
@AknotDefaultAttribute
public class TestListByte {
public List<Byte> values;
}
@AknotDefaultAttribute
public class TestListByteFunc {
private List<Byte> values;
public List<Byte> getValues() {
return this.values;
}
public void setValues(final List<Byte> values) {
this.values = values;
}
}
public class TestListNodeByte {
public List<Byte> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeByteFunc {
private List<Byte> values;
public List<Byte> getValues() {
return this.values;
}
public void setValues(final List<Byte> values) {
this.values = values;
}
}
public class TestListNodeByteStructured {
@AknotList(value = "elem")
public List<Byte> values;
}
public class TestListNodeByteStructuredFunc {
private List<Byte> values;
@AknotList(value = "elem")
public List<Byte> getValues() {
return this.values;
}
public void setValues(final List<Byte> values) {
this.values = values;
}
}
public class TestNodeByte {
public Byte valueA;
public Byte valueB;
public Byte valueNull;
}
public class TestNodeByteFunc {
private Byte valueA;
private Byte valueB;
private Byte valueNull;
public Byte getValueA() {
return this.valueA;
}
public Byte getValueB() {
return this.valueB;
}
public Byte getValueNull() {
return this.valueNull;
}
public void setValueA(final Byte valueA) {
this.valueA = valueA;
}
public void setValueB(final Byte valueB) {
this.valueB = valueB;
}
public void setValueNull(final Byte valueNull) {
this.valueNull = valueNull;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeByteStructured() {
final TestArrayNodeByteStructured elem = new TestArrayNodeByteStructured();
elem.values = new Byte[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByteStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeByteStructured>""", dataTest);
final TestArrayNodeByteStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByteStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((byte) 12, root.values[0]);
Assertions.assertEquals((byte) -13, root.values[1]);
Assertions.assertEquals((byte) 33, root.values[2]);
Assertions.assertEquals((byte) 78, root.values[3]);
Assertions.assertEquals((byte) -127, root.values[4]);
}
@Test
public void testArrayNodeByteStructuredFunc() {
final TestArrayNodeByteStructuredFunc elem = new TestArrayNodeByteStructuredFunc();
elem.setValues(new Byte[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByteStructuredFunc>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeByteStructuredFunc>""", dataTest);
final TestArrayNodeByteStructuredFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByteStructuredFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((byte) 12, root.getValues()[0]);
Assertions.assertEquals((byte) -13, root.getValues()[1]);
Assertions.assertEquals((byte) 33, root.getValues()[2]);
Assertions.assertEquals((byte) 78, root.getValues()[3]);
Assertions.assertEquals((byte) -127, root.getValues()[4]);
}
@Test
public void testListNodeByteStructured() {
final TestListNodeByteStructured elem = new TestListNodeByteStructured();
elem.values = List.of((byte) 12, (byte) -13, (byte) 33, (byte) 78, (byte) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeByteStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestListNodeByteStructured>""", dataTest);
final TestListNodeByteStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeByteStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals((byte) 12, root.values.get(0));
Assertions.assertEquals((byte) -13, root.values.get(1));
Assertions.assertEquals((byte) 33, root.values.get(2));
Assertions.assertEquals((byte) 78, root.values.get(3));
Assertions.assertEquals((byte) -127, root.values.get(4));
}
@Test
public void testListNodeByteStructuredFunc() {
final TestListNodeByteStructuredFunc elem = new TestListNodeByteStructuredFunc();
elem.setValues(List.of((byte) 12, (byte) -13, (byte) 33, (byte) 78, (byte) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeByteStructuredFunc>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestListNodeByteStructuredFunc>""", dataTest);
final TestListNodeByteStructuredFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeByteStructuredFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals((byte) 12, root.getValues().get(0));
Assertions.assertEquals((byte) -13, root.getValues().get(1));
Assertions.assertEquals((byte) 33, root.getValues().get(2));
Assertions.assertEquals((byte) 78, root.getValues().get(3));
Assertions.assertEquals((byte) -127, root.getValues().get(4));
}
@Test
public void testModelArrayByte() {
final TestArrayByte elem = new TestArrayByte();
elem.values = new Byte[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayByte values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayByte root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayByte.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((byte) 12, root.values[0]);
Assertions.assertEquals((byte) -13, root.values[1]);
Assertions.assertEquals((byte) 33, root.values[2]);
Assertions.assertEquals((byte) 78, root.values[3]);
Assertions.assertEquals((byte) -127, root.values[4]);
}
@Test
public void testModelArrayByteFunc() {
final TestArrayByteFunc elem = new TestArrayByteFunc();
elem.setValues(new Byte[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayByteFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayByteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((byte) 12, root.getValues()[0]);
Assertions.assertEquals((byte) -13, root.getValues()[1]);
Assertions.assertEquals((byte) 33, root.getValues()[2]);
Assertions.assertEquals((byte) 78, root.getValues()[3]);
Assertions.assertEquals((byte) -127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeByte() {
final TestArrayNodeByte elem = new TestArrayNodeByte();
elem.values = new Byte[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByte>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeByte>""", dataTest);
final TestArrayNodeByte root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByte.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((byte) 12, root.values[0]);
Assertions.assertEquals((byte) -13, root.values[1]);
Assertions.assertEquals((byte) 33, root.values[2]);
Assertions.assertEquals((byte) 78, root.values[3]);
Assertions.assertEquals((byte) -127, root.values[4]);
}
@Test
public void testModelArrayNodeByteFunc() {
final TestArrayNodeByteFunc elem = new TestArrayNodeByteFunc();
elem.setValues(new Byte[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByteFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeByteFunc>""", dataTest);
final TestArrayNodeByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((byte) 12, root.getValues()[0]);
Assertions.assertEquals((byte) -13, root.getValues()[1]);
Assertions.assertEquals((byte) 33, root.getValues()[2]);
Assertions.assertEquals((byte) 78, root.getValues()[3]);
Assertions.assertEquals((byte) -127, root.getValues()[4]);
}
@Test
public void testModelByte() {
final TestByte elem = new TestByte();
elem.valueA = (byte) 12;
elem.valueB = (byte) -13;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestByte valueA=\"12\" valueB=\"-13\"/>", dataTest);
final TestByte root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestByte.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) 12, root.valueA);
Assertions.assertEquals((byte) -13, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelByteFunc() {
final TestByteFunc elem = new TestByteFunc();
elem.setValueA((byte) -55);
elem.setValueB((byte) 57);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestByteFunc valueA=\"-55\" valueB=\"57\"/>", dataTest);
final TestByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestByteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) -55, root.getValueA());
Assertions.assertEquals((byte) 57, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
@Test
public void testModelListByte() {
final TestListByte elem = new TestListByte();
elem.values = List.of((byte) 12, (byte) -13, (byte) 33, (byte) 78, (byte) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListByte values=\"12;-13;33;78;-127\"/>", dataTest);
final TestListByte root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListByte.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals((byte) 12, root.values.get(0));
Assertions.assertEquals((byte) -13, root.values.get(1));
Assertions.assertEquals((byte) 33, root.values.get(2));
Assertions.assertEquals((byte) 78, root.values.get(3));
Assertions.assertEquals((byte) -127, root.values.get(4));
}
@Test
public void testModelListByteFunc() {
final TestListByteFunc elem = new TestListByteFunc();
elem.setValues(List.of((byte) 12, (byte) -13, (byte) 33, (byte) 78, (byte) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListByteFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestListByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListByteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals((byte) 12, root.getValues().get(0));
Assertions.assertEquals((byte) -13, root.getValues().get(1));
Assertions.assertEquals((byte) 33, root.getValues().get(2));
Assertions.assertEquals((byte) 78, root.getValues().get(3));
Assertions.assertEquals((byte) -127, root.getValues().get(4));
}
@Test
public void testModelListNodeByte() {
final TestListNodeByte elem = new TestListNodeByte();
elem.values = List.of((byte) 12, (byte) -13, (byte) 33, (byte) 78, (byte) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeByte>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestListNodeByte>""", dataTest);
final TestListNodeByte root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeByte.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals((byte) 12, root.values.get(0));
Assertions.assertEquals((byte) -13, root.values.get(1));
Assertions.assertEquals((byte) 33, root.values.get(2));
Assertions.assertEquals((byte) 78, root.values.get(3));
Assertions.assertEquals((byte) -127, root.values.get(4));
}
@Test
public void testModelListNodeByteFunc() {
final TestListNodeByteFunc elem = new TestListNodeByteFunc();
elem.setValues(List.of((byte) 12, (byte) -13, (byte) 33, (byte) 78, (byte) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
final String dataGenerated = """
<TestListNodeByteFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestListNodeByteFunc>""";
LOGGER.warn("compared with: " + dataGenerated);
Assertions.assertEquals(dataGenerated, dataTest);
final TestListNodeByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeByteFunc.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals((byte) 12, root.getValues().get(0));
Assertions.assertEquals((byte) -13, root.getValues().get(1));
Assertions.assertEquals((byte) 33, root.getValues().get(2));
Assertions.assertEquals((byte) 78, root.getValues().get(3));
Assertions.assertEquals((byte) -127, root.getValues().get(4));
}
@Test
public void testModelNodeByte() {
final TestNodeByte elem = new TestNodeByte();
elem.valueA = (byte) 11;
elem.valueB = (byte) -120;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeByte>
<valueA>11</valueA>
<valueB>-120</valueB>
</TestNodeByte>""", dataTest);
final TestNodeByte root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeByte.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) 11, root.valueA);
Assertions.assertEquals((byte) -120, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelNodeByteFunc() {
final TestNodeByteFunc elem = new TestNodeByteFunc();
elem.setValueA((byte) 54);
elem.setValueB((byte) -68);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeByteFunc>
<valueA>54</valueA>
<valueB>-68</valueB>
</TestNodeByteFunc>""", dataTest);
final TestNodeByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeByteFunc.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals((byte) 54, root.getValueA());
Assertions.assertEquals((byte) -68, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
}

View File

@ -0,0 +1,404 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionByteNative {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionByteNative.class);
@AknotDefaultAttribute
public class TestArrayByteFunc {
private byte[] values;
public byte[] getValues() {
return this.values;
}
public void setValues(final byte[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestArrayByteNative {
public byte[] values;
}
public class TestArrayNodeByteFunc {
private byte[] values;
public byte[] getValues() {
return this.values;
}
public void setValues(final byte[] values) {
this.values = values;
}
}
public class TestArrayNodeByteNative {
public byte[] values;
}
public class TestArrayNodeByteNativeStructured {
@AknotList(value = "elem")
public byte[] values;
}
public class TestArrayNodeByteNativeStructuredFunc {
private byte[] values;
@AknotList(value = "elem")
public byte[] getValues() {
return this.values;
}
public void setValues(final byte[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestbyteFunc {
private byte valueA;
private byte valueB;
public byte getValueA() {
return this.valueA;
}
public byte getValueB() {
return this.valueB;
}
public void setValueA(final byte valueA) {
this.valueA = valueA;
}
public void setValueB(final byte valueB) {
this.valueB = valueB;
}
}
@AknotDefaultAttribute
public class TestByteNative {
public byte valueA;
public byte valueB;
}
public class TestNodebyteFunc {
private byte valueA;
private byte valueB;
public byte getValueA() {
return this.valueA;
}
public byte getValueB() {
return this.valueB;
}
public void setValueA(final byte valueA) {
this.valueA = valueA;
}
public void setValueB(final byte valueB) {
this.valueB = valueB;
}
}
public class TestNodeByteNative {
public byte valueA;
public byte valueB;
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeByteNativeStructured() {
final TestArrayNodeByteNativeStructured elem = new TestArrayNodeByteNativeStructured();
elem.values = new byte[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByteNativeStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeByteNativeStructured>""", dataTest);
final TestArrayNodeByteNativeStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByteNativeStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((byte) 12, root.values[0]);
Assertions.assertEquals((byte) -13, root.values[1]);
Assertions.assertEquals((byte) 33, root.values[2]);
Assertions.assertEquals((byte) 78, root.values[3]);
Assertions.assertEquals((byte) -127, root.values[4]);
}
@Test
public void testArrayNodeByteNativeStructuredFunc() {
final TestArrayNodeByteNativeStructuredFunc elem = new TestArrayNodeByteNativeStructuredFunc();
elem.setValues(new byte[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByteNativeStructuredFunc>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeByteNativeStructuredFunc>""", dataTest);
final TestArrayNodeByteNativeStructuredFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByteNativeStructuredFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((byte) 12, root.getValues()[0]);
Assertions.assertEquals((byte) -13, root.getValues()[1]);
Assertions.assertEquals((byte) 33, root.getValues()[2]);
Assertions.assertEquals((byte) 78, root.getValues()[3]);
Assertions.assertEquals((byte) -127, root.getValues()[4]);
}
@Test
public void testModelArrayByteFunc() {
final TestArrayByteFunc elem = new TestArrayByteFunc();
elem.setValues(new byte[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayByteFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayByteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((byte) 12, root.getValues()[0]);
Assertions.assertEquals((byte) -13, root.getValues()[1]);
Assertions.assertEquals((byte) 33, root.getValues()[2]);
Assertions.assertEquals((byte) 78, root.getValues()[3]);
Assertions.assertEquals((byte) -127, root.getValues()[4]);
}
@Test
public void testModelArrayByteNative() {
final TestArrayByteNative elem = new TestArrayByteNative();
elem.values = new byte[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayByteNative values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayByteNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayByteNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((byte) 12, root.values[0]);
Assertions.assertEquals((byte) -13, root.values[1]);
Assertions.assertEquals((byte) 33, root.values[2]);
Assertions.assertEquals((byte) 78, root.values[3]);
Assertions.assertEquals((byte) -127, root.values[4]);
}
@Test
public void testModelArrayNodeByteFunc() {
final TestArrayNodeByteFunc elem = new TestArrayNodeByteFunc();
elem.setValues(new byte[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByteFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeByteFunc>""", dataTest);
final TestArrayNodeByteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((byte) 12, root.getValues()[0]);
Assertions.assertEquals((byte) -13, root.getValues()[1]);
Assertions.assertEquals((byte) 33, root.getValues()[2]);
Assertions.assertEquals((byte) 78, root.getValues()[3]);
Assertions.assertEquals((byte) -127, root.getValues()[4]);
}
@Test
public void testModelArrayNodebyteNative() {
final TestArrayNodeByteNative elem = new TestArrayNodeByteNative();
elem.values = new byte[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeByteNative>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeByteNative>""", dataTest);
final TestArrayNodeByteNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeByteNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((byte) 12, root.values[0]);
Assertions.assertEquals((byte) -13, root.values[1]);
Assertions.assertEquals((byte) 33, root.values[2]);
Assertions.assertEquals((byte) 78, root.values[3]);
Assertions.assertEquals((byte) -127, root.values[4]);
}
@Test
public void testModelByteFunc() {
final TestbyteFunc elem = new TestbyteFunc();
elem.setValueA((byte) -55);
elem.setValueB((byte) 57);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestbyteFunc valueA=\"-55\" valueB=\"57\"/>", dataTest);
final TestbyteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestbyteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) -55, root.getValueA());
Assertions.assertEquals((byte) 57, root.getValueB());
}
@Test
public void testModelByteNative() {
final TestByteNative elem = new TestByteNative();
elem.valueA = (byte) 12;
elem.valueB = (byte) -13;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestByteNative valueA=\"12\" valueB=\"-13\"/>", dataTest);
final TestByteNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestByteNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) 12, root.valueA);
Assertions.assertEquals((byte) -13, root.valueB);
}
@Test
public void testModelNodeByteFunc() {
final TestNodebyteFunc elem = new TestNodebyteFunc();
elem.setValueA((byte) 54);
elem.setValueB((byte) -68);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodebyteFunc>
<valueA>54</valueA>
<valueB>-68</valueB>
</TestNodebyteFunc>""", dataTest);
final TestNodebyteFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodebyteFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((byte) 54, root.getValueA());
Assertions.assertEquals((byte) -68, root.getValueB());
}
@Test
public void testModelNodeByteNative() {
final TestNodeByteNative elem = new TestNodeByteNative();
elem.valueA = (byte) 11;
elem.valueB = (byte) -120;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeByteNative>
<valueA>11</valueA>
<valueB>-120</valueB>
</TestNodeByteNative>""", dataTest);
final TestNodeByteNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeByteNative.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals((byte) 11, root.valueA);
Assertions.assertEquals((byte) -120, root.valueB);
}
}

View File

@ -0,0 +1,638 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotAttribute;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionDecoratorAttribute {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionDecoratorAttribute.class);
@AknotDefaultAttribute
public class TestNodeObject {
public int valueA;
@AknotAttribute
public int valueB;
@AknotAttribute(true)
public int valueC;
@AknotAttribute(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotAttribute
public final int finalValueN;
@AknotAttribute(true)
public final int finalValueO;
@AknotAttribute(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObject(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotAttribute final int finalValueR,
@AknotAttribute(true) final int finalValueS, @AknotAttribute(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotAttribute
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotAttribute(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotAttribute(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotAttribute
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotAttribute(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotAttribute(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotAttribute
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotAttribute(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotAttribute(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultAttribute(false)
public class TestNodeObjectFalse {
public int valueA;
@AknotAttribute
public int valueB;
@AknotAttribute(true)
public int valueC;
@AknotAttribute(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotAttribute
public final int finalValueN;
@AknotAttribute(true)
public final int finalValueO;
@AknotAttribute(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObjectFalse(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotAttribute final int finalValueR,
@AknotAttribute(true) final int finalValueS, @AknotAttribute(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotAttribute
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotAttribute(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotAttribute(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotAttribute
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotAttribute(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotAttribute(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotAttribute
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotAttribute(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotAttribute(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultAttribute(true)
public class TestNodeObjectTrue {
public int valueA;
@AknotAttribute
public int valueB;
@AknotAttribute(true)
public int valueC;
@AknotAttribute(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotAttribute
public final int finalValueN;
@AknotAttribute(true)
public final int finalValueO;
@AknotAttribute(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObjectTrue(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotAttribute final int finalValueR,
@AknotAttribute(true) final int finalValueS, @AknotAttribute(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotAttribute
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotAttribute(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotAttribute(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotAttribute
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotAttribute(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotAttribute(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotAttribute
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotAttribute(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotAttribute(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
// ************************************************************
// ** Attribute
// ************************************************************
@Test
public void testDefaultAttribute() {
final TestNodeObject elem = new TestNodeObject(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + dataTest);
Assertions.assertEquals(
"""
<TestNodeObject finalValueM="321" finalValueN="654" finalValueO="987" finalValueQ="267" finalValueR="264" finalValueS="1524" pFinalValueQ="-552" pFinalValueR="-965" pFinalValueS="-98885" valueA="55" valueB="78" valueC="51" valueE="651" valueF="654" valueG="8552" valueH="9531" valueI="87465">
<finalValueP>159</finalValueP>
<finalValueT>182445</finalValueT>
<pFinalValueT>-8754</pFinalValueT>
<valueD>24</valueD>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObject>""",
dataTest);
final TestNodeObject root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObject.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
@Test
public void testDefaultAttributeFalse() {
final TestNodeObjectFalse elem = new TestNodeObjectFalse(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals(
"""
<TestNodeObjectFalse finalValueN="654" finalValueO="987" finalValueR="264" finalValueS="1524" pFinalValueR="-965" pFinalValueS="-98885" valueB="78" valueC="51" valueF="654" valueG="8552" valueH="9531" valueI="87465">
<finalValueM>321</finalValueM>
<finalValueP>159</finalValueP>
<finalValueQ>267</finalValueQ>
<finalValueT>182445</finalValueT>
<pFinalValueQ>-552</pFinalValueQ>
<pFinalValueT>-8754</pFinalValueT>
<valueA>55</valueA>
<valueD>24</valueD>
<valueE>651</valueE>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObjectFalse>""",
dataTest);
final TestNodeObjectFalse root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectFalse.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
@Test
public void testDefaultAttributeTrue() {
final TestNodeObjectTrue elem = new TestNodeObjectTrue(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals(
"""
<TestNodeObjectTrue finalValueM="321" finalValueN="654" finalValueO="987" finalValueQ="267" finalValueR="264" finalValueS="1524" pFinalValueQ="-552" pFinalValueR="-965" pFinalValueS="-98885" valueA="55" valueB="78" valueC="51" valueE="651" valueF="654" valueG="8552" valueH="9531" valueI="87465">
<finalValueP>159</finalValueP>
<finalValueT>182445</finalValueT>
<pFinalValueT>-8754</pFinalValueT>
<valueD>24</valueD>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObjectTrue>""",
dataTest);
final TestNodeObjectTrue root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectTrue.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
}

View File

@ -0,0 +1,686 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultManaged;
import org.atriasoft.aknot.annotation.AknotManaged;
import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionDecoratorManaged {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionDecoratorManaged.class);
@AknotDefaultManaged
public class TestNodeObject {
public int valueA;
@AknotManaged
public int valueB;
@AknotManaged(true)
public int valueC;
@AknotManaged(false)
public int valueD = 8542;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ = 879454;
private int valueK = 74564;
public final int finalValueM;
@AknotManaged
public final int finalValueN;
@AknotManaged(true)
public final int finalValueO;
@AknotManaged(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueQ", "finalValueR", "finalValueS", "pFinalValueQ", "pFinalValueR", "pFinalValueS", "finalValueT" })
public TestNodeObject(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueQ, @AknotManaged final int finalValueR,
@AknotManaged(true) final int finalValueS, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS, final int finalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = 9988;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = 8454;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = finalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotManaged
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotManaged(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotManaged(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotManaged
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotManaged(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotManaged(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotManaged
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotManaged(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotManaged(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultManaged(false)
public class TestNodeObjectFalse {
public int valueA;
@AknotManaged
public int valueB;
@AknotManaged(true)
public int valueC;
@AknotManaged(false)
public int valueD;
private int valueE = 564;
private int valueF = 655;
private int valueG = 852;
private int valueH = 566;
private int valueI = 456;
private int valueJ = 857;
private int valueK = 9875;
public final int finalValueM;
@AknotManaged
public final int finalValueN;
@AknotManaged(true)
public final int finalValueO;
@AknotManaged(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT; // Note that element can be never defined outside the constructor static values
@AknotManaged(false)
public TestNodeObjectFalse() {
this.finalValueM = 45646;
this.finalValueN = 789645363;
this.finalValueO = 7894;
this.finalValueP = 45646;
this.finalValueQ = 45646;
this.finalValueR = 45645;
this.finalValueS = 1231;
this.finalValueT = 8976545;
this.pFinalValueQ = 7;
this.pFinalValueR = 456456;
this.pFinalValueS = 4564;
this.pFinalValueT = 1;
}
@AknotName({ "finalValueN", "finalValueO", "finalValueR", "finalValueS", "pFinalValueR", "pFinalValueS" })
@AknotManaged
public TestNodeObjectFalse(final int finalValueN, final int finalValueO, @AknotManaged final int finalValueR, @AknotManaged(true) final int finalValueS, final int pFinalValueR,
final int pFinalValueS) {
this.finalValueM = 987;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = 852;
this.finalValueQ = 951;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = 9999;
this.pFinalValueQ = 7523;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = 753;
this.valueA = 99;
this.valueD = 9845;
}
public TestNodeObjectFalse(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotManaged final int finalValueR,
@AknotManaged(true) final int finalValueS, @AknotManaged(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS, final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotManaged
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotManaged(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotManaged(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotManaged
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotManaged(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotManaged(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotManaged
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotManaged(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotManaged(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultManaged(true)
public class TestNodeObjectTrue {
public int valueA;
@AknotManaged
public int valueB;
@AknotManaged(true)
public int valueC;
@AknotManaged(false)
public int valueD = 8542;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ = 879454;
private int valueK = 74564;
public final int finalValueM;
@AknotManaged
public final int finalValueN;
@AknotManaged(true)
public final int finalValueO;
@AknotManaged(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueQ", "finalValueR", "finalValueS", "pFinalValueQ", "pFinalValueR", "pFinalValueS", "finalValueT" })
public TestNodeObjectTrue(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueQ, @AknotManaged final int finalValueR,
@AknotManaged(true) final int finalValueS, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS, final int finalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = 9988;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = 8454;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = finalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotManaged
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotManaged(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotManaged(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotManaged
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotManaged(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotManaged(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotManaged
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotManaged(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotManaged(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
// ************************************************************
// ** Managed
// ************************************************************
@Test
public void testDefaultManaged() {
final TestNodeObject elem = new TestNodeObject(321, 654, 987, 267, 264, 1524, -552, -965, -98885, 8452);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeObject>
<finalValueM>321</finalValueM>
<finalValueN>654</finalValueN>
<finalValueO>987</finalValueO>
<finalValueQ>267</finalValueQ>
<finalValueR>264</finalValueR>
<finalValueS>1524</finalValueS>
<finalValueT>8454</finalValueT>
<pFinalValueQ>-552</pFinalValueQ>
<pFinalValueR>-965</pFinalValueR>
<pFinalValueS>-98885</pFinalValueS>
<valueA>55</valueA>
<valueB>78</valueB>
<valueC>51</valueC>
<valueE>651</valueE>
<valueF>654</valueF>
<valueG>8552</valueG>
<valueH>9531</valueH>
<valueI>87465</valueI>
</TestNodeObject>""", dataTest);
final TestNodeObject root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObject.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(8542, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(879454, root.getValueJ());
Assertions.assertEquals(74564, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(9988, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(8454, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(8454, root.getPFinalValueT());
}
@Test
public void testDefaultManagedFalse() {
final TestNodeObjectFalse elem = new TestNodeObjectFalse(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeObjectFalse>
<finalValueN>654</finalValueN>
<finalValueO>987</finalValueO>
<finalValueR>264</finalValueR>
<finalValueS>1524</finalValueS>
<pFinalValueR>-965</pFinalValueR>
<pFinalValueS>-98885</pFinalValueS>
<valueB>78</valueB>
<valueC>51</valueC>
<valueF>654</valueF>
<valueG>8552</valueG>
<valueH>9531</valueH>
<valueI>87465</valueI>
</TestNodeObjectFalse>""", dataTest);
final TestNodeObjectFalse root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectFalse.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(99, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(9845, root.valueD);
Assertions.assertEquals(564, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(857, root.getValueJ());
Assertions.assertEquals(9875, root.getValueK());
Assertions.assertEquals(987, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(852, root.finalValueP);
Assertions.assertEquals(951, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(9999, root.finalValueT);
Assertions.assertEquals(7523, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(753, root.getPFinalValueT());
}
@Test
public void testDefaultManagedTrue() {
final TestNodeObjectTrue elem = new TestNodeObjectTrue(321, 654, 987, 267, 264, 1524, -552, -965, -98885, 8452);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeObjectTrue>
<finalValueM>321</finalValueM>
<finalValueN>654</finalValueN>
<finalValueO>987</finalValueO>
<finalValueQ>267</finalValueQ>
<finalValueR>264</finalValueR>
<finalValueS>1524</finalValueS>
<finalValueT>8454</finalValueT>
<pFinalValueQ>-552</pFinalValueQ>
<pFinalValueR>-965</pFinalValueR>
<pFinalValueS>-98885</pFinalValueS>
<valueA>55</valueA>
<valueB>78</valueB>
<valueC>51</valueC>
<valueE>651</valueE>
<valueF>654</valueF>
<valueG>8552</valueG>
<valueH>9531</valueH>
<valueI>87465</valueI>
</TestNodeObjectTrue>""", dataTest);
final TestNodeObjectTrue root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectTrue.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(8542, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(879454, root.getValueJ());
Assertions.assertEquals(74564, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(9988, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(8454, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(8454, root.getPFinalValueT());
}
}

View File

@ -0,0 +1,695 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotAttribute;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionDecoratorNames {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionDecoratorNames.class);
public class ChangingNames {
private String value1RataPlouf;
@AknotName("value2")
public String value2Ballet;
private String value3RataPlouf;
@AknotAttribute
@AknotName("value4")
public String value4Ballet;
@AknotName("value1")
public String getValue1RataPlouf() {
return this.value1RataPlouf;
}
@AknotAttribute
@AknotName("value3")
public String getValue3RataPlouf() {
return this.value3RataPlouf;
}
public void setValue1RataPlouf(final String value1RataPlouf) {
this.value1RataPlouf = value1RataPlouf;
}
public void setValue3RataPlouf(final String value3RataPlouf) {
this.value3RataPlouf = value3RataPlouf;
}
}
@AknotDefaultAttribute
public class TestNodeObject {
public int valueA;
@AknotAttribute
public int valueB;
@AknotAttribute(true)
public int valueC;
@AknotAttribute(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotAttribute
public final int finalValueN;
@AknotAttribute(true)
public final int finalValueO;
@AknotAttribute(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObject(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotAttribute final int finalValueR,
@AknotAttribute(true) final int finalValueS, @AknotAttribute(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotAttribute
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotAttribute(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotAttribute(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotAttribute
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotAttribute(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotAttribute(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotAttribute
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotAttribute(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotAttribute(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultAttribute(false)
public class TestNodeObjectFalse {
public int valueA;
@AknotAttribute
public int valueB;
@AknotAttribute(true)
public int valueC;
@AknotAttribute(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotAttribute
public final int finalValueN;
@AknotAttribute(true)
public final int finalValueO;
@AknotAttribute(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObjectFalse(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotAttribute final int finalValueR,
@AknotAttribute(true) final int finalValueS, @AknotAttribute(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotAttribute
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotAttribute(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotAttribute(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotAttribute
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotAttribute(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotAttribute(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotAttribute
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotAttribute(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotAttribute(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultAttribute(true)
public class TestNodeObjectTrue {
public int valueA;
@AknotAttribute
public int valueB;
@AknotAttribute(true)
public int valueC;
@AknotAttribute(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotAttribute
public final int finalValueN;
@AknotAttribute(true)
public final int finalValueO;
@AknotAttribute(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObjectTrue(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotAttribute final int finalValueR,
@AknotAttribute(true) final int finalValueS, @AknotAttribute(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotAttribute
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotAttribute(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotAttribute(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotAttribute
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotAttribute(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotAttribute(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotAttribute
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotAttribute(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotAttribute(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
// ************************************************************
// ** Attribute
// ************************************************************
@Test
public void testChangingNames() {
final ChangingNames elem = new ChangingNames();
elem.value2Ballet = "55";
elem.value4Ballet = "78";
elem.setValue1RataPlouf("51");
elem.setValue3RataPlouf("24");
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<ChangingNames value3="24" value4="78">
<value1>51</value1>
<value2>55</value2>
</ChangingNames>""", dataTest);
final ChangingNames root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, ChangingNames.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals("55", root.value2Ballet);
Assertions.assertEquals("78", root.value4Ballet);
Assertions.assertEquals("51", root.getValue1RataPlouf());
Assertions.assertEquals("24", root.getValue3RataPlouf());
}
@Test
public void testDefaultAttribute() {
final TestNodeObject elem = new TestNodeObject(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + dataTest);
Assertions.assertEquals(
"""
<TestNodeObject finalValueM="321" finalValueN="654" finalValueO="987" finalValueQ="267" finalValueR="264" finalValueS="1524" pFinalValueQ="-552" pFinalValueR="-965" pFinalValueS="-98885" valueA="55" valueB="78" valueC="51" valueE="651" valueF="654" valueG="8552" valueH="9531" valueI="87465">
<finalValueP>159</finalValueP>
<finalValueT>182445</finalValueT>
<pFinalValueT>-8754</pFinalValueT>
<valueD>24</valueD>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObject>""",
dataTest);
final TestNodeObject root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObject.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
@Test
public void testDefaultAttributeFalse() {
final TestNodeObjectFalse elem = new TestNodeObjectFalse(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals(
"""
<TestNodeObjectFalse finalValueN="654" finalValueO="987" finalValueR="264" finalValueS="1524" pFinalValueR="-965" pFinalValueS="-98885" valueB="78" valueC="51" valueF="654" valueG="8552" valueH="9531" valueI="87465">
<finalValueM>321</finalValueM>
<finalValueP>159</finalValueP>
<finalValueQ>267</finalValueQ>
<finalValueT>182445</finalValueT>
<pFinalValueQ>-552</pFinalValueQ>
<pFinalValueT>-8754</pFinalValueT>
<valueA>55</valueA>
<valueD>24</valueD>
<valueE>651</valueE>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObjectFalse>""",
dataTest);
final TestNodeObjectFalse root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectFalse.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
@Test
public void testDefaultAttributeTrue() {
final TestNodeObjectTrue elem = new TestNodeObjectTrue(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals(
"""
<TestNodeObjectTrue finalValueM="321" finalValueN="654" finalValueO="987" finalValueQ="267" finalValueR="264" finalValueS="1524" pFinalValueQ="-552" pFinalValueR="-965" pFinalValueS="-98885" valueA="55" valueB="78" valueC="51" valueE="651" valueF="654" valueG="8552" valueH="9531" valueI="87465">
<finalValueP>159</finalValueP>
<finalValueT>182445</finalValueT>
<pFinalValueT>-8754</pFinalValueT>
<valueD>24</valueD>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObjectTrue>""",
dataTest);
final TestNodeObjectTrue root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectTrue.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
}

View File

@ -0,0 +1,678 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultOptional;
import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.aknot.annotation.AknotOptional;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionDecoratorOptionnal {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionDecoratorOptionnal.class);
@AknotDefaultOptional
public class TestNodeObject {
public int valueA;
@AknotOptional
public int valueB;
@AknotOptional(true)
public int valueC;
@AknotOptional(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotOptional
public final int finalValueN;
@AknotOptional(true)
public final int finalValueO;
@AknotOptional(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObject(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotOptional final int finalValueR,
@AknotOptional(true) final int finalValueS, @AknotOptional(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotOptional
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotOptional(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotOptional(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotOptional
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotOptional(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotOptional(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotOptional
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotOptional(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotOptional(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultOptional(false)
public class TestNodeObjectFalse {
public int valueA;
@AknotOptional
public int valueB;
@AknotOptional(true)
public int valueC;
@AknotOptional(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotOptional
public final int finalValueN;
@AknotOptional(true)
public final int finalValueO;
@AknotOptional(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObjectFalse(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotOptional final int finalValueR,
@AknotOptional(true) final int finalValueS, @AknotOptional(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotOptional
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotOptional(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotOptional(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotOptional
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotOptional(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotOptional(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotOptional
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotOptional(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotOptional(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
@AknotDefaultOptional(true)
public class TestNodeObjectTrue {
public int valueA;
@AknotOptional
public int valueB;
@AknotOptional(true)
public int valueC;
@AknotOptional(false)
public int valueD;
private int valueE;
private int valueF;
private int valueG;
private int valueH;
private int valueI;
private int valueJ;
private int valueK;
public final int finalValueM;
@AknotOptional
public final int finalValueN;
@AknotOptional(true)
public final int finalValueO;
@AknotOptional(false)
public final int finalValueP;
// special case for bijectivity with records
public final int finalValueQ;
public final int finalValueR;
public final int finalValueS;
public final int finalValueT;
private final int pFinalValueQ;
private final int pFinalValueR;
private final int pFinalValueS;
private final int pFinalValueT;
@AknotName({ "finalValueM", "finalValueN", "finalValueO", "finalValueP", "finalValueQ", "finalValueR", "finalValueS", "finalValueT", "pFinalValueQ", "pFinalValueR", "pFinalValueS",
"pFinalValueT" })
public TestNodeObjectTrue(final int finalValueM, final int finalValueN, final int finalValueO, final int finalValueP, final int finalValueQ, @AknotOptional final int finalValueR,
@AknotOptional(true) final int finalValueS, @AknotOptional(false) final int finalValueT, final int pFinalValueQ, final int pFinalValueR, final int pFinalValueS,
final int pFinalValueT) {
this.finalValueM = finalValueM;
this.finalValueN = finalValueN;
this.finalValueO = finalValueO;
this.finalValueP = finalValueP;
this.finalValueQ = finalValueQ;
this.finalValueR = finalValueR;
this.finalValueS = finalValueS;
this.finalValueT = finalValueT;
this.pFinalValueQ = pFinalValueQ;
this.pFinalValueR = pFinalValueR;
this.pFinalValueS = pFinalValueS;
this.pFinalValueT = pFinalValueT;
}
public int getPFinalValueQ() {
return this.pFinalValueQ;
}
@AknotOptional
public int getPFinalValueR() {
return this.pFinalValueR;
}
@AknotOptional(true)
public int getPFinalValueS() {
return this.pFinalValueS;
}
@AknotOptional(false)
public int getPFinalValueT() {
return this.pFinalValueT;
}
public int getValueE() {
return this.valueE;
}
@AknotOptional
public int getValueF() {
return this.valueF;
}
public int getValueG() {
return this.valueG;
}
@AknotOptional(true)
public int getValueH() {
return this.valueH;
}
public int getValueI() {
return this.valueI;
}
@AknotOptional(false)
public int getValueJ() {
return this.valueJ;
}
public int getValueK() {
return this.valueK;
}
public void setValueE(final int valueE) {
this.valueE = valueE;
}
public void setValueF(final int valueF) {
this.valueF = valueF;
}
@AknotOptional
public void setValueG(final int valueG) {
this.valueG = valueG;
}
public void setValueH(final int valueH) {
this.valueH = valueH;
}
@AknotOptional(true)
public void setValueI(final int valueI) {
this.valueI = valueI;
}
public void setValueJ(final int valueJ) {
this.valueJ = valueJ;
}
@AknotOptional(false)
public void setValueK(final int valueK) {
this.valueK = valueK;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
// ************************************************************
// ** Attribute
// ************************************************************
@Test
public void testDefaultAttribute() {
final TestNodeObject elem = new TestNodeObject(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + dataTest);
Assertions.assertEquals("""
<TestNodeObject>
<finalValueM>321</finalValueM>
<finalValueN>654</finalValueN>
<finalValueO>987</finalValueO>
<finalValueP>159</finalValueP>
<finalValueQ>267</finalValueQ>
<finalValueR>264</finalValueR>
<finalValueS>1524</finalValueS>
<finalValueT>182445</finalValueT>
<pFinalValueQ>-552</pFinalValueQ>
<pFinalValueR>-965</pFinalValueR>
<pFinalValueS>-98885</pFinalValueS>
<pFinalValueT>-8754</pFinalValueT>
<valueA>55</valueA>
<valueB>78</valueB>
<valueC>51</valueC>
<valueD>24</valueD>
<valueE>651</valueE>
<valueF>654</valueF>
<valueG>8552</valueG>
<valueH>9531</valueH>
<valueI>87465</valueI>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObject>""", dataTest);
final TestNodeObject root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObject.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
@Test
public void testDefaultAttributeFalse() {
final TestNodeObjectFalse elem = new TestNodeObjectFalse(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeObjectFalse>
<finalValueM>321</finalValueM>
<finalValueN>654</finalValueN>
<finalValueO>987</finalValueO>
<finalValueP>159</finalValueP>
<finalValueQ>267</finalValueQ>
<finalValueR>264</finalValueR>
<finalValueS>1524</finalValueS>
<finalValueT>182445</finalValueT>
<pFinalValueQ>-552</pFinalValueQ>
<pFinalValueR>-965</pFinalValueR>
<pFinalValueS>-98885</pFinalValueS>
<pFinalValueT>-8754</pFinalValueT>
<valueA>55</valueA>
<valueB>78</valueB>
<valueC>51</valueC>
<valueD>24</valueD>
<valueE>651</valueE>
<valueF>654</valueF>
<valueG>8552</valueG>
<valueH>9531</valueH>
<valueI>87465</valueI>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObjectFalse>""", dataTest);
final TestNodeObjectFalse root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectFalse.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
@Test
public void testDefaultAttributeTrue() {
final TestNodeObjectTrue elem = new TestNodeObjectTrue(321, 654, 987, 159, 267, 264, 1524, 182445, -552, -965, -98885, -8754);
elem.valueA = 55;
elem.valueB = 78;
elem.valueC = 51;
elem.valueD = 24;
elem.setValueE(651);
elem.setValueF(654);
elem.setValueG(8552);
elem.setValueH(9531);
elem.setValueI(87465);
elem.setValueJ(8247);
elem.setValueK(885522);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeObjectTrue>
<finalValueM>321</finalValueM>
<finalValueN>654</finalValueN>
<finalValueO>987</finalValueO>
<finalValueP>159</finalValueP>
<finalValueQ>267</finalValueQ>
<finalValueR>264</finalValueR>
<finalValueS>1524</finalValueS>
<finalValueT>182445</finalValueT>
<pFinalValueQ>-552</pFinalValueQ>
<pFinalValueR>-965</pFinalValueR>
<pFinalValueS>-98885</pFinalValueS>
<pFinalValueT>-8754</pFinalValueT>
<valueA>55</valueA>
<valueB>78</valueB>
<valueC>51</valueC>
<valueD>24</valueD>
<valueE>651</valueE>
<valueF>654</valueF>
<valueG>8552</valueG>
<valueH>9531</valueH>
<valueI>87465</valueI>
<valueJ>8247</valueJ>
<valueK>885522</valueK>
</TestNodeObjectTrue>""", dataTest);
final TestNodeObjectTrue root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectTrue.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA);
Assertions.assertEquals(78, root.valueB);
Assertions.assertEquals(51, root.valueC);
Assertions.assertEquals(24, root.valueD);
Assertions.assertEquals(651, root.getValueE());
Assertions.assertEquals(654, root.getValueF());
Assertions.assertEquals(8552, root.getValueG());
Assertions.assertEquals(9531, root.getValueH());
Assertions.assertEquals(87465, root.getValueI());
Assertions.assertEquals(8247, root.getValueJ());
Assertions.assertEquals(885522, root.getValueK());
Assertions.assertEquals(321, root.finalValueM);
Assertions.assertEquals(654, root.finalValueN);
Assertions.assertEquals(987, root.finalValueO);
Assertions.assertEquals(159, root.finalValueP);
Assertions.assertEquals(267, root.finalValueQ);
Assertions.assertEquals(264, root.finalValueR);
Assertions.assertEquals(1524, root.finalValueS);
Assertions.assertEquals(182445, root.finalValueT);
Assertions.assertEquals(-552, root.getPFinalValueQ());
Assertions.assertEquals(-965, root.getPFinalValueR());
Assertions.assertEquals(-98885, root.getPFinalValueS());
Assertions.assertEquals(-8754, root.getPFinalValueT());
}
}

View File

@ -0,0 +1,570 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionDouble {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionDouble.class);
@AknotDefaultAttribute
public class TestArrayDouble {
public Double[] values;
}
@AknotDefaultAttribute
public class TestArrayDoubleFunc {
private Double[] values;
public Double[] getValues() {
return this.values;
}
public void setValues(final Double[] values) {
this.values = values;
}
}
public class TestArrayNodeDouble {
public Double[] values;
}
public class TestArrayNodeDoubleFunc {
private Double[] values;
public Double[] getValues() {
return this.values;
}
public void setValues(final Double[] values) {
this.values = values;
}
}
public class TestArrayNodeDoubleStructured {
@AknotList(value = "elem")
public Double[] values;
}
@AknotDefaultAttribute
public class TestDouble {
public Double valueA;
public Double valueB;
public Double valueNull;
}
@AknotDefaultAttribute
public class TestDoubleFunc {
private Double valueA;
private Double valueB;
private Double valueNull;
public Double getValueA() {
return this.valueA;
}
public Double getValueB() {
return this.valueB;
}
public Double getValueNull() {
return this.valueNull;
}
public void setValueA(final Double valueA) {
this.valueA = valueA;
}
public void setValueB(final Double valueB) {
this.valueB = valueB;
}
public void setValueNull(final Double valueNull) {
this.valueNull = valueNull;
}
}
@AknotDefaultAttribute
public class TestListDouble {
public List<Double> values;
}
@AknotDefaultAttribute
public class TestListDoubleFunc {
private List<Double> values;
public List<Double> getValues() {
return this.values;
}
public void setValues(final List<Double> values) {
this.values = values;
}
}
public class TestListNodeDouble {
public List<Double> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeDoubleFunc {
private List<Double> values;
public List<Double> getValues() {
return this.values;
}
public void setValues(final List<Double> values) {
this.values = values;
}
}
public class TestListNodeDoubleStructured {
@AknotList(value = "elem")
public List<Double> values;
}
public class TestNodeDouble {
public Double valueA;
public Double valueB;
public Double valueNull;
}
public class TestNodeDoubleFunc {
private Double valueA;
private Double valueB;
private Double valueNull;
public Double getValueA() {
return this.valueA;
}
public Double getValueB() {
return this.valueB;
}
public Double getValueNull() {
return this.valueNull;
}
public void setValueA(final Double valueA) {
this.valueA = valueA;
}
public void setValueB(final Double valueB) {
this.valueB = valueB;
}
public void setValueNull(final Double valueNull) {
this.valueNull = valueNull;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeDoubleStructured() {
final TestArrayNodeDoubleStructured elem = new TestArrayNodeDoubleStructured();
elem.values = new Double[] { (double) 12, (double) -13, (double) 33, (double) 78, (double) -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeDoubleStructured>
<values>
<elem>12.0</elem>
<elem>-13.0</elem>
<elem>33.0</elem>
<elem>78.0</elem>
<elem>-127.0</elem>
</values>
</TestArrayNodeDoubleStructured>""", dataTest);
final TestArrayNodeDoubleStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeDoubleStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((double) 5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testListNodeDoubleStructured() {
final TestListNodeDoubleStructured elem = new TestListNodeDoubleStructured();
elem.values = List.of((double) 12, (double) -13, (double) 33, (double) 78, (double) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeDoubleStructured>
<values>
<elem>12.0</elem>
<elem>-13.0</elem>
<elem>33.0</elem>
<elem>78.0</elem>
<elem>-127.0</elem>
</values>
</TestListNodeDoubleStructured>""", dataTest);
final TestListNodeDoubleStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeDoubleStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelArrayDouble() {
final TestArrayDouble elem = new TestArrayDouble();
elem.values = new Double[] { (double) 12, (double) -13, (double) 33, (double) 78, (double) -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayDouble values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayDouble root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayDouble.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayDoubleFunc() {
final TestArrayDoubleFunc elem = new TestArrayDoubleFunc();
elem.setValues(new Double[] { (double) 12, (double) -13, (double) 33, (double) 78, (double) -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayDoubleFunc values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeDouble() {
final TestArrayNodeDouble elem = new TestArrayNodeDouble();
elem.values = new Double[] { (double) 12, (double) -13, (double) 33, (double) 78, (double) -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeDouble>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeDouble>""", dataTest);
final TestArrayNodeDouble root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeDouble.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayNodeDoubleFunc() {
final TestArrayNodeDoubleFunc elem = new TestArrayNodeDoubleFunc();
elem.setValues(new Double[] { (double) 12, (double) -13, (double) 33, (double) 78, (double) -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeDoubleFunc>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeDoubleFunc>""", dataTest);
final TestArrayNodeDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelDouble() {
final TestDouble elem = new TestDouble();
elem.valueA = (double) 12;
elem.valueB = (double) -13;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestDouble valueA=\"12.0\" valueB=\"-13.0\"/>", dataTest);
final TestDouble root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestDouble.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(12, root.valueA);
Assertions.assertEquals(-13, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelDoubleFunc() {
final TestDoubleFunc elem = new TestDoubleFunc();
elem.setValueA((double) -55);
elem.setValueB((double) 57);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestDoubleFunc valueA=\"-55.0\" valueB=\"57.0\"/>", dataTest);
final TestDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(-55, root.getValueA());
Assertions.assertEquals(57, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
@Test
public void testModelListDouble() {
final TestListDouble elem = new TestListDouble();
elem.values = List.of((double) 12, (double) -13, (double) 33, (double) 78, (double) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListDouble values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestListDouble root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListDouble.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelListDoubleFunc() {
final TestListDoubleFunc elem = new TestListDoubleFunc();
elem.setValues(List.of((double) 12, (double) -13, (double) 33, (double) 78, (double) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListDoubleFunc values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestListDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(12, root.getValues().get(0));
Assertions.assertEquals(-13, root.getValues().get(1));
Assertions.assertEquals(33, root.getValues().get(2));
Assertions.assertEquals(78, root.getValues().get(3));
Assertions.assertEquals(-127, root.getValues().get(4));
}
@Test
public void testModelListNodeDouble() {
final TestListNodeDouble elem = new TestListNodeDouble();
elem.values = List.of((double) 12, (double) -13, (double) 33, (double) 78, (double) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeDouble>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestListNodeDouble>""", dataTest);
final TestListNodeDouble root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeDouble.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelListNodeDoubleFunc() {
final TestListNodeDoubleFunc elem = new TestListNodeDoubleFunc();
elem.setValues(List.of((double) 12, (double) -13, (double) 33, (double) 78, (double) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeDoubleFunc>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestListNodeDoubleFunc>""", dataTest);
final TestListNodeDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(12, root.getValues().get(0));
Assertions.assertEquals(-13, root.getValues().get(1));
Assertions.assertEquals(33, root.getValues().get(2));
Assertions.assertEquals(78, root.getValues().get(3));
Assertions.assertEquals(-127, root.getValues().get(4));
}
@Test
public void testModelNodeDouble() {
final TestNodeDouble elem = new TestNodeDouble();
elem.valueA = (double) 11;
elem.valueB = (double) -120;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeDouble>
<valueA>11.0</valueA>
<valueB>-120.0</valueB>
</TestNodeDouble>""", dataTest);
final TestNodeDouble root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeDouble.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(11, root.valueA);
Assertions.assertEquals(-120, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelNodeDoubleFunc() {
final TestNodeDoubleFunc elem = new TestNodeDoubleFunc();
elem.setValueA((double) 54);
elem.setValueB((double) -68);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeDoubleFunc>
<valueA>54.0</valueA>
<valueB>-68.0</valueB>
</TestNodeDoubleFunc>""", dataTest);
final TestNodeDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(54, root.getValueA());
Assertions.assertEquals(-68, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
}

View File

@ -0,0 +1,357 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionDoubleNative {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionDoubleNative.class);
@AknotDefaultAttribute
public class TestArrayDoubleFunc {
private double[] values;
public double[] getValues() {
return this.values;
}
public void setValues(final double[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestArrayDoubleNative {
public double[] values;
}
public class TestArrayNodeDoubleFunc {
private double[] values;
public double[] getValues() {
return this.values;
}
public void setValues(final double[] values) {
this.values = values;
}
}
public class TestArrayNodeDoubleNative {
public double[] values;
}
public class TestArrayNodeDoubleNativeStructured {
@AknotList(value = "elem")
public double[] values;
}
@AknotDefaultAttribute
public class TestdoubleFunc {
private double valueA;
private double valueB;
public double getValueA() {
return this.valueA;
}
public double getValueB() {
return this.valueB;
}
public void setValueA(final double valueA) {
this.valueA = valueA;
}
public void setValueB(final double valueB) {
this.valueB = valueB;
}
}
@AknotDefaultAttribute
public class TestDoubleNative {
public double valueA;
public double valueB;
}
public class TestNodedoubleFunc {
private double valueA;
private double valueB;
public double getValueA() {
return this.valueA;
}
public double getValueB() {
return this.valueB;
}
public void setValueA(final double valueA) {
this.valueA = valueA;
}
public void setValueB(final double valueB) {
this.valueB = valueB;
}
}
public class TestNodeDoubleNative {
public double valueA;
public double valueB;
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeDoubleNativeStructured() {
final TestArrayNodeDoubleNativeStructured elem = new TestArrayNodeDoubleNativeStructured();
elem.values = new double[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeDoubleNativeStructured>
<values>
<elem>12.0</elem>
<elem>-13.0</elem>
<elem>33.0</elem>
<elem>78.0</elem>
<elem>-127.0</elem>
</values>
</TestArrayNodeDoubleNativeStructured>""", dataTest);
final TestArrayNodeDoubleNativeStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeDoubleNativeStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayDoubleFunc() {
final TestArrayDoubleFunc elem = new TestArrayDoubleFunc();
elem.setValues(new double[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayDoubleFunc values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayDoubleNative() {
final TestArrayDoubleNative elem = new TestArrayDoubleNative();
elem.values = new double[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayDoubleNative values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayDoubleNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayDoubleNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayNodeDoubleFunc() {
final TestArrayNodeDoubleFunc elem = new TestArrayNodeDoubleFunc();
elem.setValues(new double[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeDoubleFunc>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeDoubleFunc>""", dataTest);
final TestArrayNodeDoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeDoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeDoubleNative() {
final TestArrayNodeDoubleNative elem = new TestArrayNodeDoubleNative();
elem.values = new double[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeDoubleNative>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeDoubleNative>""", dataTest);
final TestArrayNodeDoubleNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeDoubleNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelDoubleFunc() {
final TestdoubleFunc elem = new TestdoubleFunc();
elem.setValueA(-55);
elem.setValueB(57);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestdoubleFunc valueA=\"-55.0\" valueB=\"57.0\"/>", dataTest);
final TestdoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestdoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(-55, root.getValueA());
Assertions.assertEquals(57, root.getValueB());
}
@Test
public void testModelDoubleNative() {
final TestDoubleNative elem = new TestDoubleNative();
elem.valueA = 12;
elem.valueB = -13;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestDoubleNative valueA=\"12.0\" valueB=\"-13.0\"/>", dataTest);
final TestDoubleNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestDoubleNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(12, root.valueA);
Assertions.assertEquals(-13, root.valueB);
}
@Test
public void testModelNodeDoubleFunc() {
final TestNodedoubleFunc elem = new TestNodedoubleFunc();
elem.setValueA(54);
elem.setValueB(-68);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodedoubleFunc>
<valueA>54.0</valueA>
<valueB>-68.0</valueB>
</TestNodedoubleFunc>""", dataTest);
final TestNodedoubleFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodedoubleFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(54, root.getValueA());
Assertions.assertEquals(-68, root.getValueB());
}
@Test
public void testModelNodeDoubleNative() {
final TestNodeDoubleNative elem = new TestNodeDoubleNative();
elem.valueA = 11;
elem.valueB = -120;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeDoubleNative>
<valueA>11.0</valueA>
<valueB>-120.0</valueB>
</TestNodeDoubleNative>""", dataTest);
final TestNodeDoubleNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeDoubleNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(11, root.valueA);
Assertions.assertEquals(-120, root.valueB);
}
}

View File

@ -0,0 +1,546 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionEnum {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionEnum.class);
@AknotDefaultAttribute
public class TestArrayEnum {
public TestEnumVal[] values;
}
@AknotDefaultAttribute
public class TestArrayEnumFunc {
private TestEnumVal[] values;
public TestEnumVal[] getValues() {
return this.values;
}
public void setValues(final TestEnumVal[] values) {
this.values = values;
}
}
public class TestArrayNodeEnum {
public TestEnumVal[] values;
}
public class TestArrayNodeEnumFunc {
private TestEnumVal[] values;
public TestEnumVal[] getValues() {
return this.values;
}
public void setValues(final TestEnumVal[] values) {
this.values = values;
}
}
public class TestArrayNodeEnumStructured {
@AknotList(value = "elem")
public TestEnumVal[] values;
}
@AknotDefaultAttribute
public class TestEnum {
public TestEnumVal valueA;
public TestEnumVal valueB;
}
@AknotDefaultAttribute
public class TestEnumFunc {
private TestEnumVal valueA;
private TestEnumVal valueB;
public TestEnumVal getValueA() {
return this.valueA;
}
public TestEnumVal getValueB() {
return this.valueB;
}
public void setValueA(final TestEnumVal valueA) {
this.valueA = valueA;
}
public void setValueB(final TestEnumVal valueB) {
this.valueB = valueB;
}
}
public enum TestEnumVal {
VALUE_1, VALUE_2, VALUE_3;
}
@AknotDefaultAttribute
public class TestListEnum {
public List<TestEnumVal> values;
}
@AknotDefaultAttribute
public class TestListEnumFunc {
private List<TestEnumVal> values;
public List<TestEnumVal> getValues() {
return this.values;
}
public void setValues(final List<TestEnumVal> values) {
this.values = values;
}
}
public class TestListNodeEnum {
public List<TestEnumVal> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeEnumFunc {
private List<TestEnumVal> values;
public List<TestEnumVal> getValues() {
return this.values;
}
public void setValues(final List<TestEnumVal> values) {
this.values = values;
}
}
public class TestListNodeEnumStructured {
@AknotList(value = "elem")
public List<TestEnumVal> values;
}
public class TestNodeEnum {
public TestEnumVal valueA;
public TestEnumVal valueB;
}
public class TestNodeEnumFunc {
private TestEnumVal valueA;
private TestEnumVal valueB;
public TestEnumVal getValueA() {
return this.valueA;
}
public TestEnumVal getValueB() {
return this.valueB;
}
public void setValueA(final TestEnumVal valueA) {
this.valueA = valueA;
}
public void setValueB(final TestEnumVal valueB) {
this.valueB = valueB;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeTestEnumValStructured() {
final TestArrayNodeEnumStructured elem = new TestArrayNodeEnumStructured();
elem.values = new TestEnumVal[] { TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeEnumStructured>
<values>
<elem>VALUE_1</elem>
<elem>VALUE_2</elem>
<elem>VALUE_3</elem>
<elem>VALUE_1</elem>
<elem>VALUE_2</elem>
</values>
</TestArrayNodeEnumStructured>""", dataTest);
final TestArrayNodeEnumStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeEnumStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values[0]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values[1]);
Assertions.assertEquals(TestEnumVal.VALUE_3, root.values[2]);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values[3]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values[4]);
}
@Test
public void testListNodeTestEnumValStructured() {
final TestListNodeEnumStructured elem = new TestListNodeEnumStructured();
elem.values = List.of(TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeEnumStructured>
<values>
<elem>VALUE_1</elem>
<elem>VALUE_2</elem>
<elem>VALUE_3</elem>
<elem>VALUE_1</elem>
<elem>VALUE_2</elem>
</values>
</TestListNodeEnumStructured>""", dataTest);
final TestListNodeEnumStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeEnumStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values.get(0));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values.get(1));
Assertions.assertEquals(TestEnumVal.VALUE_3, root.values.get(2));
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values.get(3));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values.get(4));
}
@Test
public void testModelArrayEnum() {
final TestArrayEnum elem = new TestArrayEnum();
elem.values = new TestEnumVal[] { TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayEnum values=\"VALUE_1;VALUE_2;VALUE_3;VALUE_1;VALUE_2\"/>", dataTest);
final TestArrayEnum root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayEnum.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values[0]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values[1]);
Assertions.assertEquals(TestEnumVal.VALUE_3, root.values[2]);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values[3]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values[4]);
}
@Test
public void testModelArrayEnumFunc() {
final TestArrayEnumFunc elem = new TestArrayEnumFunc();
elem.setValues(new TestEnumVal[] { TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayEnumFunc values=\"VALUE_1;VALUE_2;VALUE_3;VALUE_1;VALUE_2\"/>", dataTest);
final TestArrayEnumFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayEnumFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues()[0]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues()[1]);
Assertions.assertEquals(TestEnumVal.VALUE_3, root.getValues()[2]);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues()[3]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues()[4]);
}
@Test
public void testModelArrayNodeEnum() {
final TestArrayNodeEnum elem = new TestArrayNodeEnum();
elem.values = new TestEnumVal[] { TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeEnum>
<values>VALUE_1</values>
<values>VALUE_2</values>
<values>VALUE_3</values>
<values>VALUE_1</values>
<values>VALUE_2</values>
</TestArrayNodeEnum>""", dataTest);
final TestArrayNodeEnum root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeEnum.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values[0]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values[1]);
Assertions.assertEquals(TestEnumVal.VALUE_3, root.values[2]);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values[3]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values[4]);
}
@Test
public void testModelArrayNodeEnumFunc() {
final TestArrayNodeEnumFunc elem = new TestArrayNodeEnumFunc();
elem.setValues(new TestEnumVal[] { TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeEnumFunc>
<values>VALUE_1</values>
<values>VALUE_2</values>
<values>VALUE_3</values>
<values>VALUE_1</values>
<values>VALUE_2</values>
</TestArrayNodeEnumFunc>""", dataTest);
final TestArrayNodeEnumFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeEnumFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues()[0]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues()[1]);
Assertions.assertEquals(TestEnumVal.VALUE_3, root.getValues()[2]);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues()[3]);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues()[4]);
}
@Test
public void testModelEnum() {
final TestEnum elem = new TestEnum();
elem.valueA = TestEnumVal.VALUE_1;
elem.valueB = TestEnumVal.VALUE_3;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestEnum valueA=\"VALUE_1\" valueB=\"VALUE_3\"/>", dataTest);
final TestEnum root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestEnum.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.valueA);
Assertions.assertEquals(TestEnumVal.VALUE_3, root.valueB);
}
@Test
public void testModelEnumFunc() {
final TestEnumFunc elem = new TestEnumFunc();
elem.setValueA(TestEnumVal.VALUE_1);
elem.setValueB(TestEnumVal.VALUE_2);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestEnumFunc valueA=\"VALUE_1\" valueB=\"VALUE_2\"/>", dataTest);
final TestEnumFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestEnumFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValueA());
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValueB());
}
@Test
public void testModelListEnum() {
final TestListEnum elem = new TestListEnum();
elem.values = List.of(TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListEnum values=\"VALUE_1;VALUE_2;VALUE_3;VALUE_1;VALUE_2\"/>", dataTest);
final TestListEnum root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListEnum.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values.get(0));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values.get(1));
Assertions.assertEquals(TestEnumVal.VALUE_3, root.values.get(2));
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values.get(3));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values.get(4));
}
@Test
public void testModelListEnumFunc() {
final TestListEnumFunc elem = new TestListEnumFunc();
elem.setValues(List.of(TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListEnumFunc values=\"VALUE_1;VALUE_2;VALUE_3;VALUE_1;VALUE_2\"/>", dataTest);
final TestListEnumFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListEnumFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues().get(0));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues().get(1));
Assertions.assertEquals(TestEnumVal.VALUE_3, root.getValues().get(2));
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues().get(3));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues().get(4));
}
@Test
public void testModelListNodeEnum() {
final TestListNodeEnum elem = new TestListNodeEnum();
elem.values = List.of(TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeEnum>
<values>VALUE_1</values>
<values>VALUE_2</values>
<values>VALUE_3</values>
<values>VALUE_1</values>
<values>VALUE_2</values>
</TestListNodeEnum>""", dataTest);
final TestListNodeEnum root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeEnum.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values.get(0));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values.get(1));
Assertions.assertEquals(TestEnumVal.VALUE_3, root.values.get(2));
Assertions.assertEquals(TestEnumVal.VALUE_1, root.values.get(3));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.values.get(4));
}
@Test
public void testModelListNodeEnumFunc() {
final TestListNodeEnumFunc elem = new TestListNodeEnumFunc();
elem.setValues(List.of(TestEnumVal.VALUE_1, TestEnumVal.VALUE_2, TestEnumVal.VALUE_3, TestEnumVal.VALUE_1, TestEnumVal.VALUE_2));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeEnumFunc>
<values>VALUE_1</values>
<values>VALUE_2</values>
<values>VALUE_3</values>
<values>VALUE_1</values>
<values>VALUE_2</values>
</TestListNodeEnumFunc>""", dataTest);
final TestListNodeEnumFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeEnumFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues().get(0));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues().get(1));
Assertions.assertEquals(TestEnumVal.VALUE_3, root.getValues().get(2));
Assertions.assertEquals(TestEnumVal.VALUE_1, root.getValues().get(3));
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValues().get(4));
}
@Test
public void testModelNodeEnum() {
final TestNodeEnum elem = new TestNodeEnum();
elem.valueA = TestEnumVal.VALUE_3;
elem.valueB = TestEnumVal.VALUE_1;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeEnum>
<valueA>VALUE_3</valueA>
<valueB>VALUE_1</valueB>
</TestNodeEnum>""", dataTest);
final TestNodeEnum root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeEnum.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(TestEnumVal.VALUE_3, root.valueA);
Assertions.assertEquals(TestEnumVal.VALUE_1, root.valueB);
}
@Test
public void testModelNodeEnumFunc() {
final TestNodeEnumFunc elem = new TestNodeEnumFunc();
elem.setValueA(TestEnumVal.VALUE_2);
elem.setValueB(TestEnumVal.VALUE_3);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeEnumFunc>
<valueA>VALUE_2</valueA>
<valueB>VALUE_3</valueB>
</TestNodeEnumFunc>""", dataTest);
final TestNodeEnumFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeEnumFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(TestEnumVal.VALUE_2, root.getValueA());
Assertions.assertEquals(TestEnumVal.VALUE_3, root.getValueB());
}
}

View File

@ -0,0 +1,570 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionFloat {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionFloat.class);
@AknotDefaultAttribute
public class TestArrayFloat {
public Float[] values;
}
@AknotDefaultAttribute
public class TestArrayFloatFunc {
private Float[] values;
public Float[] getValues() {
return this.values;
}
public void setValues(final Float[] values) {
this.values = values;
}
}
public class TestArrayNodeFloat {
public Float[] values;
}
public class TestArrayNodeFloatFunc {
private Float[] values;
public Float[] getValues() {
return this.values;
}
public void setValues(final Float[] values) {
this.values = values;
}
}
public class TestArrayNodeFloatStructured {
@AknotList(value = "elem")
public Float[] values;
}
@AknotDefaultAttribute
public class TestFloat {
public Float valueA;
public Float valueB;
public Float valueNull;
}
@AknotDefaultAttribute
public class TestFloatFunc {
private Float valueA;
private Float valueB;
private Float valueNull;
public Float getValueA() {
return this.valueA;
}
public Float getValueB() {
return this.valueB;
}
public Float getValueNull() {
return this.valueNull;
}
public void setValueA(final Float valueA) {
this.valueA = valueA;
}
public void setValueB(final Float valueB) {
this.valueB = valueB;
}
public void setValueNull(final Float valueNull) {
this.valueNull = valueNull;
}
}
@AknotDefaultAttribute
public class TestListFloat {
public List<Float> values;
}
@AknotDefaultAttribute
public class TestListFloatFunc {
private List<Float> values;
public List<Float> getValues() {
return this.values;
}
public void setValues(final List<Float> values) {
this.values = values;
}
}
public class TestListNodeByteStructured {
@AknotList(value = "elem")
public List<Float> values;
}
public class TestListNodeFloat {
public List<Float> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeFloatFunc {
private List<Float> values;
public List<Float> getValues() {
return this.values;
}
public void setValues(final List<Float> values) {
this.values = values;
}
}
public class TestNodeFloat {
public Float valueA;
public Float valueB;
public Float valueNull;
}
public class TestNodeFloatFunc {
private Float valueA;
private Float valueB;
private Float valueNull;
public Float getValueA() {
return this.valueA;
}
public Float getValueB() {
return this.valueB;
}
public Float getValueNull() {
return this.valueNull;
}
public void setValueA(final Float valueA) {
this.valueA = valueA;
}
public void setValueB(final Float valueB) {
this.valueB = valueB;
}
public void setValueNull(final Float valueNull) {
this.valueNull = valueNull;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeFloatStructured() {
final TestArrayNodeFloatStructured elem = new TestArrayNodeFloatStructured();
elem.values = new Float[] { (float) 12, (float) -13, (float) 33, (float) 78, (float) -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeFloatStructured>
<values>
<elem>12.0</elem>
<elem>-13.0</elem>
<elem>33.0</elem>
<elem>78.0</elem>
<elem>-127.0</elem>
</values>
</TestArrayNodeFloatStructured>""", dataTest);
final TestArrayNodeFloatStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeFloatStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testListNodeByteStructured() {
final TestListNodeByteStructured elem = new TestListNodeByteStructured();
elem.values = List.of((float) 12, (float) -13, (float) 33, (float) 78, (float) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeByteStructured>
<values>
<elem>12.0</elem>
<elem>-13.0</elem>
<elem>33.0</elem>
<elem>78.0</elem>
<elem>-127.0</elem>
</values>
</TestListNodeByteStructured>""", dataTest);
final TestListNodeByteStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeByteStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelArrayFloat() {
final TestArrayFloat elem = new TestArrayFloat();
elem.values = new Float[] { (float) 12, (float) -13, (float) 33, (float) 78, (float) -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayFloat values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayFloat root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayFloat.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayFloatFunc() {
final TestArrayFloatFunc elem = new TestArrayFloatFunc();
elem.setValues(new Float[] { (float) 12, (float) -13, (float) 33, (float) 78, (float) -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayFloatFunc values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeFloat() {
final TestArrayNodeFloat elem = new TestArrayNodeFloat();
elem.values = new Float[] { (float) 12, (float) -13, (float) 33, (float) 78, (float) -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeFloat>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeFloat>""", dataTest);
final TestArrayNodeFloat root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeFloat.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayNodeFloatFunc() {
final TestArrayNodeFloatFunc elem = new TestArrayNodeFloatFunc();
elem.setValues(new Float[] { (float) 12, (float) -13, (float) 33, (float) 78, (float) -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeFloatFunc>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeFloatFunc>""", dataTest);
final TestArrayNodeFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelFloat() {
final TestFloat elem = new TestFloat();
elem.valueA = (float) 12;
elem.valueB = (float) -13;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestFloat valueA=\"12.0\" valueB=\"-13.0\"/>", dataTest);
final TestFloat root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestFloat.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(12, root.valueA);
Assertions.assertEquals(-13, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelFloatFunc() {
final TestFloatFunc elem = new TestFloatFunc();
elem.setValueA((float) -55);
elem.setValueB((float) 57);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestFloatFunc valueA=\"-55.0\" valueB=\"57.0\"/>", dataTest);
final TestFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(-55, root.getValueA());
Assertions.assertEquals(57, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
@Test
public void testModelListFloat() {
final TestListFloat elem = new TestListFloat();
elem.values = List.of((float) 12, (float) -13, (float) 33, (float) 78, (float) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListFloat values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestListFloat root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListFloat.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelListFloatFunc() {
final TestListFloatFunc elem = new TestListFloatFunc();
elem.setValues(List.of((float) 12, (float) -13, (float) 33, (float) 78, (float) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListFloatFunc values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestListFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(12, root.getValues().get(0));
Assertions.assertEquals(-13, root.getValues().get(1));
Assertions.assertEquals(33, root.getValues().get(2));
Assertions.assertEquals(78, root.getValues().get(3));
Assertions.assertEquals(-127, root.getValues().get(4));
}
@Test
public void testModelListNodeFloat() {
final TestListNodeFloat elem = new TestListNodeFloat();
elem.values = List.of((float) 12, (float) -13, (float) 33, (float) 78, (float) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeFloat>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestListNodeFloat>""", dataTest);
final TestListNodeFloat root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeFloat.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelListNodeFloatFunc() {
final TestListNodeFloatFunc elem = new TestListNodeFloatFunc();
elem.setValues(List.of((float) 12, (float) -13, (float) 33, (float) 78, (float) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeFloatFunc>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestListNodeFloatFunc>""", dataTest);
final TestListNodeFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(12, root.getValues().get(0));
Assertions.assertEquals(-13, root.getValues().get(1));
Assertions.assertEquals(33, root.getValues().get(2));
Assertions.assertEquals(78, root.getValues().get(3));
Assertions.assertEquals(-127, root.getValues().get(4));
}
@Test
public void testModelNodeFloat() {
final TestNodeFloat elem = new TestNodeFloat();
elem.valueA = (float) 11;
elem.valueB = (float) -120;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeFloat>
<valueA>11.0</valueA>
<valueB>-120.0</valueB>
</TestNodeFloat>""", dataTest);
final TestNodeFloat root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeFloat.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(11, root.valueA);
Assertions.assertEquals(-120, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelNodeFloatFunc() {
final TestNodeFloatFunc elem = new TestNodeFloatFunc();
elem.setValueA((float) 54);
elem.setValueB((float) -68);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeFloatFunc>
<valueA>54.0</valueA>
<valueB>-68.0</valueB>
</TestNodeFloatFunc>""", dataTest);
final TestNodeFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(54, root.getValueA());
Assertions.assertEquals(-68, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
}

View File

@ -0,0 +1,357 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionFloatNative {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionFloatNative.class);
@AknotDefaultAttribute
public class TestArrayFloatFunc {
private float[] values;
public float[] getValues() {
return this.values;
}
public void setValues(final float[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestArrayFloatNative {
public float[] values;
}
public class TestArrayNodeFloatFunc {
private float[] values;
public float[] getValues() {
return this.values;
}
public void setValues(final float[] values) {
this.values = values;
}
}
public class TestArrayNodeFloatNative {
public float[] values;
}
public class TestArrayNodeFloatNativeStructured {
@AknotList(value = "elem")
public float[] values;
}
@AknotDefaultAttribute
public class TestfloatFunc {
private float valueA;
private float valueB;
public float getValueA() {
return this.valueA;
}
public float getValueB() {
return this.valueB;
}
public void setValueA(final float valueA) {
this.valueA = valueA;
}
public void setValueB(final float valueB) {
this.valueB = valueB;
}
}
@AknotDefaultAttribute
public class TestFloatNative {
public float valueA;
public float valueB;
}
public class TestNodefloatFunc {
private float valueA;
private float valueB;
public float getValueA() {
return this.valueA;
}
public float getValueB() {
return this.valueB;
}
public void setValueA(final float valueA) {
this.valueA = valueA;
}
public void setValueB(final float valueB) {
this.valueB = valueB;
}
}
public class TestNodeFloatNative {
public float valueA;
public float valueB;
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeFloatNativeStructured() {
final TestArrayNodeFloatNativeStructured elem = new TestArrayNodeFloatNativeStructured();
elem.values = new float[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeFloatNativeStructured>
<values>
<elem>12.0</elem>
<elem>-13.0</elem>
<elem>33.0</elem>
<elem>78.0</elem>
<elem>-127.0</elem>
</values>
</TestArrayNodeFloatNativeStructured>""", dataTest);
final TestArrayNodeFloatNativeStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeFloatNativeStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayFloatFunc() {
final TestArrayFloatFunc elem = new TestArrayFloatFunc();
elem.setValues(new float[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayFloatFunc values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayFloatNative() {
final TestArrayFloatNative elem = new TestArrayFloatNative();
elem.values = new float[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayFloatNative values=\"12.0;-13.0;33.0;78.0;-127.0\"/>", dataTest);
final TestArrayFloatNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayFloatNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayNodeFloatFunc() {
final TestArrayNodeFloatFunc elem = new TestArrayNodeFloatFunc();
elem.setValues(new float[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeFloatFunc>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeFloatFunc>""", dataTest);
final TestArrayNodeFloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeFloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeFloatNative() {
final TestArrayNodeFloatNative elem = new TestArrayNodeFloatNative();
elem.values = new float[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeFloatNative>
<values>12.0</values>
<values>-13.0</values>
<values>33.0</values>
<values>78.0</values>
<values>-127.0</values>
</TestArrayNodeFloatNative>""", dataTest);
final TestArrayNodeFloatNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeFloatNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelFloatFunc() {
final TestfloatFunc elem = new TestfloatFunc();
elem.setValueA(-55);
elem.setValueB(57);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestfloatFunc valueA=\"-55.0\" valueB=\"57.0\"/>", dataTest);
final TestfloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestfloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(-55, root.getValueA());
Assertions.assertEquals(57, root.getValueB());
}
@Test
public void testModelFloatNative() {
final TestFloatNative elem = new TestFloatNative();
elem.valueA = 12;
elem.valueB = -13;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestFloatNative valueA=\"12.0\" valueB=\"-13.0\"/>", dataTest);
final TestFloatNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestFloatNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(12, root.valueA);
Assertions.assertEquals(-13, root.valueB);
}
@Test
public void testModelNodeFloatFunc() {
final TestNodefloatFunc elem = new TestNodefloatFunc();
elem.setValueA(54);
elem.setValueB(-68);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodefloatFunc>
<valueA>54.0</valueA>
<valueB>-68.0</valueB>
</TestNodefloatFunc>""", dataTest);
final TestNodefloatFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodefloatFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(54, root.getValueA());
Assertions.assertEquals(-68, root.getValueB());
}
@Test
public void testModelNodeFloatNative() {
final TestNodeFloatNative elem = new TestNodeFloatNative();
elem.valueA = 11;
elem.valueB = -120;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeFloatNative>
<valueA>11.0</valueA>
<valueB>-120.0</valueB>
</TestNodeFloatNative>""", dataTest);
final TestNodeFloatNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeFloatNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(11, root.valueA);
Assertions.assertEquals(-120, root.valueB);
}
}

View File

@ -0,0 +1,121 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.exml.XmlMapper;
import org.atriasoft.exml.exception.ExmlException;
import org.atriasoft.exml.exception.ExmlParserErrorMulti;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import test.atriasoft.exml.introspection.model.ClassPublicMemberOnly;
import test.atriasoft.exml.introspection.model.ClassPublicMethodOnly;
import test.atriasoft.exml.introspection.model.ClassPublicMethodeNode;
public class TestExmlIntrospectionGenerate {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionGenerate.class);
private static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.trace("----------------------------------------------------------------");
}
@Test
public void test1() throws ExmlParserErrorMulti, ExmlException {
final ClassPublicMemberOnly elem = new ClassPublicMemberOnly();
elem.memberArrayBoolean = new boolean[] { false, true };
elem.memberArrayBooleanClass = new Boolean[] { false, true, true };
elem.memberArrayByte = new byte[] { 21, 21, 58 };
elem.memberArrayByteClass = new Byte[] { 54, 21, 65, 32 };
elem.memberArrayInteger = new int[] { 1521, 2151, 2156, 216354 };
elem.memberArrayIntegerClass = new Integer[] { 5564, 6546321, 654564, 231321, 54654 };
elem.memberArrayLong = new long[] { 6546544L, 654654651L, 5646546541L, 5465465163L };
elem.memberArrayLongClass = new Long[] { 561651L, 6541321L, 651351L };
elem.memberArrayShort = new short[] { 4564, -54, -564 };
elem.memberArrayShortClass = new Short[] { -54, 5646, -8465, 852 };
elem.memberBoolean = false;
elem.memberBooleanClass = true;
elem.memberByte = 12;
elem.memberByteClass = 54;
elem.memberInteger = 6543524;
elem.memberIntegerClass = 545666;
elem.memberLong = 400000055L;
elem.memberLongClass = 54654546L;
elem.memberShort = 31252;
elem.memberShortClass = -25212;
elem.memberStringClass = "lkjhlkjlkjlkj";
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
LOGGER.warn("data generated: " + builder.toString());
}
@Test
public void test2() throws ExmlParserErrorMulti, ExmlException {
final ClassPublicMethodOnly elem = new ClassPublicMethodOnly();
elem.setMemberArrayBoolean(new boolean[] { false, true });
elem.setMemberArrayBooleanClass(new Boolean[] { false, true, true });
elem.setMemberArrayByte(new byte[] { 21, 21, 58 });
elem.setMemberArrayByteClass(new Byte[] { 54, 21, 65, 32 });
elem.setMemberArrayInteger(new int[] { 1521, 2151, 2156, 216354 });
elem.setMemberArrayIntegerClass(new Integer[] { 5564, 6546321, 654564, 231321, 54654 });
elem.setMemberArrayLong(new long[] { 6546544L, 654654651L, 5646546541L, 5465465163L });
elem.setMemberArrayLongClass(new Long[] { 561651L, 6541321L, 651351L });
elem.setMemberArrayShort(new short[] { 4564, -54, -564 });
elem.setMemberArrayShortClass(new Short[] { -54, 5646, -8465, 852 });
elem.setMemberBoolean(false);
elem.setMemberBooleanClass(true);
elem.setMemberByte((byte) 12);
elem.setMemberByteClass((byte) 54);
elem.setMemberInteger(6543524);
elem.setMemberIntegerClass(545666);
elem.setMemberLong(400000055L);
elem.setMemberLongClass(54654546L);
elem.setMemberShort((short) 31252);
elem.setMemberShortClass((short) -25212);
elem.setMemberStringClass("lkjhlkjlkjlkj");
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
LOGGER.warn("data generated: " + builder.toString());
}
@Test
public void test3() throws ExmlParserErrorMulti, ExmlException {
final ClassPublicMethodeNode elem = new ClassPublicMethodeNode();
elem.setMemberArrayBoolean(new boolean[] { false, true });
elem.setMemberArrayBooleanClass(new Boolean[] { false, true, true });
elem.setMemberArrayByte(new byte[] { 21, 21, 58 });
elem.setMemberArrayByteClass(new Byte[] { 54, 21, 65, 32 });
elem.setMemberArrayInteger(new int[] { 1521, 2151, 2156, 216354 });
elem.setMemberArrayIntegerClass(new Integer[] { 5564, 6546321, 654564, 231321, 54654 });
elem.setMemberArrayLong(new long[] { 6546544L, 654654651L, 5646546541L, 5465465163L });
elem.setMemberArrayLongClass(new Long[] { 561651L, 6541321L, 651351L });
elem.setMemberArrayShort(new short[] { 4564, -54, -564 });
elem.setMemberArrayShortClass(new Short[] { -54, 5646, -8465, 852 });
elem.setMemberBoolean(false);
elem.setMemberBooleanClass(true);
elem.setMemberByte((byte) 12);
elem.setMemberByteClass((byte) 54);
elem.setMemberInteger(6543524);
elem.setMemberIntegerClass(545666);
elem.setMemberLong(400000055L);
elem.setMemberLongClass(54654546L);
elem.setMemberShort((short) 31252);
elem.setMemberShortClass((short) -25212);
elem.setMemberStringClass("lkjhlkjlkjlkj");
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
LOGGER.warn("data generated: " + builder.toString());
}
}

View File

@ -0,0 +1,570 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionInteger {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionInteger.class);
@AknotDefaultAttribute
public class TestArrayInteger {
public Integer[] values;
}
@AknotDefaultAttribute
public class TestArrayIntegerFunc {
private Integer[] values;
public Integer[] getValues() {
return this.values;
}
public void setValues(final Integer[] values) {
this.values = values;
}
}
public class TestArrayNodeInteger {
public Integer[] values;
}
public class TestArrayNodeIntegerFunc {
private Integer[] values;
public Integer[] getValues() {
return this.values;
}
public void setValues(final Integer[] values) {
this.values = values;
}
}
public class TestArrayNodeIntegerStructured {
@AknotList(value = "elem")
public Integer[] values;
}
@AknotDefaultAttribute
public class TestInteger {
public Integer valueA;
public Integer valueB;
public Integer valueNull;
}
@AknotDefaultAttribute
public class TestIntegerFunc {
private Integer valueA;
private Integer valueB;
private Integer valueNull;
public Integer getValueA() {
return this.valueA;
}
public Integer getValueB() {
return this.valueB;
}
public Integer getValueNull() {
return this.valueNull;
}
public void setValueA(final Integer valueA) {
this.valueA = valueA;
}
public void setValueB(final Integer valueB) {
this.valueB = valueB;
}
public void setValueNull(final Integer valueNull) {
this.valueNull = valueNull;
}
}
@AknotDefaultAttribute
public class TestListInteger {
public List<Integer> values;
}
@AknotDefaultAttribute
public class TestListIntegerFunc {
private List<Integer> values;
public List<Integer> getValues() {
return this.values;
}
public void setValues(final List<Integer> values) {
this.values = values;
}
}
public class TestListNodeInteger {
public List<Integer> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeIntegerFunc {
private List<Integer> values;
public List<Integer> getValues() {
return this.values;
}
public void setValues(final List<Integer> values) {
this.values = values;
}
}
public class TestListNodeIntegerStructured {
@AknotList(value = "elem")
public List<Integer> values;
}
public class TestNodeInteger {
public Integer valueA;
public Integer valueB;
public Integer valueNull;
}
public class TestNodeIntegerFunc {
private Integer valueA;
private Integer valueB;
private Integer valueNull;
public Integer getValueA() {
return this.valueA;
}
public Integer getValueB() {
return this.valueB;
}
public Integer getValueNull() {
return this.valueNull;
}
public void setValueA(final Integer valueA) {
this.valueA = valueA;
}
public void setValueB(final Integer valueB) {
this.valueB = valueB;
}
public void setValueNull(final Integer valueNull) {
this.valueNull = valueNull;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeIntegerStructured() {
final TestArrayNodeIntegerStructured elem = new TestArrayNodeIntegerStructured();
elem.values = new Integer[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeIntegerStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeIntegerStructured>""", dataTest);
final TestArrayNodeIntegerStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeIntegerStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testListNodeIntegerStructured() {
final TestListNodeIntegerStructured elem = new TestListNodeIntegerStructured();
elem.values = List.of(12, -13, 33, 78, -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeIntegerStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestListNodeIntegerStructured>""", dataTest);
final TestListNodeIntegerStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeIntegerStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelArrayInteger() {
final TestArrayInteger elem = new TestArrayInteger();
elem.values = new Integer[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayInteger values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayInteger root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayInteger.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayIntegerFunc() {
final TestArrayIntegerFunc elem = new TestArrayIntegerFunc();
elem.setValues(new Integer[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayIntegerFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayIntegerFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeInteger() {
final TestArrayNodeInteger elem = new TestArrayNodeInteger();
elem.values = new Integer[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeInteger>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeInteger>""", dataTest);
final TestArrayNodeInteger root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeInteger.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayNodeIntegerFunc() {
final TestArrayNodeIntegerFunc elem = new TestArrayNodeIntegerFunc();
elem.setValues(new Integer[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeIntegerFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeIntegerFunc>""", dataTest);
final TestArrayNodeIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeIntegerFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelInteger() {
final TestInteger elem = new TestInteger();
elem.valueA = (int) 12;
elem.valueB = (int) -13;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestInteger valueA=\"12\" valueB=\"-13\"/>", dataTest);
final TestInteger root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestInteger.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(12, root.valueA);
Assertions.assertEquals(-13, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelIntegerFunc() {
final TestIntegerFunc elem = new TestIntegerFunc();
elem.setValueA(-55);
elem.setValueB(57);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestIntegerFunc valueA=\"-55\" valueB=\"57\"/>", dataTest);
final TestIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestIntegerFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(-55, root.getValueA());
Assertions.assertEquals(57, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
@Test
public void testModelListInteger() {
final TestListInteger elem = new TestListInteger();
elem.values = List.of(12, -13, 33, 78, -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListInteger values=\"12;-13;33;78;-127\"/>", dataTest);
final TestListInteger root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListInteger.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelListIntegerFunc() {
final TestListIntegerFunc elem = new TestListIntegerFunc();
elem.setValues(List.of(12, -13, 33, 78, -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListIntegerFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestListIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListIntegerFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(12, root.getValues().get(0));
Assertions.assertEquals(-13, root.getValues().get(1));
Assertions.assertEquals(33, root.getValues().get(2));
Assertions.assertEquals(78, root.getValues().get(3));
Assertions.assertEquals(-127, root.getValues().get(4));
}
@Test
public void testModelListNodeInteger() {
final TestListNodeInteger elem = new TestListNodeInteger();
elem.values = List.of(12, -13, 33, 78, -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeInteger>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestListNodeInteger>""", dataTest);
final TestListNodeInteger root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeInteger.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals(12, root.values.get(0));
Assertions.assertEquals(-13, root.values.get(1));
Assertions.assertEquals(33, root.values.get(2));
Assertions.assertEquals(78, root.values.get(3));
Assertions.assertEquals(-127, root.values.get(4));
}
@Test
public void testModelListNodeIntegerFunc() {
final TestListNodeIntegerFunc elem = new TestListNodeIntegerFunc();
elem.setValues(List.of(12, -13, 33, 78, -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeIntegerFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestListNodeIntegerFunc>""", dataTest);
final TestListNodeIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeIntegerFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals(12, root.getValues().get(0));
Assertions.assertEquals(-13, root.getValues().get(1));
Assertions.assertEquals(33, root.getValues().get(2));
Assertions.assertEquals(78, root.getValues().get(3));
Assertions.assertEquals(-127, root.getValues().get(4));
}
@Test
public void testModelNodeInteger() {
final TestNodeInteger elem = new TestNodeInteger();
elem.valueA = (int) 11;
elem.valueB = (int) -120;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeInteger>
<valueA>11</valueA>
<valueB>-120</valueB>
</TestNodeInteger>""", dataTest);
final TestNodeInteger root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeInteger.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(11, root.valueA);
Assertions.assertEquals(-120, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelNodeIntegerFunc() {
final TestNodeIntegerFunc elem = new TestNodeIntegerFunc();
elem.setValueA(54);
elem.setValueB(-68);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeIntegerFunc>
<valueA>54</valueA>
<valueB>-68</valueB>
</TestNodeIntegerFunc>""", dataTest);
final TestNodeIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeIntegerFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(54, root.getValueA());
Assertions.assertEquals(-68, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
}

View File

@ -0,0 +1,358 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionIntegerNative {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionIntegerNative.class);
@AknotDefaultAttribute
public class TestArrayIntegerFunc {
private int[] values;
public int[] getValues() {
return this.values;
}
public void setValues(final int[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestArrayIntegerNative {
public int[] values;
}
public class TestArrayNodeIntegerFunc {
private int[] values;
public int[] getValues() {
return this.values;
}
public void setValues(final int[] values) {
this.values = values;
}
}
public class TestArrayNodeIntegerNative {
public int[] values;
}
public class TestArrayNodeIntegerNativeStructured {
@AknotList(value = "elem")
public byte[] values;
}
@AknotDefaultAttribute
public class TestIntegerNative {
public int valueA;
public int valueB;
}
@AknotDefaultAttribute
public class TestintFunc {
private int valueA;
private int valueB;
public int getValueA() {
return this.valueA;
}
public int getValueB() {
return this.valueB;
}
public void setValueA(final int valueA) {
this.valueA = valueA;
}
public void setValueB(final int valueB) {
this.valueB = valueB;
}
}
public class TestNodeIntegerNative {
public int valueA;
public int valueB;
}
public class TestNodeintFunc {
private int valueA;
private int valueB;
public int getValueA() {
return this.valueA;
}
public int getValueB() {
return this.valueB;
}
public void setValueA(final int valueA) {
this.valueA = valueA;
}
public void setValueB(final int valueB) {
this.valueB = valueB;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeIntegerNativeStructured() {
final TestArrayNodeIntegerNativeStructured elem = new TestArrayNodeIntegerNativeStructured();
elem.values = new byte[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeIntegerNativeStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeIntegerNativeStructured>""", dataTest);
final TestArrayNodeIntegerNativeStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeIntegerNativeStructured.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((byte) 12, root.values[0]);
Assertions.assertEquals((byte) -13, root.values[1]);
Assertions.assertEquals((byte) 33, root.values[2]);
Assertions.assertEquals((byte) 78, root.values[3]);
Assertions.assertEquals((byte) -127, root.values[4]);
}
@Test
public void testModelArrayIntegerFunc() {
final TestArrayIntegerFunc elem = new TestArrayIntegerFunc();
elem.setValues(new int[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayIntegerFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayIntegerFunc.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayIntegerNative() {
final TestArrayIntegerNative elem = new TestArrayIntegerNative();
elem.values = new int[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayIntegerNative values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayIntegerNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayIntegerNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelArrayNodeIntegerFunc() {
final TestArrayNodeIntegerFunc elem = new TestArrayNodeIntegerFunc();
elem.setValues(new int[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeIntegerFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeIntegerFunc>""", dataTest);
final TestArrayNodeIntegerFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeIntegerFunc.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals(12, root.getValues()[0]);
Assertions.assertEquals(-13, root.getValues()[1]);
Assertions.assertEquals(33, root.getValues()[2]);
Assertions.assertEquals(78, root.getValues()[3]);
Assertions.assertEquals(-127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeintNative() {
final TestArrayNodeIntegerNative elem = new TestArrayNodeIntegerNative();
elem.values = new int[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeIntegerNative>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeIntegerNative>""", dataTest);
final TestArrayNodeIntegerNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeIntegerNative.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals(12, root.values[0]);
Assertions.assertEquals(-13, root.values[1]);
Assertions.assertEquals(33, root.values[2]);
Assertions.assertEquals(78, root.values[3]);
Assertions.assertEquals(-127, root.values[4]);
}
@Test
public void testModelIntegerFunc() {
final TestintFunc elem = new TestintFunc();
elem.setValueA(-55);
elem.setValueB(57);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestintFunc valueA=\"-55\" valueB=\"57\"/>", dataTest);
final TestintFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestintFunc.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(-55, root.getValueA());
Assertions.assertEquals(57, root.getValueB());
}
@Test
public void testModelIntegerNative() {
final TestIntegerNative elem = new TestIntegerNative();
elem.valueA = 12;
elem.valueB = -13;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestIntegerNative valueA=\"12\" valueB=\"-13\"/>", dataTest);
final TestIntegerNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestIntegerNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(12, root.valueA);
Assertions.assertEquals(-13, root.valueB);
}
@Test
public void testModelNodeIntegerFunc() {
final TestNodeintFunc elem = new TestNodeintFunc();
elem.setValueA(54);
elem.setValueB(-68);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeintFunc>
<valueA>54</valueA>
<valueB>-68</valueB>
</TestNodeintFunc>""", dataTest);
final TestNodeintFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeintFunc.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(54, root.getValueA());
Assertions.assertEquals(-68, root.getValueB());
}
@Test
public void testModelNodeIntegerNative() {
final TestNodeIntegerNative elem = new TestNodeIntegerNative();
elem.valueA = 11;
elem.valueB = -120;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeIntegerNative>
<valueA>11</valueA>
<valueB>-120</valueB>
</TestNodeIntegerNative>""", dataTest);
final TestNodeIntegerNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeIntegerNative.class);
});
Assertions.assertNotNull(root);
Assertions.assertEquals(11, root.valueA);
Assertions.assertEquals(-120, root.valueB);
}
}

View File

@ -0,0 +1,450 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionObject {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionObject.class);
public class SimpleObject {
@AknotAttribute
public int value1;
public float value2;
}
public class TestArrayNodeObject {
public SimpleObject[] values;
}
public class TestArrayNodeObjectFunc {
private SimpleObject[] values;
public SimpleObject[] getValues() {
return this.values;
}
public void setValues(final SimpleObject[] values) {
this.values = values;
}
}
public class TestArrayNodeStructuredObjectFunc {
private SimpleObject[] values;
@AknotList(value = "elem")
public SimpleObject[] getValues() {
return this.values;
}
public void setValues(final SimpleObject[] values) {
this.values = values;
}
}
public class TestListNodeObject {
public List<SimpleObject> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeObjectFunc {
private List<SimpleObject> values;
public List<SimpleObject> getValues() {
return this.values;
}
public void setValues(final List<SimpleObject> values) {
this.values = values;
}
}
// Note this is set in static to test an other part of code...
public static class TestListNodeStructuredObjectFunc {
private List<SimpleObject> values;
@AknotList(value = "elem")
public List<SimpleObject> getValues() {
return this.values;
}
public void setValues(final List<SimpleObject> values) {
this.values = values;
}
}
public class TestNodeObject {
public SimpleObject valueA;
public SimpleObject valueB;
}
public class TestNodeObjectFunc {
private SimpleObject valueA;
private SimpleObject valueB;
public SimpleObject getValueA() {
return this.valueA;
}
public SimpleObject getValueB() {
return this.valueB;
}
public void setValueA(final SimpleObject valueA) {
this.valueA = valueA;
}
public void setValueB(final SimpleObject valueB) {
this.valueB = valueB;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testModelArrayNodeObject() {
final TestArrayNodeObject elem = new TestArrayNodeObject();
elem.values = new SimpleObject[] { new SimpleObject(), new SimpleObject(), new SimpleObject() };
elem.values[0].value1 = 55;
elem.values[0].value2 = 12568.0f;
elem.values[1].value1 = 77;
elem.values[1].value2 = 15.0f;
elem.values[2].value1 = 152654;
elem.values[2].value2 = -75.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeObject>
<values value1="55">
<value2>12568.0</value2>
</values>
<values value1="77">
<value2>15.0</value2>
</values>
<values value1="152654">
<value2>-75.0</value2>
</values>
</TestArrayNodeObject>""", dataTest);
final TestArrayNodeObject root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeObject.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(3, root.values.length);
Assertions.assertEquals(55, root.values[0].value1);
Assertions.assertEquals(12568.0f, root.values[0].value2);
Assertions.assertEquals(77, root.values[1].value1);
Assertions.assertEquals(15.0f, root.values[1].value2);
Assertions.assertEquals(152654, root.values[2].value1);
Assertions.assertEquals(-75.0f, root.values[2].value2);
}
@Test
public void testModelArrayNodeObjectFunc() {
final TestArrayNodeObjectFunc elem = new TestArrayNodeObjectFunc();
elem.setValues(new SimpleObject[] { new SimpleObject(), new SimpleObject(), new SimpleObject() });
elem.getValues()[0].value1 = 55;
elem.getValues()[0].value2 = 12568.0f;
elem.getValues()[1].value1 = 77;
elem.getValues()[1].value2 = 15.0f;
elem.getValues()[2].value1 = 152654;
elem.getValues()[2].value2 = -75.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeObjectFunc>
<values value1="55">
<value2>12568.0</value2>
</values>
<values value1="77">
<value2>15.0</value2>
</values>
<values value1="152654">
<value2>-75.0</value2>
</values>
</TestArrayNodeObjectFunc>""", dataTest);
final TestArrayNodeObjectFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeObjectFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(3, root.getValues().length);
Assertions.assertEquals(55, root.getValues()[0].value1);
Assertions.assertEquals(12568.0f, root.getValues()[0].value2);
Assertions.assertEquals(77, root.getValues()[1].value1);
Assertions.assertEquals(15.0f, root.getValues()[1].value2);
Assertions.assertEquals(152654, root.getValues()[2].value1);
Assertions.assertEquals(-75.0f, root.getValues()[2].value2);
}
@Test
public void testModelArrayNodeStructuredObjectFunc() {
final TestArrayNodeStructuredObjectFunc elem = new TestArrayNodeStructuredObjectFunc();
elem.setValues(new SimpleObject[] { new SimpleObject(), new SimpleObject(), new SimpleObject() });
elem.getValues()[0].value1 = 55;
elem.getValues()[0].value2 = 12568.0f;
elem.getValues()[1].value1 = 77;
elem.getValues()[1].value2 = 15.0f;
elem.getValues()[2].value1 = 152654;
elem.getValues()[2].value2 = -75.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeStructuredObjectFunc>
<values>
<elem value1="55">
<value2>12568.0</value2>
</elem>
<elem value1="77">
<value2>15.0</value2>
</elem>
<elem value1="152654">
<value2>-75.0</value2>
</elem>
</values>
</TestArrayNodeStructuredObjectFunc>""", dataTest);
final TestArrayNodeStructuredObjectFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeStructuredObjectFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(3, root.getValues().length);
Assertions.assertEquals(55, root.getValues()[0].value1);
Assertions.assertEquals(12568.0f, root.getValues()[0].value2);
Assertions.assertEquals(77, root.getValues()[1].value1);
Assertions.assertEquals(15.0f, root.getValues()[1].value2);
Assertions.assertEquals(152654, root.getValues()[2].value1);
Assertions.assertEquals(-75.0f, root.getValues()[2].value2);
}
@Test
public void testModelListNodeObject() {
final TestListNodeObject elem = new TestListNodeObject();
elem.values = List.of(new SimpleObject(), new SimpleObject(), new SimpleObject());
elem.values.get(0).value1 = 55;
elem.values.get(0).value2 = 12568.0f;
elem.values.get(1).value1 = 77;
elem.values.get(1).value2 = 15.0f;
elem.values.get(2).value1 = 152654;
elem.values.get(2).value2 = -75.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeObject>
<values value1="55">
<value2>12568.0</value2>
</values>
<values value1="77">
<value2>15.0</value2>
</values>
<values value1="152654">
<value2>-75.0</value2>
</values>
</TestListNodeObject>""", dataTest);
final TestListNodeObject root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeObject.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(3, root.values.size());
Assertions.assertEquals(55, root.values.get(0).value1);
Assertions.assertEquals(12568.0f, root.values.get(0).value2);
Assertions.assertEquals(77, root.values.get(1).value1);
Assertions.assertEquals(15.0f, root.values.get(1).value2);
Assertions.assertEquals(152654, root.values.get(2).value1);
Assertions.assertEquals(-75.0f, root.values.get(2).value2);
}
@Test
public void testModelListNodeObjectFunc() {
final TestListNodeObjectFunc elem = new TestListNodeObjectFunc();
elem.values = List.of(new SimpleObject(), new SimpleObject(), new SimpleObject());
elem.getValues().get(0).value1 = 55;
elem.getValues().get(0).value2 = 12568.0f;
elem.getValues().get(1).value1 = 77;
elem.getValues().get(1).value2 = 15.0f;
elem.getValues().get(2).value1 = 152654;
elem.getValues().get(2).value2 = -75.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeObjectFunc>
<values value1="55">
<value2>12568.0</value2>
</values>
<values value1="77">
<value2>15.0</value2>
</values>
<values value1="152654">
<value2>-75.0</value2>
</values>
</TestListNodeObjectFunc>""", dataTest);
final TestListNodeObjectFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeObjectFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(3, root.getValues().size());
Assertions.assertEquals(55, root.getValues().get(0).value1);
Assertions.assertEquals(12568.0f, root.getValues().get(0).value2);
Assertions.assertEquals(77, root.getValues().get(1).value1);
Assertions.assertEquals(15.0f, root.getValues().get(1).value2);
Assertions.assertEquals(152654, root.getValues().get(2).value1);
Assertions.assertEquals(-75.0f, root.getValues().get(2).value2);
}
@Test
public void testModelListNodeStructuredObjectFunc() {
final TestListNodeStructuredObjectFunc elem = new TestListNodeStructuredObjectFunc();
elem.values = List.of(new SimpleObject(), new SimpleObject(), new SimpleObject());
elem.getValues().get(0).value1 = 55;
elem.getValues().get(0).value2 = 12568.0f;
elem.getValues().get(1).value1 = 77;
elem.getValues().get(1).value2 = 15.0f;
elem.getValues().get(2).value1 = 152654;
elem.getValues().get(2).value2 = -75.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeStructuredObjectFunc>
<values>
<elem value1="55">
<value2>12568.0</value2>
</elem>
<elem value1="77">
<value2>15.0</value2>
</elem>
<elem value1="152654">
<value2>-75.0</value2>
</elem>
</values>
</TestListNodeStructuredObjectFunc>""", dataTest);
final TestListNodeStructuredObjectFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeStructuredObjectFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(3, root.getValues().size());
Assertions.assertEquals(55, root.getValues().get(0).value1);
Assertions.assertEquals(12568.0f, root.getValues().get(0).value2);
Assertions.assertEquals(77, root.getValues().get(1).value1);
Assertions.assertEquals(15.0f, root.getValues().get(1).value2);
Assertions.assertEquals(152654, root.getValues().get(2).value1);
Assertions.assertEquals(-75.0f, root.getValues().get(2).value2);
}
@Test
public void testModelNodeObject() {
final TestNodeObject elem = new TestNodeObject();
elem.valueA = new SimpleObject();
elem.valueA.value1 = 55;
elem.valueA.value2 = 12568.0f;
elem.valueB = new SimpleObject();
elem.valueB.value1 = -55;
elem.valueB.value2 = -12568.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeObject>
<valueA value1="55">
<value2>12568.0</value2>
</valueA>
<valueB value1="-55">
<value2>-12568.0</value2>
</valueB>
</TestNodeObject>""", dataTest);
final TestNodeObject root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObject.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(55, root.valueA.value1);
Assertions.assertEquals(12568.0f, root.valueA.value2);
Assertions.assertEquals(-55, root.valueB.value1);
Assertions.assertEquals(-12568.0f, root.valueB.value2);
}
@Test
public void testModelNodeObjectFunc() {
final TestNodeObjectFunc elem = new TestNodeObjectFunc();
elem.setValueA(new SimpleObject());
elem.getValueA().value1 = 4564;
elem.getValueA().value2 = 152.0f;
elem.setValueB(new SimpleObject());
elem.getValueB().value1 = 454564;
elem.getValueB().value2 = 85422.0f;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeObjectFunc>
<valueA value1="4564">
<value2>152.0</value2>
</valueA>
<valueB value1="454564">
<value2>85422.0</value2>
</valueB>
</TestNodeObjectFunc>""", dataTest);
final TestNodeObjectFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeObjectFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(4564, root.getValueA().value1);
Assertions.assertEquals(152.0f, root.getValueA().value2);
Assertions.assertEquals(454564, root.getValueB().value1);
Assertions.assertEquals(85422.0f, root.getValueB().value2);
}
}

View File

@ -0,0 +1,126 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotAttribute;
import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionObjectConstructor {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionObjectConstructor.class);
public class TestConstructorSpecific {
@AknotAttribute
public Integer valueA;
public double valueB;
@AknotName({ "valueA", "valueB" })
public TestConstructorSpecific(final Integer valueA, final double valueB) {
this.valueA = valueA;
this.valueB = valueB;
}
}
public class TestConstructorSpecificParameter {
@AknotAttribute
public Integer valueA;
public double valueB;
public TestConstructorSpecificParameter(@AknotName("valueA") final Integer valueA, @AknotName("valueB") final double valueB) {
this.valueA = valueA;
this.valueB = valueB;
}
}
public class TestMultiConstructor {
@AknotAttribute
public Integer valueA;
public double valueB;
public TestMultiConstructor() {}
public TestMultiConstructor(final Integer valueA, final double valueB) {
this.valueA = valueA;
this.valueB = valueB;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testModelConstructorSpecific() {
final TestConstructorSpecific elem = new TestConstructorSpecific(66, 18523.0);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestConstructorSpecific valueA="66">
<valueB>18523.0</valueB>
</TestConstructorSpecific>""", dataTest);
final TestConstructorSpecific root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestConstructorSpecific.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(66, root.valueA);
Assertions.assertEquals(18523.0f, root.valueB);
}
@Test
public void testModelConstructorSpecificParameter() {
final TestConstructorSpecificParameter elem = new TestConstructorSpecificParameter(66, 18523.0);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestConstructorSpecificParameter valueA="66">
<valueB>18523.0</valueB>
</TestConstructorSpecificParameter>""", dataTest);
final TestConstructorSpecificParameter root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestConstructorSpecificParameter.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(66, root.valueA);
Assertions.assertEquals(18523.0f, root.valueB);
}
@Test
public void testModelMultiConstructor() {
final TestMultiConstructor elem = new TestMultiConstructor(66, 18523.0);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestMultiConstructor valueA="66">
<valueB>18523.0</valueB>
</TestMultiConstructor>""", dataTest);
final TestMultiConstructor root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestMultiConstructor.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(66, root.valueA);
Assertions.assertEquals(18523.0f, root.valueB);
}
}

View File

@ -0,0 +1,76 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotAttribute;
import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionRecord {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionRecord.class);
public record TestRecord(
@AknotName("valueA") Integer valueA,
@AknotName("valueB") double valueB) {}
public record TestRecordProperty(
@AknotName("valueA") @AknotAttribute Integer valueA,
@AknotName("valueB") @AknotAttribute double valueB) {}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testModelRecord() {
final TestRecord elem = new TestRecord(66, 18523.0);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestRecord>
<valueA>66</valueA>
<valueB>18523.0</valueB>
</TestRecord>""", dataTest);
final TestRecord root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestRecord.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(66, root.valueA);
Assertions.assertEquals(18523.0f, root.valueB);
}
@Test
public void testModelRecordProperty() {
final TestRecordProperty elem = new TestRecordProperty(66, 18523.0);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestRecordProperty valueA=\"66\" valueB=\"18523.0\"/>", dataTest);
final TestRecordProperty root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestRecordProperty.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(66, root.valueA);
Assertions.assertEquals(18523.0f, root.valueB);
}
}

View File

@ -0,0 +1,570 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionShort {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionShort.class);
public class TestArrayNodeShort {
public Short[] values;
}
public class TestArrayNodeShortFunc {
private Short[] values;
public Short[] getValues() {
return this.values;
}
public void setValues(final Short[] values) {
this.values = values;
}
}
public class TestArrayNodeShortStructured {
@AknotList(value = "elem")
public Short[] values;
}
@AknotDefaultAttribute
public class TestArrayShort {
public Short[] values;
}
@AknotDefaultAttribute
public class TestArrayShortFunc {
private Short[] values;
public Short[] getValues() {
return this.values;
}
public void setValues(final Short[] values) {
this.values = values;
}
}
public class TestListNodeShort {
public List<Short> values;
}
// Note this is set in static to test an other part of code...
public static class TestListNodeShortFunc {
private List<Short> values;
public List<Short> getValues() {
return this.values;
}
public void setValues(final List<Short> values) {
this.values = values;
}
}
public class TestListNodeShortStructured {
@AknotList(value = "elem")
public List<Short> values;
}
@AknotDefaultAttribute
public class TestListShort {
public List<Short> values;
}
@AknotDefaultAttribute
public class TestListShortFunc {
private List<Short> values;
public List<Short> getValues() {
return this.values;
}
public void setValues(final List<Short> values) {
this.values = values;
}
}
public class TestNodeShort {
public Short valueA;
public Short valueB;
public Short valueNull;
}
public class TestNodeShortFunc {
private Short valueA;
private Short valueB;
private Short valueNull;
public Short getValueA() {
return this.valueA;
}
public Short getValueB() {
return this.valueB;
}
public Short getValueNull() {
return this.valueNull;
}
public void setValueA(final Short valueA) {
this.valueA = valueA;
}
public void setValueB(final Short valueB) {
this.valueB = valueB;
}
public void setValueNull(final Short valueNull) {
this.valueNull = valueNull;
}
}
@AknotDefaultAttribute
public class TestShort {
public Short valueA;
public Short valueB;
public Short valueNull;
}
@AknotDefaultAttribute
public class TestShortFunc {
private Short valueA;
private Short valueB;
private Short valueNull;
public Short getValueA() {
return this.valueA;
}
public Short getValueB() {
return this.valueB;
}
public Short getValueNull() {
return this.valueNull;
}
public void setValueA(final Short valueA) {
this.valueA = valueA;
}
public void setValueB(final Short valueB) {
this.valueB = valueB;
}
public void setValueNull(final Short valueNull) {
this.valueNull = valueNull;
}
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeShortStructured() {
final TestArrayNodeShortStructured elem = new TestArrayNodeShortStructured();
elem.values = new Short[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeShortStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeShortStructured>""", dataTest);
final TestArrayNodeShortStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeShortStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((short) 12, root.values[0]);
Assertions.assertEquals((short) -13, root.values[1]);
Assertions.assertEquals((short) 33, root.values[2]);
Assertions.assertEquals((short) 78, root.values[3]);
Assertions.assertEquals((short) -127, root.values[4]);
}
@Test
public void testListNodeShortStructured() {
final TestListNodeShortStructured elem = new TestListNodeShortStructured();
elem.values = List.of((short) 12, (short) -13, (short) 33, (short) 78, (short) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeShortStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestListNodeShortStructured>""", dataTest);
final TestListNodeShortStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeShortStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals((short) 12, root.values.get(0));
Assertions.assertEquals((short) -13, root.values.get(1));
Assertions.assertEquals((short) 33, root.values.get(2));
Assertions.assertEquals((short) 78, root.values.get(3));
Assertions.assertEquals((short) -127, root.values.get(4));
}
@Test
public void testModelArrayNodeShort() {
final TestArrayNodeShort elem = new TestArrayNodeShort();
elem.values = new Short[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeShort>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeShort>""", dataTest);
final TestArrayNodeShort root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeShort.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((short) 12, root.values[0]);
Assertions.assertEquals((short) -13, root.values[1]);
Assertions.assertEquals((short) 33, root.values[2]);
Assertions.assertEquals((short) 78, root.values[3]);
Assertions.assertEquals((short) -127, root.values[4]);
}
@Test
public void testModelArrayNodeShortFunc() {
final TestArrayNodeShortFunc elem = new TestArrayNodeShortFunc();
elem.setValues(new Short[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeShortFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeShortFunc>""", dataTest);
final TestArrayNodeShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((short) 12, root.getValues()[0]);
Assertions.assertEquals((short) -13, root.getValues()[1]);
Assertions.assertEquals((short) 33, root.getValues()[2]);
Assertions.assertEquals((short) 78, root.getValues()[3]);
Assertions.assertEquals((short) -127, root.getValues()[4]);
}
@Test
public void testModelArrayShort() {
final TestArrayShort elem = new TestArrayShort();
elem.values = new Short[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayShort values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayShort root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayShort.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((short) 12, root.values[0]);
Assertions.assertEquals((short) -13, root.values[1]);
Assertions.assertEquals((short) 33, root.values[2]);
Assertions.assertEquals((short) 78, root.values[3]);
Assertions.assertEquals((short) -127, root.values[4]);
}
@Test
public void testModelArrayShortFunc() {
final TestArrayShortFunc elem = new TestArrayShortFunc();
elem.setValues(new Short[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayShortFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((short) 12, root.getValues()[0]);
Assertions.assertEquals((short) -13, root.getValues()[1]);
Assertions.assertEquals((short) 33, root.getValues()[2]);
Assertions.assertEquals((short) 78, root.getValues()[3]);
Assertions.assertEquals((short) -127, root.getValues()[4]);
}
@Test
public void testModelListNodeShort() {
final TestListNodeShort elem = new TestListNodeShort();
elem.values = List.of((short) 12, (short) -13, (short) 33, (short) 78, (short) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeShort>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestListNodeShort>""", dataTest);
final TestListNodeShort root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeShort.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals((short) 12, root.values.get(0));
Assertions.assertEquals((short) -13, root.values.get(1));
Assertions.assertEquals((short) 33, root.values.get(2));
Assertions.assertEquals((short) 78, root.values.get(3));
Assertions.assertEquals((short) -127, root.values.get(4));
}
@Test
public void testModelListNodeShortFunc() {
final TestListNodeShortFunc elem = new TestListNodeShortFunc();
elem.setValues(List.of((short) 12, (short) -13, (short) 33, (short) 78, (short) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestListNodeShortFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestListNodeShortFunc>""", dataTest);
final TestListNodeShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListNodeShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals((short) 12, root.getValues().get(0));
Assertions.assertEquals((short) -13, root.getValues().get(1));
Assertions.assertEquals((short) 33, root.getValues().get(2));
Assertions.assertEquals((short) 78, root.getValues().get(3));
Assertions.assertEquals((short) -127, root.getValues().get(4));
}
@Test
public void testModelListShort() {
final TestListShort elem = new TestListShort();
elem.values = List.of((short) 12, (short) -13, (short) 33, (short) 78, (short) -127);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListShort values=\"12;-13;33;78;-127\"/>", dataTest);
final TestListShort root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListShort.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.size());
Assertions.assertEquals((short) 12, root.values.get(0));
Assertions.assertEquals((short) -13, root.values.get(1));
Assertions.assertEquals((short) 33, root.values.get(2));
Assertions.assertEquals((short) 78, root.values.get(3));
Assertions.assertEquals((short) -127, root.values.get(4));
}
@Test
public void testModelListShortFunc() {
final TestListShortFunc elem = new TestListShortFunc();
elem.setValues(List.of((short) 12, (short) -13, (short) 33, (short) 78, (short) -127));
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestListShortFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestListShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestListShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().size());
Assertions.assertEquals((short) 12, root.getValues().get(0));
Assertions.assertEquals((short) -13, root.getValues().get(1));
Assertions.assertEquals((short) 33, root.getValues().get(2));
Assertions.assertEquals((short) 78, root.getValues().get(3));
Assertions.assertEquals((short) -127, root.getValues().get(4));
}
@Test
public void testModelNodeShort() {
final TestNodeShort elem = new TestNodeShort();
elem.valueA = (short) 11;
elem.valueB = (short) -120;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeShort>
<valueA>11</valueA>
<valueB>-120</valueB>
</TestNodeShort>""", dataTest);
final TestNodeShort root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeShort.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) 11, root.valueA);
Assertions.assertEquals((short) -120, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelNodeShortFunc() {
final TestNodeShortFunc elem = new TestNodeShortFunc();
elem.setValueA((short) 54);
elem.setValueB((short) -68);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeShortFunc>
<valueA>54</valueA>
<valueB>-68</valueB>
</TestNodeShortFunc>""", dataTest);
final TestNodeShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) 54, root.getValueA());
Assertions.assertEquals((short) -68, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
@Test
public void testModelShort() {
final TestShort elem = new TestShort();
elem.valueA = (short) 12;
elem.valueB = (short) -13;
elem.valueNull = null;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestShort valueA=\"12\" valueB=\"-13\"/>", dataTest);
final TestShort root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestShort.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) 12, root.valueA);
Assertions.assertEquals((short) -13, root.valueB);
Assertions.assertEquals(null, root.valueNull);
}
@Test
public void testModelShortFunc() {
final TestShortFunc elem = new TestShortFunc();
elem.setValueA((short) -55);
elem.setValueB((short) 57);
elem.setValueNull(null);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestShortFunc valueA=\"-55\" valueB=\"57\"/>", dataTest);
final TestShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) -55, root.getValueA());
Assertions.assertEquals((short) 57, root.getValueB());
Assertions.assertEquals(null, root.getValueNull());
}
}

View File

@ -0,0 +1,357 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml.introspection;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.exml.XmlMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestExmlIntrospectionShortNative {
final static Logger LOGGER = LoggerFactory.getLogger(TestExmlIntrospectionShortNative.class);
public class TestArrayNodeShortFunc {
private short[] values;
public short[] getValues() {
return this.values;
}
public void setValues(final short[] values) {
this.values = values;
}
}
public class TestArrayNodeShortNative {
public short[] values;
}
public class TestArrayNodeShortNativeStructured {
@AknotList(value = "elem")
public short[] values;
}
@AknotDefaultAttribute
public class TestArrayShortFunc {
private short[] values;
public short[] getValues() {
return this.values;
}
public void setValues(final short[] values) {
this.values = values;
}
}
@AknotDefaultAttribute
public class TestArrayShortNative {
public short[] values;
}
public class TestNodeshortFunc {
private short valueA;
private short valueB;
public short getValueA() {
return this.valueA;
}
public short getValueB() {
return this.valueB;
}
public void setValueA(final short valueA) {
this.valueA = valueA;
}
public void setValueB(final short valueB) {
this.valueB = valueB;
}
}
public class TestNodeShortNative {
public short valueA;
public short valueB;
}
@AknotDefaultAttribute
public class TestshortFunc {
private short valueA;
private short valueB;
public short getValueA() {
return this.valueA;
}
public short getValueB() {
return this.valueB;
}
public void setValueA(final short valueA) {
this.valueA = valueA;
}
public void setValueB(final short valueB) {
this.valueB = valueB;
}
}
@AknotDefaultAttribute
public class TestShortNative {
public short valueA;
public short valueB;
}
static final String NODE_NAME = "elem";
@BeforeAll
public static void beforeClass() {
LOGGER.warn("================================================================");
}
@Test
public void testArrayNodeShortNativeStructured() {
final TestArrayNodeShortNativeStructured elem = new TestArrayNodeShortNativeStructured();
elem.values = new short[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeShortNativeStructured>
<values>
<elem>12</elem>
<elem>-13</elem>
<elem>33</elem>
<elem>78</elem>
<elem>-127</elem>
</values>
</TestArrayNodeShortNativeStructured>""", dataTest);
final TestArrayNodeShortNativeStructured root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeShortNativeStructured.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((short) 12, root.values[0]);
Assertions.assertEquals((short) -13, root.values[1]);
Assertions.assertEquals((short) 33, root.values[2]);
Assertions.assertEquals((short) 78, root.values[3]);
Assertions.assertEquals((short) -127, root.values[4]);
}
@Test
public void testModelArrayNodeShortFunc() {
final TestArrayNodeShortFunc elem = new TestArrayNodeShortFunc();
elem.setValues(new short[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeShortFunc>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeShortFunc>""", dataTest);
final TestArrayNodeShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((short) 12, root.getValues()[0]);
Assertions.assertEquals((short) -13, root.getValues()[1]);
Assertions.assertEquals((short) 33, root.getValues()[2]);
Assertions.assertEquals((short) 78, root.getValues()[3]);
Assertions.assertEquals((short) -127, root.getValues()[4]);
}
@Test
public void testModelArrayNodeshortNative() {
final TestArrayNodeShortNative elem = new TestArrayNodeShortNative();
elem.values = new short[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestArrayNodeShortNative>
<values>12</values>
<values>-13</values>
<values>33</values>
<values>78</values>
<values>-127</values>
</TestArrayNodeShortNative>""", dataTest);
final TestArrayNodeShortNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayNodeShortNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((short) 12, root.values[0]);
Assertions.assertEquals((short) -13, root.values[1]);
Assertions.assertEquals((short) 33, root.values[2]);
Assertions.assertEquals((short) 78, root.values[3]);
Assertions.assertEquals((short) -127, root.values[4]);
}
@Test
public void testModelArrayShortFunc() {
final TestArrayShortFunc elem = new TestArrayShortFunc();
elem.setValues(new short[] { 12, -13, 33, 78, -127 });
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayShortFunc values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayShortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayShortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.getValues().length);
Assertions.assertEquals((short) 12, root.getValues()[0]);
Assertions.assertEquals((short) -13, root.getValues()[1]);
Assertions.assertEquals((short) 33, root.getValues()[2]);
Assertions.assertEquals((short) 78, root.getValues()[3]);
Assertions.assertEquals((short) -127, root.getValues()[4]);
}
@Test
public void testModelArrayShortNative() {
final TestArrayShortNative elem = new TestArrayShortNative();
elem.values = new short[] { 12, -13, 33, 78, -127 };
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestArrayShortNative values=\"12;-13;33;78;-127\"/>", dataTest);
final TestArrayShortNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestArrayShortNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals(5, root.values.length);
Assertions.assertEquals((short) 12, root.values[0]);
Assertions.assertEquals((short) -13, root.values[1]);
Assertions.assertEquals((short) 33, root.values[2]);
Assertions.assertEquals((short) 78, root.values[3]);
Assertions.assertEquals((short) -127, root.values[4]);
}
@Test
public void testModelNodeShortFunc() {
final TestNodeshortFunc elem = new TestNodeshortFunc();
elem.setValueA((short) 54);
elem.setValueB((short) -68);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeshortFunc>
<valueA>54</valueA>
<valueB>-68</valueB>
</TestNodeshortFunc>""", dataTest);
final TestNodeshortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeshortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) 54, root.getValueA());
Assertions.assertEquals((short) -68, root.getValueB());
}
@Test
public void testModelNodeShortNative() {
final TestNodeShortNative elem = new TestNodeShortNative();
elem.valueA = (short) 11;
elem.valueB = (short) -120;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("""
<TestNodeShortNative>
<valueA>11</valueA>
<valueB>-120</valueB>
</TestNodeShortNative>""", dataTest);
final TestNodeShortNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestNodeShortNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) 11, root.valueA);
Assertions.assertEquals((short) -120, root.valueB);
}
@Test
public void testModelShortFunc() {
final TestshortFunc elem = new TestshortFunc();
elem.setValueA((short) -55);
elem.setValueB((short) 57);
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestshortFunc valueA=\"-55\" valueB=\"57\"/>", dataTest);
final TestshortFunc root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestshortFunc.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) -55, root.getValueA());
Assertions.assertEquals((short) 57, root.getValueB());
}
@Test
public void testModelShortNative() {
final TestShortNative elem = new TestShortNative();
elem.valueA = (short) 12;
elem.valueB = (short) -13;
final StringBuilder builder = new StringBuilder();
Assertions.assertDoesNotThrow(() -> (new XmlMapper()).generate(elem, builder));
final String dataTest = builder.toString();
LOGGER.warn("data generated: " + builder.toString());
Assertions.assertEquals("<TestShortNative valueA=\"12\" valueB=\"-13\"/>", dataTest);
final TestShortNative root = Assertions.assertDoesNotThrow(() -> {
final XmlMapper mapper = new XmlMapper();
return mapper.parse(dataTest, TestShortNative.class);
});
Assertions.assertNotNull(elem);
Assertions.assertEquals((short) 12, root.valueA);
Assertions.assertEquals((short) -13, root.valueB);
}
}

View File

@ -0,0 +1,8 @@
package test.atriasoft.exml.introspection.model;
import org.atriasoft.aknot.annotation.AknotDefaultManaged;
@AknotDefaultManaged(value = false)
public class ClassInversion {
}

View File

@ -0,0 +1,17 @@
package test.atriasoft.exml.introspection.model;
import org.atriasoft.aknot.annotation.AknotName;
@AknotName("elem")
public class ClassMethodEnum {
private SimpleEnum data;
public SimpleEnum getData() {
return this.data;
}
public void setData(final SimpleEnum data) {
this.data = data;
}
}

View File

@ -0,0 +1,31 @@
package test.atriasoft.exml.introspection.model;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotName;
@AknotDefaultAttribute
@AknotName("elem")
public class ClassPublicMemberOnly {
public boolean[] memberArrayBoolean;
public Boolean[] memberArrayBooleanClass;
public byte[] memberArrayByte;
public Byte[] memberArrayByteClass;
public int[] memberArrayInteger;
public Integer[] memberArrayIntegerClass;
public long[] memberArrayLong;
public Long[] memberArrayLongClass;
public short[] memberArrayShort;
public Short[] memberArrayShortClass;
public boolean memberBoolean;
public Boolean memberBooleanClass;
//this work !!! @AKName(value = "jhkjhhkj")
public byte memberByte;
public Byte memberByteClass;
public int memberInteger;
public Integer memberIntegerClass;
public long memberLong;
public Long memberLongClass;
public short memberShort;
public Short memberShortClass;
public String memberStringClass;
}

View File

@ -0,0 +1,198 @@
package test.atriasoft.exml.introspection.model;
import org.atriasoft.aknot.annotation.AknotDefaultAttribute;
import org.atriasoft.aknot.annotation.AknotName;
@AknotDefaultAttribute
@AknotName("elem")
public class ClassPublicMethodOnly {
private boolean[] memberArrayBoolean;
private Boolean[] memberArrayBooleanClass;
private byte[] memberArrayByte;
private Byte[] memberArrayByteClass;
private int[] memberArrayInteger;
private Integer[] memberArrayIntegerClass;
private long[] memberArrayLong;
private Long[] memberArrayLongClass;
private short[] memberArrayShort;
private Short[] memberArrayShortClass;
private boolean memberBoolean;
private Boolean memberBooleanClass;
private byte memberByte;
private Byte memberByteClass;
private int memberInteger;
private Integer memberIntegerClass;
private long memberLong;
private Long memberLongClass;
private short memberShort;
private Short memberShortClass;
private String memberStringClass;
public boolean[] getMemberArrayBoolean() {
return this.memberArrayBoolean;
}
public Boolean[] getMemberArrayBooleanClass() {
return this.memberArrayBooleanClass;
}
public byte[] getMemberArrayByte() {
return this.memberArrayByte;
}
public Byte[] getMemberArrayByteClass() {
return this.memberArrayByteClass;
}
public int[] getMemberArrayInteger() {
return this.memberArrayInteger;
}
public Integer[] getMemberArrayIntegerClass() {
return this.memberArrayIntegerClass;
}
public long[] getMemberArrayLong() {
return this.memberArrayLong;
}
public Long[] getMemberArrayLongClass() {
return this.memberArrayLongClass;
}
public short[] getMemberArrayShort() {
return this.memberArrayShort;
}
public Short[] getMemberArrayShortClass() {
return this.memberArrayShortClass;
}
public byte getMemberByte() {
return this.memberByte;
}
public Byte getMemberByteClass() {
return this.memberByteClass;
}
public int getMemberInteger() {
return this.memberInteger;
}
public Integer getMemberIntegerClass() {
return this.memberIntegerClass;
}
public long getMemberLong() {
return this.memberLong;
}
public Long getMemberLongClass() {
return this.memberLongClass;
}
public short getMemberShort() {
return this.memberShort;
}
public Short getMemberShortClass() {
return this.memberShortClass;
}
public String getMemberStringClass() {
return this.memberStringClass;
}
public boolean isMemberBoolean() {
return this.memberBoolean;
}
public Boolean isMemberBooleanClass() {
return this.memberBooleanClass;
}
public void setMemberArrayBoolean(final boolean[] memberArrayBoolean) {
this.memberArrayBoolean = memberArrayBoolean;
}
public void setMemberArrayBooleanClass(final Boolean[] memberArrayBooleanClass) {
this.memberArrayBooleanClass = memberArrayBooleanClass;
}
public void setMemberArrayByte(final byte[] memberArrayByte) {
this.memberArrayByte = memberArrayByte;
}
public void setMemberArrayByteClass(final Byte[] memberArrayByteClass) {
this.memberArrayByteClass = memberArrayByteClass;
}
public void setMemberArrayInteger(final int[] memberArrayInteger) {
this.memberArrayInteger = memberArrayInteger;
}
public void setMemberArrayIntegerClass(final Integer[] memberArrayIntegerClass) {
this.memberArrayIntegerClass = memberArrayIntegerClass;
}
public void setMemberArrayLong(final long[] memberArrayLong) {
this.memberArrayLong = memberArrayLong;
}
public void setMemberArrayLongClass(final Long[] memberArrayLongClass) {
this.memberArrayLongClass = memberArrayLongClass;
}
public void setMemberArrayShort(final short[] memberArrayShort) {
this.memberArrayShort = memberArrayShort;
}
public void setMemberArrayShortClass(final Short[] memberArrayShortClass) {
this.memberArrayShortClass = memberArrayShortClass;
}
public void setMemberBoolean(final boolean memberBoolean) {
this.memberBoolean = memberBoolean;
}
public void setMemberBooleanClass(final Boolean memberBooleanClass) {
this.memberBooleanClass = memberBooleanClass;
}
public void setMemberByte(final byte memberByte) {
this.memberByte = memberByte;
}
public void setMemberByteClass(final Byte memberByteClass) {
this.memberByteClass = memberByteClass;
}
public void setMemberInteger(final int memberInteger) {
this.memberInteger = memberInteger;
}
public void setMemberIntegerClass(final Integer memberIntegerClass) {
this.memberIntegerClass = memberIntegerClass;
}
public void setMemberLong(final long memberLong) {
this.memberLong = memberLong;
}
public void setMemberLongClass(final Long memberLongClass) {
this.memberLongClass = memberLongClass;
}
public void setMemberShort(final short memberShort) {
this.memberShort = memberShort;
}
public void setMemberShortClass(final Short memberShortClass) {
this.memberShortClass = memberShortClass;
}
public void setMemberStringClass(final String memberStringClass) {
this.memberStringClass = memberStringClass;
}
}

View File

@ -0,0 +1,248 @@
package test.atriasoft.exml.introspection.model;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotName;
@AknotName("elem")
public class ClassPublicMethodeNode {
private boolean[] memberArrayBoolean;
private Boolean[] memberArrayBooleanClass;
private byte[] memberArrayByte;
private Byte[] memberArrayByteClass;
private int[] memberArrayInteger;
private Integer[] memberArrayIntegerClass;
private long[] memberArrayLong;
private Long[] memberArrayLongClass;
private short[] memberArrayShort;
private Short[] memberArrayShortClass;
private List<Boolean> memberListBooleanClass;
private List<Byte> memberListByteClass;
private List<Integer> memberListIntegerClass;
private List<Long> memberListLongClass;
private List<Short> memberListShortClass;
private boolean memberBoolean;
private Boolean memberBooleanClass;
private byte memberByte;
private Byte memberByteClass;
private int memberInteger;
private Integer memberIntegerClass;
private long memberLong;
private Long memberLongClass;
private short memberShort;
private Short memberShortClass;
private String memberStringClass;
public boolean[] getMemberArrayBoolean() {
return this.memberArrayBoolean;
}
public Boolean[] getMemberArrayBooleanClass() {
return this.memberArrayBooleanClass;
}
public byte[] getMemberArrayByte() {
return this.memberArrayByte;
}
public Byte[] getMemberArrayByteClass() {
return this.memberArrayByteClass;
}
public int[] getMemberArrayInteger() {
return this.memberArrayInteger;
}
public Integer[] getMemberArrayIntegerClass() {
return this.memberArrayIntegerClass;
}
public long[] getMemberArrayLong() {
return this.memberArrayLong;
}
public Long[] getMemberArrayLongClass() {
return this.memberArrayLongClass;
}
public short[] getMemberArrayShort() {
return this.memberArrayShort;
}
public Short[] getMemberArrayShortClass() {
return this.memberArrayShortClass;
}
public Boolean getMemberBooleanClass() {
return this.memberBooleanClass;
}
public byte getMemberByte() {
return this.memberByte;
}
public Byte getMemberByteClass() {
return this.memberByteClass;
}
public int getMemberInteger() {
return this.memberInteger;
}
public Integer getMemberIntegerClass() {
return this.memberIntegerClass;
}
public List<Boolean> getMemberListBooleanClass() {
return this.memberListBooleanClass;
}
public List<Byte> getMemberListByteClass() {
return this.memberListByteClass;
}
public List<Integer> getMemberListIntegerClass() {
return this.memberListIntegerClass;
}
public List<Long> getMemberListLongClass() {
return this.memberListLongClass;
}
public List<Short> getMemberListShortClass() {
return this.memberListShortClass;
}
public long getMemberLong() {
return this.memberLong;
}
public Long getMemberLongClass() {
return this.memberLongClass;
}
public short getMemberShort() {
return this.memberShort;
}
public Short getMemberShortClass() {
return this.memberShortClass;
}
public String getMemberStringClass() {
return this.memberStringClass;
}
public boolean isMemberBoolean() {
return this.memberBoolean;
}
public Boolean isMemberBooleanClass() {
return this.memberBooleanClass;
}
public void setMemberArrayBoolean(final boolean[] memberArrayBoolean) {
this.memberArrayBoolean = memberArrayBoolean;
}
public void setMemberArrayBooleanClass(final Boolean[] memberArrayBooleanClass) {
this.memberArrayBooleanClass = memberArrayBooleanClass;
}
public void setMemberArrayByte(final byte[] memberArrayByte) {
this.memberArrayByte = memberArrayByte;
}
public void setMemberArrayByteClass(final Byte[] memberArrayByteClass) {
this.memberArrayByteClass = memberArrayByteClass;
}
public void setMemberArrayInteger(final int[] memberArrayInteger) {
this.memberArrayInteger = memberArrayInteger;
}
public void setMemberArrayIntegerClass(final Integer[] memberArrayIntegerClass) {
this.memberArrayIntegerClass = memberArrayIntegerClass;
}
public void setMemberArrayLong(final long[] memberArrayLong) {
this.memberArrayLong = memberArrayLong;
}
public void setMemberArrayLongClass(final Long[] memberArrayLongClass) {
this.memberArrayLongClass = memberArrayLongClass;
}
public void setMemberArrayShort(final short[] memberArrayShort) {
this.memberArrayShort = memberArrayShort;
}
public void setMemberArrayShortClass(final Short[] memberArrayShortClass) {
this.memberArrayShortClass = memberArrayShortClass;
}
public void setMemberBoolean(final boolean memberBoolean) {
this.memberBoolean = memberBoolean;
}
public void setMemberBooleanClass(final Boolean memberBooleanClass) {
this.memberBooleanClass = memberBooleanClass;
}
public void setMemberByte(final byte memberByte) {
this.memberByte = memberByte;
}
public void setMemberByteClass(final Byte memberByteClass) {
this.memberByteClass = memberByteClass;
}
public void setMemberInteger(final int memberInteger) {
this.memberInteger = memberInteger;
}
public void setMemberIntegerClass(final Integer memberIntegerClass) {
this.memberIntegerClass = memberIntegerClass;
}
public void setMemberListBooleanClass(final List<Boolean> memberListBooleanClass) {
this.memberListBooleanClass = memberListBooleanClass;
}
public void setMemberListByteClass(final List<Byte> memberListByteClass) {
this.memberListByteClass = memberListByteClass;
}
public void setMemberListIntegerClass(final List<Integer> memberListIntegerClass) {
this.memberListIntegerClass = memberListIntegerClass;
}
public void setMemberListLongClass(final List<Long> memberListLongClass) {
this.memberListLongClass = memberListLongClass;
}
public void setMemberListShortClass(final List<Short> memberListShortClass) {
this.memberListShortClass = memberListShortClass;
}
public void setMemberLong(final long memberLong) {
this.memberLong = memberLong;
}
public void setMemberLongClass(final Long memberLongClass) {
this.memberLongClass = memberLongClass;
}
public void setMemberShort(final short memberShort) {
this.memberShort = memberShort;
}
public void setMemberShortClass(final Short memberShortClass) {
this.memberShortClass = memberShortClass;
}
public void setMemberStringClass(final String memberStringClass) {
this.memberStringClass = memberStringClass;
}
}

View File

@ -0,0 +1,32 @@
package test.atriasoft.exml.introspection.model;
import java.util.List;
import org.atriasoft.aknot.annotation.AknotList;
import org.atriasoft.aknot.annotation.AknotName;
@AknotName("elem")
public class ClassPublicMethodeStructured {
// note: when private the decorator must be set on getter or setter, liker this you can use the internal name you want...
private byte[] memberArrayByte;
private List<Byte> memberListByte;
@AknotList(value = "value")
public byte[] getMemberArrayByte() {
return this.memberArrayByte;
}
@AknotList(value = "elem")
public List<Byte> getMemberListByte() {
return this.memberListByte;
}
public void setMemberArrayByte(final byte[] memberArrayByte) {
this.memberArrayByte = memberArrayByte;
}
public void setMemberListByte(final List<Byte> memberListByte) {
this.memberListByte = memberListByte;
}
}

View File

@ -0,0 +1,7 @@
package test.atriasoft.exml.introspection.model;
public enum SimpleEnum {
PLIF,
PLAF,
PROUT;
}

View File

@ -0,0 +1,35 @@
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=trace
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=
# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
#org.slf4j.simpleLogger.showDateTime=false
# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
# Set to true if you want to output the current thread name.
# Defaults to true.
org.slf4j.simpleLogger.showThreadName=true
# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
#org.slf4j.simpleLogger.showLogName=true
# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
#org.slf4j.simpleLogger.showShortLogName=false

2
test/.gitignore vendored
View File

@ -1 +1,3 @@
/__pycache__/
/bin/ /bin/

View File

@ -1,44 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.atriasoft.exml.Document;
import org.junit.jupiter.api.Assertions;
class ExmlLocal {
// _errorPos : -1 : no error , 1 : parsing error, 2 generation error, 3 comparaison error ????
public static void test(final String _ref, final String _input, final int _errorPos) {
test(_ref, _input, _errorPos, false);
}
public static void test(final String _ref, final String _input, final int _errorPos, final boolean _caseInSensitive) {
final Document doc = new Document();
//doc.setCaseSensitive(!_caseInSensitive);
Log.verbose("parse : \n" + _input);
final boolean retParse = doc.parse(_input);
if (_errorPos == 1) {
Assertions.assertEquals(retParse, false);
return;
} else {
Assertions.assertEquals(retParse, true);
}
final StringBuilder out = new StringBuilder();
final boolean retGenerate = doc.generate(out);
if (_errorPos == 2) {
Assertions.assertEquals(retGenerate, false);
return;
} else {
Assertions.assertEquals(retGenerate, true);
}
final String data = out.toString();
if (_errorPos == 3) {
Assertions.assertNotEquals(_ref, data);
return;
} else {
Assertions.assertEquals(_ref, data);
}
}
}

View File

@ -1,40 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.atriasoft.exml.Document;
import org.atriasoft.exml.Element;
import org.atriasoft.exml.TextCDATA;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class ExmlTestCData {
@BeforeAll
public static void beforeClass() {
Log.verbose("----------------------------------------------------------------");
}
@Test
public void generate() {
final Document doc = new Document();
doc.append(new TextCDATA("Text &é<>examp]le]] ..."));
doc.append(new TextCDATA("Text &é<>examp]le]] ..."));
final String out = doc.getText();
doc.parse("<elem><![CDATA[Text &é<>examp]le]] ...]]></elem>");
Assertions.assertEquals("<![CDATA[Text &é<>examp]le]] ...]]><![CDATA[Text &é<>examp]le]] ...]]>", out);
}
@Test
public void parseCDATA() {
final Document doc = new Document();
doc.parse("<elem><![CDATA[Text &é<>examp]le]] ...]]></elem>");
final Element elem = Assertions.assertDoesNotThrow(() -> {
return (Element) doc.getNode("elem");
});
Assertions.assertEquals("Text &é<>examp]le]] ...", elem.getText());
}
}

View File

@ -1,48 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.atriasoft.exml.Comment;
import org.atriasoft.exml.Node;
import org.atriasoft.exml.NodeType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class ExmlTestComment {
@BeforeAll
public static void beforeClass() {
Log.verbose("----------------------------------------------------------------");
}
@Test
public void create() {
final Comment myComment = new Comment("my Comment");
Assertions.assertEquals(myComment.getType(), NodeType.COMMENT);
}
@Test
public void createAssignement() {
final Comment myComment = new Comment("my comment");
final Comment myOtherComment = myComment.clone();
Assertions.assertEquals(myComment.getValue(), myOtherComment.getValue());
}
@Test
public void createCopy() {
final Comment myComment = new Comment("my Comment");
final Comment myOtherComment = new Comment(myComment);
Assertions.assertEquals(myComment.getValue(), myOtherComment.getValue());
}
@Test
public void transform() {
Comment myComment = new Comment("my comment");
final Node myNode = myComment;
myComment = myNode.toComment();
Assertions.assertEquals(myComment.getValue(), "my comment");
}
}

View File

@ -1,56 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class ExmlTestParseDeclaration {
@BeforeAll
public static void beforeClass() {
Log.verbose("----------------------------------------------------------------");
}
@Test
public void testAll() {
ExmlLocal.test("<?xml attr=\"p65421lop\"?>\n", "<?xml attr \n = \n\t p65421lop?>\n", -1);
}
@Test
public void testAttribute() {
ExmlLocal.test("<?xml attr=\"plop\"?>\n", "<?xml attr=\"plop\"?>\n", -1);
}
@Test
public void testBase() {
ExmlLocal.test("<?testDeclaration?>\n", "<?testDeclaration?>\n", -1);
}
@Test
public void testMultiline() {
ExmlLocal.test("<?xml attr=\"plop\"?>\n", "<?xml attr\n=\n\"plop\"?>\n", -1);
}
@Test
public void testNoQuote() {
ExmlLocal.test("<?xml attr=\"plop\"?>\n", "<?xml attr=plop?>\n", -1);
}
@Test
public void testNumberNoQuote() {
ExmlLocal.test("<?xml attr=\"234345@3452345_.'\"?>\n", "<?xml attr=234345@3452345_.' ?>\n", -1);
}
@Test
public void testSpace1() {
ExmlLocal.test("<?xml attr=\"plop\"?>\n", "<?xml attr =\"plop\"?>\n", -1);
}
@Test
public void testSpace2() {
ExmlLocal.test("<?xml attr=\"plop\"?>\n", "<?xml attr= \"plop\"?>\n", -1);
}
}

View File

@ -1,73 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2021, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package test.atriasoft.exml;
import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
public class Log {
private static final String LIB_NAME = "exml-test";
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR);
private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING);
private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO);
private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG);
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE);
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
public static void critical(final String data) {
if (PRINT_CRITICAL) {
Logger.critical(LIB_NAME_DRAW, data);
}
}
public static void debug(final String data) {
if (PRINT_DEBUG) {
Logger.debug(LIB_NAME_DRAW, data);
}
}
public static void error(final String data) {
if (PRINT_ERROR) {
Logger.error(LIB_NAME_DRAW, data);
}
}
public static void info(final String data) {
if (PRINT_INFO) {
Logger.info(LIB_NAME_DRAW, data);
}
}
public static void print(final String data) {
if (PRINT_PRINT) {
Logger.print(LIB_NAME_DRAW, data);
}
}
public static void todo(final String data) {
if (PRINT_TODO) {
Logger.todo(LIB_NAME_DRAW, data);
}
}
public static void verbose(final String data) {
if (PRINT_VERBOSE) {
Logger.verbose(LIB_NAME_DRAW, data);
}
}
public static void warning(final String data) {
if (PRINT_WARNING) {
Logger.warning(LIB_NAME_DRAW, data);
}
}
private Log() {}
}