You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2011/09/21 14:20:21 UTC
svn commit: r1173585 - in /incubator/isis/trunk/framework/viewer/json:
json-applib/src/main/java/org/apache/isis/viewer/json/applib/
json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/
json-applib/src/test/java/org/apache/isis/viewer/j...
Author: danhaywood
Date: Wed Sep 21 12:20:21 2011
New Revision: 1173585
URL: http://svn.apache.org/viewvc?rev=1173585&view=rev
Log:
ISIS-109: more on json applib and representations
Added:
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink_isLink.java
- copied, changed from r1167069, incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString_isString.java
- copied, changed from r1167069, incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypeCollectionRepBuilder.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypePropertyRepBuilder.java
Removed:
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString.java
Modified:
incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/ArgumentList.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBigInteger.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBoolean.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getDouble.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getInt.java
incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLong.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectActionRepBuilder.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectCollectionRepBuilder.java
incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectPropertyRepBuilder.java
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/JsonRepresentation.java Wed Sep 21 12:20:21 2011
@@ -163,70 +163,241 @@ public class JsonRepresentation {
/////////////////////////////////////////////////////////////////////////
- // getInt, getLong, getDouble, getString
+ // getRepresentation
/////////////////////////////////////////////////////////////////////////
+ public JsonRepresentation getRepresentation(String path) {
+ JsonNode node = getNode(path);
+ if (representsNull(node)) {
+ return null;
+ }
- public Boolean getBoolean(String path) {
+ return new JsonRepresentation(node);
+ }
+
+ /////////////////////////////////////////////////////////////////////////
+ // getArray, isArray, asArray
+ /////////////////////////////////////////////////////////////////////////
+
+ public JsonRepresentation getArray(String path) {
JsonNode node = getNode(path);
if (representsNull(node)) {
return null;
}
+ if (!node.isArray()) {
+ throw new IllegalArgumentException(formatExMsg(path, "is not an array"));
+ }
+ return new JsonRepresentation(node);
+ }
+
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // getMap, isMap, asMap
+ /////////////////////////////////////////////////////////////////////////
+
+ public JsonRepresentation getMap(String path) {
+ JsonNode node = getNode(path);
+ if (representsNull(node)) {
+ return null;
+ }
+ if (node.isArray() || node.isValueNode()) {
+ throw new IllegalArgumentException(formatExMsg(path, "is not a map"));
+ }
+ return new JsonRepresentation(node);
+ }
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // isBoolean, getBoolean, asBoolean
+ /////////////////////////////////////////////////////////////////////////
+
+ public boolean isBoolean(String path) {
+ return isBoolean(getNode(path));
+ }
+
+ public boolean isBoolean() {
+ return isBoolean(asJsonNode());
+ }
+
+ private boolean isBoolean(JsonNode node) {
+ return !representsNull(node) && node.isValueNode() && node.isBoolean();
+ }
+
+ public Boolean getBoolean(String path) {
+ return getBoolean(path, getNode(path));
+ }
+
+ public Boolean asBoolean() {
+ return getBoolean(null, asJsonNode());
+ }
+
+ private Boolean getBoolean(String path, JsonNode node) {
+ if (representsNull(node)) {
+ return null;
+ }
checkValue(path, node, "a boolean");
if (!node.isBoolean()) {
- throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not a boolean");
+ throw new IllegalArgumentException(formatExMsg(path, "is not a boolean"));
}
return node.getBooleanValue();
}
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // isBigInteger, getBigInteger, asBigInteger
+ /////////////////////////////////////////////////////////////////////////
+
+ public boolean isBigInteger(String path) {
+ return isBigInteger(getNode(path));
+ }
+
+ public boolean isBigInteger() {
+ return isBigInteger(asJsonNode());
+ }
+
+ private boolean isBigInteger(JsonNode node) {
+ return !representsNull(node) && node.isValueNode() && node.isBigInteger();
+ }
+
public BigInteger getBigInteger(String path) {
JsonNode node = getNode(path);
+ return getBigInteger(path, node);
+ }
+
+ public BigInteger asBigInteger() {
+ return getBigInteger(null, asJsonNode());
+ }
+
+ private BigInteger getBigInteger(String path, JsonNode node) {
if (representsNull(node)) {
return null;
}
checkValue(path, node, "a biginteger");
if (!node.isBigInteger()) {
- throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not a biginteger");
+ throw new IllegalArgumentException(formatExMsg(path, "is not a biginteger"));
}
return node.getBigIntegerValue();
}
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // isInt, getInt, asInt
+ /////////////////////////////////////////////////////////////////////////
+
+ public boolean isInt(String path) {
+ return isInt(getNode(path));
+ }
+
+ public boolean isInt() {
+ return isInt(asJsonNode());
+ }
+
+ private boolean isInt(JsonNode node) {
+ return !representsNull(node) && node.isValueNode() && node.isInt();
+ }
+
public Integer getInt(String path) {
JsonNode node = getNode(path);
+ return getInt(path, node);
+ }
+
+ public Integer asInt() {
+ return getInt(null, asJsonNode());
+ }
+
+ private Integer getInt(String path, JsonNode node) {
if (representsNull(node)) {
return null;
}
checkValue(path, node, "an int");
if (!node.isInt()) {
- throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not an int");
+ throw new IllegalArgumentException(formatExMsg(path, "is not an int"));
}
return node.getIntValue();
}
+
+ /////////////////////////////////////////////////////////////////////////
+ // isLong, getLong, asLong
+ /////////////////////////////////////////////////////////////////////////
+
+ public boolean isLong(String path) {
+ return isLong(getNode(path));
+ }
+
+ public boolean isLong() {
+ return isLong(asJsonNode());
+ }
+
+ private boolean isLong(JsonNode node) {
+ return !representsNull(node) && node.isValueNode() && node.isLong();
+ }
+
public Long getLong(String path) {
JsonNode node = getNode(path);
+ return getLong(path, node);
+ }
+
+ public Long asLong() {
+ return getLong(null, asJsonNode());
+ }
+
+ private Long getLong(String path, JsonNode node) {
if (representsNull(node)) {
return null;
}
checkValue(path, node, "a long");
if (!node.isLong()) {
- throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not a long");
+ throw new IllegalArgumentException(formatExMsg(path, "is not a long"));
}
return node.getLongValue();
}
-
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // isDouble, getDouble, asDouble
+ /////////////////////////////////////////////////////////////////////////
+
+ public boolean isDouble(String path) {
+ return isDouble(getNode(path));
+ }
+
+ public boolean isDouble() {
+ return isDouble(asJsonNode());
+ }
+
+ private boolean isDouble(JsonNode node) {
+ return !representsNull(node) && node.isValueNode() && node.isDouble();
+ }
+
public Double getDouble(String path) {
JsonNode node = getNode(path);
+ return getDouble(path, node);
+ }
+
+ public Double asDouble() {
+ return getDouble(null, asJsonNode());
+ }
+
+ private Double getDouble(String path, JsonNode node) {
if (representsNull(node)) {
return null;
}
checkValue(path, node, "a double");
if (!node.isDouble()) {
- throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not a double");
+ throw new IllegalArgumentException(formatExMsg(path, "is not a double"));
}
return node.getDoubleValue();
}
+ /////////////////////////////////////////////////////////////////////////
+ // getString, isString, asString
+ /////////////////////////////////////////////////////////////////////////
+
+
public boolean isString(String path) {
return isString(getNode(path));
}
@@ -241,186 +412,120 @@ public class JsonRepresentation {
public String getString(String path) {
JsonNode node = getNode(path);
- if (representsNull(node)) {
- return null;
- }
- checkValue(path, node, "a string");
- if (!node.isTextual()) {
- throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not a string");
- }
- return node.getTextValue();
+ return getString(path, node);
}
public String asString() {
- JsonNode node = asJsonNode();
+ return getString(null, asJsonNode());
+ }
+
+ private String getString(String path, JsonNode node) {
if (representsNull(node)) {
return null;
}
-
- if (node.isArray()) {
- throw new IllegalArgumentException("is an array, not a string");
- }
- if (!node.isValueNode()) {
- throw new IllegalArgumentException("is a map, not a string");
- }
+ checkValue(path, node, "a string");
if (!node.isTextual()) {
- throw new IllegalArgumentException("is a value but is not a string");
+ throw new IllegalArgumentException(formatExMsg(path, "is not a string"));
}
return node.getTextValue();
}
- /**
- * Either returns a {@link JsonRepresentation} that indicates that the wrapped node has <tt>null</tt> value
- * (ie {@link JsonRepresentation#isNull()}), or returns <tt>null</tt> if there was no node with the
- * provided path.
- */
- public JsonRepresentation getNull(String path) {
- JsonNode node = getNode(path);
- if (node == null || node.isMissingNode()) {
- // not exclude if node.isNull, cos that's the point of this.
- return null;
- }
- checkValue(path, node, "the null value");
- if (!node.isNull()) {
- throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not the null value");
- }
- return new JsonRepresentation(node);
- }
-
- /**
- * Indicates that the wrapped node has <tt>null</tt> value
- * (ie {@link JsonRepresentation#isNull()}), or returns <tt>null</tt> if there was no node with the
- * provided path.
- */
- public Boolean isNull(String path) {
- JsonNode node = getNode(path);
- if (node == null || node.isMissingNode()) {
- // not exclude if node.isNull, cos that's the point of this.
- return null;
- }
- return node.isNull();
- }
-
- private JsonNode getNode(String path) {
- return JsonNodeUtils.walkNode(jsonNode, path);
- }
-
- private static void checkValue(String path, JsonNode node, String requiredType) {
- if (node.isValueNode()) {
- return;
- }
- if (node.isArray()) {
- throw new IllegalArgumentException("'" + path + "' (an array) is not " + requiredType);
- } else {
- throw new IllegalArgumentException("'" + path + "' (a map) is not " + requiredType);
- }
- }
-
- private static boolean representsNull(JsonNode node) {
- return node == null || node.isMissingNode() || node.isNull();
- }
-
-
/////////////////////////////////////////////////////////////////////////
- // getArray, getRepresentation, getLink
+ // getLink, asLink, isLink
/////////////////////////////////////////////////////////////////////////
- public JsonRepresentation getRepresentation(String path) {
- JsonNode node = getNode(path);
- if (representsNull(node)) {
- return null;
- }
-
- return new JsonRepresentation(node);
- }
- public JsonRepresentation getArray(String path) {
- JsonNode node = getNode(path);
- if (representsNull(node)) {
- return null;
- }
- if (!node.isArray()) {
- throw new IllegalArgumentException("'" + path + "' is not an array");
- }
- return new JsonRepresentation(node);
+ public boolean isLink() {
+ return isLink(asJsonNode());
}
- public JsonRepresentation getMap(String path) {
- JsonNode node = getNode(path);
- if (representsNull(node)) {
- return null;
- }
- if (node.isArray() || node.isValueNode()) {
- throw new IllegalArgumentException("'" + path + "' is not a map");
- }
- return new JsonRepresentation(node);
+ public boolean isLink(String path) {
+ return isLink(getNode(path));
}
- public Link getLink(String path) {
- JsonNode node = getNode(path);
- if (representsNull(node)) {
- return null;
- }
-
- if (node.isArray()) {
- throw new IllegalArgumentException("'" + path + "' (an array) does not represent a link");
- }
- if (node.isValueNode()) {
- throw new IllegalArgumentException("'" + path + "' (a value) does not represent a link");
+ public boolean isLink(JsonNode node) {
+ if (representsNull(node) || node.isArray() || node.isValueNode()) {
+ return false;
}
Link link = new Link(node);
if(link.getHref() == null || link.getRel() == null) {
- throw new IllegalArgumentException("'" + path + "' (a map) does not fully represent a link");
+ return false;
}
- return link;
+ return true;
+ }
+
+ public Link getLink(String path) {
+ return getLink(path, getNode(path));
}
public Link asLink() {
- JsonNode node = asJsonNode();
+ return getLink(null, asJsonNode());
+ }
+
+ private Link getLink(String path, JsonNode node) {
if (representsNull(node)) {
return null;
}
if (node.isArray()) {
- throw new IllegalArgumentException("is an array, does not represent a link");
+ throw new IllegalArgumentException(formatExMsg(path, "is an array that does not represent a link"));
}
if (node.isValueNode()) {
- throw new IllegalArgumentException("is a value, does not represent a link");
+ throw new IllegalArgumentException(formatExMsg(path, "is a value that does not represent a link"));
}
Link link = new Link(node);
if(link.getHref() == null || link.getRel() == null) {
- throw new IllegalArgumentException("is a map but does not fully represent a link");
+ throw new IllegalArgumentException(formatExMsg(path, "is a map that does not fully represent a link"));
}
return link;
}
-
- public boolean isLink() {
- return isLink(asJsonNode());
- }
-
- public boolean isLink(String path) {
- return isLink(getNode(path));
+
+ /////////////////////////////////////////////////////////////////////////
+ // getNull, isNull
+ /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Indicates that the wrapped node has <tt>null</tt> value
+ * (ie {@link JsonRepresentation#isNull()}), or returns <tt>null</tt> if there was no node with the
+ * provided path.
+ */
+ public Boolean isNull(String path) {
+ JsonNode node = getNode(path);
+ if (node == null || node.isMissingNode()) {
+ // not exclude if node.isNull, cos that's the point of this.
+ return null;
+ }
+ return node.isNull();
}
- public boolean isLink(JsonNode node) {
- if (representsNull(node)) {
- return false;
- }
- if(node.isArray() || node.isValueNode()) {
- return false;
+ /**
+ * Either returns a {@link JsonRepresentation} that indicates that the wrapped node has <tt>null</tt> value
+ * (ie {@link JsonRepresentation#isNull()}), or returns <tt>null</tt> if there was no node with the
+ * provided path.
+ */
+ public JsonRepresentation getNull(String path) {
+ JsonNode node = getNode(path);
+ if (node == null || node.isMissingNode()) {
+ // not exclude if node.isNull, cos that's the point of this.
+ return null;
}
-
- Link link = new Link(node);
- if(link.getHref() == null || link.getRel() == null) {
- return false;
+ checkValue(path, node, "the null value");
+ if (!node.isNull()) {
+ throw new IllegalArgumentException("'" + path + "' (" + node.toString() + ") is not the null value");
}
- return true;
+ return new JsonRepresentation(node);
}
+
+
+ /////////////////////////////////////////////////////////////////////////
+ // mapValueAsLink
+ /////////////////////////////////////////////////////////////////////////
+
/**
* Convert a representation that contains a single node representing a link
* into a {@link Link}.
@@ -436,7 +541,7 @@ public class JsonRepresentation {
/**
* Convert underlying representation into an array.
*/
- protected ArrayNode nodeAsArray() {
+ protected ArrayNode asArrayNode() {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
@@ -446,7 +551,7 @@ public class JsonRepresentation {
/**
* Convert underlying representation into an object (map).
*/
- protected ObjectNode nodeAsMap() {
+ protected ObjectNode asObjectNode() {
if(!isMap()) {
throw new IllegalStateException("does not represent map");
}
@@ -456,7 +561,7 @@ public class JsonRepresentation {
/////////////////////////////////////////////////////////////////////////
- // streaming support
+ // asInputStream
/////////////////////////////////////////////////////////////////////////
public InputStream asInputStream() {
@@ -537,15 +642,6 @@ public class JsonRepresentation {
return json;
}
- private static JsonRepresentation asJsonRepresentation(JSON json) throws JsonParseException, JsonMappingException, IOException {
- if(json == JSONNull.getInstance()) {
- return null;
- }
- String jsonStr = json.toString();
- return JsonMapper.instance().read(jsonStr, JsonRepresentation.class);
- }
-
-
public String asUrlEncoded() {
return JsonNodeUtils.asUrlEncoded(asJsonNode());
}
@@ -560,63 +656,63 @@ public class JsonRepresentation {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(new POJONode(value));
+ asArrayNode().add(new POJONode(value));
}
public void arrayAdd(JsonRepresentation value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value.asJsonNode());
+ asArrayNode().add(value.asJsonNode());
}
public void arrayAdd(String value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value);
+ asArrayNode().add(value);
}
public void arrayAdd(JsonNode value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value);
+ asArrayNode().add(value);
}
public void arrayAdd(long value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value);
+ asArrayNode().add(value);
}
public void arrayAdd(int value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value);
+ asArrayNode().add(value);
}
public void arrayAdd(double value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value);
+ asArrayNode().add(value);
}
public void arrayAdd(float value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value);
+ asArrayNode().add(value);
}
public void arrayAdd(boolean value) {
if(!isArray()) {
throw new IllegalStateException("does not represent array");
}
- nodeAsArray().add(value);
+ asArrayNode().add(value);
}
public Iterable<JsonRepresentation> arrayIterable() {
@@ -686,7 +782,7 @@ public class JsonRepresentation {
return;
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), new POJONode(value));
}
@@ -698,7 +794,7 @@ public class JsonRepresentation {
return;
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
if(node.has(path.getTail())) {
throw new IllegalStateException("already has key " + key);
}
@@ -713,7 +809,7 @@ public class JsonRepresentation {
return;
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), value);
}
@@ -725,7 +821,7 @@ public class JsonRepresentation {
return;
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), value);
}
@@ -734,7 +830,7 @@ public class JsonRepresentation {
throw new IllegalStateException("does not represent map");
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), value);
}
@@ -743,7 +839,7 @@ public class JsonRepresentation {
throw new IllegalStateException("does not represent map");
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), value);
}
@@ -752,7 +848,7 @@ public class JsonRepresentation {
throw new IllegalStateException("does not represent map");
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), value);
}
@@ -761,7 +857,7 @@ public class JsonRepresentation {
throw new IllegalStateException("does not represent map");
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), value);
}
@@ -770,7 +866,7 @@ public class JsonRepresentation {
throw new IllegalStateException("does not represent map");
}
Path path = Path.parse(key);
- ObjectNode node = JsonNodeUtils.walkNodeUpTo(nodeAsMap(), path.getHead());
+ ObjectNode node = JsonNodeUtils.walkNodeUpTo(asObjectNode(), path.getHead());
node.put(path.getTail(), value);
}
@@ -803,6 +899,49 @@ public class JsonRepresentation {
/////////////////////////////////////////////////////////////////////////
+ // helpers
+ /////////////////////////////////////////////////////////////////////////
+
+ private JsonNode getNode(String path) {
+ return JsonNodeUtils.walkNode(jsonNode, path);
+ }
+
+ private static void checkValue(String path, JsonNode node, String requiredType) {
+ if (node.isValueNode()) {
+ return;
+ }
+ if (node.isArray()) {
+ throw new IllegalArgumentException("'" + path + "' (an array) is not " + requiredType);
+ } else {
+ throw new IllegalArgumentException("'" + path + "' (a map) is not " + requiredType);
+ }
+ }
+
+ private static boolean representsNull(JsonNode node) {
+ return node == null || node.isMissingNode() || node.isNull();
+ }
+
+ private static JsonRepresentation asJsonRepresentation(JSON json) throws JsonParseException, JsonMappingException, IOException {
+ if(json == JSONNull.getInstance()) {
+ return null;
+ }
+ String jsonStr = json.toString();
+ return JsonMapper.instance().read(jsonStr, JsonRepresentation.class);
+ }
+
+ private static String formatExMsg(String pathIfAny, String errorText) {
+ StringBuilder buf = new StringBuilder();
+ if(pathIfAny != null) {
+ buf.append("'").append(pathIfAny).append("' ");
+ }
+ buf.append(errorText);
+ return buf.toString();
+ }
+
+
+
+
+ /////////////////////////////////////////////////////////////////////////
// toString
/////////////////////////////////////////////////////////////////////////
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/ArgumentList.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/ArgumentList.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/ArgumentList.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/ArgumentList.java Wed Sep 21 12:20:21 2011
@@ -12,7 +12,7 @@ public class ArgumentList extends JsonRe
}
public void add(ArgumentNode value) {
- nodeAsArray().add(value.asJsonNode());
+ asArrayNode().add(value.asJsonNode());
}
public void add(Link value) {
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/main/java/org/apache/isis/viewer/json/applib/blocks/Link.java Wed Sep 21 12:20:21 2011
@@ -43,32 +43,32 @@ public final class Link extends JsonRepr
}
public String getRel() {
- return nodeAsMap().path("rel").getTextValue();
+ return asObjectNode().path("rel").getTextValue();
}
public Link withRel(String rel) {
- nodeAsMap().put("rel", rel);
+ asObjectNode().put("rel", rel);
return this;
}
public String getHref() {
- return nodeAsMap().path("href").getTextValue();
+ return asObjectNode().path("href").getTextValue();
}
public Link withHref(String href) {
- nodeAsMap().put("href", href);
+ asObjectNode().put("href", href);
return this;
}
public Method getMethod() {
- String methodStr = nodeAsMap().path("method").getTextValue();
+ String methodStr = asObjectNode().path("method").getTextValue();
return Method.valueOf(methodStr);
}
public Link withMethod(Method method) {
- nodeAsMap().put("method", method.name());
+ asObjectNode().put("method", method.name());
return this;
}
public JsonRepresentation getArguments() {
- JsonNode arguments = nodeAsMap().get("arguments");
+ JsonNode arguments = asObjectNode().get("arguments");
return new JsonRepresentation(arguments);
}
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBigInteger.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBigInteger.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBigInteger.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBigInteger.java Wed Sep 21 12:20:21 2011
@@ -57,7 +57,7 @@ public class JsonRepresentationTest_getB
jsonRepresentation.getBigInteger("aString");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aString' (\"aStringValue\") is not a biginteger"));
+ assertThat(e.getMessage(), is("'aString' is not a biginteger"));
}
}
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBoolean.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBoolean.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBoolean.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getBoolean.java Wed Sep 21 12:20:21 2011
@@ -56,7 +56,7 @@ public class JsonRepresentationTest_getB
jsonRepresentation.getBoolean("aString");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aString' (\"aStringValue\") is not a boolean"));
+ assertThat(e.getMessage(), is("'aString' is not a boolean"));
}
}
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getDouble.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getDouble.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getDouble.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getDouble.java Wed Sep 21 12:20:21 2011
@@ -56,7 +56,7 @@ public class JsonRepresentationTest_getD
jsonRepresentation.getDouble("aString");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aString' (\"aStringValue\") is not a double"));
+ assertThat(e.getMessage(), is("'aString' is not a double"));
}
}
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getInt.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getInt.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getInt.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getInt.java Wed Sep 21 12:20:21 2011
@@ -56,7 +56,7 @@ public class JsonRepresentationTest_getI
jsonRepresentation.getInt("aString");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aString' (\"aStringValue\") is not an int"));
+ assertThat(e.getMessage(), is("'aString' is not an int"));
}
}
Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink_isLink.java (from r1167069, incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink_isLink.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink_isLink.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink.java&r1=1167069&r2=1173585&rev=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLink_isLink.java Wed Sep 21 12:20:21 2011
@@ -15,7 +15,7 @@ import org.codehaus.jackson.map.JsonMapp
import org.junit.Before;
import org.junit.Test;
-public class JsonRepresentationTest_getLink {
+public class JsonRepresentationTest_getLink_isLink {
private Link link;
private JsonRepresentation jsonRepresentation;
@@ -29,49 +29,54 @@ public class JsonRepresentationTest_getL
@Test
public void forLink_whenSimpleKey() throws JsonParseException, JsonMappingException, IOException {
link.withRel("someRel");
+ assertThat(jsonRepresentation.isLink("aLink"), is(true));
assertThat(jsonRepresentation.getLink("aLink"), is(link));
}
@Test
public void forLink_whenMultipartKey() throws JsonParseException, JsonMappingException, IOException {
link.withRel("someSubRel");
+ assertThat(jsonRepresentation.isLink("aSubMap.aLink"), is(true));
assertThat(jsonRepresentation.getLink("aSubMap.aLink"), is(link));
}
@Test
public void forNonExistent() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isLink("doesNotExist"), is(false));
assertThat(jsonRepresentation.getLink("doesNotExist"), is(nullValue()));
}
@Test
public void forValue() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isLink("anInt"), is(false));
try {
jsonRepresentation.getLink("anInt");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'anInt' (a value) does not represent a link"));
+ assertThat(e.getMessage(), is("'anInt' is a value that does not represent a link"));
}
}
@Test
public void forMap() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isLink("aSubMap"), is(false));
try {
jsonRepresentation.getLink("aSubMap");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aSubMap' (a map) does not fully represent a link"));
+ assertThat(e.getMessage(), is("'aSubMap' is a map that does not fully represent a link"));
}
}
@Test
public void forList() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isLink("aSubList"), is(false));
try {
jsonRepresentation.getLink("aSubList");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aSubList' (an array) does not represent a link"));
+ assertThat(e.getMessage(), is("'aSubList' is an array that does not represent a link"));
}
}
-
}
Modified: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLong.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLong.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLong.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getLong.java Wed Sep 21 12:20:21 2011
@@ -56,7 +56,7 @@ public class JsonRepresentationTest_getL
jsonRepresentation.getLong("aString");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'aString' (\"aStringValue\") is not a long"));
+ assertThat(e.getMessage(), is("'aString' is not a long"));
}
}
Copied: incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString_isString.java (from r1167069, incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString.java)
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString_isString.java?p2=incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString_isString.java&p1=incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString.java&r1=1167069&r2=1173585&rev=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-applib/src/test/java/org/apache/isis/viewer/json/applib/JsonRepresentationTest_getString_isString.java Wed Sep 21 12:20:21 2011
@@ -31,7 +31,7 @@ import org.codehaus.jackson.map.JsonMapp
import org.junit.Before;
import org.junit.Test;
-public class JsonRepresentationTest_getString {
+public class JsonRepresentationTest_getString_isString {
private JsonRepresentation jsonRepresentation;
@@ -42,26 +42,30 @@ public class JsonRepresentationTest_getS
@Test
public void happyCase() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isString("aString"), is(true));
assertThat(jsonRepresentation.getString("aString"), is("aStringValue"));
}
@Test
public void forNonExistent() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isString("doesNotExist"), is(false));
assertThat(jsonRepresentation.getString("doesNotExist"), is(nullValue()));
}
@Test
public void forValueButNotAString() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isString("anInt"), is(false));
try {
jsonRepresentation.getString("anInt");
fail();
} catch (IllegalArgumentException e) {
- assertThat(e.getMessage(), is("'anInt' (123) is not a string"));
+ assertThat(e.getMessage(), is("'anInt' is not a string"));
}
}
@Test
public void forMap() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isString("aSubMap"), is(false));
try {
jsonRepresentation.getString("aSubMap");
fail();
@@ -72,6 +76,7 @@ public class JsonRepresentationTest_getS
@Test
public void forList() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isString("aSubList"), is(false));
try {
jsonRepresentation.getString("aSubList");
fail();
@@ -82,6 +87,7 @@ public class JsonRepresentationTest_getS
@Test
public void forMultipartKey() throws JsonParseException, JsonMappingException, IOException {
+ assertThat(jsonRepresentation.isString("aSubMap.aString"), is(true));
assertThat(jsonRepresentation.getString("aSubMap.aString"), is("aSubMapStringValue"));
}
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/DomainResourceAbstract.java Wed Sep 21 12:20:21 2011
@@ -91,7 +91,7 @@ public abstract class DomainResourceAbst
ObjectActionRepBuilder repBuilder =
ObjectActionRepBuilder.newBuilder(getResourceContext(), serviceAdapter, action)
- .withDetailsLink()
+ .withSelf()
.withMutatorsIfEnabled();
return responseOfOk(RepresentationType.OBJECT_ACTION, repBuilder, Caching.NONE)
@@ -290,6 +290,15 @@ public abstract class DomainResourceAbst
// value (encodable)
if (objectSpec.isEncodeable()) {
+
+ // special case handling for JSON built-ins
+ final Class<?> specClass = objectSpec.getCorrespondingClass();
+ if(specClass == boolean.class || specClass == Boolean.class) {
+ if(representation.isBoolean()) {
+
+ }
+ }
+
EncodableFacet encodableFacet = objectSpec.getFacet(EncodableFacet.class);
if(!representation.isString()) {
throw new ExpectedStringRepresentingValueException();
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectActionRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectActionRepBuilder.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectActionRepBuilder.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectActionRepBuilder.java Wed Sep 21 12:20:21 2011
@@ -46,7 +46,6 @@ public class ObjectActionRepBuilder exte
public JsonRepresentation build() {
-
putDisabledReasonIfDisabled();
JsonRepresentation extensions = JsonRepresentation.newMap();
@@ -188,10 +187,10 @@ public class ObjectActionRepBuilder exte
/////////////////////////////////////////////////////
private void putExtensionsIsisProprietary(JsonRepresentation extensions) {
- extensions.mapPut("actionType", objectMember.getType());
+ extensions.mapPut("actionType", objectMember.getType().name().toLowerCase());
final ActionSemantics semantics = ActionSemantics.determine(resourceContext, objectMember);
- extensions.mapPut("actionSemantics", semantics.name());
+ extensions.mapPut("actionSemantics", semantics.name().toLowerCase());
}
private void addLinksFormalDomainModel(JsonRepresentation links, ResourceContext resourceContext) {
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectCollectionRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectCollectionRepBuilder.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectCollectionRepBuilder.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectCollectionRepBuilder.java Wed Sep 21 12:20:21 2011
@@ -27,7 +27,7 @@ import org.apache.isis.viewer.json.appli
import org.apache.isis.viewer.json.viewer.ResourceContext;
import org.apache.isis.viewer.json.viewer.representations.LinkToBuilder;
import org.apache.isis.viewer.json.viewer.resources.domaintypes.DomainTypeRepBuilder;
-import org.apache.isis.viewer.json.viewer.resources.domaintypes.TypeActionRepBuilder;
+import org.apache.isis.viewer.json.viewer.resources.domaintypes.TypeCollectionRepBuilder;
import com.google.common.collect.Lists;
@@ -125,12 +125,16 @@ public class ObjectCollectionRepBuilder
/////////////////////////////////////////////////////
private void putExtensionsIsisProprietary(JsonRepresentation extensions) {
+ final CollectionSemantics semantics = CollectionSemantics.determine(resourceContext, objectMember);
+ extensions.mapPut("collectionSemantics", semantics.name().toLowerCase());
}
private void addLinksFormalDomainModel(JsonRepresentation links, ResourceContext resourceContext) {
+ links.arrayAdd(TypeCollectionRepBuilder.newLinkToBuilder(resourceContext, "typeCollection", objectAdapter.getSpecification(), objectMember).build());
}
private void addLinksIsisProprietary(JsonRepresentation links, ResourceContext resourceContext) {
+ links.arrayAdd(DomainTypeRepBuilder.newLinkToBuilder(resourceContext, "domainType", objectAdapter.getSpecification()).build());
}
Modified: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectPropertyRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectPropertyRepBuilder.java?rev=1173585&r1=1173584&r2=1173585&view=diff
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectPropertyRepBuilder.java (original)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domainobjects/ObjectPropertyRepBuilder.java Wed Sep 21 12:20:21 2011
@@ -24,6 +24,8 @@ import org.apache.isis.core.metamodel.sp
import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
import org.apache.isis.viewer.json.applib.JsonRepresentation;
import org.apache.isis.viewer.json.viewer.ResourceContext;
+import org.apache.isis.viewer.json.viewer.resources.domaintypes.DomainTypeRepBuilder;
+import org.apache.isis.viewer.json.viewer.resources.domaintypes.TypePropertyRepBuilder;
import com.google.common.collect.Lists;
@@ -142,9 +144,11 @@ public class ObjectPropertyRepBuilder ex
}
private void addLinksFormalDomainModel(JsonRepresentation links, ResourceContext resourceContext) {
+ links.arrayAdd(TypePropertyRepBuilder.newLinkToBuilder(resourceContext, "typeProperty", objectAdapter.getSpecification(), objectMember).build());
}
private void addLinksIsisProprietary(JsonRepresentation links, ResourceContext resourceContext) {
+ links.arrayAdd(DomainTypeRepBuilder.newLinkToBuilder(resourceContext, "domainType", objectAdapter.getSpecification()).build());
}
}
\ No newline at end of file
Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypeCollectionRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypeCollectionRepBuilder.java?rev=1173585&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypeCollectionRepBuilder.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypeCollectionRepBuilder.java Wed Sep 21 12:20:21 2011
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.viewer.json.viewer.resources.domaintypes;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.OneToManyAssociation;
+import org.apache.isis.viewer.json.applib.JsonRepresentation;
+import org.apache.isis.viewer.json.viewer.ResourceContext;
+import org.apache.isis.viewer.json.viewer.representations.LinkToBuilder;
+import org.apache.isis.viewer.json.viewer.resources.domainobjects.MemberType;
+
+public class TypeCollectionRepBuilder extends AbstractTypeMemberRepBuilder<TypeCollectionRepBuilder, OneToManyAssociation> {
+
+ public static TypeCollectionRepBuilder newBuilder(ResourceContext representationContext, ObjectSpecification objectSpecification, OneToManyAssociation collection) {
+ return new TypeCollectionRepBuilder(representationContext, objectSpecification, collection);
+ }
+
+ public static LinkToBuilder newLinkToBuilder(ResourceContext resourceContext, String rel, ObjectSpecification objectSpecification, OneToManyAssociation collection) {
+ String typeFullName = objectSpecification.getFullIdentifier();
+ String collectionId = collection.getId();
+ String url = "domainTypes/" + typeFullName + "/collections/" + collectionId;
+ return LinkToBuilder.newBuilder(resourceContext, rel, url);
+ }
+
+ public TypeCollectionRepBuilder(ResourceContext resourceContext, ObjectSpecification objectSpecification, OneToManyAssociation collection) {
+ super(resourceContext, objectSpecification, MemberType.OBJECT_COLLECTION, collection);
+ }
+
+ public JsonRepresentation build() {
+ return representation;
+ }
+
+
+}
\ No newline at end of file
Added: incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypePropertyRepBuilder.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypePropertyRepBuilder.java?rev=1173585&view=auto
==============================================================================
--- incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypePropertyRepBuilder.java (added)
+++ incubator/isis/trunk/framework/viewer/json/json-viewer/src/main/java/org/apache/isis/viewer/json/viewer/resources/domaintypes/TypePropertyRepBuilder.java Wed Sep 21 12:20:21 2011
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.isis.viewer.json.viewer.resources.domaintypes;
+
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
+import org.apache.isis.viewer.json.applib.JsonRepresentation;
+import org.apache.isis.viewer.json.viewer.ResourceContext;
+import org.apache.isis.viewer.json.viewer.representations.LinkToBuilder;
+import org.apache.isis.viewer.json.viewer.resources.domainobjects.MemberType;
+
+public class TypePropertyRepBuilder extends AbstractTypeMemberRepBuilder<TypePropertyRepBuilder, OneToOneAssociation> {
+
+ public static TypePropertyRepBuilder newBuilder(ResourceContext representationContext, ObjectSpecification objectSpecification, OneToOneAssociation property) {
+ return new TypePropertyRepBuilder(representationContext, objectSpecification, property);
+ }
+
+ public static LinkToBuilder newLinkToBuilder(ResourceContext resourceContext, String rel, ObjectSpecification objectSpecification, OneToOneAssociation property) {
+ String typeFullName = objectSpecification.getFullIdentifier();
+ String propertyId = property.getId();
+ String url = "domainTypes/" + typeFullName + "/properties/" + propertyId;
+ return LinkToBuilder.newBuilder(resourceContext, rel, url);
+ }
+
+ public TypePropertyRepBuilder(ResourceContext resourceContext, ObjectSpecification objectSpecification, OneToOneAssociation property) {
+ super(resourceContext, objectSpecification, MemberType.OBJECT_COLLECTION, property);
+ }
+
+ public JsonRepresentation build() {
+ return representation;
+ }
+
+
+}
\ No newline at end of file