001/* 002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * bstefanescu 018 */ 019package org.nuxeo.ecm.automation.client.model; 020 021import java.io.Serializable; 022import java.util.ArrayList; 023import java.util.Iterator; 024import java.util.List; 025 026/** 027 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 028 */ 029public class Documents implements Serializable, OperationInput, Iterable<Document> { 030 031 private static final long serialVersionUID = 1L; 032 033 protected List<Document> docs; 034 035 public Documents() { 036 docs = new ArrayList<Document>(); 037 } 038 039 public Documents(int size) { 040 docs = new ArrayList<Document>(size); 041 } 042 043 public Documents(Documents docs) { 044 this(docs.list()); 045 } 046 047 public Documents(List<Document> docs) { 048 this.docs = docs; 049 } 050 051 public final List<Document> list() { 052 return docs; 053 } 054 055 @Override 056 public Iterator<Document> iterator() { 057 return docs.iterator(); 058 } 059 060 public void add(Document doc) { 061 docs.add(doc); 062 } 063 064 public int size() { 065 return docs.size(); 066 } 067 068 public boolean isEmpty() { 069 return docs.isEmpty(); 070 } 071 072 public Document get(int i) { 073 return docs.get(i); 074 } 075 076 public String getInputType() { 077 return "documents"; 078 } 079 080 public boolean isBinary() { 081 return false; 082 } 083 084 public String toString() { 085 StringBuilder buf = new StringBuilder("docs:"); 086 int size = size(); 087 if (size == 0) { 088 return buf.toString(); 089 } 090 buf.append(get(0).getId()); 091 for (int i = 1; i < size; i++) { 092 buf.append(",").append(get(i).getId()); 093 } 094 return buf.toString(); 095 } 096 097 public String getInputRef() { 098 return toString(); 099 } 100 101 public String dump() { 102 return super.toString(); 103 } 104}