本文整理汇总了Java中xdi2.core.Graph类的典型用法代码示例。如果您正苦于以下问题:Java Graph类的具体用法?Java Graph怎么用?Java Graph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Graph类属于xdi2.core包,在下文中一共展示了Graph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertXdiToCards
import xdi2.core.Graph; //导入依赖的package包/类
public List<Card> convertXdiToCards(Graph graph) {
Assert.notNull(graph);
CloudUser user = (CloudUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
List<Card> cards = new ArrayList<Card>();
ContextNode contextNode = graph.getDeepContextNode(XDIAddressUtil.concatXDIAddresses(user.getCloudNumber().getXDIAddress(), XDI_CARDS));
if (contextNode == null) {
return cards;
}
XdiEntityCollection cardCollection = XdiEntityCollection.fromContextNode(contextNode);
if (cardCollection == null) {
return cards;
}
long start = System.currentTimeMillis();
ReadOnlyIterator<XdiEntityInstance> iCards = cardCollection.getXdiInstances();
while (iCards.hasNext()) {
XdiEntityInstance cardXdi = iCards.next();
cards.add(convertXdiToCard(cardXdi));
}
log.debug("Took " + (System.currentTimeMillis()-start) + "ms to convert " + cards.size() + " cards");
return cards;
}
示例2: testAccessGranting
import xdi2.core.Graph; //导入依赖的package包/类
public static void testAccessGranting(){
PersonalCloud pc1 = PersonalCloud.open(
XDI3Segment.create("=dev.animesh"), "animesh123",
PersonalCloud.XRI_S_DEFAULT_LINKCONTRACT, "","");
ProfileInfo pc1Prof = new ProfileInfo();
pc1Prof.setEmail("[email protected]");
pc1Prof.setPhone("1-240-620-4205");
pc1.saveProfileInfo(pc1Prof);
pc1.allowAccess(pc1Prof, XDILinkContractConstants.XRI_S_GET,
XDI3Segment.create("=markus"));
Graph pc1Graph = pc1.getWholeGraph();
// open someone else's personal cloud
// PersonalCloud pc_markus = PersonalCloud.open(
// XDI3Segment.create("=markus"),pc1.getCloudNumber(),
// XDI3Segment.create(pc1.getCloudNumber().toString() +"$do"), "");
//
// System.out.println(pc_markus.getProfileInfo().getPhone());
// pc1.allowAccess(todoList, XDILinkContractConstants.XRI_S_GET,
// XDI3Segment.create("=markus"));
}
示例3: generateFacebookField
import xdi2.core.Graph; //导入依赖的package包/类
private FacebookProfileField generateFacebookField(XDIAddress fieldXdiAddress, Graph graph) {
LiteralNode l = graph.getRootContextNode().getDeepLiteralNode(fieldXdiAddress);
if (l != null) {
return new FacebookProfileField(l.getLiteralDataString(), fieldXdiAddress.toString());
}
return null;
}
示例4: signMessage
import xdi2.core.Graph; //导入依赖的package包/类
public static Graph signMessage(String message, XDIAddress[] addresses, String key) {
try {
// parse the message to graph
Graph graph = MemoryGraphFactory.getInstance().openGraph();
XDIReader xdiReader = XDIReaderRegistry.getAuto();
xdiReader.read(graph, new StringReader(message));
// find the addresses
for (XDIAddress address : addresses) {
ContextNode contextNode = graph.getDeepContextNode(address, true);
if (contextNode == null) throw new RuntimeException("No context node found at address " + address);
// sign
RSASignature signature = (RSASignature) Signatures.createSignature(contextNode, "sha", 256, "rsa", 2048, true);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decodeBase64(key));
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
Key k = keyFactory.generatePrivate(keySpec);
new RSAStaticPrivateKeySignatureCreator((PrivateKey) k).createSignature(signature);
}
return graph;
}
catch(Exception e) {
log.warn("Error while signing a message:\n" + message, e);
}
return null;
}
示例5: convertToPersonalProfile
import xdi2.core.Graph; //导入依赖的package包/类
public PersonalProfile convertToPersonalProfile(Graph graph) {
CloudUser user = (CloudUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
PersonalProfile profile = new PersonalProfile();
profile.setXdiData(graph.toString("XDI DISPLAY", null));
profile.setFirstName(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_FIRST_NAME));
profile.setLastName(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_LAST_NAME));
profile.setNickname(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_NICKNAME));
profile.setGender(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_GENDER));
profile.setBirthDate(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_BIRTH_DATE));
profile.setNationality(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_NATIONALITY));
profile.setPhone(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_PHONE));
profile.setMobilePhone(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_MOBILE_PHONE));
profile.setWorkPhone(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_WORK_PHONE));
profile.setEmail(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_EMAIL));
profile.setWebsite(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_WEBSITE));
PostalAddress address = new PostalAddress();
address.setStreet(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_ADDRESS_STREET));
address.setCountry(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_ADDRESS_COUNTRY));
address.setLocality(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_ADDRESS_LOCALITY));
address.setPostalCode(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_ADDRESS_POSTAL_CODE));
address.setRegion(getStringLiteralForSegment(graph, user.getCloudNumber(), XDI_ADDRESS_REGION));
profile.setAddress(address);
return profile;
}
示例6: convertLCBaseToAbstractConnection
import xdi2.core.Graph; //导入依赖的package包/类
private AbstractConnection convertLCBaseToAbstractConnection(LinkContractBase<?> linkContract, AbstractConnection connection) {
Assert.notNull(linkContract);
Assert.notNull(connection);
// isolate the LC part of the graph
Graph tempGraph = MemoryGraphFactory.getInstance().openGraph();
CopyUtil.copyContextNode(linkContract.getContextNode(), tempGraph, null);
connection.setXdi(tempGraph.toString("XDI DISPLAY", null));
connection.setXdiAddress(linkContract.getContextNode().getXDIAddress().toString());
// Permissions
IterableIterator<XDIAddress> permissions = linkContract.getPermissionTargetXDIAddresses(XDILinkContractConstants.XDI_ADD_GET);
CollectionUtils.forAllDo(permissions.iterator(), new PermissionsClosure<XDIAddress>(connection, "get"));
permissions = linkContract.getPermissionTargetXDIAddresses(XDILinkContractConstants.XDI_ADD_SET);
CollectionUtils.forAllDo(permissions.iterator(), new PermissionsClosure<XDIAddress>(connection, "set"));
permissions = linkContract.getPermissionTargetXDIAddresses(XDILinkContractConstants.XDI_ADD_DEL);
CollectionUtils.forAllDo(permissions.iterator(), new PermissionsClosure<XDIAddress>(connection, "del"));
permissions = linkContract.getPermissionTargetXDIAddresses(XDILinkContractConstants.XDI_ADD_ALL);
CollectionUtils.forAllDo(permissions.iterator(), new PermissionsClosure<XDIAddress>(connection, "all"));
IterableIterator<XDIStatement> permissionStatements = linkContract.getPermissionTargetXDIStatements(XDILinkContractConstants.XDI_ADD_GET);
CollectionUtils.forAllDo(permissionStatements.iterator(), new PermissionsClosure<XDIStatement>(connection, "get"));
permissionStatements = linkContract.getPermissionTargetXDIStatements(XDILinkContractConstants.XDI_ADD_SET);
CollectionUtils.forAllDo(permissionStatements.iterator(), new PermissionsClosure<XDIStatement>(connection, "set"));
permissionStatements = linkContract.getPermissionTargetXDIStatements(XDILinkContractConstants.XDI_ADD_DEL);
CollectionUtils.forAllDo(permissionStatements.iterator(), new PermissionsClosure<XDIStatement>(connection, "del"));
permissionStatements = linkContract.getPermissionTargetXDIStatements(XDILinkContractConstants.XDI_ADD_ALL);
CollectionUtils.forAllDo(permissionStatements.iterator(), new PermissionsClosure<XDIStatement>(connection, "all"));
return connection;
}
示例7: addCardButtonMessages
import xdi2.core.Graph; //导入依赖的package包/类
private void addCardButtonMessages(List<XDIStatement> statements, XDIAddress cardXdiAddress) throws Xdi2ClientException {
CloudUser user = (CloudUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String signatureKeys[] = cloudService.getSignatureKeyPair();
String cloudCardUri = null;
try {
cloudCardUri = configuration.getCloudCardAppUri() + URLEncoder.encode(cardXdiAddress.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("Unable to URI encode (" + cardXdiAddress.toString() + ") ");
}
String messageConnectXdiAddress = user.getCloudNumber() + "[$msg]@0";
String messageConnect = messageConnectXdiAddress + "/$is()/({$to})\n";
messageConnect += messageConnectXdiAddress + "/$do/({$to}/[+]!:uuid:ca51aeb9-e09e-4305-89d7-87a944a1e1fa)[+]!:uuid:ca51aeb9-e09e-4305-89d7-87a944a1e1fa#community$do\n";
messageConnect += messageConnectXdiAddress + "/$is$do/(" + user.getCloudNumber() + "/[+]!:uuid:ca51aeb9-e09e-4305-89d7-87a944a1e1fa)[+]!:uuid:ca51aeb9-e09e-4305-89d7-87a944a1e1fa#community$do\n";
messageConnect += messageConnectXdiAddress + "$do/$do$is{}/+danubeclouds#forever{$do}\n";
messageConnect += messageConnectXdiAddress + "{$card}/$is/" + cardXdiAddress + "\n";
messageConnect += messageConnectXdiAddress + "<#return><$uri>&/&/\"" + cloudCardUri + "\"\n";
String messageGetXdiAddress = user.getCloudNumber() + "[$msg]@1";
messageConnect += messageGetXdiAddress + "/$is()/({$to})\n";
messageConnect += messageGetXdiAddress + "/$do/({$to}/[+]!:uuid:ca51aeb9-e09e-4305-89d7-87a944a1e1fa)[+]!:uuid:ca51aeb9-e09e-4305-89d7-87a944a1e1fa#community$do\n";
messageConnect += messageGetXdiAddress + "/$is$do/("+ user.getCloudNumber() +"/{$to})+danubeclouds#forever$do\n";
messageConnect += messageGetXdiAddress + "$do/$get$is/" + cardXdiAddress + "\n";
messageConnect += "(" + messageGetXdiAddress + "$do/$get$is)" + user.getCloudNumber() + "/$is$ref/{}\n";
messageConnect += messageGetXdiAddress + "<#return><$uri>&/&/\"" + cloudCardUri + "\"\n";
messageConnect += messageGetXdiAddress + "$get<$deref>&/&/true\n";
XDIAddress[] messagesXdiAddress = new XDIAddress[]{XDIAddress.create(messageConnectXdiAddress), XDIAddress.create(messageGetXdiAddress)};
Graph signedMessage = XdiUtils.signMessage(messageConnect, messagesXdiAddress, signatureKeys[1]);
log.debug("signed connect message:\n" + signedMessage.toString("XDI DISPLAY", null));
addStatement(statements, XDIAddressUtil.concatXDIAddresses(cardXdiAddress, XDI_CARD_CONNECT_BUTTON), Base64.encodeBase64String(signedMessage.toString("XDI/JSON", null).getBytes()));
}
示例8: getDependentData
import xdi2.core.Graph; //导入依赖的package包/类
public static DependentData getDependentData( Statement stmt )
{
try
{
CloudNumber cloudNumber = CloudNumber.create(stmt.getObject().toString());
XDIDiscoveryResult result = getXDIDiscoveryClient().discoverFromRegistry(cloudNumber.getXDIAddress(), null);
URL cloudUrl = result.getXdiEndpointUrl();
Graph tempGraph = MemoryGraphFactory.getInstance().openGraph();
MessageEnvelope getMessageEnvelope = new MessageEnvelope();
Message getMessage = getMessageEnvelope.createMessage(cloudNumber.getXDIAddress());
getMessage.setToPeerRootXDIArc(cloudNumber.getPeerRootXDIArc());
getMessage.setLinkContract(PublicLinkContract.class);
getMessage.createGetOperation(XDIStatement.fromRelationComponents(cloudNumber.getXDIAddress(), XDIDictionaryConstants.XDI_ADD_IS_REF, XDIConstants.XDI_ADD_COMMON_VARIABLE));
MessageResult getMessageResult = new XDIHttpClient(cloudUrl).send(getMessageEnvelope, null);
for( Statement stmt1 : getMessageResult.getGraph().getRootContextNode().getAllStatements())
{
if( XDIDictionaryConstants.XDI_ADD_IS_REF.equals(stmt1.getPredicate()) == false )
{
logger.debug("getDependentData() - Ignore " + stmt1);
continue;
}
logger.debug("getDependentData() - Process " + stmt1);
String cloudName = stmt1.getObject().toString();
DependentData rtn = new DependentData();
rtn.setCloudName(cloudName);
rtn.setCloudNumber(cloudNumber);
rtn.setCloudUrl(cloudUrl);
return rtn;
}
}
catch( Exception e )
{
logger.error("getDependentData() failed - " + e.getMessage(), e);
}
logger.error("getDependentData() - Cannot find dependent cloud " + stmt);
return null;
}
示例9: setDependentProxyServer
import xdi2.core.Graph; //导入依赖的package包/类
public static void setDependentProxyServer( DependentData data )
{
logger.info("setDependentProxyServer - " + data);
try
{
String server = "";
if( data.getPort() != null )
{
server = data.getHostname() + ":" + data.getPort();
}
CloudNumber cloudNumber = data.getCloudNumber();
Graph tempGraph = MemoryGraphFactory.getInstance().openGraph();
XdiAttribute proxyServerMessage = XdiCommonRoot.findCommonRoot(tempGraph)
.getXdiEntity(cloudNumber.getXDIAddress(), true)
.getXdiAttributeSingleton(XDIAddress.create("<#proxy>"), true)
.getXdiAttributeSingleton(XDIAddress.create("<#server>"), true);
proxyServerMessage.setLiteralDataString(server);
logger.info("Setting proxy server as '" + server + "'");
logger.info(tempGraph.toString("XDI DISPLAY", null));
MessageEnvelope messageEnvelope = new MessageEnvelope();
Message message = messageEnvelope.createMessage(cloudNumber.getXDIAddress());
message.setToPeerRootXDIArc(cloudNumber.getPeerRootXDIArc());
message.setLinkContract(RootLinkContract.class);
message.setSecretToken(data.getSecretToken());
message.createSetOperation(tempGraph);
new XDIHttpClient(data.getCloudUrl()).send(messageEnvelope, null);
}
catch( Exception e )
{
logger.error("setDependentProxyServer() failed - " + e.getMessage(), e);
}
}
示例10: testAccessRemoval
import xdi2.core.Graph; //导入依赖的package包/类
public static void testAccessRemoval(){
PersonalCloud pc1 = PersonalCloud.open(
XDI3Segment.create("=dev.animesh"), "animesh123",
PersonalCloud.XRI_S_DEFAULT_LINKCONTRACT, "","");
ProfileInfo pc1Prof = new ProfileInfo();
pc1.removeAccess( null,XDI3Segment.create("=markus"));
Graph pc1Graph = pc1.getWholeGraph();
}
示例11: geAllCollections
import xdi2.core.Graph; //导入依赖的package包/类
public ArrayList<PCAttributeCollection> geAllCollections() {
Graph g = this.getWholeGraph();
ContextNode root = g.getRootContextNode();
ReadOnlyIterator<Literal> allLiterals = root.getAllLiterals();
while (allLiterals.hasNext()) {
Literal lit = allLiterals.next();
String value = lit.getLiteralData().toString();
String name = lit.getContextNode().toString();
}
return null;
}
示例12: callbackGraph
import xdi2.core.Graph; //导入依赖的package包/类
@Override
protected void callbackGraph(String messagingContainerPath, Graph graph, MyState state) throws Xdi2MessagingException, IOException {
XDIReader reader = XDIReaderRegistry.getAuto();
try {
graph.clear();
reader.read(graph, System.in);
} catch (Exception ex) {
System.err.println("Problem while loading graph " + messagingContainerPath);
ex.printStackTrace(System.err);
}
}
示例13: main
import xdi2.core.Graph; //导入依赖的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();
}
示例14: getStringLiteralForSegment
import xdi2.core.Graph; //导入依赖的package包/类
private static String getStringLiteralForSegment(Graph graph, CloudNumber cloudNumber, XDIAddress segment) {
LiteralNode l = graph.getRootContextNode().getDeepLiteralNode(XDIAddressUtil.concatXDIAddresses(cloudNumber.getXDIAddress(), segment, XDIAddress.create("&")));
return l != null ? l.getLiteralDataString() : null;
}
示例15: convertConnectionToLinkContract
import xdi2.core.Graph; //导入依赖的package包/类
public LinkContract convertConnectionToLinkContract (Connection connection) {
Assert.notNull(connection);
if (StringUtils.isEmpty(connection.getRaCloudNumber())) {
throw new RuntimeException("Invalid Cloud Name.");
}
CloudUser user = (CloudUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Graph g = MemoryGraphFactory.getInstance().openGraph();
LinkContract l = RelationshipLinkContract.findRelationshipLinkContract(g, XDIAddress.create(user.getCloudNumber().toString()), XDIAddress.create(connection.getRaCloudNumber()), null, null, true);
l = (LinkContract) this.convertAbstractConnectionToLinkContractBase(connection, l);
PolicyAnd policyAnd = l.getPolicyRoot(true).createAndPolicy(true);
PolicyUtil.createSenderIsOperator(policyAnd, XDIAddress.create(connection.getRaCloudNumber()));
if (connection.getRequireSecretToken()) PolicyUtil.createSecretTokenValidOperator(policyAnd);
if (connection.getRequireSignature()) PolicyUtil.createSignatureValidOperator(policyAnd);
return l;
}