001/**
002 * Copyright 2015 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.contentstorage;
017
018import java.util.HashSet;
019import java.util.List;
020
021import javax.xml.bind.annotation.XmlAccessType;
022import javax.xml.bind.annotation.XmlAccessorType;
023import javax.xml.bind.annotation.XmlElementRef;
024import javax.xml.bind.annotation.XmlRootElement;
025
026import service.tut.pori.contentanalysis.Media;
027import core.tut.pori.http.ResponseData;
028
029/**
030 * 
031 * This is a container class for media elements, which can be used directly with Response to provide XML output.
032 * 
033 * <h3>XML Example</h3>
034 * 
035 * {@doc.restlet service="[service.tut.pori.contentstorage.reference.Definitions#SERVICE_COS_REFERENCE_EXAMPLE]" method="[service.tut.pori.contentstorage.Definitions#ELEMENT_MEDIALIST]" type="GET" query="" body_uri=""}
036 *  
037 * @see service.tut.pori.contentanalysis.Media
038 */
039@XmlRootElement(name = Definitions.ELEMENT_MEDIALIST)
040@XmlAccessorType(value=XmlAccessType.NONE)
041public class MediaList extends ResponseData {
042  @XmlElementRef
043  private List<Media> _media = null;
044
045  /**
046   * @return the media
047   */
048  public List<Media> getMedia() {
049    return _media;
050  }
051
052  /**
053   * @param media the media to set
054   */
055  public void setMedia(List<Media> media) {
056    _media = media;
057  }
058  
059  /**
060   * only for sub-classing
061   * @return true if media contains no items
062   * @see #isEmpty(MediaList)
063   */
064  protected boolean isEmpty() {
065    return (_media == null || _media.isEmpty());
066  }
067
068  /**
069   * 
070   * @param media
071   * @return true if the media is null or contains no items
072   */
073  public static boolean isEmpty(MediaList media) {
074    return (media == null || media.isEmpty());
075  }
076
077  @Override
078  public Class<?>[] getDataClasses() {
079    if(isEmpty()){
080      return super.getDataClasses();
081    }
082    
083    HashSet<Class<?>> classes = new HashSet<>();
084    classes.add(getClass());
085    for(Media m : _media){
086      classes.add(m.getClass());
087    }
088    return classes.toArray(new Class<?>[classes.size()]);
089  }
090}