1 |
/* |
2 |
* jlscp - a java LinuxSampler control protocol API |
3 |
* |
4 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
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 implements the <code>Parameter<String[]></code> interface. |
27 |
* @author Grigor Iliev |
28 |
*/ |
29 |
public class StringListParameter extends AbstractParameter<String[]> { |
30 |
/** Creates a new instance of <code>StringListParameter</code> */ |
31 |
public StringListParameter() { |
32 |
setType(ParameterType.STRING_LIST); |
33 |
setMultiplicity(true); |
34 |
} |
35 |
|
36 |
/** |
37 |
* Creates a <code>StringListParameter</code> instance with the specified name. |
38 |
* @param name The parameter name. |
39 |
*/ |
40 |
public |
41 |
StringListParameter(String name) { |
42 |
this(name, null); |
43 |
} |
44 |
|
45 |
/** |
46 |
* Creates a <code>StringListParameter</code> instance with the specified name and value. |
47 |
* @param name The parameter name. |
48 |
* @param value The parameter value. |
49 |
*/ |
50 |
public |
51 |
StringListParameter(String name, String[] value) { |
52 |
this(); |
53 |
setName(name); |
54 |
setValue(value); |
55 |
} |
56 |
|
57 |
/** |
58 |
* Creates a new instance of <code>StringListParameter</code> |
59 |
* and parses the specified lines. |
60 |
* @param lnS A <code>String</code> array with lines to be parsed. |
61 |
* @throws LscpException If the parse fail. |
62 |
*/ |
63 |
protected |
64 |
StringListParameter(String[] lnS) throws LscpException { |
65 |
this(); |
66 |
parseLines(lnS); |
67 |
} |
68 |
|
69 |
/** |
70 |
* Parses a line of text. |
71 |
* @param s The string to be parsed. |
72 |
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
73 |
* @throws LscpException If some error occurs. |
74 |
*/ |
75 |
public boolean |
76 |
parse(String s) throws LscpException { |
77 |
if(super.parse(s)) return true; |
78 |
else if(s.startsWith("DEFAULT: ")) { |
79 |
setDefault(Parser.parseStringList(s.substring("DEFAULT: ".length()))); |
80 |
return true; |
81 |
} else if(s.startsWith("POSSIBILITIES: ")) { |
82 |
s = s.substring("POSSIBILITIES: ".length(), s.length()); |
83 |
setPossibilities(Parser.parseListOfStringLists(s)); |
84 |
|
85 |
return true; |
86 |
} |
87 |
|
88 |
return false; |
89 |
} |
90 |
|
91 |
/** |
92 |
* Parses the specified character string and sets the value of this parameter |
93 |
* with the parsed result. |
94 |
* @param s A character string containing the value to be parsed. |
95 |
* @throws LscpException If the parsing failed. |
96 |
*/ |
97 |
public void |
98 |
parseValue(String s) throws LscpException { setValue(Parser.parseStringList(s)); } |
99 |
|
100 |
/** |
101 |
* Gets the current value of this parameter. |
102 |
* @return The current value of this parameter. |
103 |
*/ |
104 |
public String |
105 |
getStringValue() { |
106 |
String[] ar = getValue(); |
107 |
|
108 |
if(ar == null || ar.length == 0) return ""; |
109 |
|
110 |
StringBuffer sb = new StringBuffer(); |
111 |
sb.append('\'').append(ar[0]).append('\''); |
112 |
|
113 |
for(int i = 1; i < ar.length; i++) sb.append(",'").append(ar[i]).append('\''); |
114 |
|
115 |
return sb.toString(); |
116 |
} |
117 |
} |