public static Class<? extends LwM2mNode> nodeClassFromPath(LwM2mPath path) { if (path.isObject()) { return LwM2mObject.class; } else if (path.isObjectInstance()) { return LwM2mObjectInstance.class; } else if (path.isResource()) { return LwM2mResource.class; } throw new IllegalArgumentException("invalid path level: " + path); }
private DeleteRequest(LwM2mPath target) { super(target); if (target.isRoot()) throw new InvalidRequestException("Delete request cannot target root path"); if (!target.isObjectInstance()) throw new InvalidRequestException("Invalid path %s : Only object instances can be delete", target); }
@Override public void visit(LwM2mObjectInstance instance) { LOG.trace("Encoding object instance {} into JSON", instance); resourceList = new ArrayList<>(); for (LwM2mResource resource : instance.getResources().values()) { // Validate request path & compute resource path String prefixPath; if (requestPath.isObject()) { prefixPath = instance.getId() + "/" + resource.getId(); } else if (requestPath.isObjectInstance()) { prefixPath = Integer.toString(resource.getId()); } else { throw new CodecException("Invalid request path %s for JSON instance encoding", requestPath); } // Create resources resourceList.addAll(lwM2mResourceToJsonArrayEntry(prefixPath, timestamp, resource)); } }
/** * Create a Object Link referencing an object instance with the given path. */ public static ObjectLink fromPath(String path) { LwM2mPath lwM2mPath = new LwM2mPath(path); if (lwM2mPath.isRoot()) { return new ObjectLink(); // create null link } else if (lwM2mPath.isObjectInstance()) { return new ObjectLink(lwM2mPath.getObjectId(), lwM2mPath.getObjectInstanceId()); } else { throw new IllegalArgumentException("Invalid path: ObjectLink should reference an object instance"); } }
private CreateRequest(ContentFormat format, LwM2mPath target, Integer instanceId, LwM2mResource[] resources) { super(target); // accept only object and object instance path if (target.isRoot()) throw new InvalidRequestException("Create request cannot target root path"); if (!target.isObject() && !target.isObjectInstance()) throw new InvalidRequestException( "Invalid path %s: Create request must not target an object or object instance", target); // validate instance id if (instanceId != null && instanceId == LwM2mObjectInstance.UNDEFINED) { instanceId = null; } if (target.isObjectInstance()) { if (instanceId == null) { instanceId = target.getObjectInstanceId(); } else { if (!instanceId.equals(target.getObjectInstanceId())) { throw new InvalidRequestException("Conflict between path instance id %s and node instance id %s", target, instanceId); } } } if (instanceId != null && instanceId < 0) throw new InvalidRequestException("Invalid instance id %s for path %s ", instanceId, target); // store attributes this.instanceId = instanceId; this.resources = Collections.unmodifiableList(Arrays.asList(resources)); this.contentFormat = format != null ? format : ContentFormat.TLV; // default to TLV }
@Override public void visit(LwM2mObjectInstance instance) { LOG.trace("Encoding object instance {} into TLV", instance); Tlv[] tlvs; if (path.isObjectInstance() || instance.getId() == LwM2mObjectInstance.UNDEFINED) { // the instanceId is part of the request path or is undefined // so the instance TLV layer is not needed. // encoded as an array of resource TLVs tlvs = encodeResources(instance.getResources().values(), new LwM2mPath(path.getObjectId(), instance.getId())); } else { // encoded as an instance TLV Tlv[] resources = encodeResources(instance.getResources().values(), new LwM2mPath(path.getObjectId(), instance.getId())); tlvs = new Tlv[] { new Tlv(TlvType.OBJECT_INSTANCE, resources, null, instance.getId()) }; } try { out.write(TlvEncoder.encode(tlvs).array()); } catch (IOException e) { throw new RuntimeException(e); } }
return BootstrapDeleteResponse.success(); } else if (request.getPath().isObjectInstance()) { if (id == LwM2mId.SECURITY) {
} else if (path.isObjectInstance()) {
return WriteResponse.notFound(); if (path.isObjectInstance()) {
node.getClass().getSimpleName()); } else if (getPath().isObjectInstance()) { if (!(node instanceof LwM2mObjectInstance)) { throw new InvalidRequestException("path '%s' and node type '%s' do not match", target,
protected DiscoverResponse doDiscover(DiscoverRequest request) { LwM2mPath path = request.getPath(); if (path.isObject()) { // Manage discover on object Link[] ObjectLinks = LinkFormatHelper.getObjectDescription(this, null); return DiscoverResponse.success(ObjectLinks); } else if (path.isObjectInstance()) { // Manage discover on instance if (!getAvailableInstanceIds().contains(path.getObjectInstanceId())) return DiscoverResponse.notFound(); Link[] instanceLink = LinkFormatHelper.getInstanceDescription(this, path.getObjectInstanceId(), null); return DiscoverResponse.success(instanceLink); } else if (path.isResource()) { // Manage discover on resource if (!getAvailableInstanceIds().contains(path.getObjectInstanceId())) return DiscoverResponse.notFound(); ResourceModel resourceModel = getObjectModel().resources.get(path.getResourceId()); if (resourceModel == null) return DiscoverResponse.notFound(); if (!getAvailableResourceIds(path.getObjectInstanceId()).contains(path.getResourceId())) return DiscoverResponse.notFound(); Link resourceLink = LinkFormatHelper.getResourceDescription(this, path.getObjectInstanceId(), path.getResourceId(), null); return DiscoverResponse.success(new Link[] { resourceLink }); } return DiscoverResponse.badRequest(null); }
if (path.isObjectInstance()) { LwM2mObjectInstance instanceNode = (LwM2mObjectInstance) request.getNode(); LwM2mInstanceEnabler instanceEnabler = instances.get(path.getObjectInstanceId());
node.getClass().getSimpleName()); } else if (getPath().isObjectInstance()) { if (!(node instanceof LwM2mObjectInstance)) { throw new InvalidRequestException("path '%s' and node type '%s' do not match", target,
if (path.isObjectInstance() && tlvs[0].getIdentifier() != path.getObjectInstanceId()) { throw new CodecException("Id conflict between path [%s] and instance TLV [object instance id=%d]", path, tlvs[0].getIdentifier());
if (path.isObjectInstance()) { try { LwM2mNode lwM2mNode = decoder.decode(exchange.getRequestPayload(), contentFormat, path, model);