本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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()});
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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<>());
}
示例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;
}
示例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);
}
示例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());
}