1 /*
2 * Licensed to The Apereo Foundation under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work for additional
4 * information regarding copyright ownership.
5 *
6 *
7 * The Apereo Foundation licenses this file to you under the Educational
8 * Community License, Version 2.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of the License
10 * at:
11 *
12 * http://opensource.org/licenses/ecl2.txt
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 * License for the specific language governing permissions and limitations under
18 * the License.
19 *
20 */
21
22 package org.opencastproject.smil.entity;
23
24 import org.opencastproject.mediapackage.identifier.IdImpl;
25 import org.opencastproject.smil.entity.api.SmilObject;
26
27 import java.util.List;
28
29 import javax.xml.bind.annotation.XmlAttribute;
30 import javax.xml.bind.annotation.XmlID;
31
32 /**
33 * Implementation of {@link SmilObject}.
34 */
35 public abstract class SmilObjectImpl implements SmilObject {
36
37 /**
38 * Smil object Id
39 */
40 private String id;
41
42 /**
43 * Constructor. Generate a new Id.
44 */
45 public SmilObjectImpl() {
46 id = String.format("%s-%s", getIdPrefix(), IdImpl.fromUUID().toString());
47 }
48
49 /**
50 * Constructor.
51 *
52 * @param id Id to set
53 */
54 public SmilObjectImpl(String id) {
55 this.id = id;
56 }
57
58 /**
59 * {@inheritDoc }
60 */
61 @XmlAttribute(namespace = "http://www.w3.org/XML/1998/namespace")
62 @XmlID
63 @Override
64 public String getId() {
65 return id;
66 }
67
68 /**
69 * Set Id.
70 *
71 * @param id Id to set
72 */
73 private void setId(String id) {
74 this.id = id;
75 }
76
77 /**
78 * Returns {@link SmilObject} Id prefix (must begin with alphanumeric
79 * charackter).
80 *
81 * @return Id prefix
82 */
83 protected abstract String getIdPrefix();
84
85 /**
86 * Returns element with given elementId or null.
87 *
88 * @param elementId element Id
89 * @return element with given elementId or null
90 */
91 public abstract SmilObject getElementOrNull(String elementId);
92
93 /**
94 * Put all containing elements into {@link List} given as parameter.
95 *
96 * @param elements {@link List} where to pul child elements to
97 */
98 public abstract void putAllChilds(List<SmilObject> elements);
99
100 /**
101 * Remove element with given Id and returns it. Returns null if there is no
102 * element with given Id.
103 *
104 * @param elementId element Id
105 * @return removed element or null
106 */
107 public abstract SmilObject removeElement(String elementId);
108 }