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 java.util.ArrayList; 015 016import org.nuxeo.ecm.automation.OperationContext; 017import org.nuxeo.ecm.automation.OperationException; 018import org.nuxeo.ecm.automation.OutputCollector; 019import org.nuxeo.ecm.core.api.DocumentModel; 020import org.nuxeo.ecm.core.api.DocumentModelList; 021 022/** 023 * This implementation collect {@link DocumentModel} objects and return them as a {@link DocumentModelList} object. 024 * <p> 025 * You may use this to automatically iterate over iterable inputs in operation methods that <b>return</b> a 026 * {@link DocumentModel} object 027 * 028 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 029 */ 030public class DocumentModelListCollector extends ArrayList<DocumentModel> implements DocumentModelList, 031 OutputCollector<DocumentModelList, DocumentModelList> { 032 033 private static final long serialVersionUID = 5732663048354570870L; 034 035 @Override 036 public long totalSize() { 037 return size(); 038 } 039 040 @Override 041 public void collect(OperationContext ctx, DocumentModelList obj) throws OperationException { 042 if (obj != null) { 043 addAll(obj); 044 } 045 } 046 047 @Override 048 public DocumentModelList getOutput() { 049 return this; 050 } 051}