Source code: jreceiver/common/rpc/xmlrpc/SettingsImpl.java
1 /* $Header: /cvsroot/jreceiver/jreceiver/src/jreceiver/common/rpc/xmlrpc/SettingsImpl.java,v 1.4 2002/07/31 11:29:42 reedesau Exp $ */
2
3 package jreceiver.common.rpc.xmlrpc;
4
5 import java.util.Vector;
6 import java.net.URL;
7
8 //import org.apache.commons.logging.*;
9
10 import jreceiver.common.rec.security.User;
11 import jreceiver.common.rpc.Settings;
12 import jreceiver.common.rpc.RpcException;
13
14 /**
15 * Settings-related queries to a remote server via XML-RPC.
16 * <p>
17 *
18 * @author Reed Esau
19 * @version $Revision: 1.4 $ $Date: 2002/07/31 11:29:42 $
20 */
21 public class SettingsImpl extends XmlRpcBaseImpl implements Settings {
22
23 /**
24 * ctor for this implementation
25 */
26 public SettingsImpl(URL remote_host, User user)
27 throws RpcException {
28 super(HANDLER_NAME, remote_host, user);
29 }
30
31 //
32 // public methods
33 //
34
35 /**
36 * access to the settings table
37 */
38 public String get(String key)
39 throws RpcException {
40 if (key == null)
41 throw new IllegalArgumentException();
42 Vector params = new Vector();
43 params.addElement(key);
44 return(String)execute(GET, params);
45 }
46
47
48 /**
49 * access to the settings table
50 */
51 public String get(String key, String defaultValue)
52 throws RpcException {
53 if (key == null || defaultValue == null)
54 throw new IllegalArgumentException();
55 Vector params = new Vector();
56 params.addElement(key);
57 params.addElement(defaultValue);
58 return(String)execute(GET, params);
59 }
60
61
62 /**
63 * access to the settings table
64 */
65 public int getInt(String key)
66 throws RpcException {
67 if (key == null)
68 throw new IllegalArgumentException();
69 Vector params = new Vector();
70 params.addElement(key);
71 Integer n = (Integer)execute(GET_INT, params);
72 return n.intValue();
73 }
74
75
76 /**
77 * access to the settings table
78 */
79 public int getInt(String key, int defaultValue)
80 throws RpcException {
81 if (key == null)
82 throw new IllegalArgumentException();
83 Vector params = new Vector();
84 params.addElement(key);
85 params.addElement( new Integer(defaultValue) );
86 Integer n = (Integer)execute(GET_INT, params);
87 return n.intValue();
88 }
89
90
91 /**
92 * access to the settings table
93 */
94 public boolean getBool(String key)
95 throws RpcException {
96 if (key == null)
97 throw new IllegalArgumentException();
98 Vector params = new Vector();
99 params.addElement(key);
100 Boolean n = (Boolean)execute(GET_BOOL, params);
101 return n.booleanValue();
102 }
103
104
105 /**
106 * access to the settings table
107 */
108 public boolean getBool(String key, boolean defaultValue)
109 throws RpcException {
110 if (key == null)
111 throw new IllegalArgumentException();
112 Vector params = new Vector();
113 params.addElement(key);
114 params.addElement( new Boolean(defaultValue) );
115 Boolean n = (Boolean)execute(GET_BOOL, params);
116 return n.booleanValue();
117 }
118
119
120 //
121 // put methods
122 //
123
124 /**
125 * insert or update an integer settings value
126 */
127 public void put( String key, int value)
128 throws RpcException {
129 if (key == null)
130 throw new IllegalArgumentException();
131 Vector params = new Vector();
132 params.addElement(key);
133 params.addElement( new Integer(value) );
134 execute(PUT, params);
135 }
136
137
138 /**
139 * insert or update an boolean settings value
140 */
141 public void put( String key, boolean value)
142 throws RpcException {
143 if (key == null)
144 throw new IllegalArgumentException();
145 Vector params = new Vector();
146 params.addElement(key);
147 params.addElement( new Boolean(value) );
148 execute(PUT, params);
149 }
150
151
152 /**
153 * insert or update a settings value
154 */
155 public void put( String key, String value)
156 throws RpcException {
157 if (key == null || value == null)
158 throw new IllegalArgumentException();
159 String canonized_value = value.trim();
160 Vector params = new Vector();
161 params.addElement(key);
162 params.addElement(canonized_value);
163 execute(PUT, params);
164 }
165
166
167 /**
168 * remove a settings value
169 */
170 public void delete( String key)
171 throws RpcException {
172 if (key == null)
173 throw new IllegalArgumentException();
174 Vector params = new Vector();
175 params.addElement(key);
176 execute(DELETE, params);
177 }
178
179 /**
180 * logging object
181 */
182 //protected static Log log = LogFactory.getLog(Settings.class);
183 }
184
185 /*
186 JRECEIVER MODIFIED BSD LICENSE
187
188 Copyright (c) 2001-2002, Reed Esau (reed.esau@pobox.com) All rights reserved.
189
190 Redistribution and use in source and binary forms, with or without
191 modification, are permitted provided that the following conditions are
192 met:
193
194 Redistributions of source code must retain the above copyright notice,
195 this list of conditions and the following disclaimer.
196
197 Redistributions in binary form must reproduce the above copyright notice,
198 this list of conditions and the following disclaimer in the documentation
199 and/or other materials provided with the distribution.
200
201 Neither the name of the JReceiver Project
202 (http://jreceiver.sourceforge.net) nor the names of its contributors may
203 be used to endorse or promote products derived from this software without
204 specific prior written permission.
205
206 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
207 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
208 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
209 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
210 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
212 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
213 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
214 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
215 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
216 POSSIBILITY OF SUCH DAMAGE.
217 */
218