001/**
002 * Copyright 2014 Tampere University of Technology, Pori Department
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 */
016package service.tut.pori.fileservice;
017
018import java.util.List;
019
020import javax.xml.bind.annotation.XmlAccessType;
021import javax.xml.bind.annotation.XmlAccessorType;
022import javax.xml.bind.annotation.XmlElement;
023import javax.xml.bind.annotation.XmlRootElement;
024
025import core.tut.pori.http.ResponseData;
026
027/**
028 * A container for file objects, which can be directly used with XML Response.
029 * 
030 * <h3>XML Example</h3>
031 * 
032 * {@doc.restlet service="[service.tut.pori.fileservice.reference.Definitions#SERVICE_FS_REFERENCE_EXAMPLE]" method="[service.tut.pori.fileservice.Definitions#ELEMENT_FILELIST]" type="GET" query="" body_uri=""}
033 * 
034 * @see service.tut.pori.fileservice.File
035 */
036@XmlRootElement(name=Definitions.ELEMENT_FILELIST)
037@XmlAccessorType(value=XmlAccessType.NONE)
038public class FileList extends ResponseData {
039  @XmlElement(name = Definitions.ELEMENT_FILE)
040  private List<File> _files = null;
041
042  /**
043   * @return the files
044   */
045  public List<File> getFiles() {
046    return _files;
047  }
048
049  /**
050   * @param files the files to set
051   */
052  public void setFiles(List<File> files) {
053    _files = files;
054  }
055  
056  /**
057   * 
058   */
059  public FileList(){
060    // nothing needed
061  }
062  
063  /**
064   * 
065   * @param files
066   * @return new file list or null if null or empty list was passed
067   */
068  public static FileList getFileList(List<File> files){
069    if(files == null || files.isEmpty()){
070      return null;
071    }else{
072      FileList fileList = new FileList();
073      fileList._files = files;
074      return fileList;
075    }
076  }
077  
078  /**
079   * for sub-classing, use the static
080   * 
081   * @return true if this list is empty
082   * @see #isEmpty(FileList)
083   */
084  protected boolean isEmpty(){
085    return (_files == null || _files.isEmpty());
086  }
087  
088  /**
089   * 
090   * @param fileList
091   * @return true if the given list is null or empty
092   */
093  public static boolean isEmpty(FileList fileList){
094    return (fileList == null ? true : fileList.isEmpty());
095  }
096}