aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornegrello2013-12-11 12:55:34 (EST)
committerGerrit Code Review @ Eclipse.org2013-12-12 08:59:01 (EST)
commit0edf7f9a60b7bd73adc3c3fcf1c64d76a1ed34f4 (patch)
tree67d979b62a9cb1b10322366d5c92664630ebc184
parent3129a3d2981fb30e23d21d11503fe07c7f57de0b (diff)
downloadorg.eclipse.lyo.core-0edf7f9a60b7bd73adc3c3fcf1c64d76a1ed34f4.zip
org.eclipse.lyo.core-0edf7f9a60b7bd73adc3c3fcf1c64d76a1ed34f4.tar.gz
org.eclipse.lyo.core-0edf7f9a60b7bd73adc3c3fcf1c64d76a1ed34f4.tar.bz2
Bug 413580: Support for ResponseInfoCollection<URI>refs/changes/60/19660/2
Change-Id: Iaa8d00511122e1f13c1b0cd2373c6f2ac1b4d192 Signed-off-by: negrello <fnegre@br.ibm.com>
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java73
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java7
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java73
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonProvider.java7
4 files changed, 102 insertions, 58 deletions
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
index e60e6a3..1dc0c70 100644
--- a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
@@ -224,6 +224,9 @@ public final class JenaModelHelper
}
}
+ // add global namespace mappings
+ namespaceMappings.putAll(OslcGlobalNamespaceProvider.getInstance().getPrefixDefinitionMap());
+
for (final Object object : objects)
{
handleSingleResource(descriptionResource,
@@ -276,49 +279,57 @@ public final class JenaModelHelper
OslcCoreApplicationException
{
final Class<? extends Object> objectClass = object.getClass();
- namespaceMappings.putAll(OslcGlobalNamespaceProvider.getInstance().getPrefixDefinitionMap());
+
// Collect the namespace prefix -> namespace mappings
recursivelyCollectNamespaceMappings(namespaceMappings,
objectClass);
-
- URI aboutURI = null;
- if (object instanceof IResource)
- {
- aboutURI = ((IResource) object).getAbout();
- }
final Resource mainResource;
- if (aboutURI != null)
- {
- if (OSLC4JUtils.relativeURIsAreDisabled() && !aboutURI.isAbsolute())
- {
- throw new OslcCoreRelativeURIException(objectClass,
- "getAbout",
- aboutURI);
- }
-
- mainResource = model.createResource(aboutURI.toString());
- }
- else
+
+ if (object instanceof URI)
{
- mainResource = model.createResource();
+ mainResource = model.createResource(((URI) object).toASCIIString());
}
-
- if (objectClass.getAnnotation(OslcResourceShape.class) != null)
+ else
{
- String qualifiedName = TypeFactory.getQualifiedName(objectClass);
- if (qualifiedName != null)
+ URI aboutURI = null;
+ if (object instanceof IResource)
{
- mainResource.addProperty(RDF.type, model.createResource(qualifiedName));
+ aboutURI = ((IResource) object).getAbout();
}
+
+ if (aboutURI != null)
+ {
+ if (OSLC4JUtils.relativeURIsAreDisabled() && !aboutURI.isAbsolute())
+ {
+ throw new OslcCoreRelativeURIException(objectClass,
+ "getAbout",
+ aboutURI);
+ }
+
+ mainResource = model.createResource(aboutURI.toString());
+ }
+ else
+ {
+ mainResource = model.createResource();
+ }
+
+ if (objectClass.getAnnotation(OslcResourceShape.class) != null)
+ {
+ String qualifiedName = TypeFactory.getQualifiedName(objectClass);
+ if (qualifiedName != null)
+ {
+ mainResource.addProperty(RDF.type, model.createResource(qualifiedName));
+ }
+ }
+
+ buildResource(object,
+ objectClass,
+ model,
+ mainResource,
+ properties);
}
- buildResource(object,
- objectClass,
- model,
- mainResource,
- properties);
-
if (descriptionResource != null)
{
descriptionResource.addProperty(RDFS.member,
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java
index 2faf7e2..fe2e53d 100644
--- a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java
@@ -123,6 +123,13 @@ public class OslcRdfXmlProvider
{
return false;
}
+
+ Type rawType = parameterizedType.getRawType();
+ if (URI.class.equals(actualType)
+ && (ResponseInfoCollection.class.equals(rawType) || ResponseInfoArray.class.equals(rawType)))
+ {
+ return true;
+ }
}
else
{
diff --git a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java
index 1270727..fc73f94 100644
--- a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java
+++ b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java
@@ -166,6 +166,13 @@ public final class JsonHelper
final Map<String, String> namespaceMappings = new TreeMap<String, String>();
final Map<String, String> reverseNamespaceMappings = new HashMap<String, String>();
+ // Add all global namespace mappings, since they have lower precedence
+ Map<String, String> globalPrefixDefinitionMap = OslcGlobalNamespaceProvider.getInstance().getPrefixDefinitionMap();
+ for(Map.Entry<String, String> prefixDefinitionEntry : globalPrefixDefinitionMap.entrySet()) {
+ namespaceMappings.put(prefixDefinitionEntry.getKey(), prefixDefinitionEntry.getValue());
+ reverseNamespaceMappings.put(prefixDefinitionEntry.getValue(), prefixDefinitionEntry.getKey());
+ }
+
if (descriptionAbout != null)
{
final JSONArray jsonArray = new JSONArray();
@@ -1278,34 +1285,46 @@ public final class JsonHelper
OslcCoreApplicationException
{
final Class<? extends Object> objectClass = object.getClass();
- // Add all global namespace mappings, since they have lower precedence
- Map<String, String> globalPrefixDefinitionMap = OslcGlobalNamespaceProvider.getInstance().getPrefixDefinitionMap();
- for(Map.Entry<String, String> prefixDefinitionEntry : globalPrefixDefinitionMap.entrySet()) {
- namespaceMappings.put(prefixDefinitionEntry.getKey(), prefixDefinitionEntry.getValue());
- reverseNamespaceMappings.put(prefixDefinitionEntry.getValue(), prefixDefinitionEntry.getKey());
- }
- // Collect the namespace prefix -> namespace mappings
- recursivelyCollectNamespaceMappings(namespaceMappings,
- reverseNamespaceMappings,
- objectClass);
-
- if (object instanceof IResource)
- {
- final URI aboutURI = ((IResource) object).getAbout();
- addAboutURI(jsonObject,
- namespaceMappings,
- reverseNamespaceMappings,
- objectClass,
- aboutURI);
+
+ if (object instanceof URI) {
+
+ // Ensure we have an rdf prefix
+ final String rdfPrefix = ensureNamespacePrefix(OslcConstants.RDF_NAMESPACE_PREFIX,
+ OslcConstants.RDF_NAMESPACE,
+ namespaceMappings,
+ reverseNamespaceMappings);
+
+ jsonObject.put(rdfPrefix + JSON_PROPERTY_DELIMITER + JSON_PROPERTY_SUFFIX_RESOURCE,
+ ((URI) object).toASCIIString());
+
+ visitedObjects.put(object, jsonObject);
+
+ }
+ else {
+
+ // Collect the namespace prefix -> namespace mappings
+ recursivelyCollectNamespaceMappings(namespaceMappings,
+ reverseNamespaceMappings,
+ objectClass);
+
+ if (object instanceof IResource)
+ {
+ final URI aboutURI = ((IResource) object).getAbout();
+ addAboutURI(jsonObject,
+ namespaceMappings,
+ reverseNamespaceMappings,
+ objectClass,
+ aboutURI);
+ }
+
+ buildResource(namespaceMappings,
+ reverseNamespaceMappings,
+ object,
+ objectClass,
+ jsonObject,
+ properties,
+ visitedObjects);
}
-
- buildResource(namespaceMappings,
- reverseNamespaceMappings,
- object,
- objectClass,
- jsonObject,
- properties,
- visitedObjects);
return jsonObject;
}
diff --git a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonProvider.java b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonProvider.java
index 28bfda6..abe991e 100644
--- a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonProvider.java
+++ b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonProvider.java
@@ -123,6 +123,13 @@ public final class OslcRdfJsonProvider
{
return false;
}
+
+ Type rawType = parameterizedType.getRawType();
+ if (URI.class.equals(actualType)
+ && (ResponseInfoCollection.class.equals(rawType) || ResponseInfoArray.class.equals(rawType)))
+ {
+ return true;
+ }
}
else
{