当前位置: 首页>>代码示例>>Java>>正文


Java NativeArray.getLength方法代码示例

本文整理汇总了Java中org.mozilla.javascript.NativeArray.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java NativeArray.getLength方法的具体用法?Java NativeArray.getLength怎么用?Java NativeArray.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mozilla.javascript.NativeArray的用法示例。


在下文中一共展示了NativeArray.getLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseCalloutResponse

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
private String parseCalloutResponse(String calloutResponse, List<NativeArray> returnedArray) {
  String initS = "id=\"paramArray\">";
  String resp = calloutResponse.substring(calloutResponse.indexOf(initS) + initS.length());
  resp = resp.substring(0, resp.indexOf("</SCRIPT")).trim();
  if (!resp.contains("new Array(") && !resp.contains("[[")) {
    return null;
  }
  try {
    Context cx = Context.enter();
    Scriptable scope = cx.initStandardObjects();
    cx.evaluateString(scope, resp, "<cmd>", 1, null);
    NativeArray array = (NativeArray) scope.get("respuesta", scope);
    Object calloutName = scope.get("calloutName", scope);
    String calloutNameS = calloutName == null ? null : calloutName.toString();
    log.debug("Callout Name: " + calloutNameS);
    for (int i = 0; i < array.getLength(); i++) {
      returnedArray.add((NativeArray) array.get(i, null));
    }
    return calloutNameS;
  } catch (Exception e) {
    log.error("Couldn't parse callout response. The parsed response was: " + resp, e);
  }
  return null;
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:25,代码来源:FormInitializationComponent.java

示例2: deserialize

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
static public Map<String,Object> deserialize(NativeObject object) {
    HashMap<String,Object> map = new HashMap<>();
    for (Object key : object.keySet()) {
        Object value = object.get(key);
        if (value == null) {
            map.put(key.toString(), null);
        } else if (value instanceof Number) {
            map.put(key.toString(), value);
        } else if (value instanceof Boolean) {
            map.put(key.toString(), value);
        } else if (value instanceof NativeObject) {
            map.put(key.toString(), deserialize((NativeObject)value));
        } else if (value instanceof NativeArray) {
            NativeArray array = (NativeArray)value;
            Object[] a = new Object[(int)array.getLength()];
            for (int i = 0; i < array.getLength(); ++i) {
                Object o = array.get(i);
                a[i] = deserialize(o);
            }
            map.put(key.toString(), a);
        } else {
            map.put(key.toString(), value.toString());
        }
    }
    return map;
}
 
开发者ID:loadtestgo,项目名称:pizzascript,代码行数:27,代码来源:RhinoUtils.java

示例3: call

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
    if (args.length == 0) {
        throw new RuntimeException("'load' function takes at least one argument");
    }

    for (Object arg : args) {
        if (arg instanceof NativeArray) {
            NativeArray array = (NativeArray)arg;
            for (int i = 0; i < array.getLength(); i++) {
                Object path = array.get(i);
                if (path != null) {
                    load(path.toString(), cx, scope);
                } else {
                    throw new NullPointerException("Cannot have null argument in load function");
                }
            }
        } else if (arg == null) {
            throw new NullPointerException("Cannot have null argument in load function");
        } else {
            load(arg.toString(), cx, scope);
        }
    }
    return null;
}
 
开发者ID:galenframework,项目名称:galen,代码行数:26,代码来源:JsFunctionLoad.java

示例4: convertFromScriptObject

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
public Object convertFromScriptObject(Object scriptObject, Class expectedClass) {
    if (scriptObject != null && conversionRequires(scriptObject, expectedClass)) {
        Object result = RhinoUtil.convertResult(null, expectedClass, scriptObject);
        if (result instanceof NativeArray) {
            NativeArray jsArray = (NativeArray) result;
            int length = (int) jsArray.getLength();
            Object[] array = new Object[length];
            for (int i = 0; i < length; i++) {
                array[i] = jsArray.get(i, null);
            }
            result = array;
        }
        return result;
    }
    return scriptObject;
}
 
开发者ID:seasarorg,项目名称:mayaa,代码行数:17,代码来源:ScriptEnvironmentImpl.java

示例5: toStringList

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
public static List<String> toStringList(Object ob) {
	List<String> list;
	if (ob != null) {
		if (ob instanceof NativeJavaObject) {
			NativeJavaObject nativeJavaObject = (NativeJavaObject) ob;
			list = toStringList(nativeJavaObject.unwrap());
		} else if (ob instanceof NativeJavaArray) {
			Object object = ((NativeJavaArray) ob).unwrap();
			list = toStringList(object);
		} else if (ob.getClass().isArray()) {
			list = toStringList(Arrays.asList((Object[]) ob));
		} else if (ob instanceof NativeArray) {
			NativeArray array = (NativeArray) ob;
			list = new ArrayList<String>((int) array.getLength());
			for (java.util.Iterator<?> i = array.iterator(); i.hasNext();) {
				list.add(toString(i.next()));
			}
		} else if (ob instanceof Collection<?>) {
			Collection<?> collection = GenericUtils.cast(ob);
			list = new ArrayList<String>(collection.size());
			for (Object o : collection) {
				list.add(toString(o));
			}
		} else {
			list = Arrays.asList(toString(ob));
		}
	} else {
		list = Collections.emptyList();
	}
	return list;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:32,代码来源:ParameterUtils.java

示例6: init

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
private void init() {
			if ((evaluated != null) && (list == null)) {
				if (evaluated instanceof NodeList) {
					list = new ArrayList<Object>();
					NodeList nodeList = (NodeList)evaluated;
					for (int i=0; i<nodeList.getLength(); i++)
						list.add(nodeList.item(i));
				}
				else if (evaluated instanceof Collection<?>) {
					list = new ArrayList<Object>((Collection<?>) evaluated);
				}
				else if (evaluated instanceof NativeJavaArray) {
					Object object = ((NativeJavaArray)evaluated).unwrap();
					list = Arrays.asList((Object[])object);
				}
				else if (evaluated instanceof NativeArray) {
					list = new ArrayList<Object>();
					NativeArray array = (NativeArray)evaluated;
					for (int i=0; i<array.getLength(); i++)
						list.add(array.get(i,array));
				}
//				else if (evaluated instanceof NativeJavaObject) {
//					list = Arrays.asList(new String[] {(String) ((NativeJavaObject)evaluated).getDefaultValue(String.class)});
//				}
				else if (evaluated.getClass().isArray()) {
					list = Arrays.asList((Object[])evaluated);
				}
				else
					list = Arrays.asList(new Object[] {evaluated.toString()});
			}
		}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:32,代码来源:SimpleIteratorStep.java

示例7: execute

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
@Override
public boolean execute(Context javascriptContext, Scriptable scope) throws EngineException {
	if (isEnabled()) {
		if (super.execute(javascriptContext, scope)) {
			HttpConnector connector = this.getConnector();
			if(connector.handleCookie){
				HttpState httpState = this.getParentTransaction().context.httpState;
				if(httpState==null){
					connector.resetHttpState(this.getParentTransaction().context);
					httpState = this.getParentTransaction().context.httpState;
				}
				evaluate(javascriptContext, scope, expression, "CookiesGet", true);
				if(evaluated!=null){
					if(evaluated instanceof NativeArray){
						NativeArray array = (NativeArray)evaluated;
						long len = array.getLength();
						for(int i=0;i<len;i++)
							addCookie(httpState, array.get(i, array).toString());

					}else{
						addCookie(httpState, evaluated.toString());
					}
				}
			}
			return true;
		}
	}
	return false;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:30,代码来源:CookiesAddStatement.java

示例8: toStringList

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
public static String[] toStringList(Object value) {
    if (value == null) {
        return null;
    } else if (value instanceof NativeArray) {
        NativeArray array = (NativeArray)value;
        String[] a = new String[(int)array.getLength()];
        for (int i = 0; i < array.getLength(); ++i) {
            Object o = array.get(i);
            a[i] = toString(o);
        }
        return a;
    } else {
        return null;
    }
}
 
开发者ID:loadtestgo,项目名称:pizzascript,代码行数:16,代码来源:RhinoUtils.java

示例9: get_array

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
static Object[] get_array(String path, Object base) throws ObjectNotFoundException {
	NativeArray arr = (NativeArray)get_object(path, base);
	Object[] out = new Object[(int)arr.getLength()];
	int idx;
	for(Object o : arr.getIds()) out[idx = (Integer)o] = arr.get(idx, arr); 
	return out;
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:8,代码来源:JSHelper.java

示例10: get_string_array

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
static String[] get_string_array(String path, Object base) throws ObjectNotFoundException {
	NativeArray arr = (NativeArray)get_object(path, base);
	String[] out = new String[(int)arr.getLength()];
	int idx;
	for(Object o : arr.getIds()) out[idx = (Integer)o] = arr.get(idx, arr).toString(); 
	return out;
}
 
开发者ID:dzhw,项目名称:metadatamanagement,代码行数:8,代码来源:JSHelper.java

示例11: toIntArray

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
/**
 * 将NativeArray返回结果转换为int[]对象
 * 
 * @Title: toIntArray
 * @Description: TODO(这里用一句话描述这个方法的作用)
 * @param 参数
 * @return int[] 返回类型
 * @throws
 */
public static int[] toIntArray(NativeArray nv) {
	int[] result = new int[(int) nv.getLength()];
	for (int i = 0; i < result.length; i++) {
		Object obj = nv.get(i, null);
		if (obj instanceof Number) {
			result[i] = ((Number) obj).intValue();
		} else {
			result[i] = StringUtils.toInt(StringUtils.toString(obj), 0);
		}
	}
	return result;
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:22,代码来源:JavaScriptUtil.java

示例12: jsConstructor

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
public static Scriptable jsConstructor(final Context ctx, final Object[] args, final Function ctor, final boolean newExpr) {
    if (args.length == 3 && args[0] instanceof NativeArray) {
        final List<List<Object>> data = new ArrayList<>();
        final NativeArray array = NativeArray.class.cast(args[2]);
        final Object[] ids = array.getIds();
        for (int i = 0; i < array.getLength(); i++) {
            data.add(asList(array.get((int)ids[i], null)));
        }
        return new DataFrameAdapter(
                new DataFrame<Object>(
                        asList(args[0]),
                        asList(args[1]),
                        data
                    )
            );
    } else if (args.length == 2 && args[0] instanceof NativeArray) {
        return new DataFrameAdapter(new DataFrame<Object>(
                asList(args[0]),
                asList(args[1])
            ));
    } else if (args.length == 1 && args[0] instanceof NativeArray) {
        return new DataFrameAdapter(new DataFrame<Object>(
                asList(args[0])
            ));
    } else if (args.length > 0) {
        final String[] columns = new String[args.length];
        for (int i = 0; i < args.length; i++) {
            columns[i] = Context.toString(args[i]);
        }
        return new DataFrameAdapter(new DataFrame<>(columns));
    }
    return new DataFrameAdapter(new DataFrame<>());
}
 
开发者ID:cardillo,项目名称:joinery,代码行数:34,代码来源:DataFrameAdapter.java

示例13: asList

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
private static List<Object> asList(final NativeArray array) {
    final List<Object> list = new ArrayList<>((int)array.getLength());
    for (final Object id : array.getIds()) {
        list.add(array.get((int)id, null));
    }
    return list;
}
 
开发者ID:cardillo,项目名称:joinery,代码行数:8,代码来源:DataFrameAdapter.java

示例14: checkURIs

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
/**
 * Java wrapper for {@link DistributedCache#checkURIs(URI[], URI[])}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return whether or not the uris are without conflict or issue
 */
@JSStaticFunction
public static boolean checkURIs(final Context ctx, final Scriptable thisObj, final Object[] args,
                                final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof NativeArray)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_ARRAY);
    } else if (!(arg1 instanceof NativeArray)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_ARRAY);
    }

    final NativeArray jsFileUris = (NativeArray)arg0;
    final NativeArray jsArchiveUris = (NativeArray)arg1;
    final URI[] fileUris = new URI[(int)jsFileUris.getLength()];
    final URI[] archiveUris = new URI[(int)jsArchiveUris.getLength()];

    for (int i = 0; i < fileUris.length; i++) {
        fileUris[i] = URI.create(jsFileUris.get(i).toString());
    }

    for (int i = 0; i < archiveUris.length; i++) {
        archiveUris[i] = URI.create(jsArchiveUris.get(i).toString());
    }

    return DistributedCache.checkURIs(fileUris, archiveUris);
}
 
开发者ID:apigee,项目名称:lembos,代码行数:44,代码来源:DistributedCacheWrap.java

示例15: setCacheArchives

import org.mozilla.javascript.NativeArray; //导入方法依赖的package包/类
/**
 * Java wrapper for {@link DistributedCache#setCacheArchives(URI[], Configuration)}.
 *
 * @param ctx the JavaScript context
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 */
@JSStaticFunction
public static void setCacheArchives(final Context ctx, final Scriptable thisObj, final Object[] args,
                                    final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof NativeArray)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_ARRAY);
    } else if (!(arg1 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF);
    }

    final NativeArray jsArchiveUris = (NativeArray)arg0;
    final URI[] archiveUris = new URI[(int)jsArchiveUris.getLength()];

    for (int i = 0; i < archiveUris.length; i++) {
        archiveUris[i] = URI.create(jsArchiveUris.get(i).toString());
    }

    DistributedCache.setCacheArchives(archiveUris, ((ConfigurationWrap)arg1).getConf());
}
 
开发者ID:apigee,项目名称:lembos,代码行数:36,代码来源:DistributedCacheWrap.java


注:本文中的org.mozilla.javascript.NativeArray.getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。