Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jreceiver/common/rpc/xmlrpc/MenusImpl.java


1   /* $Header: /cvsroot/jreceiver/jreceiver/src/jreceiver/common/rpc/xmlrpc/MenusImpl.java,v 1.6 2002/07/31 11:29:42 reedesau Exp $ */
2   
3   package jreceiver.common.rpc.xmlrpc;
4   
5   import java.util.Hashtable;
6   import java.util.Vector;
7   import java.net.URL;
8   
9   //import org.apache.commons.logging.*;
10  
11  import jreceiver.common.rec.security.User;
12  import jreceiver.common.rec.util.MenuRec;
13  import jreceiver.common.rec.util.TuneQuery;
14  import jreceiver.common.rpc.Menus;
15  import jreceiver.common.rpc.RpcException;
16  
17  /**
18   * Menu-related queries to a remote server via XML-RPC.
19   *
20   * @author Reed Esau
21   * @version $Revision: 1.6 $ $Date: 2002/07/31 11:29:42 $
22   */
23  public class MenusImpl extends XmlRpcBaseImpl implements Menus {
24  
25      /**
26       * ctor for this implementation
27       */
28      public MenusImpl(URL remote_host, User user)
29      throws RpcException {
30          super(HANDLER_NAME, remote_host, user);
31      }
32  
33  
34      /**
35       * obtain a list of MenuRecs that specify artist names
36       */
37      public Vector getArtistMenuRecs(TuneQuery tune_query,
38                                      int driver_id,
39                                      int rec_offset, int rec_count) throws RpcException {
40  
41          return getRecsHelper(GET_ARTIST_MENU_RECS, tune_query, driver_id,
42                               rec_offset, rec_count);
43      }
44      /**
45       * obtain a list of MenuRecs that specify album/cd names
46       */
47      public Vector getAlbumMenuRecs(TuneQuery tune_query, int driver_id,
48                                     int rec_offset, int rec_count) throws RpcException {
49          return getRecsHelper(GET_ALBUM_MENU_RECS, tune_query, driver_id,
50                               rec_offset, rec_count);
51      }
52      /**
53       * obtain a list of MenuRecs that specify genre names
54       */
55      public Vector getGenreMenuRecs(TuneQuery tune_query, int driver_id,
56                                     int rec_offset, int rec_count) throws RpcException {
57          return getRecsHelper(GET_GENRE_MENU_RECS, tune_query, driver_id,
58                               rec_offset, rec_count);
59      }
60      /**
61       * obtain a list of MenuRecs that specify tune titles
62       */
63      public Vector getTitleMenuRecs(TuneQuery tune_query, int driver_id,
64                                     int rec_offset, int rec_count) throws RpcException {
65          return getRecsHelper(GET_TITLE_MENU_RECS, tune_query, driver_id,
66                               rec_offset, rec_count);
67      }
68  
69  
70      /**
71       * obtain a list of artists, custom formatted, for use in a menu.
72       */
73      public String encodeArtists(TuneQuery tune_query, int driver_id,
74                                  String pattern,
75                                  int rec_offset, int rec_count) throws RpcException {
76          return encodeHelper(ENCODE_ARTISTS, tune_query, driver_id,
77                              pattern,
78                              rec_offset, rec_count);
79      }
80  
81      /**
82       * obtain a list of albums, custom formatted, for use in a menu.
83       */
84      public String encodeAlbums(TuneQuery tune_query, int driver_id,
85                                 String pattern,
86                                 int rec_offset, int rec_count) throws RpcException {
87          return encodeHelper(ENCODE_ALBUMS, tune_query, driver_id,
88                              pattern,
89                              rec_offset, rec_count);
90      }
91  
92      /**
93       * obtain a list of genres, custom formatted, for use in a menu.
94       */
95      public String encodeGenres(TuneQuery tune_query, int driver_id,
96                                 String pattern,
97                                 int rec_offset, int rec_count) throws RpcException {
98          return encodeHelper(ENCODE_GENRES, tune_query, driver_id,
99                              pattern,
100                             rec_offset, rec_count);
101     }
102 
103     /**
104      * obtain a list of titles, custom formatted, for use in a menu.
105      */
106     public String encodeTitles(TuneQuery tune_query, int driver_id,
107                                String pattern,
108                                int rec_offset, int rec_count) throws RpcException {
109         return encodeHelper(ENCODE_TITLES, tune_query, driver_id,
110                             pattern,
111                             rec_offset, rec_count);
112     }
113 
114 //
115 // internal methods
116 //
117 
118     /**
119      * obtain formatted results from the host
120      */
121     private Vector getRecsHelper(String method_name,
122                                  TuneQuery tune_query,
123                                  int driver_id,
124                                  int rec_offset, int rec_count) throws RpcException {
125         if (method_name == null || rec_offset < 0)
126             throw new IllegalArgumentException();
127 
128         Vector params = new Vector();
129         params.add( tune_query != null ? tune_query.toHash() : new Hashtable());
130         params.add( new Integer(driver_id) );
131         params.add( new Integer(rec_offset) );
132         params.add( new Integer(rec_count) );
133         if (log.isDebugEnabled())
134             log.debug(method_name + ": params=" + params);
135         Vector hashed_recs = (Vector)execute(method_name, params);
136         return MenuRec.reconstitute(hashed_recs);
137     }
138 
139     /**
140      * obtain formatted results from the host
141      */
142     private String encodeHelper(String method_name,
143                                 TuneQuery tune_query,
144                                 int driver_id,
145                                 String pattern,
146                                 int rec_offset, int rec_count) throws RpcException {
147         if (method_name == null || pattern == null || rec_offset < 0)
148             throw new IllegalArgumentException();
149 
150         Vector params = new Vector();
151         params.add( tune_query != null ? tune_query.toHash() : new Hashtable());
152         params.add( new Integer(driver_id) );
153         params.add(pattern);  //{0}=idx, {1}=count, {2}=artist/album/genre/title
154         params.add( new Integer(rec_offset) );
155         params.add( new Integer(rec_count) );
156         if (log.isDebugEnabled())
157             log.debug(method_name + ": params=" + params);
158         return(String)execute(method_name, params);
159     }
160 
161     /**
162     * logging sink
163     */
164     //protected static Log log = LogFactory.getLog(MenusImpl.class);
165 }
166 
167 /*
168 JRECEIVER MODIFIED BSD LICENSE
169 
170 Copyright (c) 2001-2002, Reed Esau (reed.esau@pobox.com) All rights reserved.
171 
172 Redistribution and use in source and binary forms, with or without
173 modification, are permitted provided that the following conditions are
174 met:
175 
176 Redistributions of source code must retain the above copyright notice,
177 this list of conditions and the following disclaimer.
178 
179 Redistributions in binary form must reproduce the above copyright notice,
180 this list of conditions and the following disclaimer in the documentation
181 and/or other materials provided with the distribution.
182 
183 Neither the name of the JReceiver Project
184 (http://jreceiver.sourceforge.net) nor the names of its contributors may
185 be used to endorse or promote products derived from this software without
186 specific prior written permission.
187 
188 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
189 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
190 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191 PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
192 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
193 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
194 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
195 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
196 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
197 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
198 POSSIBILITY OF SUCH DAMAGE.
199 */
200