1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.om.impl;
18
19 import java.io.Serializable;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.Iterator;
23 import java.util.Locale;
24
25 import org.apache.jetspeed.om.common.MutableDescriptionSet;
26 import org.apache.jetspeed.util.JetspeedLocale;
27 import org.apache.pluto.om.common.Description;
28
29 /***
30 * BaseDescriptionSet
31 *
32 * Supports
33 *
34 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
35 * @version $Id: DescriptionSetImpl.java 516448 2007-03-09 16:25:47Z ate $
36 *
37 */
38 public class DescriptionSetImpl implements MutableDescriptionSet, Serializable
39 {
40 /*** Specifies the type Description we are storing */
41 protected String descriptionType;
42 protected Collection innerCollection;
43
44 /***
45 *
46 */
47 public DescriptionSetImpl()
48 {
49 super();
50 this.innerCollection = new ArrayList();
51 }
52
53 /***
54 * @param c
55 */
56 public DescriptionSetImpl(Collection c)
57 {
58 this.innerCollection = c;
59 }
60
61
62
63
64 public DescriptionSetImpl(String descriptionType)
65 {
66 super();
67 this.descriptionType = descriptionType;
68 this.innerCollection = new ArrayList();
69 }
70
71 /***
72 * @see org.apache.pluto.om.common.DescriptionSet#get(java.util.Locale)
73 */
74 public Description get(Locale arg0)
75 {
76 if (arg0 == null)
77 {
78 throw new IllegalArgumentException("The Locale argument cannot be null");
79 }
80
81
82 Iterator itr = iterator();
83 Description fallBack = null;
84 while (itr.hasNext())
85 {
86 Description desc = (Description) itr.next();
87 if (desc.getLocale().equals(arg0))
88 {
89 return desc;
90 }
91
92
93 else if (desc.getLocale().getLanguage().equals(arg0.getLanguage()))
94 {
95 fallBack = desc;
96 }
97 else if (fallBack == null && desc.getLocale().equals(JetspeedLocale.getDefaultLocale()))
98 {
99 fallBack = desc;
100 }
101 }
102 return fallBack;
103 }
104
105 /***
106 * @see org.apache.jetspeed.om.common.MutableDescriptionSet#addDescription(java.lang.String)
107 */
108 public void addDescription(Description description)
109 {
110 innerCollection.add(description);
111 }
112
113 /***
114 * @see org.apache.pluto.om.common.DescriptionSet#iterator()
115 */
116 public Iterator iterator()
117 {
118 return innerCollection.iterator();
119 }
120
121 /***
122 * @return
123 */
124 public Collection getInnerCollection()
125 {
126 return innerCollection;
127 }
128
129 /***
130 * @param collection
131 */
132 public void setInnerCollection(Collection collection)
133 {
134 innerCollection = collection;
135 }
136
137 }