Skip to content

Commit

Permalink
Add ObjectLoader.loadAllDefault()
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Dec 17, 2021
1 parent 4b36f26 commit ed23859
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public static void createAndStartClient(String endpoint, String localAddress, in
locationInstance = new MyLocation(latitude, longitude, scaleFactor);

// Initialize model
List<ObjectModel> models = ObjectLoader.loadDefault();
List<ObjectModel> models = ObjectLoader.loadLastestDefault();
models.addAll(ObjectLoader.loadDdfResources("/models", modelPaths));
if (modelsFolderPath != null) {
models.addAll(ObjectLoader.loadObjectsFromDir(new File(modelsFolderPath), true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ public class ObjectLoader {
static final String[] lastestddfspath = new String[] { "0-1_0.xml", "1-1_0.xml", "2.xml", "3-1_0.xml", "4-1_1.xml",
"5-1_0.xml", "6.xml", "7.xml" };

static final String[] allddfspath = new String[] { "0-1_0.xml", "1-1_0.xml", "2-1_0.xml", "2.xml", "3-1_0.xml",
"4-1_0.xml", "4-1_1.xml", "5-1_0.xml", "6.xml", "7.xml" };

/**
* Load the default LWM2M objects
* Load the default LWM2M objects in the version 1.0.
* <p>
* So there is only 1 version by object.
*/
public static List<ObjectModel> loadDefault() {
List<ObjectModel> models = new ArrayList<>();
Expand All @@ -57,7 +62,9 @@ public static List<ObjectModel> loadDefault() {
/**
* Load the core LWM2M objects in their last version.
* <p>
* Warning : between 2 minor version of Leshan, you could load different version.
* So there is only 1 version by object.
* <p>
* Warning : between 2 minor version of Leshan, lastest version could change for a given object.
*
* @since 1.4
*/
Expand All @@ -71,6 +78,23 @@ public static List<ObjectModel> loadLastestDefault() {
return models;
}

/**
* Load all available version of default LWM2M objects.
* <p>
* So you could get several versions for same object.
*
* @since 1.4
*/
public static List<ObjectModel> loadAllDefault() {
List<ObjectModel> models = new ArrayList<>();

// standard objects
LOG.debug("Loading OMA standard object models");
models.addAll(loadDdfResources("/models/", allddfspath));

return models;
}

/**
* Load object definitions from DDF or JSON files.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
public class ValidateModelsTest {

@Test
public void validate_embedded_models() throws InvalidModelException, InvalidDDFFileException, IOException {
public void validate_default_embedded_models() throws InvalidModelException, InvalidDDFFileException, IOException {
ObjectLoader.loadDdfResources("/models/", ObjectLoader.ddfpaths, true);
}

@Test
public void validate_lastest_embedded_models() throws InvalidModelException, InvalidDDFFileException, IOException {
ObjectLoader.loadDdfResources("/models/", ObjectLoader.lastestddfspath, true);
}

@Test
public void validate_all_embedded_models() throws InvalidModelException, InvalidDDFFileException, IOException {
ObjectLoader.loadDdfResources("/models/", ObjectLoader.allddfspath, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public static void createAndStartServer(String webAddress, int webPort, String l
builder.setDtlsConfig(dtlsConfig);

// Define model provider
List<ObjectModel> models = ObjectLoader.loadDefault();
List<ObjectModel> models = ObjectLoader.loadAllDefault();
models.addAll(ObjectLoader.loadDdfResources("/models/", LwM2mDemoConstant.modelPaths));
if (modelsFolderPath != null) {
models.addAll(ObjectLoader.loadObjectsFromDir(new File(modelsFolderPath), true));
Expand Down

0 comments on commit ed23859

Please sign in to comment.