@Override protected ReadResponse doRead(ReadRequest request) { LwM2mPath path = request.getPath(); // Manage Object case if (path.isObject()) { List<LwM2mObjectInstance> lwM2mObjectInstances = new ArrayList<>(); for (Entry<Integer, LwM2mInstanceEnabler> entry : instances.entrySet()) { lwM2mObjectInstances.add(getLwM2mObjectInstance(entry.getKey(), entry.getValue())); } return ReadResponse.success( new LwM2mObject(getId(), lwM2mObjectInstances.toArray(new LwM2mObjectInstance[0]))); } // Manage Instance case LwM2mInstanceEnabler instance = instances.get(path.getObjectInstanceId()); if (instance == null) return ReadResponse.notFound(); if (path.getResourceId() == null) { return ReadResponse.success(getLwM2mObjectInstance(path.getObjectInstanceId(), instance)); } // Manage Resource case return instance.read(path.getResourceId()); }
@Override public ReadResponse read(int resourceid) { if (resources.containsKey(resourceid)) { return ReadResponse.success(resources.get(resourceid)); } return ReadResponse.notFound(); }