Java Javascript Mozilla Library getObjectArgument(Object[] args, int pos, Object defaultValue)

Here you can find the source of getObjectArgument(Object[] args, int pos, Object defaultValue)

Description

Get an argument as object

License

LGPL

Parameter

Parameter Description
args the argument array
pos the position of the requested argument

Return

the argument as object

Declaration

public static Object getObjectArgument(Object[] args, int pos, Object defaultValue) 

Method Source Code

//package com.java2s;
/*/* w  ww  .j a  va2s .  com*/
  ==============================================================================
    
   This file is part of the MOA Lightweight Web Runner
   Copyright 2008 by kRAkEn/gORe's Jucetice Application Development
    
  ------------------------------------------------------------------------------
    
   MOA can be redistributed and/or modified under the terms of the
   GNU Lesser General Public License, as published by the Free Software Foundation;
   version 2 of the License only.
    
   MOA is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
    
   You should have received a copy of the GNU General Public License
   along with MOA; if not, visit www.gnu.org/licenses or write to the
   Free Software Foundation, Inc., 59 Temple Place, Suite 330,
   Boston, MA 02111-1307 USA
    
  ==============================================================================
*/

import org.mozilla.javascript.Context;

import org.mozilla.javascript.Undefined;

public class Main {
    /**
     * Get an argument as object
     * @param args the argument array
     * @param pos the position of the requested argument
     * @return the argument as object
     */
    public static Object getObjectArgument(Object[] args, int pos, Object defaultValue) {
        if (pos >= args.length || args[pos] == null || args[pos] == Undefined.instance)
            return defaultValue;
        return Context.jsToJava(args[pos], Object.class);
    }
}

Related

  1. getFunctionArgsString(FunctionNode fn)
  2. getGlobalContextForValidation()
  3. getJavaObject(Scriptable scope, String name)
  4. getJsArray(Scriptable scope, Vector v)
  5. getMapArgument(Object[] args, int pos)
  6. getProperty(Scriptable obj, final String prop)
  7. getPropertyName(AstNode propKeyNode)
  8. getPrototypeClazz(List nodes)
  9. getScriptableArgument(Object[] args, int pos, boolean allowNull)