本文整理汇总了Java中jdk.nashorn.api.scripting.ScriptUtils.wrap方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptUtils.wrap方法的具体用法?Java ScriptUtils.wrap怎么用?Java ScriptUtils.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.api.scripting.ScriptUtils
的用法示例。
在下文中一共展示了ScriptUtils.wrap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例3: 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;
}
}
示例4: 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;
}
}
示例5: 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;
}
示例6: 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);
}
示例7: setMember
import jdk.nashorn.api.scripting.ScriptUtils; //导入方法依赖的package包/类
@Override
public void setMember(String name, Object value) {
value = value instanceof ScriptObject ? ScriptUtils.wrap((ScriptObject)value) : value;
if (value instanceof JSObject) {
if (session.getId() == null) {
throw new IllegalStateException(RESIDENT_MODULES_MODIFICATION_MSG);
} else {
session.registerModule(name, (JSObject) value);
}
} else if (JSType.nullOrUndefined(value)) {
session.unregisterModule(name);
}
}
示例8: createMirror
import jdk.nashorn.api.scripting.ScriptUtils; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private static Object createMirror(final Object obj) {
return obj instanceof ScriptObject? ScriptUtils.wrap((ScriptObject)obj) : obj;
}
示例9: Deserialize
import jdk.nashorn.api.scripting.ScriptUtils; //导入方法依赖的package包/类
@Override
public Object Deserialize(Object input) {
RecipeInput output = new RecipeInput();
if(input instanceof String) {
addItemStringBasedMatchers(output, (String)input);
return output;
}
// Make sure we can continue:
if(!ScriptObjectMirror.class.isAssignableFrom(input.getClass()) &&
!ScriptObject.class.isAssignableFrom(input.getClass())) return output;
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);
}
// If we don't have an item... /sigh
if (!mirror.containsKey("item")) return output;
Object item = mirror.get("item");
// Make sure we have a string and somebody's not trying to be clever..
if(!(item instanceof String)) {
LogHelper.error("Couldn't convert '" + item.toString() + "' to a valid item string.");
return output;
}
addItemStringBasedMatchers(output, (String)item);
// And if we still don't have anything, means we still had a bad input string...
if(RecipeInput.isNullOrEmpty(output)) {
LogHelper.error("Couldn't convert '" + item.toString() + "' to a valid item string.");
return output;
}
// Get our registry data...
ComponentRegistry registry = ComponentRegistry.compileRegistryFor(new Class[]{
IRecipeInputMatcher.class,
IItemStackTransformer.class}, mirror);
List<IRecipeInputMatcher> matchers = registry.getComponentsOf(IRecipeInputMatcher.class);
List<IItemStackTransformer> transformers = registry.getComponentsOf(IItemStackTransformer.class);
// Deal with matchers
if(matchers != null) {
for (IRecipeInputMatcher matcher : matchers) {
// Quick hack; should do a global registration of this later for faster lookup...
PrioritizedObject priority = matcher.getClass().getAnnotation(PrioritizedObject.class);
output.addMatcher(matcher, priority.priority());
}
}
if(transformers != null) {
for(IItemStackTransformer transformer : transformers) {
output.addTransformer(transformer);
// Also deal with any implied transformers we have (if any)
IItemStackTransformer[] impliedTransformers = transformer.getImpliedTransformers();
for(IItemStackTransformer implied : impliedTransformers) {
output.addTransformer(implied);
}
}
}
return output;
}
示例10: createMirror
import jdk.nashorn.api.scripting.ScriptUtils; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private static Object createMirror(final Object obj) {
return ScriptUtils.wrap(obj);
}