• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java XDIWriterRegistry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

import xdi2.core.io.XDIWriterRegistry; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		// create a simple graph with context nodes, a relation, and a literal

		Graph graph = MemoryGraphFactory.getInstance().openGraph();

		ContextNode root = graph.getRootContextNode();
		ContextNode markus = root.setContextNode(XDIArc.create("=markus"));
		ContextNode animesh = root.setContextNode(XDIArc.create("=animesh"));
		ContextNode name = markus.setContextNode(XDIArc.create("<#name>"));
		Relation relation = markus.setRelation(XDIAddress.create("#friend"), animesh);
		LiteralNode literalNode = name.setLiteralNode("Markus Sabadello");

		// write some statements from our graph

		System.out.println("Statement associated with a context node: " + markus.getStatement());
		System.out.println("Statement associated with a relation: " + relation.getStatement());
		System.out.println("Statement associated with a literal: " + literalNode.getStatement());
		System.out.println();

		// we can also add a whole new statement to the graph

		graph.setStatement(XDIStatement.create("=alice/#friend/=bob"));

		// write the whole graph in different serialization formats

		System.out.println("Serialization in XDI/JSON: \n");
		XDIWriterRegistry.forFormat("XDI/JSON", null).write(graph, System.out);
		System.out.println();
		System.out.println();

		System.out.println("Serialization in XDI statements:\n");
		XDIWriterRegistry.forFormat("XDI DISPLAY", null).write(graph, System.out);

		// close the graph

		graph.close();
	}
 
开发者ID:projectdanube,项目名称:xdi2-example-core,代码行数:39,代码来源:GraphModel.java


示例2: linkContractExists

import xdi2.core.io.XDIWriterRegistry; //导入依赖的package包/类
public boolean linkContractExists(String connectRequest) {
	System.out.println("\nChecking if a link contract exists\n");
	boolean result = false;
	MemoryJSONGraphFactory graphFactory = new MemoryJSONGraphFactory();
	String templateOwnerInumber = null;
	try {
		Graph g = graphFactory.parseGraph(connectRequest);
		// get remote cloud number

		XDIWriterRegistry.forFormat("XDI DISPLAY", null).write(g,
				System.out);
		ContextNode c = g.getRootContextNode();
		ReadOnlyIterator<ContextNode> allCNodes = c.getAllContextNodes();
		for (ContextNode ci : allCNodes) {
			if (ci.containsContextNode(XDI3SubSegment.create("[$msg]"))) {
				templateOwnerInumber = ci.toString();
				System.out.println(templateOwnerInumber);
				break;
			}
		}
		if (templateOwnerInumber == null) {
			System.out
					.println("No cloudnumber for requestor/template owner");
			return result;
		}
		// get the address of the link contract template
		// $set{$do}

		String lcTemplateAddress = null;

		ReadOnlyIterator<Relation> allRelations = c.getAllRelations(); // g.getDeepRelations(XDI3Segment.create(templateOwnerInumber),XDI3Segment.create("$get"));
		for (Relation r : allRelations) {
			if (r.getArcXri().toString().equals("$set{$do}")) {
				lcTemplateAddress = r.getTargetContextNodeXri().toString();
				System.out.println(r.getTargetContextNodeXri());
			}

		}
		if (lcTemplateAddress == null) {
			System.out.println("No LC template address provided");
			return result;
		}
	} catch (Exception io) {
		io.printStackTrace();
		return result;
	}

	String isPlusstmt = new String();
	isPlusstmt += this.cloudNumber;
	isPlusstmt += "$to";
	isPlusstmt += templateOwnerInumber;
	isPlusstmt += "$from";
	isPlusstmt += templateOwnerInumber;
	isPlusstmt += "+registration$do";

	ArrayList<XDI3Segment> querySegments = new ArrayList<XDI3Segment>();

	querySegments.add(XDI3Segment.create(isPlusstmt));

	MessageResult responseFromRemoteCloud = this.sendQueries(querySegments,
			null, false);

	Graph responseGraph = responseFromRemoteCloud.getGraph();
	ContextNode responseRootContext = responseGraph.getRootContextNode();
	System.out.println("\n\nLink Contract exists check\n\n"
			+ responseGraph.toString());
	if (responseRootContext.getContextNodeCount() > 1) {
		result = true;
	}

	return result;
}
 
开发者ID:peacekeeper,项目名称:clouds-client-basic,代码行数:73,代码来源:PersonalCloud.java


示例3: callbackGraph

import xdi2.core.io.XDIWriterRegistry; //导入依赖的package包/类
@Override
protected void callbackGraph(String messagingContainerPath, Graph graph, MyState state) throws Xdi2ClientException, IOException {

	GraphMessagingContainer commandGraphMessagingContainer = new GraphMessagingContainer();
	commandGraphMessagingContainer.setGraph(graph);

	MessageEnvelope commandMessageEnvelope = MessageEnvelope.fromOperationXDIAddressAndTargetXDIAddressOrTargetXDIStatement(XDIAddress.create(state.operation), state.target);
	MessagingResponse commandMessagingResponse;

	commandMessagingResponse = new XDILocalClient(commandGraphMessagingContainer).send(commandMessageEnvelope);

	XDIWriter writer = state.mimeType == null ? XDIWriterRegistry.getDefault() : XDIWriterRegistry.forMimeType(new MimeType(state.mimeType));
	writer.write(commandMessagingResponse.getResultGraph(), System.out);

	System.out.println("At path " + messagingContainerPath + " executed message on graph " + graph.getClass().getSimpleName());
}
 
开发者ID:projectdanube,项目名称:xdi2-tools,代码行数:17,代码来源:CommandMessageGraphs.java


示例4: callbackGraph

import xdi2.core.io.XDIWriterRegistry; //导入依赖的package包/类
@Override
protected void callbackGraph(String messagingContainerPath, Graph graph, MyState state) throws Xdi2MessagingException, IOException {

	System.out.println("Rebuilding graph " + messagingContainerPath + ".");

	XDIWriter writer = state.mimeType == null ? XDIWriterRegistry.getDefault() : XDIWriterRegistry.forMimeType(new MimeType(state.mimeType));
	XDIReader reader = new AutoReader(null);

	try {

		if (writer == null) throw new RuntimeException("Unknown MIME type " + state.mimeType);

		StringWriter stringWriter = new StringWriter();
		writer.write(graph, stringWriter);

		graph.clear();

		StringReader stringReader = new StringReader(stringWriter.toString());
		reader.read(graph, stringReader);
	} catch (Exception ex) {

		System.err.println("Problem while rebuilding graph " + messagingContainerPath);
		ex.printStackTrace(System.err);
	}
}
 
开发者ID:projectdanube,项目名称:xdi2-tools,代码行数:26,代码来源:CommandRebuildGraphs.java


示例5: callbackGraph

import xdi2.core.io.XDIWriterRegistry; //导入依赖的package包/类
@Override
protected void callbackGraph(String messagingContainerPath, Graph graph, MyState state) throws Xdi2MessagingException, IOException {

	XDIWriter writer = state.mimeType == null ? XDIWriterRegistry.getDefault() : XDIWriterRegistry.forMimeType(new MimeType(state.mimeType));

	try {

		if (writer == null) throw new RuntimeException("Unknown MIME type " + state.mimeType);

		writer.write(graph, System.out);
	} catch (Exception ex) {

		System.err.println("Problem while dumping graph " + messagingContainerPath);
		ex.printStackTrace(System.err);
	}
}
 
开发者ID:projectdanube,项目名称:xdi2-tools,代码行数:17,代码来源:CommandDumpGraph.java


示例6: callbackGraph

import xdi2.core.io.XDIWriterRegistry; //导入依赖的package包/类
@Override
protected void callbackGraph(String messagingContainerPath, Graph graph, MyState state) throws Xdi2MessagingException, IOException {

	String zipEntryName = messagingContainerPath + ".xdi";
	if (zipEntryName.startsWith("/")) zipEntryName = zipEntryName.substring(1);

	ZipEntry zipEntry = new ZipEntry(zipEntryName);
	state.zipOutputStream.putNextEntry(zipEntry);

	System.out.println("Backing up graph " + messagingContainerPath + ".");

	XDIWriter writer = state.mimeType == null ? XDIWriterRegistry.getDefault() : XDIWriterRegistry.forMimeType(new MimeType(state.mimeType));

	try {

		if (writer == null) throw new RuntimeException("Unknown MIME type " + state.mimeType);

		writer.write(graph, state.zipOutputStream);
	} catch (Exception ex) {

		System.err.println("Problem while backing up graph " + messagingContainerPath);
		ex.printStackTrace(System.err);
	}

	state.zipOutputStream.closeEntry();
}
 
开发者ID:projectdanube,项目名称:xdi2-tools,代码行数:27,代码来源:CommandBackupGraphs.java


示例7: main

import xdi2.core.io.XDIWriterRegistry; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

		LogManager.getLogger("xdi2").setLevel(Level.OFF);

		XDIWriter writer = XDIWriterRegistry.forFormat("XDI DISPLAY", null);

		// discovery

		XDIDiscoveryClient xdiDiscoveryClient = XDIDiscoveryClient.DEFAULT_DISCOVERY_CLIENT;
		XDIDiscoveryResult xdiDiscoveryResult = xdiDiscoveryClient.discoverFromRegistry(XDIAddress.create("=markus"));

		// construct message

		MessageEnvelope messageEnvelope = new MessageEnvelope();
		Message message = messageEnvelope.createMessage(XDIAddress.create("=sender"));
		message.createGetOperation(XDIAddress.create("=markus<#email>"));
		message.setToPeerRootXDIArc(xdiDiscoveryResult.getCloudNumber().getPeerRootXDIArc());
		message.setLinkContractClass(PublicLinkContract.class);

		// construct client, send message, read result

		XDIClient client = new XDIHttpClient(xdiDiscoveryResult.getXdiEndpointUri());

		MessagingResponse messagingResponse = client.send(messageEnvelope);

		// print results

		System.out.println("Discovery result: ");
		writer.write(xdiDiscoveryResult.getMessagingResponse().getGraph(), System.out);
		System.out.println();

		System.out.println("Message envelope: ");
		writer.write(messageEnvelope.getGraph(), System.out);
		System.out.println();

		System.out.println("Messaging response: ");
		writer.write(messagingResponse.getGraph(), System.out);
	}
 
开发者ID:projectdanube,项目名称:xdi2-example-client,代码行数:39,代码来源:SimpleClient.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MultivaluedMapImpl类代码示例发布时间:2022-05-23
下一篇:
Java EntityTNTPrimed类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap