KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > metadata > DescriptionMetaDataContainer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.metadata;
23
24 import java.io.Serializable JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Locale JavaDoc;
28
29 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
30
31 /**
32  * An abstract class for meta data that has descriptions
33  *
34  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
35  * @version $Revision: 38342 $
36  */

37 public class DescriptionMetaDataContainer implements Serializable JavaDoc
38 {
39    private static final long serialVersionUID = 2831943526217092377L;
40
41    /** The descriptions */
42    private ConcurrentReaderHashMap descriptions = new ConcurrentReaderHashMap();
43
44    public DescriptionMetaDataContainer()
45    {
46       DescriptionMetaData dmd = new DescriptionMetaData();
47       descriptions.put(dmd.getLanguage(), dmd);
48    }
49
50    /**
51     * Get the desription for the default language
52     * or the first description if there is no default
53     *
54     * @return the description for the default language
55     */

56    public DescriptionMetaData getDescription()
57    {
58       // Try the default locale
59
DescriptionMetaData dmd = (DescriptionMetaData) descriptions.get(Locale.getDefault().getLanguage());
60       // No description using the default locale, just use the first
61
if (dmd == null)
62       {
63          for (Iterator JavaDoc i = descriptions.values().iterator(); i.hasNext();)
64          {
65             dmd = (DescriptionMetaData) i.next();
66             break;
67          }
68       }
69       return dmd;
70    }
71    
72    /**
73     * Get the description for the give language
74     *
75     * @param lang the language
76     * @return the description
77     */

78    public DescriptionMetaData getDescription(String JavaDoc lang)
79    {
80       return (DescriptionMetaData) descriptions.get(lang);
81    }
82    
83    /**
84     * Add a description
85     *
86     * @param dmd the description
87     */

88    public void addDescription(DescriptionMetaData dmd)
89    {
90       descriptions.put(dmd.getLanguage(), dmd);
91    }
92    
93    /**
94     * Get the descriptions
95     *
96     * @return the descriptions
97     */

98    public Collection JavaDoc getDescriptions()
99    {
100       return descriptions.values();
101    }
102    
103    public String JavaDoc toString()
104    {
105       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
106       buffer.append("DescriptionMetaDataContainer").append('@');
107       buffer.append(Integer.toHexString(System.identityHashCode(this)));
108       buffer.append("[descriptions=").append(descriptions.values());
109       buffer.append(']');
110       return buffer.toString();
111    }
112 }
113
Popular Tags