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;
17  
18  import org.w3c.dom.Document;
19  import org.w3c.dom.Element;
20  
21  import javax.xml.parsers.DocumentBuilderFactory;
22  import java.net.URI;
23  
24  
25  /**
26   * Descriptor metadata about an item/resource.
27   *
28   * <pre>
29   * &lt;complexType>
30   *   &lt;complexContent>
31   *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
32   *       &lt;sequence>
33   *         &lt;any namespace='##other'/>
34   *       &lt;/sequence>
35   *       &lt;attribute name="id" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
36   *       &lt;attribute name="type" type="{http://www.w3.org/2001/XMLSchema}string" />
37   *       &lt;attribute name="nameSpace" use="required" type="{http://www.w3.org/2001/XMLSchema}anyURI" />
38   *     &lt;/restriction>
39   *   &lt;/complexContent>
40   * &lt;/complexType>
41   * </pre>
42   * 
43   * 
44   */
45  public class DescMeta<M> {
46  
47      protected String id;
48      protected String type;
49      protected URI nameSpace;
50      protected M metadata;
51  
52      public DescMeta() {
53      }
54  
55      public DescMeta(String id, String type, URI nameSpace, M metadata) {
56          this.id = id;
57          this.type = type;
58          this.nameSpace = nameSpace;
59          this.metadata = metadata;
60      }
61  
62      public String getId() {
63          return id;
64      }
65  
66      public void setId(String id) {
67          this.id = id;
68      }
69  
70      public String getType() {
71          return type;
72      }
73  
74      public void setType(String type) {
75          this.type = type;
76      }
77  
78      public URI getNameSpace() {
79          return nameSpace;
80      }
81  
82      public void setNameSpace(URI nameSpace) {
83          this.nameSpace = nameSpace;
84      }
85  
86      public M getMetadata() {
87          return metadata;
88      }
89  
90      public void setMetadata(M metadata) {
91          this.metadata = metadata;
92      }
93  
94      public Document createMetadataDocument() {
95          try {
96              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
97              factory.setNamespaceAware(true);
98              Document d = factory.newDocumentBuilder().newDocument();
99              Element rootElement = d.createElementNS(DIDLContent.DESC_WRAPPER_NAMESPACE_URI, "desc-wrapper");
100             d.appendChild(rootElement);
101             return d;
102         } catch (Exception ex) {
103             throw new RuntimeException(ex);
104         }
105     }
106 }