001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     bstefanescu
011 */
012package org.nuxeo.ecm.automation.core.collectors;
013
014import org.nuxeo.ecm.automation.OperationContext;
015import org.nuxeo.ecm.automation.OperationException;
016import org.nuxeo.ecm.automation.OutputCollector;
017import org.nuxeo.ecm.automation.core.util.BlobList;
018import org.nuxeo.ecm.core.api.Blob;
019
020/**
021 * This implementation collect {@link Blob} objects and return them as a {@link BlobList} object.
022 * <p>
023 * You may use this to automatically iterate over iterable inputs in operation methods that <b>return</b> a {@link Blob}
024 * object.
025 *
026 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
027 */
028public class BlobListCollector extends BlobList implements OutputCollector<BlobList, BlobList> {
029
030    private static final long serialVersionUID = 5167860889224514027L;
031
032    @Override
033    public void collect(OperationContext ctx, BlobList obj) throws OperationException {
034        if (obj != null) {
035            addAll(obj);
036        }
037    }
038
039    @Override
040    public BlobList getOutput() {
041        return this;
042    }
043}