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

Quick Search    Search Deep

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


1   /* $Header: /cvsroot/jreceiver/jreceiver/src/jreceiver/common/rpc/xmlrpc/XmlRpcBaseHandler.java,v 1.1 2002/07/31 11:29:42 reedesau Exp $ */
2   
3   package jreceiver.common.rpc.xmlrpc;
4   
5   import java.io.File;
6   import java.util.Vector;
7   
8   import org.apache.commons.logging.*;
9   import org.apache.xmlrpc.AuthenticatedXmlRpcHandler;
10  
11  import jreceiver.common.rec.security.User;
12  import jreceiver.common.rec.security.UserRec;
13  import jreceiver.common.rpc.RpcBase;
14  import jreceiver.util.HelperFile;
15  
16  /**
17   * Abstract XML-RPC interface for providing basic handler services
18   *
19   * @author Reed Esau
20   * @version $Revision: 1.1 $ $Date: 2002/07/31 11:29:42 $
21   */
22  public abstract class XmlRpcBaseHandler implements AuthenticatedXmlRpcHandler {
23  
24      /** subclasses override this to handle a request */
25      public abstract Object executeHandler(String method, Vector params, User user) throws Exception;
26  
27  //
28  // misc services
29  //
30  
31      /**
32       * Return the result, or throw an Exception if something went wrong.
33       * <p>
34       * This method is needed to capture and report exceptions.  It could be
35       * done in subclasses, but would be error-prone bloat.
36       */
37      public final Object execute(String method, Vector params, String user, String password) throws Exception {
38  
39          // everybody supports 'detect'; no authentication needed
40          if (method.equals(RpcBase.DETECT))
41              return new Boolean(true);
42  
43          try {
44              return executeHandler(method, params, new UserRec(user, password) );
45          }
46          catch (Exception e) {
47              log.warn("cannot service rpc request for method=" + method + " user=" + user, e);
48              throw e;
49          }
50      }
51  
52  //
53  // Helpers
54  //
55  
56      /** helper for extracting a primitive int from the param list */
57      protected int getInt(Vector params, int index) {
58          return((Integer)params.get(index)).intValue();
59      }
60      /** helper for extracting a primitive boolean from the param list */
61      protected boolean getBool(Vector params, int index) {
62          return((Boolean)params.get(index)).booleanValue();
63      }
64  
65      /** helper for extracting a File object from a site.Path object the param list */
66      protected File getFile(Vector params, int index) {
67          Object obj = params.get(index);
68          if (obj instanceof String) {
69              return new File( (String)obj );
70          }
71          else if (obj instanceof Vector) {     // a vector of path components
72              return HelperFile.composeFile( (Vector)obj );
73          }
74          else if (obj instanceof File) {
75              return (File)obj;
76          }
77          return null;        // don't know what to do
78      }
79  
80      /**
81      * logging sink
82      */
83      protected static Log log = LogFactory.getLog(XmlRpcBaseHandler.class);
84  }
85  
86  /*
87  JRECEIVER MODIFIED BSD LICENSE
88  
89  Copyright (c) 2001-2002, Reed Esau (reed.esau@pobox.com) All rights reserved.
90  
91  Redistribution and use in source and binary forms, with or without
92  modification, are permitted provided that the following conditions are
93  met:
94  
95  Redistributions of source code must retain the above copyright notice,
96  this list of conditions and the following disclaimer.
97  
98  Redistributions in binary form must reproduce the above copyright notice,
99  this list of conditions and the following disclaimer in the documentation
100 and/or other materials provided with the distribution.
101 
102 Neither the name of the JReceiver Project
103 (http://jreceiver.sourceforge.net) nor the names of its contributors may
104 be used to endorse or promote products derived from this software without
105 specific prior written permission.
106 
107 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
108 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
109 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
110 PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
111 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
112 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
113 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
114 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
115 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
116 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
117 POSSIBILITY OF SUCH DAMAGE.
118 */
119 
120