本文整理汇总了Java中org.mozilla.javascript.NativeArray类的典型用法代码示例。如果您正苦于以下问题:Java NativeArray类的具体用法?Java NativeArray怎么用?Java NativeArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NativeArray类属于org.mozilla.javascript包,在下文中一共展示了NativeArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jsToJava
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
static Object jsToJava(final Object obj) {
if (obj instanceof Scriptable) {
final Object javaObj = Context.jsToJava(obj, Object.class);
if (javaObj instanceof NativeArray) {
return new ScriptableList((NativeArray) javaObj);
}
if (javaObj instanceof Scriptable) {
return new ScriptableMap((Scriptable) javaObj);
}
return javaObj;
}
if (obj instanceof Wrapper) {
return ((Wrapper) obj).unwrap();
}
if (obj == Scriptable.NOT_FOUND) {
return null;
}
return obj;
}
示例2: getBondedDevices
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
@ProtoMethod(description = "Send bluetooth serial message", example = "")
@ProtoMethodParam(params = {"string"})
public NativeArray getBondedDevices() {
start();
Set<BluetoothDevice> listDevices = mAdapter.getBondedDevices();
MLog.d(TAG, "listDevices " + listDevices);
int listSize = listDevices.size();
ProtocoderNativeArray array = new ProtocoderNativeArray(listSize);
MLog.d(TAG, "array " + array);
int counter = 0;
for (BluetoothDevice b : listDevices) {
MLog.d(TAG, "bt " + b);
ReturnObject btDevice = new ReturnObject();
btDevice.put("name", b.getName());
btDevice.put("mac", b.getAddress());
array.addPE(counter++, btDevice);
}
return array;
}
示例3: init
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
public void init(NativeArray data, int numCols, ReturnInterfaceWithReturn createCallback, ReturnInterfaceWithReturn bindingCallback) {
styler = new Styler(mAppRunner, this, props);
styler.apply();
mGridLayoutManager = new GridLayoutManager(mContext, numCols);
setLayoutManager(mGridLayoutManager);
// setLayoutManager(new StaggeredGridLayoutManager(2, VERTICAL));
mViewAdapter = new PViewItemAdapter(mContext, data, createCallback, bindingCallback);
// Get GridView and set adapter
setHasFixedSize(true);
setAdapter(mViewAdapter);
notifyDataChanged();
setItemAnimator(null);
}
示例4: getKeyEntries
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
@Nullable
private List<KeyEntry> getKeyEntries(Map.Entry<Object, Object> entry) {
if (!(entry.getValue() instanceof NativeArray)) {
return null;
}
NativeArray nativeArray = (NativeArray) entry.getValue();
if (nativeArray.isEmpty()) {
return null;
}
List<KeyEntry> keyList = new ArrayList<>();
final int size = nativeArray.size();
for (int i = 0; i < size; i++) {
NativeObject elem = (NativeObject) nativeArray.get(i);
keyList.add(new KeyEntry(
Context.toString(elem.get("text")),
(int) Context.toNumber(elem.get("keyCode")),
Context.toBoolean(elem.get("enabled")),
Context.toBoolean(elem.get("isFunKey"))
));
}
return keyList;
}
示例5: setDatoMultivaluadoElemento
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
/**
* Mete dato multivaluado para un elemento
* @param indiceElemento Indice elemento
* @param column Columna
* @param data Dato
*/
public void setDatoMultivaluadoElemento(int indiceElemento,String column, NativeArray data){
if (indiceElemento > elementos.size()) return;
HashMap dataElemento = (HashMap) elementos.get(indiceElemento - 1);
// Pasamos NativeArray a List
List dataList = new ArrayList();
Object [] ids = data.getIds();
for ( int i = 0; i < ids.length; i++ )
{
Object valor = data.get( (( Integer ) ids[i] ).intValue() , data );
dataList.add( valor.toString() );
}
// Guardamos datos
dataElemento.put(column,dataList);
}
示例6: 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;
}
示例7: testCompiledJs
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
@Test
public void testCompiledJs() throws Exception {
// The main module calls a soy template and alerts the output.
// Replace alert with something that lets us capture the output.
cx.evaluateString(
scope, "var _alerts_ = []; alert = function (s) { _alerts_.push(s); }",
"test", 1, null);
loadJsModule("/closure/js/main.js");
loadJsModule("/closure/js/hello.world.js");
NativeArray alerts = (NativeArray)
ScriptableObject.getProperty(scope, "_alerts_");
assertEquals(
"<div id=\"greeting\">Hello, <b class=\"b\">Cle<eland</b>!</div>",
Context.toString(alerts.get(0)));
}
示例8: 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;
}
示例9: generateAssertionStatements
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
private List<MappingAssertionStatement> generateAssertionStatements(Object compiledJavascriptObject) {
List<MappingAssertionStatement> assertionStatements = new ArrayList<MappingAssertionStatement>();
if (compiledJavascriptObject != null && compiledJavascriptObject instanceof NativeArray) {
NativeArray array = (NativeArray) compiledJavascriptObject;
for (Object object : array) {
NativeObject nativeObject = (NativeObject) object;
String actualValuePath = (String) nativeObject
.get("actualValuePath");
Object actualValue = nativeObject.get("actualValue");
String operator = (String) nativeObject.get("operator");
Object expectedValue = nativeObject.get("expectedValue");
if (expectedValue instanceof NativeArray) {
NativeArray expectedValueNativeArray = (NativeArray) expectedValue;
expectedValue = expectedValueNativeArray.toArray();
}
assertionStatements.add(new MappingAssertionStatement(
actualValuePath, actualValue, operator, expectedValue));
}
}
return assertionStatements;
}
示例10: getAssertionStatementMetadataList
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
public List<MappingAssertionStatement> getAssertionStatementMetadataList() {
if (this.compiledJavascriptObject != null && this.compiledJavascriptObject instanceof NativeArray) {
NativeArray array = (NativeArray) this.compiledJavascriptObject;
for (Object object : array) {
NativeObject nativeObject = (NativeObject) object;
String actualValuePath = (String) nativeObject
.get("actualValuePath");
Object actualValue = nativeObject.get("actualValue");
String operator = (String) nativeObject.get("operator");
Object expectedValue = nativeObject.get("expectedValue");
this.assertionStatementMetadataList.add(new MappingAssertionStatement(
actualValuePath, actualValue, operator, expectedValue));
}
}
return this.assertionStatementMetadataList;
}
示例11: addToScope
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
/**
* Adds the values of a row to the JavaScript scope
*
* @param scope
* @param inputRow
* @param columns
* @param arrayName
*/
public static void addToScope(final Scriptable scope, final InputRow inputRow, final InputColumn<?>[] columns,
final String arrayName) {
final NativeArray values = new NativeArray(columns.length * 2);
for (int i = 0; i < columns.length; i++) {
final InputColumn<?> column = columns[i];
Object value = inputRow.getValue(column);
if (value != null) {
final Class<?> dataType = column.getDataType();
if (ReflectionUtils.isNumber(dataType)) {
value = Context.toNumber(value);
} else if (ReflectionUtils.isBoolean(dataType)) {
value = Context.toBoolean(value);
}
}
values.put(i, values, value);
values.put(column.getName(), values, value);
addToScope(scope, value, column.getName(), column.getName().toLowerCase(), column.getName().toUpperCase());
}
addToScope(scope, values, arrayName);
}
示例12: onMeasure
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
measureChildren(widthMeasureSpec, heightMeasureSpec);
int width=0, height=0;
if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY &&
MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
NativeArray calc = (NativeArray) callFunc("onMeasure");
width = ((Number) calc.get(0)).intValue();
height= ((Number) calc.get(1)).intValue();
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY) {
width = MeasureSpec.getSize(widthMeasureSpec);
} if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY) {
height = MeasureSpec.getSize(heightMeasureSpec);
}
setMeasuredDimension(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
示例13: addToScope
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
/**
* Adds the values of a row to the JavaScript scope
*
* @param scope
* @param inputRow
* @param columns
* @param arrayName
*/
public static void addToScope(Scriptable scope, InputRow inputRow, InputColumn<?>[] columns, String arrayName) {
NativeArray values = new NativeArray(columns.length * 2);
for (int i = 0; i < columns.length; i++) {
InputColumn<?> column = columns[i];
Object value = inputRow.getValue(column);
if (value != null) {
Class<?> dataType = column.getDataType();
if (ReflectionUtils.isNumber(dataType)) {
value = Context.toNumber(value);
} else if (ReflectionUtils.isBoolean(dataType)) {
value = Context.toBoolean(value);
}
}
values.put(i, values, value);
values.put(column.getName(), values, value);
addToScope(scope, value, column.getName(), column.getName().toLowerCase(), column.getName().toUpperCase());
}
addToScope(scope, values, arrayName);
}
示例14: testWrap
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
@Test
public void testWrap( )
{
// test nativeArray
NativeArray nativeArray = new NativeArray( new Object[]{
"one", "two"
} );
Object object = coreWrapper.wrap( cx, scope, nativeArray, null );
assertTrue( object instanceof org.mozilla.javascript.NativeArray );
// test list
List<Integer> list = new ArrayList<>( );
object = coreWrapper.wrap( cx, scope, list, null );
assertTrue( object instanceof NativeJavaList );
// test map
Map<Integer, Integer> linkedHashMap = new LinkedHashMap<>( );
object = coreWrapper.wrap( cx, scope, linkedHashMap, null );
assertTrue( object instanceof NativeJavaLinkedHashMap );
// test BirtHashMap
BirtHashMap birtHashMap = new BirtHashMap( );
object = coreWrapper.wrap( cx, scope, birtHashMap, null );
assertTrue( object instanceof NativeJavaMap );
}
示例15: shouldListJobs
import org.mozilla.javascript.NativeArray; //导入依赖的package包/类
@Test
public void shouldListJobs(){
try {
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
scriptJobService.setScope(scope);
final NativeArray allJobs = (NativeArray) scriptJobService.getAllJobs();
Assert.assertTrue(allJobs.getIds().length > 0);
ScriptJob job = (ScriptJob) allJobs.get(0);
Assert.assertNotNull(job.jobName);
Assert.assertNotNull(job.nextFireTime);
}finally{
Context.exit();
}
}