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

Contents of /jlscp/trunk/src/org/linuxsampler/lscp/StringListParameter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1393 - (show annotations) (download)
Sun Oct 7 20:29:41 2007 UTC (16 years, 6 months ago) by iliev
File size: 3448 byte(s)
* added extended escape sequences support

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&lt;String[]&gt;</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 {
99 setValue(Parser.parseEscapedStringList(s)); // TODO: always escaped?
100 }
101
102 /**
103 * Gets the current value of this parameter.
104 * @return The current value of this parameter.
105 */
106 public String
107 getStringValue() {
108 String[] ar = getValue();
109
110 if(ar == null || ar.length == 0) return "NONE";
111
112 StringBuffer sb = new StringBuffer();
113 sb.append('\'').append(ar[0]).append('\'');
114
115 for(int i = 1; i < ar.length; i++) sb.append(",'").append(ar[i]).append('\'');
116
117 return sb.toString();
118 }
119 }

  ViewVC Help
Powered by ViewVC