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


Java JsonNode类代码示例

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


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

示例1: replaceChildren

import argo.jdom.JsonNode; //导入依赖的package包/类
/**
 * Replace a set of children in a JSON object.
 * @param parent the parent node
 * @param replacingChildren the map key: newNode to replace. Key must exist in parent node beforehand
 * @return an instance of JsonNode with all children in replacing children replaced.
 */
public static JsonNode replaceChildren(JsonNode parent, Map<String, JsonNode> replacingChildren) {
	if (parent == null) {
		return null;
	}
	List<JsonField> fields = new ArrayList<JsonField>();

	for (JsonField field : parent.getFieldList()) {
		String key = field.getName().getText();

		if (parent.isNode(key)) { // Fail safe
			if (replacingChildren.containsKey(key)) {
				fields.add(JsonNodeFactories.field(key, replacingChildren.get(key)));
			} else {
				fields.add(field);
			}
		}
	}

	return JsonNodeFactories.object(fields);
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:27,代码来源:JSONUtility.java

示例2: parseJSON

import argo.jdom.JsonNode; //导入依赖的package包/类
/**
 * Construct a new object from a json node.
 *
 * @param node json node to parse
 * @return the new object with content parsed, or null if cannot parse.
 */
public static TaskActivation parseJSON(JsonNode node) {
	try {
		List<JsonNode> hotkeysNode = node.getArrayNode("hotkey");
		List<JsonNode> mouseGestureNode = node.getArrayNode("mouse_gesture");

		Set<KeyChain> keyChains = new HashSet<>();
		for (JsonNode hotkeyNode : hotkeysNode) {
			KeyChain newKeyChain = KeyChain.parseJSON(hotkeyNode.getArrayNode());
			if (newKeyChain == null) {
				LOGGER.log(Level.WARNING, "Cannot parse key chain " + hotkeyNode);
			} else {
				keyChains.add(newKeyChain);
			}
		}

		Set<MouseGesture> gestures = MouseGesture.parseJSON(mouseGestureNode);
		TaskActivation output = TaskActivation.newBuilder().withHotKeys(keyChains).withMouseGestures(gestures).build();
		return output;
	} catch (Exception e) {
		LOGGER.log(Level.WARNING, "Exception while parsing task activation.", e);
		return null;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:30,代码来源:TaskActivation.java

示例3: parseJSON

import argo.jdom.JsonNode; //导入依赖的package包/类
public boolean parseJSON(List<JsonNode> compilerSettings) {
	for (JsonNode compilerNode : compilerSettings) {
		String name = compilerNode.getStringValue("name");
		String path = compilerNode.getStringValue("path");
		JsonNode compilerSpecificArgs = compilerNode.getNode("compiler_specific_args");

		AbstractNativeCompiler compiler = getCompiler(name);
		if (compiler != null) {
			compiler.setPath(new File(path));
			if (!compiler.parseCompilerSpecificArgs(compilerSpecificArgs)) {
				LOGGER.log(Level.WARNING, "Compiler " + name + " was unable to parse its specific arguments.");
			}
		} else {
			throw new IllegalStateException("Unknown compiler " + name);
		}
	}
	return true;
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:19,代码来源:DynamicCompilerManager.java

示例4: parseCompilerSpecificArgs

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
public boolean parseCompilerSpecificArgs(JsonNode node) {
	if (!node.isArrayNode("classpath")) {
		return false;
	}

	List<String> paths = new ArrayList<>();
	JSONUtility.addAllJson(node.getArrayNode("classpath"), new Function<JsonNode, String>(){
		@Override
		public String apply(JsonNode d) {
			return d.getStringValue().toString();
		}
	}, paths);
	// Override current class paths
	classPaths = paths.toArray(classPaths);
	try {
		applyClassPath();
	} catch (MalformedURLException | NoSuchMethodException | SecurityException |
			IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
		getLogger().log(Level.WARNING, "Unable to apply class path.", e);
		return false;
	}

	return true;
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:26,代码来源:JavaNativeCompiler.java

示例5: parseJSON

import argo.jdom.JsonNode; //导入依赖的package包/类
public static TaskGroup parseJSON(DynamicCompilerManager factory, JsonNode node) {
	try {
		TaskGroup output = new TaskGroup("");
		String name = node.getStringValue("name");
		output.name = name;

		for (JsonNode task : node.getArrayNode("tasks")) {
			UserDefinedAction action = UserDefinedAction.parseJSON(factory, task);
			if (action != null) {
				output.tasks.add(action);
			}
		}

		output.enabled = node.getBooleanValue("enabled");

		return output;
	} catch (Exception e) {
		Logger.getLogger(TaskGroup.class.getName()).log(Level.WARNING, "Exception parsing task group from JSON", e);
		return null;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:22,代码来源:TaskGroup.java

示例6: internalConvertFromPreviousVersion

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
protected JsonRootNode internalConvertFromPreviousVersion(JsonRootNode previousVersion) {
	try {
		JsonNode globalSettings = JsonNodeFactories.object(
				JsonNodeFactories.field("debug",
						JsonNodeFactories.object(
								JsonNodeFactories.field("level", JsonNodeFactories.string(Level.WARNING.toString()))
						)
				),
				JsonNodeFactories.field("tray_icon_enabled", JsonNodeFactories.booleanNode(true)),
				JsonNodeFactories.field("enabled_halt_by_key", JsonNodeFactories.booleanNode(true))
				);

		JsonNode newNode = JSONUtility.addChild(previousVersion, "global_settings", globalSettings);
		return newNode.getRootNode();
	} catch (Exception e) {
		LOGGER.log(Level.WARNING, "Unable to convert json from previous version " + getPreviousVersion(), e);
		return null;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:21,代码来源:Parser1_6.java

示例7: internalConvertFromPreviousVersion

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
protected JsonRootNode internalConvertFromPreviousVersion(JsonRootNode previousVersion) {
	try {
		// Move ipc settings into config
		List<JsonNode> ipcSettingNodes = previousVersion.getArrayNode("ipc_settings");
		List<JsonNode> converted = new Function<JsonNode, JsonNode>() {
			@Override
			public JsonNode apply(JsonNode d) {
				String name = d.getStringValue("name");
				boolean launchAtStartup = d.getBooleanValue("launch_at_startup");

				return JsonNodeFactories.object(
						JsonNodeFactories.field("name", JsonNodeFactories.string(name)),
						JsonNodeFactories.field("config", JsonNodeFactories.object(
								JsonNodeFactories.field("launch_at_startup", JsonNodeFactories.booleanNode(launchAtStartup))
								))
						);
			}
		}.map(ipcSettingNodes);

		return JSONUtility.replaceChild(previousVersion, "ipc_settings", JsonNodeFactories.array(converted)).getRootNode();
	} catch (Exception e) {
		LOGGER.log(Level.WARNING, "Unable to convert json from previous version " + getPreviousVersion(), e);
		return null;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:27,代码来源:Parser2_1.java

示例8: internalConvertFromPreviousVersion

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
protected JsonRootNode internalConvertFromPreviousVersion(JsonRootNode previousVersion) {
	try {
		// Add classpath to java compiler as compiler specific args
		List<JsonNode> compilers = previousVersion.getArrayNode("compilers");

		List<JsonNode> replacement = new ArrayList<>();
		for (JsonNode compiler : compilers) {
			if (compiler.getStringValue("name").equals(Language.JAVA.toString())) {
				replacement.add(JSONUtility.replaceChild(compiler, "compiler_specific_args",
						JsonNodeFactories.object(JsonNodeFactories.field("classpath", JsonNodeFactories.array()))));
			} else {
				replacement.add(compiler);
			}
		}

		return JSONUtility.replaceChild(previousVersion, "compilers", JsonNodeFactories.array(replacement)).getRootNode();
	} catch (Exception e) {
		LOGGER.log(Level.WARNING, "Unable to convert json from previous version " + getPreviousVersion(), e);
		return null;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:23,代码来源:Parser2_2.java

示例9: internalConvertFromPreviousVersion

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
protected JsonRootNode internalConvertFromPreviousVersion(JsonRootNode previousVersion) {
	try {
		JsonNode globalHotkeys = previousVersion.getNode("global_hotkey");
		JsonNode result = JSONUtility.removeChild(previousVersion, "global_hotkey");

		JsonNode globalSettings = JSONUtility.addChild(result.getNode("global_settings"), "global_hotkey", globalHotkeys);
		result = JSONUtility.replaceChild(result, "global_settings", globalSettings);
		result = JSONUtility.addChild(result, "ipc_settings", JsonNodeFactories.array(
				new Function<Language, JsonNode>(){
					@Override
					public JsonNode apply(Language l) {
						return JsonNodeFactories.object(
									JsonNodeFactories.field("name", JsonNodeFactories.string(l.toString())),
									JsonNodeFactories.field("launch_at_startup", JsonNodeFactories.booleanNode(true))
									);
					}
				}.map(Language.values())
			));

		return result.getRootNode();
	} catch (Exception e) {
		LOGGER.log(Level.WARNING, "Unable to convert json from previous version " + getPreviousVersion(), e);
		return null;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:27,代码来源:Parser1_8.java

示例10: internalConvertFromPreviousVersion

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
protected JsonRootNode internalConvertFromPreviousVersion(JsonRootNode previousVersion) {
	try {
		JsonNode newCompiler = JsonNodeFactories.array(new Function<JsonNode, JsonNode>(){
			@Override
			public JsonNode apply(JsonNode compiler) {
				return JsonNodeFactories.object(
							JsonNodeFactories.field("name", compiler.getNode("name")),
							JsonNodeFactories.field("path", compiler.getNode("path")),
							JsonNodeFactories.field("compiler_specific_args", JsonNodeFactories.object())
							);
			}
		}.map(previousVersion.getArrayNode("compilers")));

		JsonRootNode newRoot = JsonNodeFactories.object(
				JsonNodeFactories.field("version", JsonNodeFactories.string(getVersion())),
				JsonNodeFactories.field("global_hotkey", previousVersion.getNode("global_hotkey")),
				JsonNodeFactories.field("compilers", newCompiler),
				JsonNodeFactories.field("task_groups", previousVersion.getNode("task_groups"))
				);
		return newRoot;
	} catch (Exception e) {
		LOGGER.log(Level.WARNING, "Unable to convert json from previous version " + getPreviousVersion(), e);
		return null;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:27,代码来源:Parser1_5.java

示例11: convertFromPreviousVersion

import argo.jdom.JsonNode; //导入依赖的package包/类
protected final JsonRootNode convertFromPreviousVersion(JsonRootNode previousVersion) {
	if (previousVersion != null && previousVersion.isStringValue("version")) {
		if (previousVersion.getStringValue("version").equals(getPreviousVersion())) {
			JsonRootNode output = internalConvertFromPreviousVersion(previousVersion);

			try {
				JsonNode convertedVersion = JSONUtility.replaceChild(output, "version", JsonNodeFactories.string(getVersion()));
				return convertedVersion.getRootNode();
			} catch (Exception e) {
				LOGGER.log(Level.WARNING, "Unable to modify version when converting versions " + getPreviousVersion() + " to " + getVersion(), e);
				return null;
			}
		}
	}
	LOGGER.warning("Invalid previous version " + getPreviousVersion() + " cannot "
			+ "be converted to this version " + getVersion() + ". Only accept previous version " + getPreviousVersion());
	return null;
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:19,代码来源:ConfigParser.java

示例12: process

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
public boolean process(String type, long id, JsonNode content) {
	if (locks.containsKey(id)) {
		if (!verifyReplyContent(content)) {
			getLogger().warning("Invalid reply." + content + ". Drop message!");
			return false;
		}

		String status = content.getStringValue("status");
		JsonNode message = content.getNode("message");
		Reply output = locks.get(id);
		output.status = status;
		output.message = message;

		synchronized (output) {
			output.timeout = false;
			output.notify();
		}
		return true;
	}

	getLogger().warning("Unknown id " + id + ". Drop message!");
	return false;
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:25,代码来源:TaskProcessor.java

示例13: processRequest

import argo.jdom.JsonNode; //导入依赖的package包/类
/**
 * Parse a request from client.
 * @param message request from client as JSON string
 * @param core Core controller that will execute the action
 * @return list of actions need to perform in order
 */
public boolean processRequest(String message) {
	JsonRootNode root = JSONUtility.jsonFromString(message);
	if (root == null || !verifyMessage(root)) {
		getLogger().warning("Invalid messaged received " + message);
		return false;
	}

	getLogger().fine("Receive " + message);
	IpcMessageType type = IpcMessageType.identify(root.getStringValue("type"));
	long id = Long.parseLong(root.getNumberValue("id"));
	JsonNode content = root.getNode("content");

	try {
		messageProcesssors.get(type).process(type.getValue(), id, content);
		return true;
	} catch (InterruptedException e) {
		getLogger().log(Level.WARNING, "Interrupted while processing message", e);
		return false;
	}
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:27,代码来源:ServerMainProcessor.java

示例14: process

import argo.jdom.JsonNode; //导入依赖的package包/类
@Override
public boolean process(String type, long id, JsonNode content) throws InterruptedException {
	final String device = content.getStringValue("device");
	String action = content.getStringValue("action");

	List<Object> parsedParams = parseParams(content.getArrayNode("parameters"));

	if (device.equals(DEVICE_MOUSE)) {
		return mouseAction(type, id, action, parsedParams);
	} else if (device.equals(DEVICE_KEYBOARD)) {
		return keyboardAction(type, id, action, parsedParams);
	} else if (device.equals(DEVICE_TOOL)) {
		return toolAction(type, id, action, parsedParams);
	}

	return failure(type, id, "Unknown device " + device);
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:18,代码来源:ControllerRequestProcessor.java

示例15: sendMessage

import argo.jdom.JsonNode; //导入依赖的package包/类
public synchronized boolean sendMessage(String type, long id, JsonNode content) {
	JsonRootNode toSend = getMessage(type, id, content);

	synchronized (this) {
		try {
			writer.write(ClientServingThread.MESSAGE_DELIMITER);
			writer.write(ClientServingThread.MESSAGE_DELIMITER);
			writer.write(encode(JSONUtility.jsonToString(toSend)));
			writer.write(ClientServingThread.MESSAGE_DELIMITER);
			writer.write(ClientServingThread.MESSAGE_DELIMITER);
			writer.flush();
		} catch (IOException e) {
			getLogger().log(Level.WARNING, "Exception while writing message", e);
			return false;
		}
	}

	return true;
}
 
开发者ID:repeats,项目名称:Repeat,代码行数:20,代码来源:MainMessageSender.java


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