Skip to content

Commit

Permalink
Merge branch 'great-symbol-shift'
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Apr 4, 2014
2 parents 88cdb94 + b940d46 commit 946b5c8
Show file tree
Hide file tree
Showing 197 changed files with 1,784 additions and 1,203 deletions.
16 changes: 8 additions & 8 deletions core/src/main/java/xdi2/core/constants/XDIConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
*/
public class XDIConstants {

public static final Character CS_EQUALS = new Character('=');
public static final Character CS_AT = new Character('@');
public static final Character CS_PLUS = new Character('+');
public static final Character CS_DOLLAR = new Character('$');
public static final Character CS_STAR = new Character('*');
public static final Character CS_BANG = new Character('!');
public static final Character CS_ORDER = new Character('#');
public static final Character CS_AUTHORITY_PERSONAL = new Character('=');
public static final Character CS_AUTHORITY_LEGAL = new Character('+');
public static final Character CS_AUTHORITY_GENERAL = new Character('*');
public static final Character CS_CLASS_UNRESERVED = new Character('#');
public static final Character CS_CLASS_RESERVED = new Character('$');
public static final Character CS_VALUE = new Character('&');
public static final Character CS_MEMBER_UNORDERED = new Character('!');
public static final Character CS_MEMBER_ORDERED = new Character('@');

public static final String XS_ROOT = "()";
public static final String XS_VARIABLE = "{}";
public static final String XS_DEFINITION = "||";
public static final String XS_CLASS = "[]";
public static final String XS_ATTRIBUTE = "<>";

public static final Character[] CS_ARRAY = new Character[] { CS_EQUALS, CS_AT, CS_PLUS, CS_DOLLAR, CS_STAR, CS_BANG, CS_ORDER, CS_VALUE };
public static final Character[] CS_ARRAY = new Character[] { CS_AUTHORITY_PERSONAL, CS_AUTHORITY_LEGAL, CS_AUTHORITY_GENERAL, CS_CLASS_UNRESERVED, CS_CLASS_RESERVED, CS_VALUE, CS_MEMBER_UNORDERED, CS_MEMBER_ORDERED };

public static final XDI3Segment XRI_S_ROOT = XDI3Segment.create("");
public static final XDI3Segment XRI_S_CONTEXT = XDI3Segment.create("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public final class XDIDictionaryConstants {

public static final XDI3Segment XRI_S_IS = XDI3Segment.create("$is");

public static final XDI3Segment XRI_S_IS_TYPE = XDI3Segment.create("$is+");
public static final XDI3Segment XRI_S_IS_TYPE = XDI3Segment.create("$is#");

public static final XDI3Segment XRI_S_REF = XDI3Segment.create("$ref");
public static final XDI3Segment XRI_S_IS_REF = XDI3Segment.create("$is$ref");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ public final class XDILinkContractConstants {

public static final XDI3Segment XRI_S_DO = XDI3Segment.create("$do");
public static final XDI3Segment XRI_S_EC_DO = XDI3Segment.create("[$do]");
public static final XDI3Segment XRI_S_DO_VARIABLE = XDI3Segment.create("{$do}");

public static final XDI3SubSegment XRI_SS_DO = XDI3SubSegment.create("$do");
public static final XDI3SubSegment XRI_SS_EC_DO = XDI3SubSegment.create("[$do]");
public static final XDI3SubSegment XRI_SS_DO_VARIABLE = XDI3SubSegment.create("{$do}");

public static final XDI3Segment XRI_S_PUBLIC = XDI3Segment.create("$public");

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/xdi2/core/features/datatypes/DataTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class DataTypes {

private DataTypes() { }

public static final XDI3Segment XRI_DATATYPE_XSD = XDI3Segment.create("" + XDIConstants.CS_PLUS + XDIConstants.CS_DOLLAR + "xsd");
public static final XDI3Segment XRI_DATATYPE_JSON = XDI3Segment.create("" + XDIConstants.CS_PLUS + XDIConstants.CS_DOLLAR + "json");
public static final XDI3Segment XRI_DATATYPE_MIME = XDI3Segment.create("" + XDIConstants.CS_PLUS + XDIConstants.CS_DOLLAR + "mime");
public static final XDI3Segment XRI_DATATYPE_XSD = XDI3Segment.create("" + XDIConstants.CS_CLASS_UNRESERVED + XDIConstants.CS_CLASS_RESERVED + "xsd");
public static final XDI3Segment XRI_DATATYPE_JSON = XDI3Segment.create("" + XDIConstants.CS_CLASS_UNRESERVED + XDIConstants.CS_CLASS_RESERVED + "json");
public static final XDI3Segment XRI_DATATYPE_MIME = XDI3Segment.create("" + XDIConstants.CS_CLASS_UNRESERVED + XDIConstants.CS_CLASS_RESERVED + "mime");

/*
* Methods for data types of context nodes
Expand Down Expand Up @@ -79,7 +79,7 @@ public static XDI3Segment getDataType(ContextNode contextNode) {
*/
public static XDI3Segment dataTypeXriFromXsdType(String xsdType) {

return XDI3Segment.create("" + XRI_DATATYPE_XSD + XDIConstants.CS_DOLLAR + xsdType);
return XDI3Segment.create("" + XRI_DATATYPE_XSD + XDIConstants.CS_CLASS_RESERVED + xsdType);
}

/**
Expand All @@ -103,7 +103,7 @@ public static String xsdTypeFromDataTypeXri(XDI3Segment dataTypeXri) {
*/
public static XDI3Segment dataTypeXriFromJsonType(String jsonType) {

return XDI3Segment.create("" + XRI_DATATYPE_JSON + XDIConstants.CS_DOLLAR + jsonType);
return XDI3Segment.create("" + XRI_DATATYPE_JSON + XDIConstants.CS_CLASS_RESERVED + jsonType);
}

/**
Expand Down Expand Up @@ -133,7 +133,7 @@ public static XDI3Segment dataTypeXriFromMimeType(String mimeType) {
try {

parts = mimeType.split("/");
xri = XDI3Segment.create("" + XRI_DATATYPE_MIME + XDIConstants.CS_DOLLAR + parts[0] + XDIConstants.CS_DOLLAR + parts[1]);
xri = XDI3Segment.create("" + XRI_DATATYPE_MIME + XDIConstants.CS_CLASS_RESERVED + parts[0] + XDIConstants.CS_CLASS_UNRESERVED + parts[1]);
} catch (Exception ex) {

throw new Xdi2RuntimeException("Invalid MIME Type ", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ private Dictionary() { }

public static XDI3SubSegment instanceXriToDictionaryXri(XDI3SubSegment instanceXri) {

return XDI3SubSegment.create("" + XDIConstants.CS_PLUS + "(" + instanceXri + ")");
return XDI3SubSegment.create("" + XDIConstants.CS_CLASS_UNRESERVED + "(" + instanceXri + ")");
}

public static XDI3SubSegment dictionaryXriToInstanceXri(XDI3SubSegment dictionaryXri) {

if (! XDIConstants.CS_PLUS.equals(dictionaryXri.getCs())) return null;
if (! XDIConstants.CS_CLASS_UNRESERVED.equals(dictionaryXri.getCs())) return null;
if (! dictionaryXri.hasXRef()) return null;

return XDI3SubSegment.create(dictionaryXri.getXRef().getValue());
}

public static XDI3SubSegment nativeIdentifierToInstanceXri(String nativeIdentifier) {

return XDI3SubSegment.create("" + XDIConstants.CS_PLUS + "(" + nativeIdentifier + ")");
return XDI3SubSegment.create("" + XDIConstants.CS_CLASS_UNRESERVED + "(" + nativeIdentifier + ")");
}

public static String instanceXriToNativeIdentifier(XDI3SubSegment instanceXri) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ public static boolean isValid(XdiEntity xdiEntity) {

if (! ((XdiEntitySingleton) xdiEntity).getArcXri().equals(XDILinkContractConstants.XRI_SS_DO)) return false;

// TODO? if (getAuthorizingAuthority(xdiEntity.getXri()) == null) return false;
// TODO? if (getRequestingAuthority(xdiEntity.getXri()) == null) return false;
if (getAuthorizingAuthority(xdiEntity.getXri()) == null) return false;

return true;
} else if (xdiEntity instanceof XdiEntityMember) {

if (! ((XdiEntityMember) xdiEntity).getXdiCollection().getArcXri().equals(XDILinkContractConstants.XRI_SS_EC_DO)) return false;

// TODO? if (getAuthorizingAuthority(xdiEntity.getXri()) == null) return false;
// TODO? if (getRequestingAuthority(xdiEntity.getXri()) == null) return false;
if (getAuthorizingAuthority(xdiEntity.getXri()) == null) return false;

return true;
} else {
Expand All @@ -74,14 +72,24 @@ public static GenericLinkContract fromXdiEntity(XdiEntity xdiEntity) {
return new GenericLinkContract(xdiEntity);
}

public static XDI3Segment createGenericLinkContractXri(XDI3Segment authorizingAuthority, XDI3Segment requestingAuthority, XDI3Segment templateId) {
public static XDI3Segment createGenericLinkContractXri(XDI3Segment authorizingAuthority, XDI3Segment requestingAuthority, XDI3Segment templateAuthorityAndId) {

List<XDI3SubSegment> genericLinkContractArcXris = new ArrayList<XDI3SubSegment> ();

genericLinkContractArcXris.addAll(authorizingAuthority.getSubSegments());
genericLinkContractArcXris.add(XDILinkContractConstants.XRI_SS_TO);
genericLinkContractArcXris.addAll(requestingAuthority.getSubSegments());
genericLinkContractArcXris.add(XDILinkContractConstants.XRI_SS_FROM);
if (templateId != null) genericLinkContractArcXris.addAll(templateId.getSubSegments());

if (requestingAuthority != null) {

genericLinkContractArcXris.addAll(requestingAuthority.getSubSegments());
genericLinkContractArcXris.add(XDILinkContractConstants.XRI_SS_FROM);
}

if (templateAuthorityAndId != null) {

genericLinkContractArcXris.addAll(templateAuthorityAndId.getSubSegments());
}

genericLinkContractArcXris.add(XDILinkContractConstants.XRI_SS_DO);

return XDI3Segment.fromComponents(genericLinkContractArcXris);
Expand All @@ -91,9 +99,9 @@ public static XDI3Segment createGenericLinkContractXri(XDI3Segment authorizingAu
* Factory method that finds or creates an XDI generic link contract for a graph.
* @return The XDI generic link contract.
*/
public static GenericLinkContract findGenericLinkContract(Graph graph, XDI3Segment authorizingAuthority, XDI3Segment requestingAuthority, XDI3Segment templateId, boolean create) {
public static GenericLinkContract findGenericLinkContract(Graph graph, XDI3Segment authorizingAuthority, XDI3Segment requestingAuthority, XDI3Segment templateAuthorityAndId, boolean create) {

XDI3Segment genericLinkContractXri = createGenericLinkContractXri(authorizingAuthority, requestingAuthority, templateId);
XDI3Segment genericLinkContractXri = createGenericLinkContractXri(authorizingAuthority, requestingAuthority, templateAuthorityAndId);

ContextNode genericLinkContractContextNode = create ? graph.setDeepContextNode(genericLinkContractXri) : graph.getDeepContextNode(genericLinkContractXri, true);
if (genericLinkContractContextNode == null) return null;
Expand Down Expand Up @@ -124,12 +132,14 @@ public static XDI3Segment getRequestingAuthority(XDI3Segment xri) {

public static XDI3Segment getTemplateAuthorityAndId(XDI3Segment xri) {

int index1 = XDI3Util.indexOfXri(xri, XDILinkContractConstants.XRI_SS_FROM);
int index2 = XDI3Util.indexOfXri(xri, XDILinkContractConstants.XRI_SS_DO);
if (index2 < 0) index2 = XDI3Util.indexOfXri(xri, XdiEntityCollection.createArcXri(XDILinkContractConstants.XRI_SS_DO));
if (index1 < 0 || index2 < 0 || index1 >= index2) return null;
int index1 = XDI3Util.indexOfXri(xri, XDILinkContractConstants.XRI_SS_TO);
int index2 = XDI3Util.indexOfXri(xri, XDILinkContractConstants.XRI_SS_FROM);
int index3 = XDI3Util.indexOfXri(xri, XDILinkContractConstants.XRI_SS_DO);
if (index3 < 0) index3 = XDI3Util.indexOfXri(xri, XdiEntityCollection.createArcXri(XDILinkContractConstants.XRI_SS_DO));
if (index2 < 0) index2 = index1;
if (index2 < 0 || index3 < 0 || index2 >= index3) return null;

return XDI3Util.subXri(xri, index1 + 1, index2);
return XDI3Util.subXri(xri, index2 + 1, index3);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,76 @@
import xdi2.core.features.nodetypes.XdiEntity;
import xdi2.core.features.nodetypes.XdiEntitySingleton;
import xdi2.core.features.nodetypes.XdiInnerRoot;
import xdi2.core.features.nodetypes.XdiSubGraph;
import xdi2.core.features.nodetypes.XdiVariable;
import xdi2.core.util.XDI3Util;
import xdi2.core.util.iterators.MappingRelationTargetContextNodeXriIterator;
import xdi2.core.xri3.XDI3Segment;
import xdi2.core.xri3.XDI3Statement;

/**
* The base class for XDI link contracts and XDI link contract templates, represented as an XDI entity.
* The base class for XDI link contracts and XDI link contract templates, represented as an XDI entity or variable.
*
* @author markus
*/
public abstract class LinkContractBase implements Serializable, Comparable<LinkContractBase> {

private static final long serialVersionUID = 1604380462449272148L;

private XdiEntity xdiEntity;
private XdiSubGraph<?> xdiSubGraph;

protected LinkContractBase(XdiEntity xdiEntity) {

this.xdiEntity = xdiEntity;
this.xdiSubGraph = xdiEntity;
}

protected LinkContractBase(XdiVariable xdiVariable) {

this.xdiSubGraph = xdiVariable;
}

/*
* Instance methods
*/

/**
* Returns the underlying XDI entity to which this XDI link contract is bound.
* @return An XDI entity that represents the XDI link contract.
* Returns the underlying XDI subgraph to which this XDI link contract (template) (template) is bound.
* @return An XDI subgraph that represents the XDI link contract (template).
*/
public XdiSubGraph<?> getXdiSubGraph() {

return this.xdiSubGraph;
}

/**
* Returns the underlying XDI entity to which this XDI link contract (template) (template) is bound.
* @return An XDI entity that represents the XDI link contract (template).
*/
public XdiEntity getXdiEntity() {

return this.xdiEntity;
return (XdiEntity) this.xdiSubGraph;
}

/**
* Returns the underlying XDI variable to which this XDI link contract (template) (template) is bound.
* @return An XDI entity that represents the XDI link contract (template).
*/
public XdiVariable getXdiVariable() {

return (XdiVariable) this.xdiSubGraph;
}

/**
* Returns the underlying context node to which this XDI link contract is bound.
* @return A context node that represents the XDI link contract.
* Returns the underlying context node to which this XDI link contract (template) is bound.
* @return A context node that represents the XDI link contract (template).
*/
public ContextNode getContextNode() {

return this.getXdiEntity().getContextNode();
return this.getXdiSubGraph().getContextNode();
}

/**
* Returns an existing XDI root policy in this XDI link contract, or creates a new one.
* Returns an existing XDI root policy in this XDI link contract (template), or creates a new one.
* @param create Whether to create an XDI root policy if it does not exist.
* @return The existing or newly created XDI root policy.
*/
Expand All @@ -68,7 +93,7 @@ public PolicyRoot getPolicyRoot(boolean create) {
}

/**
* Adds a permission (one of $get, $set, $del, $copy, $move, $all) from this XDI link contract to a target context node XRI.
* Adds a permission (one of $get, $set, $del, $copy, $move, $all) from this XDI link contract (template) to a target context node XRI.
* @param permissionXri The permission XRI.
* @param targetAddress The target context node XRI of the permission.
*/
Expand Down
Loading

0 comments on commit 946b5c8

Please sign in to comment.