001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.labels;
014
015import java.util.*;
016
017import org.apache.juneau.rest.*;
018
019/**
020 * A POJO structure that describes the list of child resources associated with a resource.
021 * 
022 * <p>
023 * Typically used in top-level GET methods of router resources to render a list of available child resources.
024 * 
025 * <h5 class='section'>See Also:</h5>
026 * <ul>
027 *    <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.PredefinedLabelBeans">Overview &gt; juneau-rest-server &gt; Predefined Label Beans</a>
028 * </ul>
029 */
030public class ChildResourceDescriptions extends LinkedList<ResourceDescription> {
031
032   private static final long serialVersionUID = 1L;
033
034   /**
035    * Constructor.
036    * 
037    * @param context The servlet context that this bean describes.
038    * @param req The HTTP servlet request.
039    * @throws Exception 
040    */
041   public ChildResourceDescriptions(RestContext context, RestRequest req) throws Exception {
042      this(context, req, false);
043   }
044
045   /**
046    * Constructor.
047    * 
048    * @param context The servlet context that this bean describes.
049    * @param req The HTTP servlet request.
050    * @param sort
051    *    If <jk>true</jk>, list will be ordered by name alphabetically.
052    *    Default is to maintain the order as specified in the annotation.
053    * @throws Exception 
054    */
055   public ChildResourceDescriptions(RestContext context, RestRequest req, boolean sort) throws Exception {
056      for (Map.Entry<String,RestContext> e : context.getChildResources().entrySet())
057         add(new ResourceDescription(e.getKey(), e.getValue().getInfoProvider().getTitle(req)));
058      if (sort)
059         Collections.sort(this);
060   }
061
062   /**
063    * Bean constructor.
064    */
065   public ChildResourceDescriptions() {
066      super();
067   }
068}