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.client.model; 013 014import java.io.Serializable; 015import java.util.ArrayList; 016import java.util.Iterator; 017import java.util.List; 018 019/** 020 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 021 */ 022public class Documents implements Serializable, OperationInput, Iterable<Document> { 023 024 private static final long serialVersionUID = 1L; 025 026 protected List<Document> docs; 027 028 public Documents() { 029 docs = new ArrayList<Document>(); 030 } 031 032 public Documents(int size) { 033 docs = new ArrayList<Document>(size); 034 } 035 036 public Documents(Documents docs) { 037 this(docs.list()); 038 } 039 040 public Documents(List<Document> docs) { 041 this.docs = docs; 042 } 043 044 public final List<Document> list() { 045 return docs; 046 } 047 048 @Override 049 public Iterator<Document> iterator() { 050 return docs.iterator(); 051 } 052 053 public void add(Document doc) { 054 docs.add(doc); 055 } 056 057 public int size() { 058 return docs.size(); 059 } 060 061 public boolean isEmpty() { 062 return docs.isEmpty(); 063 } 064 065 public Document get(int i) { 066 return docs.get(i); 067 } 068 069 public String getInputType() { 070 return "documents"; 071 } 072 073 public boolean isBinary() { 074 return false; 075 } 076 077 public String toString() { 078 StringBuilder buf = new StringBuilder("docs:"); 079 int size = size(); 080 if (size == 0) { 081 return buf.toString(); 082 } 083 buf.append(get(0).getId()); 084 for (int i = 1; i < size; i++) { 085 buf.append(",").append(get(i).getId()); 086 } 087 return buf.toString(); 088 } 089 090 public String getInputRef() { 091 return toString(); 092 } 093 094 public String dump() { 095 return super.toString(); 096 } 097}