it.tidalwave.mobile.media.Media Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* $Id: Media.java,v 523e997730e9 2010/06/26 16:21:59 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.mobile.media;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import org.openide.util.Lookup;
import it.tidalwave.util.As;
import it.tidalwave.util.AsException;
import it.tidalwave.util.Id;
import it.tidalwave.util.Key;
import it.tidalwave.util.NotFoundException;
import it.tidalwave.util.TypeSafeMap;
import it.tidalwave.util.TypeSafeHashMap;
import it.tidalwave.mobile.util.AsSupport;
import it.tidalwave.mobile.util.Downloadable;
import it.tidalwave.mobile.util.DownloadableImpl;
import it.tidalwave.util.Removable;
import it.tidalwave.util.logging.Logger;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
@Immutable
public class Media extends AsSupport implements As, Lookup.Provider
{
private static final String CLASS = Media.class.getName();
private static final Logger logger = Logger.getLogger(CLASS);
public static final Class Media = Media.class;
public static final String DC = "http://purl.org/dc/elements/1.1/";
public static final String XX = "urn:bluebill-mobile:";
public static final String O = "http://www.tidalwave.it/rdf/observation/2009/02/24#"; // FIXME
// FIXME: use Dunlin Core ids
public static final Key AUTHOR = new Key(DC + "creator");
public static final Key SOURCE = new Key(DC + "publisher");
public static final Key LOCATION = new Key(O + "madeAt");
public static final Key CALL_TYPE = new Key(DC + "title");
public static final Key DATE = new Key(DC + "date");
public static final Key ID = new Key(DC + "identifier");
public static final Key RES_URL = new Key(XX + "url");
public static final Key RIGHTS = new Key(DC + "rights");
public static final Key MIME_TYPE = new Key(XX + "mime-type");
public static final Key DURATION = new Key(XX + "duration");
public static final Key FORMAT = new Key(DC + "format");
public static final Key TYPE = new Key(DC + "type");
@Nonnull
private final TypeSafeMap map;
@CheckForNull
private Downloadable downloadable;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public Media()
{
this(Collections., Object>emptyMap());
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
private Media (final @Nonnull Map, Object> map)
{
this.map = new TypeSafeHashMap(map);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public T get (final @Nonnull Key key)
throws NotFoundException
{
return map.get(key);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public boolean contains (final @Nonnull Key> item)
{
return map.containsKey(item);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Set> getKeys()
{
return map.getKeys();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnegative
public int getSize()
{
return map.getSize();
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Nonnull
public Iterator