View Javadoc
1   /*
2    * Copyright (C) 2013 4th Line GmbH, Switzerland
3    *
4    * The contents of this file are subject to the terms of either the GNU
5    * Lesser General Public License Version 2 or later ("LGPL") or the
6    * Common Development and Distribution License Version 1 or later
7    * ("CDDL") (collectively, the "License"). You may not use this file
8    * except in compliance with the License. See LICENSE.txt for more
9    * information.
10   *
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14   */
15  
16  package org.fourthline.cling.support.model.container;
17  
18  import org.fourthline.cling.support.model.Person;
19  import org.fourthline.cling.support.model.PersonWithRole;
20  import org.fourthline.cling.support.model.item.Item;
21  import org.fourthline.cling.support.model.item.MusicTrack;
22  
23  import java.net.URI;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import static org.fourthline.cling.support.model.DIDLObject.Property.UPNP;
28  
29  /**
30   * @author Christian Bauer
31   */
32  public class MusicAlbum extends Album {
33  
34      public static final Class CLASS = new Class("object.container.album.musicAlbum");
35  
36      public MusicAlbum() {
37          setClazz(CLASS);
38      }
39  
40      public MusicAlbum(Container other) {
41          super(other);
42      }
43  
44      public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount) {
45          this(id, parent.getId(), title, creator, childCount, new ArrayList<MusicTrack>());
46      }
47  
48      public MusicAlbum(String id, Container parent, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
49          this(id, parent.getId(), title, creator, childCount, musicTracks);
50      }
51  
52      public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount) {
53          this(id, parentID, title, creator, childCount, new ArrayList<MusicTrack>());
54      }
55  
56      public MusicAlbum(String id, String parentID, String title, String creator, Integer childCount, List<MusicTrack> musicTracks) {
57          super(id, parentID, title, creator, childCount);
58          setClazz(CLASS);
59          addMusicTracks(musicTracks);
60      }
61  
62      public PersonWithRole getFirstArtist() {
63          return getFirstPropertyValue(UPNP.ARTIST.class);
64      }
65  
66      public PersonWithRole[] getArtists() {
67          List<PersonWithRole> list = getPropertyValues(UPNP.ARTIST.class);
68          return list.toArray(new PersonWithRole[list.size()]);
69      }
70  
71      public MusicAlbum setArtists(PersonWithRole[] artists) {
72          removeProperties(UPNP.ARTIST.class);
73          for (PersonWithRole artist : artists) {
74              addProperty(new UPNP.ARTIST(artist));
75          }
76          return this;
77      }
78  
79      public String getFirstGenre() {
80          return getFirstPropertyValue(UPNP.GENRE.class);
81      }
82  
83      public String[] getGenres() {
84          List<String> list = getPropertyValues(UPNP.GENRE.class);
85          return list.toArray(new String[list.size()]);
86      }
87  
88      public MusicAlbum setGenres(String[] genres) {
89          removeProperties(UPNP.GENRE.class);
90          for (String genre : genres) {
91              addProperty(new UPNP.GENRE(genre));
92          }
93          return this;
94      }
95  
96      public Person getFirstProducer() {
97          return getFirstPropertyValue(UPNP.PRODUCER.class);
98      }
99  
100     public Person[] getProducers() {
101         List<Person> list = getPropertyValues(UPNP.PRODUCER.class);
102         return list.toArray(new Person[list.size()]);
103     }
104 
105     public MusicAlbum setProducers(Person[] persons) {
106         removeProperties(UPNP.PRODUCER.class);
107         for (Person p : persons) {
108             addProperty(new UPNP.PRODUCER(p));
109         }
110         return this;
111     }
112 
113     public URI getFirstAlbumArtURI() {
114         return getFirstPropertyValue(UPNP.ALBUM_ART_URI.class);
115     }
116 
117     public URI[] getAlbumArtURIs() {
118         List<URI> list = getPropertyValues(UPNP.ALBUM_ART_URI.class);
119         return list.toArray(new URI[list.size()]);
120     }
121 
122     public MusicAlbum setAlbumArtURIs(URI[] uris) {
123         removeProperties(UPNP.ALBUM_ART_URI.class);
124         for (URI uri : uris) {
125             addProperty(new UPNP.ALBUM_ART_URI(uri));
126         }
127         return this;
128     }
129 
130     public String getToc() {
131         return getFirstPropertyValue(UPNP.TOC.class);
132     }
133 
134     public MusicAlbum setToc(String toc) {
135         replaceFirstProperty(new UPNP.TOC(toc));
136         return this;
137     }
138 
139     public MusicTrack[] getMusicTracks() {
140         List<MusicTrack> list = new ArrayList<>();
141         for (Item item : getItems()) {
142             if (item instanceof MusicTrack) list.add((MusicTrack)item);
143         }
144         return list.toArray(new MusicTrack[list.size()]);
145     }
146 
147     public void addMusicTracks(List<MusicTrack> musicTracks) {
148         addMusicTracks(musicTracks.toArray(new MusicTrack[musicTracks.size()]));
149     }
150 
151     public void addMusicTracks(MusicTrack[] musicTracks) {
152         if (musicTracks != null) {
153             for (MusicTrack musicTrack : musicTracks) {
154                 musicTrack.setAlbum(getTitle());
155                 addItem(musicTrack);
156             }
157         }
158     }
159 
160 }