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