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