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.DIDLObject;
19  import org.fourthline.cling.support.model.DescMeta;
20  import org.fourthline.cling.support.model.Res;
21  import org.fourthline.cling.support.model.WriteStatus;
22  import org.fourthline.cling.support.model.item.Item;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * A container in DIDL content.
29   * <p>
30   * Note that although this container can have sub-containers, the
31   * {@link org.fourthline.cling.support.contentdirectory.DIDLParser}
32   * will never read nor write this collection to and from XML.
33   * Its only purpose is convenience when creating and manipulating a
34   * recursive structure, that is, modelling the content tree as you
35   * see fit. You can then pick a list of containers and/or a list of
36   * items and hand them to the DIDL parser, which will render them
37   * flat in XML. The only nested structure that can optionally be
38   * rendered into and read from XML are the items of containers,
39   * never their sub-containers.
40   * </p>
41   * <p>
42   * Also see ContentDirectory 1.0 specification, section 2.8.3:
43   * "Incremental navigation i.e. the full hierarchy is never returned
44   * in one call since this is likely to flood the resources available to
45   * the control point (memory, network bandwidth, etc.)."
46   * </p>
47   *
48   * @author Christian Bauer
49   */
50  public class Container extends DIDLObject {
51  
52      protected Integer childCount = null;
53      protected boolean searchable; // Default or absent == false
54      protected List<Class> createClasses = new ArrayList<>();
55      protected List<Class> searchClasses = new ArrayList<>();
56      protected List<Container> containers = new ArrayList<>();
57      protected List<Item> items = new ArrayList<>();
58  
59      public Container() {
60      }
61  
62      public Container(Container other) {
63          super(other);
64          setChildCount(other.getChildCount());
65          setSearchable(other.isSearchable());
66          setCreateClasses(other.getCreateClasses());
67          setSearchClasses(other.getSearchClasses());
68          setItems(other.getItems());
69      }
70  
71      public Container(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata) {
72          super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
73      }
74  
75      public Container(String id, String parentID, String title, String creator, boolean restricted, WriteStatus writeStatus, Class clazz, List<Res> resources, List<Property> properties, List<DescMeta> descMetadata, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
76          super(id, parentID, title, creator, restricted, writeStatus, clazz, resources, properties, descMetadata);
77          this.childCount = childCount;
78          this.searchable = searchable;
79          this.createClasses = createClasses;
80          this.searchClasses = searchClasses;
81          this.items = items;
82      }
83  
84      public Container(String id, Container parent, String title, String creator, DIDLObject.Class clazz, Integer childCount) {
85          this(id, parent.getId(), title, creator, true, null, clazz, new ArrayList<Res>(), new ArrayList<Property>(), new ArrayList<DescMeta>(), childCount, false, new ArrayList<Class>(), new ArrayList<Class>(), new ArrayList<Item>());
86      }
87  
88      public Container(String id, String parentID, String title, String creator, DIDLObject.Class clazz, Integer childCount) {
89          this(id, parentID, title, creator, true, null, clazz, new ArrayList<Res>(), new ArrayList<Property>(), new ArrayList<DescMeta>(), childCount, false, new ArrayList<Class>(), new ArrayList<Class>(), new ArrayList<Item>());
90      }
91  
92      public Container(String id, Container parent, String title, String creator, DIDLObject.Class clazz, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
93          this(id, parent.getId(), title, creator, true, null, clazz, new ArrayList<Res>(), new ArrayList<Property>(), new ArrayList<DescMeta>(), childCount, searchable, createClasses, searchClasses, items);
94      }
95  
96      public Container(String id, String parentID, String title, String creator, DIDLObject.Class clazz, Integer childCount, boolean searchable, List<Class> createClasses, List<Class> searchClasses, List<Item> items) {
97          this(id, parentID, title, creator, true, null, clazz, new ArrayList<Res>(), new ArrayList<Property>(), new ArrayList<DescMeta>(), childCount, searchable, createClasses, searchClasses, items);
98      }
99  
100     public Integer getChildCount() {
101         return childCount;
102     }
103 
104     public void setChildCount(Integer childCount) {
105         this.childCount = childCount;
106     }
107 
108     public boolean isSearchable() {
109         return searchable;
110     }
111 
112     public void setSearchable(boolean searchable) {
113         this.searchable = searchable;
114     }
115 
116     public List<Class> getCreateClasses() {
117         return createClasses;
118     }
119 
120     public void setCreateClasses(List<Class> createClasses) {
121         this.createClasses = createClasses;
122     }
123 
124     public List<Class> getSearchClasses() {
125         return searchClasses;
126     }
127 
128     public void setSearchClasses(List<Class> searchClasses) {
129         this.searchClasses = searchClasses;
130     }
131 
132     public Container getFirstContainer() {
133         return getContainers().get(0);
134     }
135 
136     public Container addContainer(Container container) {
137         getContainers().add(container);
138         return this;
139     }
140 
141     public List<Container> getContainers() {
142         return containers;
143     }
144 
145     public void setContainers(List<Container> containers) {
146         this.containers = containers;
147     }
148 
149     public List<Item> getItems() {
150         return items;
151     }
152 
153     public void setItems(List<Item> items) {
154         this.items = items;
155     }
156 
157     public Container addItem(Item item) {
158         getItems().add(item);
159         return this;
160     }
161     
162 }