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

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

Description

Get an argument as Map

License

LGPL

Parameter

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

Exception

Parameter Description
IllegalArgumentException if the argument can't be converted to a map

Return

the argument as map

Declaration

public static Map<?, ?> getMapArgument(Object[] args, int pos) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
/*//from ww w  .  j  a va2s  . c o  m
  ==============================================================================
    
   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 java.util.Map;

import org.mozilla.javascript.Undefined;

public class Main {
    /**
     * Get an argument as Map
     * 
     * @param args the argument array
     * @param pos the position of the requested argument
     * @return the argument as map
     * @throws IllegalArgumentException if the argument can't be converted to a map
     */
    public static Map<?, ?> getMapArgument(Object[] args, int pos) throws IllegalArgumentException {
        if (pos >= args.length || args[pos] == null || args[pos] == Undefined.instance)
            return null;
        if (args[pos] instanceof Map<?, ?>)
            return (Map<?, ?>) args[pos];
        throw new IllegalArgumentException("Can't convert to java.util.Map: " + args[pos]);
    }
}

Related

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