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


Java ScriptUtils类代码示例

本文整理汇总了Java中jdk.nashorn.api.scripting.ScriptUtils的典型用法代码示例。如果您正苦于以下问题:Java ScriptUtils类的具体用法?Java ScriptUtils怎么用?Java ScriptUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Deserialize

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
@Override
public Object Deserialize(Object input) {
    // Make sure we can continue:
    if(!ScriptObjectMirror.class.isAssignableFrom(input.getClass()) &&
            !ScriptObject.class.isAssignableFrom(input.getClass())) return null;

    ScriptObjectMirror mirror;

    // The first case will probably not happen, but, just in case...
    if(ScriptObjectMirror.class.isAssignableFrom(input.getClass())) {
        mirror = (ScriptObjectMirror) input;
    } else {
        mirror = ScriptUtils.wrap((ScriptObject) input);
    }

    Map<String, Object> properties = new HashMap<>();

    for(String key : mirror.keySet()) {
        properties.put(key, mirror.get(key));
    }

    return new BlockStateMatcher(properties);
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:24,代码来源:BlockStateMatcher.java

示例2: Deserialize

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
@Override
public final Object Deserialize(Object input) {
    // Make sure we can continue:
    if(!ScriptObjectMirror.class.isAssignableFrom(input.getClass()) &&
            !ScriptObject.class.isAssignableFrom(input.getClass())) return null;

    ScriptObjectMirror mirror;

    // The first case will probably not happen, but, just in case...
    if(ScriptObjectMirror.class.isAssignableFrom(input.getClass())) {
        mirror = (ScriptObjectMirror) input;
    } else {
        mirror = ScriptUtils.wrap((ScriptObject) input);
    }

    return DeserializeMirror(mirror);
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:18,代码来源:BaseMirroredDeserializer.java

示例3: DeserializeMirror

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
@Override
protected Object DeserializeMirror(ScriptObjectMirror mirror) {
    BlockCountMatcher matcher = new BlockCountMatcher();

    if(!mirror.containsKey("what") || !mirror.containsKey("dist")) {
        return null;
    }

    // Copy over all our matchers...
    matcher.what = DeserializerHelpers.convertArrayWithDeserializer(mirror, "what", BLOCK_MATCHER_DESERIALIZER, BlockMatcher.class);

    // Then the rest of our properties...
    matcher.dist = (int) ScriptUtils.convert(mirror.get("dist"), Integer.class);

    matcher.min = mirror.containsKey("min") ? (int) ScriptUtils.convert(mirror.get("min"), Integer.class) : 0;
    matcher.max = mirror.containsKey("max") ? (int) ScriptUtils.convert(mirror.get("max"), Integer.class) : Integer.MAX_VALUE;

    return matcher;
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:20,代码来源:BlockCountMatcher.java

示例4: DeserializeMirror

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
@Override
protected Object DeserializeMirror(ScriptObjectMirror mirror) {
    // Gather callbacks:
    IEntityCallback[] callbacks = DeserializerHelpers.convertArrayWithDeserializer(mirror, "onUsed",
            CALLBACK_DESERIALIZER, IEntityCallback.class);

    // And matchers:
    ComponentRegistry registry = ComponentRegistry.compileRegistryFor(new Class[]{IBlockDropMatcher.class}, mirror);
    List<IBlockDropMatcher> components = registry.getComponentsOf(IBlockDropMatcher.class);

    boolean cancel = mirror.containsKey("cancelAfterMatch")
            && (Boolean) ScriptUtils.convert(mirror.get("cancelAfterMatch"), Boolean.class);

    return new BlockInteractionHandler(components != null ? components.toArray(new IBlockDropMatcher[components.size()]) : null,
            callbacks, cancel);
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:17,代码来源:BlockInteractionHandler.java

示例5: update

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
@Override
protected void update(ScriptObjectMirror mirror, MobPotionEffect output) {
    // Our base potion
    output.what = (Potion) POTION_DESERIALIZER.Deserialize(mirror.get("what"));

    // Duration; defaults to the number of ticks between checks
    output.duration = mirror.containsKey("duration") ? (int) ScriptUtils.convert(mirror.get("duration"), Integer.class)
            : CraftingHarmonicsMod.getConfigManager().getPotionEffectTicks()+1;

    output.amplifier = mirror.containsKey("amplifier") ? (int) ScriptUtils.convert(mirror.get("amplifier"), Integer.class) : 0;
    output.showParticles = mirror.containsKey("showParticles") && (boolean) ScriptUtils.convert(mirror.get("showParticles"), Boolean.class);
    output.cures = DeserializerHelpers.convertArrayWithDeserializer(mirror, "cures", ITEM_STACK_DESERIALIZER, ItemStack.class);
    output.newCallbacks = DeserializerHelpers.convertArrayWithDeserializer(mirror, "onNew", ENTITY_CALLBACK_DESERIALIZER, IEntityCallback.class);
    output.extendedCallbacks = DeserializerHelpers.convertArrayWithDeserializer(mirror, "onExtended", ENTITY_CALLBACK_DESERIALIZER, IEntityCallback.class);
    output.applyCallbacks = DeserializerHelpers.convertArrayWithDeserializer(mirror, "onApplied", ENTITY_CALLBACK_DESERIALIZER, IEntityCallback.class);
    output.expiredCallbacks = DeserializerHelpers.convertArrayWithDeserializer(mirror, "onExpired", ENTITY_CALLBACK_DESERIALIZER, IEntityCallback.class);
    output.curedCallbacks = DeserializerHelpers.convertArrayWithDeserializer(mirror, "onCured", ENTITY_CALLBACK_DESERIALIZER, IEntityCallback.class);
    output.removedCallbacks = DeserializerHelpers.convertArrayWithDeserializer(mirror, "onRemoved", ENTITY_CALLBACK_DESERIALIZER, IEntityCallback.class);
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:20,代码来源:MobPotionEffect.java

示例6: DeserializeMirror

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
@Override
protected Object DeserializeMirror(ScriptObjectMirror mirror) {
    MobCountMatcher matcher = new MobCountMatcher();

    if(!mirror.containsKey("what") || !mirror.containsKey("dist")) {
        return null;
    }

    matcher.what = (String[]) ScriptUtils.convert(mirror.get("what"), String[].class);
    matcher.dist = (int) ScriptUtils.convert(mirror.get("dist"), Integer.class);

    matcher.min = mirror.containsKey("min") ? (int) ScriptUtils.convert(mirror.get("min"), Integer.class) : 0;
    matcher.max = mirror.containsKey("max") ? (int) ScriptUtils.convert(mirror.get("max"), Integer.class) : Integer.MAX_VALUE;

    return matcher;
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:17,代码来源:MobCountMatcher.java

示例7: exportArgument

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
static Object exportArgument(final Object arg, final boolean mirrorAlways) {
    if (arg instanceof ConsString) {
        return arg.toString();
    } else if (mirrorAlways && arg instanceof ScriptObject) {
        return ScriptUtils.wrap((ScriptObject)arg);
    } else {
        return arg;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:NashornBeansLinker.java

示例8: exportArgument

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
static Object exportArgument(final Object arg, final boolean mirrorAlways) {
    if (arg instanceof ConsString) {
        return arg.toString();
    } else if (mirrorAlways && arg instanceof ScriptObject) {
        return ScriptUtils.wrap(arg);
    } else {
        return arg;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:NashornBeansLinker.java

示例9: TranslateToItemStack

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
/**
 * Translates script data to an item stack
 * @param data  The data to translate
 * @return      The ItemStack requested
 * @throws OperationException When the item cannot be found in the registry.
 */
private static RecipeComponent TranslateToItemStack(Object data) throws OperationException {
    RecipeComponent component = new RecipeComponent();

    if(data instanceof String) {
        String itemString = (String)data;

        if(ItemUtility.isOreDictionaryEntry(itemString)) {
            component.setOreDictName(itemString, ItemUtility.getOreDictionaryName(itemString));
        } else {
            component.setItemStack(itemString, ItemUtility.translateToItemStack(itemString));
        }

        return component;
    }

    ScriptObjectMirror item;

    if(ScriptObjectMirror.class.isAssignableFrom(data.getClass())) {
        item = (ScriptObjectMirror)data;
    } else if(ScriptObject.class.isAssignableFrom(data.getClass())) {
        item = ScriptUtils.wrap((ScriptObject) data);
    } else {
        return null;
    }

    if(!item.hasMember("item")) return null;

    NashornConfigProcessor.getInstance().nashorn.parseScriptObject(item,component);

    return component;
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:38,代码来源:RecipeComponentDeserializer.java

示例10: convertArrayWithDeserializer

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
public static <T> T[] convertArrayWithDeserializer(Object input, IScriptObjectDeserializer deserializer, Class<T> toClass) {
    try {
        T[] output;

        // If we don't anything to deserialize...
        if(input == null) {
            return ObjectArrays.newArray(toClass, 0);
        }

        if(ScriptObjectMirror.class.isAssignableFrom(input.getClass())) {
            ScriptObjectMirror valMirror = (ScriptObjectMirror) input;

            // If we have an array, convert the array...
            if(valMirror.isArray()) {
                Object[] items = (Object[]) ScriptUtils.convert(input, Object[].class);
                output = ObjectArrays.newArray(toClass, items != null ? items.length : 0);

                if (items == null) return output;

                for (int i = 0; i < output.length; i++) {
                    output[i] = convertWithDeserializer(items[i], deserializer, toClass);
                }
            // Otherwise, just convert the object, and turn it into an array:
            } else {
                output = ObjectArrays.newArray(toClass, 1);
                output[0] = convertWithDeserializer(valMirror, deserializer, toClass);
            }

            return output;
        } else {
            output = ObjectArrays.newArray(toClass, 1);
            output[0] = convertWithDeserializer(input, deserializer, toClass);
        }

        return output;
    } catch (Exception e) {
        LogHelper.error("Error deserializing array of " + toClass.getName(), e);
        return ObjectArrays.newArray(toClass, 0);
    }
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:41,代码来源:DeserializerHelpers.java

示例11: deserialize

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
public static InteractionTargetData deserialize(Object input) {
    // Figure out if we have a valid input here:
    if(input == null || (!ScriptObjectMirror.class.isAssignableFrom(input.getClass()) &&
            !ScriptObject.class.isAssignableFrom(input.getClass()))) return new InteractionTargetData(null, null, null, null);

    ScriptObjectMirror mirror;

    // Convert it over...
    if(ScriptObjectMirror.class.isAssignableFrom(input.getClass())) {
        mirror = (ScriptObjectMirror) input;
    } else {
        mirror = ScriptUtils.wrap((ScriptObject) input);
    }

    // Gather our callbacks:
    IEntityCallback[] onAllowed = mirror.containsKey("onAllowed")
            ? DeserializerHelpers.convertArrayWithDeserializer(mirror, "onAllowed", CALLBACK_DESERIALIZER, IEntityCallback.class)
            : new IEntityCallback[0];
    IEntityCallback[] onDenied = mirror.containsKey("onDenied")
            ? DeserializerHelpers.convertArrayWithDeserializer(mirror, "onDenied", CALLBACK_DESERIALIZER, IEntityCallback.class)
            : new IEntityCallback[0];
    IEntityCallback[] onPassed = mirror.containsKey("onPassed")
            ? DeserializerHelpers.convertArrayWithDeserializer(mirror, "onPassed", CALLBACK_DESERIALIZER, IEntityCallback.class)
            : new IEntityCallback[0];

    // Finally, get our matchers:
    ComponentRegistry registry = ComponentRegistry.compileRegistryFor(new Class[]{IEntityMatcher.class}, mirror);
    List<IEntityMatcher> components = registry.getComponentsOf(IEntityMatcher.class);

    // And build it out...
    return new InteractionTargetData(components != null ? components.toArray(new IEntityMatcher[components.size()]) : null,
            onAllowed, onDenied, onPassed);
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:34,代码来源:EntityInteractionData.java

示例12: DeserializeMirror

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
@Override
protected Object DeserializeMirror(ScriptObjectMirror mirror) {
    WeatherMatcher output = new WeatherMatcher();

    output.presence = mirror.containsKey("presence") ? (Boolean) ScriptUtils.convert(mirror.get("presence"), Boolean.class) : true;
    output.onlyOnTarget = mirror.containsKey("onlyOnTarget") ? (Boolean)ScriptUtils.convert(mirror.get("onlyOnTarget"), Boolean.class) : false;

    // This is forced to true when we're checking the block.
    output.onlyInBiome = output.onlyOnTarget
            || (mirror.containsKey("onlyInBiome") ? (Boolean) ScriptUtils.convert(mirror.get("onlyInBiome"), Boolean.class) : false);

    return output;
}
 
开发者ID:legendblade,项目名称:CraftingHarmonics,代码行数:14,代码来源:BaseWeatherMatcher.java

示例13: toMicronode

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
/**
 * Convert the given value into a micronode.
 *
 * @param value
 *            Value to be converted
 * @return Micronode object or null if the value could not be converted
 */
public Object toMicronode(Object value) {
	if (isMicronode(value)) {
		return ScriptUtils.unwrap(value);
	} else if (isJSArray(value)) {
		return getJSArray(value).stream().findFirst().filter(o -> isMicronode(o)).map(o -> ScriptUtils.unwrap(o))
				.orElse(null);
	} else {
		return null;
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:18,代码来源:TypeConverter.java

示例14: toMicronodeList

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
/**
 * Convert the given value into a list of micronodes.
 *
 * @param value
 *            Value to be converted
 * @return List of micronodes or null if the value could not be converted
 */
public Object[] toMicronodeList(Object value) {
	if (isMicronode(value)) {
		return new Object[] { ScriptUtils.unwrap(value) };
	} else if (isJSArray(value) && getJSArray(value).stream().anyMatch(o -> isMicronode(o))) {
		List<Object> list = getJSArray(value).stream().map(e -> toMicronode(e)).filter(s -> s != null)
				.collect(Collectors.toList());
		return list.toArray(new Object[list.size()]);
	} else {
		return null;
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:19,代码来源:TypeConverter.java

示例15: toNode

import jdk.nashorn.api.scripting.ScriptUtils; //导入依赖的package包/类
/**
 * Convert the given value into a node.
 *
 * @param value
 *            Value to be converted
 * @return Node or null if the value could not be converted
 */
public Object toNode(Object value) {
	if (isNode(value)) {
		return ScriptUtils.unwrap(value);
	} else if (isJSArray(value)) {
		return getJSArray(value).stream().findFirst().filter(o -> isNode(o)).map(o -> ScriptUtils.unwrap(o))
				.orElse(null);
	} else {
		return null;
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:18,代码来源:TypeConverter.java


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