?? didlobject.java
字號:
/* * Copyright (C) 2011 Teleal GmbH, Switzerland * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */package org.teleal.cling.support.model;import org.w3c.dom.Element;import java.net.URI;import java.util.ArrayList;import java.util.Iterator;import java.util.List;/** * @author Christian Bauer * @author Mario Franco */public abstract class DIDLObject { static public abstract class Property<V> { public interface NAMESPACE { } private V value; final private String descriptorName; final private List<Property<DIDLAttribute>> attributes = new ArrayList<Property<DIDLAttribute>>(); protected Property() { this(null, null); } protected Property(String descriptorName) { this(null, descriptorName); } protected Property(V value, String descriptorName) { this.value = value; this.descriptorName = descriptorName == null ? getClass().getSimpleName().toLowerCase() : descriptorName; } protected Property(V value, String descriptorName, List<Property<DIDLAttribute>> attributes) { this.value = value; this.descriptorName = descriptorName == null ? getClass().getSimpleName().toLowerCase() : descriptorName; this.attributes.addAll(attributes); } public V getValue() { return value; } public void setValue(V value) { this.value = value; } public String getDescriptorName() { return descriptorName; } public void setOnElement(Element element) { element.setTextContent(toString()); for (Property<DIDLAttribute> attr : attributes) { element.setAttributeNS( attr.getValue().getNamespaceURI(), attr.getValue().getPrefix() + ':' + attr.getDescriptorName(), attr.getValue().getValue()); } } public void addAttribute(Property<DIDLAttribute> attr) { } public void removeAttribute(Property<DIDLAttribute> attr) { this.attributes.remove(attr); } public void removeAttribute(String descriptorName) { for (Property<DIDLAttribute> attr : attributes) { if (attr.getDescriptorName().equals(descriptorName)) { this.removeAttribute(attr); break; } } } public Property<DIDLAttribute> getAttribute(String descriptorName) { for (Property<DIDLAttribute> attr : attributes) { if (attr.getDescriptorName().equals(descriptorName)) { return attr; } } return null; } @Override public String toString() { return getValue() != null ? getValue().toString() : ""; } static public class PropertyPersonWithRole extends Property<PersonWithRole> { public PropertyPersonWithRole() { } public PropertyPersonWithRole(String descriptorName) { super(descriptorName); } public PropertyPersonWithRole(PersonWithRole value, String descriptorName) { super(value, descriptorName); } @Override public void setOnElement(Element element) { if (getValue() != null) getValue().setOnElement(element); } } static public class DC { public interface NAMESPACE extends Property.NAMESPACE { public static final String URI = "http://purl.org/dc/elements/1.1/"; } static public class DESCRIPTION extends Property<String> implements NAMESPACE { public DESCRIPTION() { } public DESCRIPTION(String value) { super(value, null); } } static public class PUBLISHER extends Property<Person> implements NAMESPACE { public PUBLISHER() { } public PUBLISHER(Person value) { super(value, null); } } static public class CONTRIBUTOR extends Property<Person> implements NAMESPACE { public CONTRIBUTOR() { } public CONTRIBUTOR(Person value) { super(value, null); } } static public class DATE extends Property<String> implements NAMESPACE { public DATE() { } public DATE(String value) { super(value, null); } } static public class LANGUAGE extends Property<String> implements NAMESPACE { public LANGUAGE() { } public LANGUAGE(String value) { super(value, null); } } static public class RELATION extends Property<URI> implements NAMESPACE { public RELATION() { } public RELATION(URI value) { super(value, null); } } static public class RIGHTS extends Property<String> implements NAMESPACE { public RIGHTS() { } public RIGHTS(String value) { super(value, null); } } } static public abstract class UPNP { public interface NAMESPACE extends Property.NAMESPACE { public static final String URI = "urn:schemas-upnp-org:metadata-1-0/upnp/"; } static public class ARTIST extends PropertyPersonWithRole implements NAMESPACE { public ARTIST() { } public ARTIST(PersonWithRole value) { super(value, null); } } static public class ACTOR extends PropertyPersonWithRole implements NAMESPACE { public ACTOR() { } public ACTOR(PersonWithRole value) { super(value, null); } } static public class AUTHOR extends PropertyPersonWithRole implements NAMESPACE { public AUTHOR() { } public AUTHOR(PersonWithRole value) { super(value, null); } } static public class PRODUCER extends Property<Person> implements NAMESPACE { public PRODUCER() { } public PRODUCER(Person value) { super(value, null); } } static public class DIRECTOR extends Property<Person> implements NAMESPACE { public DIRECTOR() { } public DIRECTOR(Person value) { super(value, null); } } static public class GENRE extends Property<String> implements NAMESPACE { public GENRE() { } public GENRE(String value) { super(value, null); } } static public class ALBUM extends Property<String> implements NAMESPACE { public ALBUM() { } public ALBUM(String value) { super(value, null); } } static public class PLAYLIST extends Property<String> implements NAMESPACE { public PLAYLIST() { } public PLAYLIST(String value) { super(value, null); } } static public class REGION extends Property<String> implements NAMESPACE { public REGION() { } public REGION(String value) { super(value, null); } } static public class RATING extends Property<String> implements NAMESPACE { public RATING() { } public RATING(String value) { super(value, null); } } static public class TOC extends Property<String> implements NAMESPACE { public TOC() { } public TOC(String value) { super(value, null); } } static public class ALBUM_ART_URI extends Property<URI> implements NAMESPACE { public ALBUM_ART_URI() { this(null); } public ALBUM_ART_URI(URI value) { super(value, "albumArtURI"); } public ALBUM_ART_URI(URI value, List<Property<DIDLAttribute>> attributes) { super(value, "albumArtURI", attributes); } } static public class ARTIST_DISCO_URI extends Property<URI> implements NAMESPACE { public ARTIST_DISCO_URI() { this(null); } public ARTIST_DISCO_URI(URI value) { super(value, "artistDiscographyURI"); } } static public class LYRICS_URI extends Property<URI> implements NAMESPACE { public LYRICS_URI() { this(null); } public LYRICS_URI(URI value) { super(value, "lyricsURI"); } } static public class STORAGE_TOTAL extends Property<Long> implements NAMESPACE { public STORAGE_TOTAL() { this(null); } public STORAGE_TOTAL(Long value) { super(value, "storageTotal"); } } static public class STORAGE_USED extends Property<Long> implements NAMESPACE { public STORAGE_USED() { this(null); } public STORAGE_USED(Long value) { super(value, "storageUsed"); } } static public class STORAGE_FREE extends Property<Long> implements NAMESPACE { public STORAGE_FREE() { this(null); } public STORAGE_FREE(Long value) { super(value, "storageFree"); } } static public class STORAGE_MAX_PARTITION extends Property<Long> implements NAMESPACE { public STORAGE_MAX_PARTITION() { this(null); } public STORAGE_MAX_PARTITION(Long value) { super(value, "storageMaxPartition"); } } static public class STORAGE_MEDIUM extends Property<StorageMedium> implements NAMESPACE { public STORAGE_MEDIUM() { this(null); } public STORAGE_MEDIUM(StorageMedium value) { super(value, "storageMedium"); } } static public class LONG_DESCRIPTION extends Property<String> implements NAMESPACE { public LONG_DESCRIPTION() { this(null); } public LONG_DESCRIPTION(String value) { super(value, "longDescription"); } } static public class ICON extends Property<URI> implements NAMESPACE { public ICON() { } public ICON(URI value) { super(value, null); } } static public class RADIO_CALL_SIGN extends Property<String> implements NAMESPACE { public RADIO_CALL_SIGN() { this(null); } public RADIO_CALL_SIGN(String value) { super(value, "radioCallSign"); } } static public class RADIO_STATION_ID extends Property<String> implements NAMESPACE { public RADIO_STATION_ID() {