aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornegrello2013-12-16 11:22:59 (EST)
committerSamuel Padgett2013-12-16 17:05:14 (EST)
commitf6b01ac1aa9e172d68ba1cccf75cb74a59215dd6 (patch)
treea7c549089fbd081f9ec4f8e7989f6469958d0b4f
parent0edf7f9a60b7bd73adc3c3fcf1c64d76a1ed34f4 (diff)
downloadorg.eclipse.lyo.core-f6b01ac1aa9e172d68ba1cccf75cb74a59215dd6.zip
org.eclipse.lyo.core-f6b01ac1aa9e172d68ba1cccf75cb74a59215dd6.tar.gz
org.eclipse.lyo.core-f6b01ac1aa9e172d68ba1cccf75cb74a59215dd6.tar.bz2
Bug 413580: Add support for reading a collection of URIsrefs/changes/16/19816/3
Change-Id: Icb90d1c0117963da44b2daada8c07cd9f8e90109 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/AbstractOslcRdfXmlProvider.java20
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java15
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java14
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java33
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonCollectionProvider.java10
5 files changed, 71 insertions, 21 deletions
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java
index 4040139..d1834d1 100644
--- a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/AbstractOslcRdfXmlProvider.java
@@ -118,12 +118,9 @@ public abstract class AbstractOslcRdfXmlProvider
}
// We do not have annotations when running from the non-web client.
- for (final MediaType requiredMediaType : requiredMediaTypes)
+ if (isCompatible(actualMediaType, requiredMediaTypes))
{
- if (requiredMediaType.isCompatible(actualMediaType))
- {
- return true;
- }
+ return true;
}
}
@@ -292,6 +289,18 @@ public abstract class AbstractOslcRdfXmlProvider
{
if (type.getAnnotation(OslcResourceShape.class) != null)
{
+ if (isCompatible(actualMediaType, requiredMediaTypes))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected static boolean isCompatible(final MediaType actualMediaType,
+ final MediaType... requiredMediaTypes)
+ {
for (final MediaType requiredMediaType : requiredMediaTypes)
{
if (requiredMediaType.isCompatible(actualMediaType))
@@ -299,7 +308,6 @@ public abstract class AbstractOslcRdfXmlProvider
return true;
}
}
- }
return false;
}
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 1dc0c70..3afb12e 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
@@ -418,6 +418,21 @@ public final class JenaModelHelper
}
}
+ else if (URI.class.equals(beanClass))
+ {
+ StmtIterator memberIterator = model.listStatements(null, RDFS.member, (RDFNode) null);
+ while (memberIterator.hasNext())
+ {
+ Statement memberStatement = memberIterator.next();
+ RDFNode memberObject = memberStatement.getObject();
+ if (memberObject.isURIResource())
+ {
+ URI memberURI = URI.create(memberObject.asResource().getURI());
+ results.add(memberURI);
+ }
+ }
+ }
+
return results.toArray((Object[]) Array.newInstance(beanClass,
results.size()));
}
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java
index 3c58d0f..765cf87 100644
--- a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlCollectionProvider.java
@@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.net.URI;
import java.util.AbstractCollection;
import java.util.AbstractList;
import java.util.AbstractSequentialList;
@@ -147,7 +148,18 @@ public class OslcRdfXmlCollectionProvider
{
final Type actualTypeArgument = actualTypeArguments[0];
- if (actualTypeArgument instanceof Class)
+ if (URI.class.equals((Class<?>) actualTypeArgument))
+ {
+ if (isCompatible(mediaType,
+ OslcMediaType.APPLICATION_RDF_XML_TYPE,
+ OslcMediaType.APPLICATION_XML_TYPE,
+ OslcMediaType.TEXT_XML_TYPE,
+ OslcMediaType.TEXT_TURTLE_TYPE))
+ {
+ return true;
+ }
+ }
+ else if (actualTypeArgument instanceof Class)
{
return isReadable((Class<?>) actualTypeArgument,
mediaType,
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 fc73f94..daa3535 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
@@ -407,18 +407,27 @@ public final class JsonHelper
{
final JSONObject resourceJSONObject = (JSONObject) object;
- final Object bean = beanClass.newInstance();
- HashSet<String> rdfTypes = new HashSet<String>();
-
- fromJSON(rdfPrefix,
- namespaceMappings,
- classPropertyDefinitionsToSetMethods,
- resourceJSONObject,
- beanClass,
- bean,
- rdfTypes);
-
- beans.add(bean);
+ if (URI.class.equals(beanClass)) {
+ String uri = resourceJSONObject.optString(rdfPrefix + JSON_PROPERTY_DELIMITER
+ + JSON_PROPERTY_SUFFIX_RESOURCE);
+
+ beans.add(URI.create(uri));
+ }
+ else
+ {
+ final Object bean = beanClass.newInstance();
+ HashSet<String> rdfTypes = new HashSet<String>();
+
+ fromJSON(rdfPrefix,
+ namespaceMappings,
+ classPropertyDefinitionsToSetMethods,
+ resourceJSONObject,
+ beanClass,
+ bean,
+ rdfTypes);
+
+ beans.add(bean);
+ }
}
}
}
diff --git a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonCollectionProvider.java b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonCollectionProvider.java
index 9e1ed38..f087cc1 100644
--- a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonCollectionProvider.java
+++ b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/OslcRdfJsonCollectionProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 IBM Corporation.
+ * Copyright (c) 2012, 2013 IBM Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -24,6 +24,7 @@ import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
+import java.net.URI;
import java.util.AbstractCollection;
import java.util.AbstractList;
import java.util.AbstractSequentialList;
@@ -139,7 +140,12 @@ public class OslcRdfJsonCollectionProvider
{
final Type actualTypeArgument = actualTypeArguments[0];
- if (actualTypeArgument instanceof Class)
+ if (URI.class.equals((Class<?>) actualTypeArgument)
+ && (OslcMediaType.APPLICATION_JSON_TYPE.isCompatible(mediaType)))
+ {
+ return true;
+ }
+ else
{
return isReadable((Class<?>) actualTypeArgument,
OslcMediaType.APPLICATION_JSON_TYPE,