Annotation Interface PutChild


@Target(METHOD) @Retention(RUNTIME) public @interface PutChild
Marks a method as one which creates a child resource containing the given content, or replaces an existing child's content with new data

Return type - Must return the created POJO object, or the updated child

Parameters:

  1. first arg must be the object to update OR..
  2. the parent object, followed by the name of the child resource
  3. items following that may include (in preferential order)
    1. inputStream or byte[]
    2. contentType
    3. content length as Long

Example: Creating a new child resource

    @PutChild
    public MyDatabase.FileContentItem createFile(MyDatabase.FolderContentItem parent, String name, byte[] bytes) {
        FileContentItem file = parent.addFile(name);
        file.setBytes(bytes);
        return file;
    }
 

Example: updating an existing resource

    @PutChild
    public Image uploadImage(Image image, byte[] bytes) throws IOException {
        File fRoot = getContentRoot();
        File content = new File(fRoot, image.getFileName());
        FileUtils.writeByteArrayToFile(content, bytes);
        return image;
    }
 

Example: Creating a new child resource from an inputstream. This uses the contentLength and contentType headers, but please note these are not always sent by client apps.

    @PutChild
    public MyDatabase.FileContentItem createFile(MyDatabase.FolderContentItem parent, String name, InputStream in, Long contentLength, String contentType) {
      ...
    }