Source:
private WriteRequest(Mode mode, ContentFormat format, LwM2mPath target, LwM2mNode node) { super(target); if (mode == null) throw new InvalidRequestException("mode is mandatory for %s", target); if (node == null) throw new InvalidRequestException("new node value is mandatory for %s", target); if (getPath().isResource() && mode == Mode.UPDATE) throw new InvalidRequestException("Invalid mode for '%s': update is not allowed on resource", target); if (getPath().isResource()) { if (!(node instanceof LwM2mResource)) { throw new InvalidRequestException("path '%s' and node type '%s' does not match", target, node.getClass().getSimpleName()); } } else if (getPath().isObjectInstance()) { if (!(node instanceof LwM2mObjectInstance)) { throw new InvalidRequestException("path '%s' and node type '%s' does not match", target, node.getClass().getSimpleName()); } } else if (getPath().isObject()) { throw new InvalidRequestException("write request %s cannot target an object", target); } if (ContentFormat.TEXT == format || ContentFormat.OPAQUE == format) { if (!getPath().isResource()) { throw new InvalidRequestException( "Invalid format for %s: %s format must be used only for single resources", target, format); } else { LwM2mResource resource = (LwM2mResource) node; if (resource.isMultiInstances()) { throw new InvalidRequestException( "Invalid format for path %s: format must be used only for single resources", target, format); } else { if (resource.getType() == Type.OPAQUE && format == ContentFormat.TEXT) { throw new InvalidRequestException( "Invalid format for %s: TEXT format must not be used for byte array single resources", target); } else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) { throw new InvalidRequestException( "Invalid format for %s: OPAQUE format must be used only for byte array single resources", target); } } } } this.node = node; if (format == null) { this.contentFormat = ContentFormat.TLV; } else { this.contentFormat = format; } this.mode = mode; }

Target:
private WriteRequest(Mode mode, ContentFormat format, LwM2mPath target, LwM2mNode node) { super(target); if (mode == null) throw new InvalidRequestException("mode is mandatory for %s", target); if (node == null) throw new InvalidRequestException("new node value is mandatory for %s", target); if (getPath().isResource() && mode == Mode.UPDATE) throw new InvalidRequestException("Invalid mode for '%s': update is not allowed on resource", target); if (getPath().isResource()) { if (!(node instanceof LwM2mResource)) { throw new InvalidRequestException("path '%s' and node type '%s' do not match", target, node.getClass().getSimpleName()); } } else if (getPath().isObjectInstance()) { if (!(node instanceof LwM2mObjectInstance)) { throw new InvalidRequestException("path '%s' and node type '%s' do not match", target, node.getClass().getSimpleName()); } } else if (getPath().isObject()) { throw new InvalidRequestException("write request %s cannot target an object", target); } if (ContentFormat.TEXT == format || ContentFormat.OPAQUE == format) { if (!getPath().isResource()) { throw new InvalidRequestException( "Invalid format for %s: %s format must be used only for single resources", target, format); } else { LwM2mResource resource = (LwM2mResource) node; if (resource.isMultiInstances()) { throw new InvalidRequestException( "Invalid format for path %s: format must be used only for single resources", target, format); } else { if (resource.getType() == Type.OPAQUE && format == ContentFormat.TEXT) { throw new InvalidRequestException( "Invalid format for %s: TEXT format must not be used for byte array single resources", target); } else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) { throw new InvalidRequestException( "Invalid format for %s: OPAQUE format must be used only for byte array single resources", target); } } } } this.node = node; if (format == null) { this.contentFormat = ContentFormat.TLV; } else { this.contentFormat = format; } this.mode = mode; }