KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > language > LanguagePackDefinition


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.language;
21
22 import java.net.URL JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 import com.sslexplorer.extensions.ExtensionDescriptor;
28
29
30 /**
31  * Encapsulates a language pack. Language packs may be added to SSL-Explorer via
32  * the extensions mechanism (in which case {@link #getExtensionDescriptor()} will
33  * return the extension that contains it or it will be loaded via the
34  * core in which the {@link #getExtensionDescriptor()} will return <code>null</code>.
35  *
36  * @author Brett Smith <a HREF="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  * @see LanguagePackManager
38  */

39 public class LanguagePackDefinition implements Comparable JavaDoc {
40     
41     // Private instance variables
42

43     private List JavaDoc classPath;
44     private String JavaDoc name;
45     private String JavaDoc date;
46     private List JavaDoc contains;
47     private ExtensionDescriptor descriptor;
48
49     /**
50      * Constructor for new empty language pack.
51      *
52      * @param descriptor the extension descriptor that contains the language pack
53      * @param name name of language pack
54      */

55     public LanguagePackDefinition(ExtensionDescriptor descriptor, String JavaDoc name) {
56         this(descriptor, name, new ArrayList JavaDoc());
57     }
58
59     /**
60      * Constructor.
61      *
62      * @param descriptor the extension descriptor that contains the language pack or <code>null</code> if the pack is part of the core
63      * @param name name of language pack
64      * @param contains {@link List} of {@link Language} objects supported by this pack
65      */

66     public LanguagePackDefinition(ExtensionDescriptor descriptor, String JavaDoc name, List JavaDoc contains) {
67         classPath = new ArrayList JavaDoc();
68         this.descriptor = descriptor;
69         this.name = name;
70         this.contains = contains;
71     }
72     
73     /**
74      * Get the extension descriptor that contains this
75      * language pack or <code>null</code> if it is part of
76      * the core.
77      *
78      * @return extension descriptor
79      */

80     public ExtensionDescriptor getExtensionDescriptor() {
81         return descriptor;
82     }
83
84     /**
85      * Add a new URL to the classpath to search for the language resources.
86      *
87      * @param url url to add to search for language resources
88      */

89     public void addClassPath(URL JavaDoc url) {
90         classPath.add(url);
91     }
92
93     /* (non-Javadoc)
94      * @see java.lang.Comparable#compareTo(T)
95      */

96     public int compareTo(Object JavaDoc o) {
97         return name.compareTo(((LanguagePackDefinition)o).name);
98     }
99
100     /**
101      * Get the name of this language pack.
102      *
103      * @return name of language pack
104      */

105     public String JavaDoc getName() {
106         return name;
107     }
108
109     /**
110      * Set the name of this language pack.
111      *
112      * @param name name of language pack
113      */

114     public void setName(String JavaDoc name) {
115         this.name = name;
116     }
117
118     /**
119      * Get the creation date of this language pack.
120      *
121      * @return date of language pack
122      */

123     public String JavaDoc getDate() {
124         return date;
125     }
126
127     /**
128      * Set the creation date of this language pack.
129      *
130      * @param date creation date of language pack
131      */

132     public void setDate(String JavaDoc date) {
133         this.date = date;
134     }
135
136     /**
137      * Get the classpath (a list of {@link String} ojects) that should be
138      * added to the server classpath to support this language pack.
139      *
140      * @return classpath
141      */

142     public List JavaDoc getClassPath() {
143         return classPath;
144     }
145
146     /**
147      * This list of language codes as {@link Language} objects
148      * this language pack supports.
149      *
150      * @return list of language codes contained in this pack
151      */

152     public List JavaDoc getContains() {
153         return contains;
154     }
155     
156     /**
157      * Add a new language to the list supported by this language pack
158      *
159      * @param language language to add
160      */

161     public void addLanguage(Language language) {
162         contains.add(language);
163     }
164
165     /**
166      * Get an iterator of all {@link Language}s supported by
167      * this pack.
168      *
169      * @return iterator of support languages
170      */

171     public Iterator JavaDoc languages() {
172         return contains.iterator();
173     }
174 }
175
Popular Tags