// endpoint--> coapendpoints/home/room1/sensor1
String[] resources = endpoint.split("/");
Resource childResource = coapServer.getRoot().getChild(resources[0]);
Resource parentResource = childResource;
if (parentResource == null && (resources.length > 1)) {
coapServer.add(new CoAPResourcePath(resources));
}
if (parentResource == null && (resources.length == 1)) {
coapServer.add(new CoAPResourceServlet(resources[0]));
} else if (parentResource != null && resources.length > 1) {
int j = 1;
for (; j < resources.length; j++) {
if (childResource != null) {
parentResource = childResource;
childResource = childResource.getChild(resources[j]);
} else {
break;
}
}
String[] coapEndpoint = Arrays.copyOfRange(resources, j - 1, resources.length);
if (coapEndpoint.length > 1) {
parentResource.add(new CoAPResourcePath(coapEndpoint));
} else if (coapEndpoint.length == 1) {
parentResource.add(new CoAPResourceServlet(coapEndpoint[0]));
}
} else if (parentResource != null && resources.length == 1) {
parentResource.add(new CoAPResourceServlet(resources[0]));
}
Here CoAPResourcePath and CoAPResourceServlet classes are extended from CoapResource.
This is the output after adding resources in this way.
Note: I just asked this question in stackoverflow and didn't get an answer. If you guys can explain little bit on this it would be really helpful for me.
Thanks,
Geesara
--
Geesara Prathap Kulathunga
Software Engineer
Mobile : +940772684174