https://github.com/inseefr/ddi-lifecycle-java
Project to generate java classes to model DDI lifecycle documents
https://github.com/inseefr/ddi-lifecycle-java
Last synced: about 1 year ago
JSON representation
Project to generate java classes to model DDI lifecycle documents
- Host: GitHub
- URL: https://github.com/inseefr/ddi-lifecycle-java
- Owner: InseeFr
- License: mit
- Created: 2024-01-03T09:18:55.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-14T23:23:46.000Z (about 1 year ago)
- Last Synced: 2025-03-15T00:26:33.458Z (about 1 year ago)
- Language: Java
- Size: 351 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DDI Lifecycle Java
Java library that contains [DDI Lifecycle 3.3](https://ddialliance.org/Specification/DDI-Lifecycle/3.3/)
classes generated from XSD sources.
Classes are generated using [Apache XMLBeans](https://xmlbeans.apache.org/documentation/index.html).
This library offers deserialization / serialization for DDI objects, using methods of the XMLBeans API.
## Get started
### Requirements
Java 17 or above.
### [Get the dependency](https://mvnrepository.com/artifact/fr.insee.ddi/ddi-lifecycle)
Maven:
```xml
fr.insee.ddi
ddi-lifecycle
1.1.0
```
Gradle:
```kotlin
implementation("fr.insee.ddi:ddi-lifecycle:1.1.0")
```
### Deserialize / serialize DDI objects
Deserialization example:
```java
String xmlDDI = """
fr.insee
example-id
1
""";
DDIInstanceDocument ddiInstanceDocument = DDIInstanceDocument.Factory.parse(xmlDDI);
DDIInstanceType ddiInstanceType = ddiInstanceDocument.getDDIInstance();
```
The `parse(...)` method accepts various input types (url, file, input stream, etc.)
Each DDI Lifecycle object has a "Document" class and a "Type" class created by XMLBeans.
Document classes are wrappers to deserialize or serialize xml content (with the root node).
Type classes are those to get or set values in java.
To serialize a DDI object, just call the `toString()` on any DDI document object.
Deserialization/serialization is not restricted to the `DDIInstance` object.
This example can be applied to any DDI Lifecycle object: `CodeList`, `Sequence`, `QuestionItem`, `Variable`, etc.
Useful link: [DDI model documentation](https://ddialliance.github.io/ddimodel-web/DDI-L-3.3/)
## Other features
### Indexing of a DDI object
You can index the objects contained within a DDI object.
```java
DDIIndex ddiIndex = new DDIIndex();
// Perform indexing
ddiIndex.indexDDIObject(someDDIObject);
// Get an object within the index
AbstractIdentifiableType innerObject = ddiIndex.get("some-inner-object-id");
// The result can be typed
VariableType variable = ddiIndex.get("some-variable-id", VariableType.class);
// Get the parent object in the hierarchy
VariableSchemeType variableScheme = ddiIndex.getParent("some-variable-id", VariableScheme.class);
```
### Utilities
XMLBeans API is pretty verbose, a utility class of the lib offers some QOE methods:
```java
VariableType variable = VariableType.Factory.newInstance();
DDIUtils.setIdValue(variable, "foo-id");
DDIUtils.getIdValue(variable) // "foo-id"
DDIUtils.ddiToString(variable) // "VariableTypeImpl[id=foo-id]"
```
## Requests
If you have a question, request or bug report, feel free to open an issue.