improved the XML-RPC library support and added a document describing all the
current XML-RPC functions
This commit is contained in:
parent
681ec6a8a0
commit
1c245749f7
BIN
doc/xmlrpc-functions-reference.sxw
Normal file
BIN
doc/xmlrpc-functions-reference.sxw
Normal file
Binary file not shown.
110
src/com/silverwrist/venice/ui/rpc/XmlRpcLibrary.java
Normal file
110
src/com/silverwrist/venice/ui/rpc/XmlRpcLibrary.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
||||
* (the "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
package com.silverwrist.venice.ui.rpc;
|
||||
|
||||
import java.util.*;
|
||||
import com.silverwrist.util.*;
|
||||
|
||||
public class XmlRpcLibrary
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static XmlRpcLibrary s_self = null;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private XmlRpcLibrary()
|
||||
{ // no external access
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public final void setIfNotNull(Map struct, String name, Object value)
|
||||
{
|
||||
if (value!=null)
|
||||
struct.put(name,value);
|
||||
|
||||
} // end setIfNotNull
|
||||
|
||||
public final int structMemberAsInt(Map struct, String name) throws XmlRpcFault
|
||||
{
|
||||
Object foo = struct.get(name);
|
||||
if (foo instanceof Integer)
|
||||
return ((Integer)foo).intValue();
|
||||
else if (foo instanceof Boolean)
|
||||
return ((Boolean)foo).booleanValue() ? 1 : 0;
|
||||
else
|
||||
throw new XmlRpcFault(10000,"type mismatch in structure member \"" + name + "\"");
|
||||
|
||||
} // end structMemberAsInt
|
||||
|
||||
public final String structMemberAsString(Map struct, String name) throws XmlRpcFault
|
||||
{
|
||||
Object foo = struct.get(name);
|
||||
if ((foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map))
|
||||
throw new XmlRpcFault(10000,"type mismatch in structure member \"" + name + "\"");
|
||||
return foo.toString();
|
||||
|
||||
} // end structMemberAsString
|
||||
|
||||
public final boolean structMemberAsBoolean(Map struct, String name) throws XmlRpcFault
|
||||
{
|
||||
Object foo = struct.get(name);
|
||||
if (foo instanceof Boolean)
|
||||
return ((Boolean)foo).booleanValue();
|
||||
else if (foo instanceof Integer)
|
||||
return (((Integer)foo).intValue()!=0);
|
||||
else if (foo instanceof String)
|
||||
return !StringUtil.isStringEmpty((String)foo);
|
||||
else
|
||||
throw new XmlRpcFault(10000,"type mismatch in structure member \"" + name + "\"");
|
||||
|
||||
} // end structMemberAsBoolean
|
||||
|
||||
public final java.util.Date structMemberAsDate(Map struct, String name) throws XmlRpcFault
|
||||
{
|
||||
Object foo = struct.get(name);
|
||||
if (!(foo instanceof java.util.Date))
|
||||
throw new XmlRpcFault(10000,"type mismatch in structure member \"" + name + "\"");
|
||||
return (java.util.Date)foo;
|
||||
|
||||
} // end structMemberAsDate
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final XmlRpcLibrary get()
|
||||
{
|
||||
if (s_self==null)
|
||||
s_self = new XmlRpcLibrary();
|
||||
return s_self;
|
||||
|
||||
} // end get
|
||||
|
||||
} // end class XmlRpcLibrary
|
|
@ -441,6 +441,44 @@ public class XmlRpcRequest
|
|||
|
||||
} // end getParamType
|
||||
|
||||
public final boolean isParamCompatible(int ndx, String type)
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
if (type.equals("int"))
|
||||
return ((foo instanceof Boolean) || (foo instanceof Integer));
|
||||
if (type.equals("boolean"))
|
||||
return ((foo instanceof Boolean) || (foo instanceof Integer) || (foo instanceof String));
|
||||
if (type.equals("string"))
|
||||
return ( (foo instanceof Boolean) || (foo instanceof Integer) || (foo instanceof Double)
|
||||
|| (foo instanceof String) || (foo instanceof java.util.Date));
|
||||
if (type.equals("double"))
|
||||
return ((foo instanceof Boolean) || (foo instanceof Integer) || (foo instanceof Double));
|
||||
if (type.equals("dateTime"))
|
||||
return (foo instanceof java.util.Date);
|
||||
if (type.equals("base64"))
|
||||
return (foo instanceof byte[]);
|
||||
if (type.equals("struct"))
|
||||
return (foo instanceof Map);
|
||||
if (type.equals("array"))
|
||||
return (foo instanceof List);
|
||||
return false;
|
||||
|
||||
} // end isParamCompatible
|
||||
|
||||
public final boolean getParamBoolean(int ndx) throws XmlRpcFault
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
if (foo instanceof Boolean)
|
||||
return ((Boolean)foo).booleanValue();
|
||||
else if (foo instanceof Integer)
|
||||
return (((Integer)foo).intValue()!=0);
|
||||
else if (foo instanceof String)
|
||||
return !StringUtil.isStringEmpty((String)foo);
|
||||
else
|
||||
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
|
||||
|
||||
} // end getParamBoolean
|
||||
|
||||
public final int getParamInt(int ndx) throws XmlRpcFault
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
|
@ -496,10 +534,42 @@ public class XmlRpcRequest
|
|||
|
||||
} // end getParamSQLDate
|
||||
|
||||
public final Map getParamStruct(int ndx) throws XmlRpcFault
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
if (foo instanceof Map)
|
||||
return (Map)foo;
|
||||
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
|
||||
|
||||
} // end getParamStruct
|
||||
|
||||
public final List getParamArray(int ndx) throws XmlRpcFault
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
if (foo instanceof List)
|
||||
return (List)foo;
|
||||
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
|
||||
|
||||
} // end getParamArray
|
||||
|
||||
public final AdminUserContext getParamUser(int ndx, AdminOperations adm) throws XmlRpcFault, DataException
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
if ( (foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map) || (foo instanceof Boolean)
|
||||
|| (foo instanceof java.util.Date))
|
||||
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
|
||||
if (foo instanceof Number)
|
||||
return adm.getUserContext(((Number)foo).intValue());
|
||||
else
|
||||
return adm.getUserContext(foo.toString().trim());
|
||||
|
||||
} // end getParamUser
|
||||
|
||||
public final CommunityContext getParamCommunity(int ndx) throws XmlRpcFault, DataException
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
if ((foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map) || (foo instanceof Boolean))
|
||||
if ( (foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map) || (foo instanceof Boolean)
|
||||
|| (foo instanceof java.util.Date))
|
||||
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
|
||||
if (foo instanceof Integer)
|
||||
return m_req.getUser().getCommunityContext(((Integer)foo).intValue());
|
||||
|
@ -512,7 +582,8 @@ public class XmlRpcRequest
|
|||
throws XmlRpcFault, DataException, AccessError
|
||||
{
|
||||
Object foo = m_method_params.get(ndx);
|
||||
if ((foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map) || (foo instanceof Boolean))
|
||||
if ( (foo instanceof byte[]) || (foo instanceof List) || (foo instanceof Map) || (foo instanceof Boolean)
|
||||
|| (foo instanceof java.util.Date))
|
||||
throw new XmlRpcFault(XmlRpcFault.INVALID_PARAMS,"parameter type mismatch");
|
||||
if (foo instanceof Integer)
|
||||
return comm.getConferenceContext(((Integer)foo).intValue());
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@ricochet.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
* Copyright (C) 2001-2004 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
|
||||
*
|
||||
|
@ -25,6 +25,7 @@ import org.apache.log4j.*;
|
|||
import com.silverwrist.util.*;
|
||||
import com.silverwrist.venice.ui.*;
|
||||
import com.silverwrist.venice.ui.helpers.ThrowableContent;
|
||||
import com.silverwrist.venice.ui.rpc.XmlRpcLibrary;
|
||||
|
||||
public class ScriptManager
|
||||
{
|
||||
|
@ -52,9 +53,9 @@ public class ScriptManager
|
|||
|
||||
public void output(Object o)
|
||||
{
|
||||
if (return_stack.size()>0)
|
||||
if (m_return_stack.size()>0)
|
||||
{ // set the return value
|
||||
ScriptReturn sro = (ScriptReturn)(return_stack.getFirst());
|
||||
ScriptReturn sro = (ScriptReturn)(m_return_stack.getFirst());
|
||||
sro.set(o);
|
||||
|
||||
} // end if
|
||||
|
@ -72,30 +73,30 @@ public class ScriptManager
|
|||
{
|
||||
public void fatal(Object message)
|
||||
{
|
||||
if (logger_stack.size()>0)
|
||||
((Logger)(logger_stack.getFirst())).fatal(message);
|
||||
if (m_logger_stack.size()>0)
|
||||
((Logger)(m_logger_stack.getFirst())).fatal(message);
|
||||
|
||||
} // end fatal
|
||||
|
||||
public void error(Object message)
|
||||
{
|
||||
if (logger_stack.size()>0)
|
||||
((Logger)(logger_stack.getFirst())).error(message);
|
||||
if (m_logger_stack.size()>0)
|
||||
((Logger)(m_logger_stack.getFirst())).error(message);
|
||||
|
||||
} // end error
|
||||
|
||||
public void warn(Object message)
|
||||
{
|
||||
if (logger_stack.size()>0)
|
||||
((Logger)(logger_stack.getFirst())).warn(message);
|
||||
if (m_logger_stack.size()>0)
|
||||
((Logger)(m_logger_stack.getFirst())).warn(message);
|
||||
|
||||
} // end warn
|
||||
|
||||
public void info(Object message)
|
||||
{
|
||||
if (logger_stack.size()>0)
|
||||
if (m_logger_stack.size()>0)
|
||||
{ // check to make sure info is enabled first
|
||||
Logger l = (Logger)(logger_stack.getFirst());
|
||||
Logger l = (Logger)(m_logger_stack.getFirst());
|
||||
if (l.isInfoEnabled())
|
||||
l.info(message);
|
||||
|
||||
|
@ -105,9 +106,9 @@ public class ScriptManager
|
|||
|
||||
public void debug(Object message)
|
||||
{
|
||||
if (logger_stack.size()>0)
|
||||
if (m_logger_stack.size()>0)
|
||||
{ // check to make sure debug is enabled first
|
||||
Logger l = (Logger)(logger_stack.getFirst());
|
||||
Logger l = (Logger)(m_logger_stack.getFirst());
|
||||
if (l.isDebugEnabled())
|
||||
l.debug(message);
|
||||
|
||||
|
@ -132,10 +133,10 @@ public class ScriptManager
|
|||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private BSFManager mgr; // Bean Scripting Framework manager
|
||||
private LinkedList registered_names; // stack of lists of registered names
|
||||
private LinkedList logger_stack; // stack of loggers for nested evaluation
|
||||
private LinkedList return_stack; // stack of return values
|
||||
private BSFManager m_bsf; // Bean Scripting Framework manager
|
||||
private LinkedList m_registered_names; // stack of lists of registered names
|
||||
private LinkedList m_logger_stack; // stack of loggers for nested evaluation
|
||||
private LinkedList m_return_stack; // stack of return values
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
|
@ -154,14 +155,14 @@ public class ScriptManager
|
|||
logger.debug("creating new ScriptManager");
|
||||
|
||||
// initialize the BSFManager
|
||||
mgr = new BSFManager();
|
||||
mgr.setTempDir(temp_dir);
|
||||
m_bsf = new BSFManager();
|
||||
m_bsf.setTempDir(temp_dir);
|
||||
|
||||
if (BSFManager.isLanguageRegistered("javascript"))
|
||||
{ // we need to so some fixing up to make Rhino work
|
||||
try
|
||||
{ // ensure the engine is loaded, and do our fixup routine
|
||||
mgr.loadScriptingEngine("javascript");
|
||||
m_bsf.loadScriptingEngine("javascript");
|
||||
fixupRhino();
|
||||
|
||||
} // end if
|
||||
|
@ -173,8 +174,9 @@ public class ScriptManager
|
|||
|
||||
try
|
||||
{ // declare beans used by the scripting engines
|
||||
mgr.declareBean("vlib",new MyScriptLibrary(),MyScriptLibrary.class);
|
||||
mgr.declareBean("logger",new ScriptLogger(),ScriptLogger.class);
|
||||
m_bsf.declareBean("vlib",new MyScriptLibrary(),MyScriptLibrary.class);
|
||||
m_bsf.declareBean("logger",new ScriptLogger(),ScriptLogger.class);
|
||||
m_bsf.declareBean("rpclib",XmlRpcLibrary.get(),XmlRpcLibrary.class);
|
||||
|
||||
} // end try
|
||||
catch (BSFException e)
|
||||
|
@ -185,10 +187,10 @@ public class ScriptManager
|
|||
} // end catch
|
||||
|
||||
// initialize the rest of the object
|
||||
registered_names = new LinkedList();
|
||||
registered_names.addFirst(new HashSet());
|
||||
logger_stack = new LinkedList();
|
||||
return_stack = new LinkedList();
|
||||
m_registered_names = new LinkedList();
|
||||
m_registered_names.addFirst(new HashSet());
|
||||
m_logger_stack = new LinkedList();
|
||||
m_return_stack = new LinkedList();
|
||||
|
||||
} // end constructor
|
||||
|
||||
|
@ -320,9 +322,9 @@ public class ScriptManager
|
|||
|
||||
public void shutdown()
|
||||
{
|
||||
mgr.terminate();
|
||||
registered_names.clear();
|
||||
logger_stack.clear();
|
||||
m_bsf.terminate();
|
||||
m_registered_names.clear();
|
||||
m_logger_stack.clear();
|
||||
|
||||
} // end shutdown
|
||||
|
||||
|
@ -337,7 +339,7 @@ public class ScriptManager
|
|||
|
||||
try
|
||||
{ // look up the scripting language for this file
|
||||
lang = mgr.getLangFromFilename(filename);
|
||||
lang = m_bsf.getLangFromFilename(filename);
|
||||
code = IOUtil.loadText(file);
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Code language is " + lang + ", loaded " + code.length() + " characters");
|
||||
|
@ -355,13 +357,13 @@ public class ScriptManager
|
|||
} // end catch
|
||||
|
||||
if (logger_name!=null) // push a new logger onto the stack
|
||||
logger_stack.addFirst(Logger.getLogger(logger_name));
|
||||
m_logger_stack.addFirst(Logger.getLogger(logger_name));
|
||||
if (sro!=null)
|
||||
return_stack.addFirst(sro);
|
||||
m_return_stack.addFirst(sro);
|
||||
|
||||
try
|
||||
{ // execute the script!
|
||||
mgr.exec(lang,filename,1,1,code);
|
||||
m_bsf.exec(lang,filename,1,1,code);
|
||||
|
||||
} // end try
|
||||
catch (BSFException e)
|
||||
|
@ -372,9 +374,9 @@ public class ScriptManager
|
|||
finally
|
||||
{ // pop the logger stack if necessary
|
||||
if (logger_name!=null)
|
||||
logger_stack.removeFirst();
|
||||
m_logger_stack.removeFirst();
|
||||
if (sro!=null)
|
||||
return_stack.removeFirst();
|
||||
m_return_stack.removeFirst();
|
||||
|
||||
} // end finally
|
||||
|
||||
|
@ -386,32 +388,32 @@ public class ScriptManager
|
|||
|
||||
public void register(String name, Object obj)
|
||||
{
|
||||
mgr.registerBean(name,obj);
|
||||
HashSet tbl = (HashSet)(registered_names.getFirst());
|
||||
m_bsf.registerBean(name,obj);
|
||||
HashSet tbl = (HashSet)(m_registered_names.getFirst());
|
||||
tbl.add(name);
|
||||
|
||||
} // end register
|
||||
|
||||
public void pushContext()
|
||||
{
|
||||
registered_names.addFirst(new HashSet());
|
||||
m_registered_names.addFirst(new HashSet());
|
||||
|
||||
} // end pushContext
|
||||
|
||||
public void popContext()
|
||||
{
|
||||
HashSet tbl = (HashSet)(registered_names.removeFirst());
|
||||
HashSet tbl = (HashSet)(m_registered_names.removeFirst());
|
||||
Iterator it = tbl.iterator();
|
||||
while (it.hasNext())
|
||||
mgr.unregisterBean((String)(it.next()));
|
||||
if (registered_names.isEmpty())
|
||||
registered_names.addFirst(new HashSet());
|
||||
m_bsf.unregisterBean((String)(it.next()));
|
||||
if (m_registered_names.isEmpty())
|
||||
m_registered_names.addFirst(new HashSet());
|
||||
|
||||
} // end popContext
|
||||
|
||||
public Object lookupObject(String name)
|
||||
{
|
||||
return mgr.lookupBean(name);
|
||||
return m_bsf.lookupBean(name);
|
||||
|
||||
} // end lookupObject
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user