/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/AbstractParameter.java
ViewVC logotype

Annotation of /jlscp/trunk/src/org/linuxsampler/lscp/AbstractParameter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 784 - (hide annotations) (download)
Mon Oct 10 14:55:44 2005 UTC (18 years, 6 months ago) by iliev
File size: 10275 byte(s)
* Updating to version 0.3a (see ChangeLog)

1 iliev 596 /*
2     * jlscp - a java LinuxSampler control protocol API
3     *
4     * Copyright (C) 2005 Grigor Kirilov Iliev
5     *
6     * This file is part of jlscp.
7     *
8     * jlscp is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * jlscp 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
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with jlscp; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.linuxsampler.lscp;
24    
25     /**
26     * This class provides default implementation of the <code>Parameter</code> interface.
27     *
28     * @author Grigor Iliev
29     */
30     public abstract class AbstractParameter<T> implements Parameter<T>, Parseable {
31     private String name = null;
32     private ParameterType type = null;
33     private String desc = null;
34     private boolean fix = true;
35     private boolean multiplicity = true;
36    
37     private boolean mandatory = false;
38     private String[] depends = null;
39    
40     private T val = null;
41     private T dflt = null;
42     private Number rangeMin = null;
43     private Number rangeMax = null;
44     private T[] possibilities = null;
45    
46    
47     public
48     AbstractParameter() {
49    
50     }
51    
52     /**
53     * Gets the name of this parameter.
54     * @return The name of this parameter.
55     */
56     public String
57     getName() { return name; }
58    
59     /**
60     * Sets the name of this parameter.
61     * @param name A <code>String</code> object containing the new name for this parameter.
62     */
63     public void
64     setName(String name) { this.name = name; }
65    
66     /**
67     * Gets the description of this parameter.
68     * @return The description of this parameter.
69     */
70     public String
71     getDescription() { return desc; }
72    
73     /**
74     * Sets the description of this parameter.
75     * @param desc A <code>String</code> instance containing the description of this parameter.
76     */
77     public void
78     setDescription(String desc) { this.desc = desc; }
79    
80     /**
81     * Gets the type of this parameter.
82     * @return The type of this parameter.
83     */
84     public ParameterType
85     getType() { return type; }
86    
87     /**
88     * Sets the type of this parameter.
89     * @param type The type of this parameter.
90     */
91     public void
92     setType(ParameterType type) { this.type = type; }
93    
94     /**
95     * Gets the current value of this parameter.
96     * @return The current value of this parameter.
97     */
98     public T
99     getValue() { return val; }
100    
101     /**
102     * Sets the current value of this parameter.
103     * @param val The new value for this parameter.
104     */
105     public void
106     setValue(T val) { this.val = val; }
107    
108     /**
109     * Determines whether this parameter contains boolean value.
110     * @return <code>true</code> if this parameter contains boolean value,
111     * <code>false</code> otherwise.
112     */
113     public boolean
114     isBoolean() { return type == ParameterType.BOOL; }
115    
116     /**
117     * Determines whether this parameter contains integer value.
118     * @return <code>true</code> if this parameter contains integer value,
119     * <code>false</code> otherwise.
120     */
121     public boolean
122     isInteger() { return type == ParameterType.INT; }
123    
124     /**
125     * Determines whether this parameter contains float value.
126     * @return <code>true</code> if this parameter contains float value,
127     * <code>false</code> otherwise.
128     */
129     public boolean
130     isFloat() { return type == ParameterType.FLOAT; }
131    
132     /**
133     * Determines whether this parameter contains string value.
134     * @return <code>true</code> if this parameter contains string value,
135     * <code>false</code> otherwise.
136     */
137     public boolean
138     isString() { return type == ParameterType.STRING; }
139    
140     /**
141     * Determines whether this parameter contains list of boolean values.
142     * @return <code>true</code> if this parameter contains list of boolean values,
143     * <code>false</code> otherwise.
144     */
145     public boolean
146     isBooleanList() { return type == ParameterType.BOOL_LIST; }
147    
148     /**
149     * Determines whether this parameter contains list of integer values.
150     * @return <code>true</code> if this parameter contains list of integer values,
151     * <code>false</code> otherwise.
152     */
153     public boolean
154     isIntegerList() { return type == ParameterType.INT_LIST; }
155    
156     /**
157     * Determines whether this parameter contains list of float values.
158     * @return <code>true</code> if this parameter contains list of float values,
159     * <code>false</code> otherwise.
160     */
161     public boolean
162     isFloatList() { return type == ParameterType.FLOAT_LIST; }
163    
164     /**
165     * Determines whether this parameter contains list of string values.
166     * @return <code>true</code> if this parameter contains list of string values,
167     * <code>false</code> otherwise.
168     */
169     public boolean
170     isStringList() { return type == ParameterType.STRING_LIST; }
171    
172     /**
173     * Defines if this parameter can be altered.
174     * @return <code>true</code> if the parameter is readonly and <code>false</code>
175     * if the parameter can be altered.
176     */
177     public boolean
178     isFixed() { return fix; }
179    
180     /**
181     * Defines if this parameter allows only one value or list of values.
182     * @return <code>false</code> if this parameter allows only one value and <code>true</code>
183     * if allows a list of values.
184     */
185     public boolean
186     isMultiplicity() { return multiplicity; }
187    
188     /**
189     * Sets if this parameter allows only one value or list of values.
190     * @param b <code>true</code> if this parameter allows list of values,
191     * <code>false</code> otherwise.
192     */
193     public void
194     setMultiplicity(boolean b) { multiplicity = b; }
195    
196     /**
197     * Defines if this parameter must be given when the device is to be created.
198     * @return <code>true</code> if this parameter must be given when the device
199     * is to be created and <code>false</code> otherwise.
200     */
201     public boolean
202     isMandatory() { return mandatory; }
203    
204     /**
205     * Gets a <code>String</code> array with parameter's names this parameter depends on.
206     * @return A <code>String</code> array with parameter's names this parameter depends on
207     * or <code>null</code> if this parameter has no dependances.
208     */
209     public String[]
210     getDependances() { return depends; }
211    
212     /**
213     * Checks if this parameter depends on some other parameter(s).
214     * @return <code>true</code> if this parameter depends on some other parameter(s)
215     * and <code>false</code> otherwise.
216     */
217     public boolean
218     hasDependances() { return depends != null; }
219    
220     /**
221     * Parses a line of text.
222     * @param s A string to be parsed.
223     * @return <code>true</code> if the line has been processed, <code>false</code> otherwise.
224     * @throws LscpException If some error occurs.
225     */
226     public boolean
227     parse(String s) throws LscpException {
228     if(s.startsWith("DESCRIPTION: ")) {
229     desc = s.substring("DESCRIPTION: ".length(), s.length());
230     return true;
231     } else if(s.startsWith("FIX: ")) {
232     fix = Boolean.parseBoolean(s.substring("FIX: ".length(), s.length()));
233     return true;
234     } else if(s.startsWith("MANDATORY: ")) {
235     mandatory = Boolean.parseBoolean (
236     s.substring("MANDATORY: ".length(), s.length())
237     );
238     return true;
239     } else if(s.startsWith("DEPENDS: ")) {
240     s = s.substring("DEPENDS: ".length(), s.length());
241     depends = Parser.parseList(s);
242     return true;
243     }else if(s.startsWith("TYPE: ")) {
244    
245     return true;
246     }else if(s.startsWith("MULTIPLICITY: ")) {
247    
248     return true;
249     }
250    
251     return false;
252     }
253    
254     /**
255     * Parses the specified lines.
256     * @param lnS The lines to be parsed.
257     * @throws LscpException If some error occurs.
258     */
259     protected void
260     parseLines(String[] lnS) throws LscpException {
261     for(String s : lnS) if(!parse(s)) {
262     Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s));
263     }
264     }
265    
266     /**
267     * Gets the default value for this parameter.
268     * @return The default value for this parameter.
269     */
270     public T
271     getDefault() { return dflt; }
272    
273     /**
274     * Sets the default value for this parameter.
275     * @param dflt Specifies the default value for this parameter.
276     */
277     public T
278     setDefault(T dflt) { return this.dflt = dflt; }
279    
280     /**
281     * Gets the lower limit of the allowed value range for this parameter.
282 iliev 784 * @return The lower limit of the allowed value range for this
283     * parameter or <code>null</code> if the parameter doesn't have lower limit.
284 iliev 596 */
285     public Number
286     getRangeMin() { return rangeMin; }
287    
288     /**
289     * Sets the lower limit of the allowed value range for this parameter.
290     * @param min Specifies the lower limit of the allowed value range for this parameter.
291     */
292     public void
293     setRangeMin(Number min) { rangeMin = min; }
294    
295     /**
296     * Gets the upper limit of the allowed value range for this parameter.
297 iliev 784 * @return The upper limit of the allowed value range for this
298     * parameter or <code>null</code> if the parameter doesn't have upper limit.
299 iliev 596 */
300     public Number
301     getRangeMax() { return rangeMax; }
302    
303     /**
304     * Sets the upper limit of the allowed value range for this parameter.
305     * @param max Specifies the upper limit of the allowed value range for this parameter.
306     */
307     public void
308     setRangeMax(Number max) { rangeMax = max; }
309    
310     /**
311     * Gets a list of possible values for this parameter.
312     * @return A list of possible values for this parameter.
313     */
314     public T[]
315     getPossibilities() { return possibilities; }
316    
317     /**
318     * Sets the list of possible values for this parameter.
319     * @param pos The new list of possible values for this parameter.
320     */
321     public void
322     setPossibilities(T[] pos) { possibilities = pos; }
323    
324     /**
325     * Determines whether this parameter has a lower limit.
326     * @return <code>true</code> if this parameter has a lower limit,
327     * <code>false</code> otherwise.
328     */
329     public boolean
330     hasRangeMin() { return rangeMin != null; }
331    
332     /**
333     * Determines whether this parameter has an upper limit.
334     * @return <code>true</code> if this parameter has an upper limit,
335     * <code>false</code> otherwise.
336     */
337     public boolean
338     hasRangeMax() { return rangeMax != null; }
339    
340     /**
341     * Determines whether this parameter has a list of possible values.
342     * @return <code>true</code> if this parameter has a list of possible values,
343     * <code>false</code> otherwise.
344     */
345     public boolean
346     hasPossibilities() { return possibilities != null; }
347    
348     /**
349     * Returns the name of this parameter.
350     * @return The name of this parameter.
351     */
352     public String
353     toString() { return getName(); }
354     }

  ViewVC Help
Powered by ViewVC