DIDLAdapter.java

  1. /*
  2.  * *********************************************************************************************************************
  3.  *
  4.  * blueMarine II: Semantic Media Centre
  5.  * http://tidalwave.it/projects/bluemarine2
  6.  *
  7.  * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
  8.  *
  9.  * *********************************************************************************************************************
  10.  *
  11.  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  12.  * the License. You may obtain a copy of the License at
  13.  *
  14.  *     http://www.apache.org/licenses/LICENSE-2.0
  15.  *
  16.  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  17.  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations under the License.
  19.  *
  20.  * *********************************************************************************************************************
  21.  *
  22.  * git clone https://bitbucket.org/tidalwave/bluemarine2-src
  23.  * git clone https://github.com/tidalwave-it/bluemarine2-src
  24.  *
  25.  * *********************************************************************************************************************
  26.  */
  27. package it.tidalwave.bluemarine2.upnp.mediaserver.impl.didl;

  28. import javax.annotation.Nonnegative;
  29. import javax.annotation.Nonnull;
  30. import lombok.EqualsAndHashCode;
  31. import lombok.Getter;
  32. import lombok.RequiredArgsConstructor;
  33. import lombok.ToString;
  34. import org.fourthline.cling.support.model.BrowseFlag;
  35. import org.fourthline.cling.support.model.DIDLContent;
  36. import org.fourthline.cling.support.model.DIDLObject;

  37. /***********************************************************************************************************************
  38.  *
  39.  * An adapter which converts an object into DIDL stuff.
  40.  *
  41.  * @stereotype  Role, Adapter
  42.  *
  43.  * @author  Fabrizio Giudici
  44.  *
  45.  **********************************************************************************************************************/
  46. public interface DIDLAdapter
  47.   {
  48.     public static final Class<DIDLAdapter> _DIDLAdapter_ = DIDLAdapter.class;

  49.     /*******************************************************************************************************************
  50.      *
  51.      ******************************************************************************************************************/
  52.     @RequiredArgsConstructor @Getter @EqualsAndHashCode  @ToString
  53.     public static class ContentHolder
  54.       {
  55.         /**
  56.          * The {@link DIDLContent}.
  57.          */
  58.         @Nonnull
  59.         private final DIDLContent content;

  60.         /**
  61.          * The number of items that are being returned - this take into account the fact that the client has
  62.          * requested a subset of data.
  63.          */
  64.         @Nonnegative
  65.         private final int numberReturned;

  66.         /**
  67.          * The number of items that would match the client request.
  68.          */
  69.         @Nonnegative
  70.         private final int totalMatches;
  71.       }

  72.     /*******************************************************************************************************************
  73.      *
  74.      * Converts the owner object to a {@link DIDLContent}.
  75.      *
  76.      * @param   browseFlag  whether metadata for a single object or enumeration of children should be returned
  77.      * @param   from        in case of multiple results, the first item to return
  78.      * @param   maxResults  in case of multiple results, how many items to return
  79.      * @return              the holder of {@code DIDLContent}
  80.      *
  81.      ******************************************************************************************************************/
  82.     @Nonnull
  83.     public default ContentHolder toContent (@Nonnull final BrowseFlag browseFlag,
  84.                                             @Nonnegative final int from,
  85.                                             @Nonnegative final int maxResults)
  86.       throws Exception
  87.       {
  88.         final DIDLContent content = new DIDLContent();
  89.         content.addObject(toObject());
  90.         return new ContentHolder(content, 1, 1);
  91.       }

  92.     /*******************************************************************************************************************
  93.      *
  94.      * Converts the owner object to a {@link DIDLObject}.
  95.      *
  96.      * @return              the {@code DIDLObject}
  97.      *
  98.      ******************************************************************************************************************/
  99.     @Nonnull
  100.     public DIDLObject toObject()
  101.       throws Exception;
  102.   }