aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabiana G. Rocha2013-07-18 10:34:56 (EDT)
committerGerrit Code Review @ Eclipse.org2013-07-18 12:20:17 (EDT)
commitaf34a78e70fc0e07929705ba03cf6a5cb14cb880 (patch)
treef27f5f8d2e4f92eef132da08bc6ddcf6538f8e56
parenta4521ad51d4c85854eff3412db665f783b062fca (diff)
downloadorg.eclipse.lyo.core-af34a78e70fc0e07929705ba03cf6a5cb14cb880.zip
org.eclipse.lyo.core-af34a78e70fc0e07929705ba03cf6a5cb14cb880.tar.gz
org.eclipse.lyo.core-af34a78e70fc0e07929705ba03cf6a5cb14cb880.tar.bz2
Bug 412755: use beanClass to map the java class.refs/changes/50/14650/2
Change-Id: I6dd51f351b293b7c4ab6099e6273533198de3fa9 Signed-off-by: Fabiana G. Rocha <fgrocha@br.ibm.com>
-rw-r--r--org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JConstants.java2
-rw-r--r--org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JUtils.java23
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java86
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java5
4 files changed, 93 insertions, 23 deletions
diff --git a/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JConstants.java b/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JConstants.java
index db62ff3..a5e490b 100644
--- a/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JConstants.java
+++ b/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JConstants.java
@@ -25,6 +25,8 @@ public interface OSLC4JConstants {
public static final String OSLC4J_DISABLE_HOST_RESOLUTION = "org.eclipse.lyo.oslc4j.disableHostResolution";
public static final String OSLC4J_DISABLE_RELATIVE_URIS = "org.eclipse.lyo.oslc4j.disableRelativeURIs";
+ public static final String OSLC4J_USE_BEAN_CLASS_FOR_PARSING = "org.eclipse.lyo.oslc4j.useBeanClassForParsing";
+
public static final Map<String, Object> OSL4J_PROPERTY_SINGLETON =
new HashMap<String, Object>(0);
diff --git a/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JUtils.java b/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JUtils.java
index df258e8..d1c8bf7 100644
--- a/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JUtils.java
+++ b/org.eclipse.lyo.oslc4j.core/src/org/eclipse/lyo/oslc4j/core/OSLC4JUtils.java
@@ -32,6 +32,13 @@ import org.eclipse.lyo.oslc4j.core.OSLC4JConstants;
public class OSLC4JUtils {
private static String publicURI = System.getProperty(OSLC4JConstants.OSLC4J_PUBLIC_URI);
+ /**
+ * This constant should be set to true for matching the resource rdf:type to
+ * the describes parameter of the OslcResourceShape annotation. By default
+ * this is set to false. This is part of the fix for defect 412755.
+ */
+ private static String useBeanClassForParsing = System.getProperty(OSLC4JConstants.OSLC4J_USE_BEAN_CLASS_FOR_PARSING);
+
private static final Logger logger = Logger.getLogger(OSLC4JUtils.class.getName());
/**
* Returns the value of org.eclipse.lyo.oslc4j.publicURI or null if not set.
@@ -60,6 +67,22 @@ public class OSLC4JUtils {
publicURI = newPublicURI;
}
+ public static boolean useBeanClassForParsing() {
+ boolean result = false;
+ if (null != useBeanClassForParsing) {
+ result = Boolean.parseBoolean(useBeanClassForParsing);
+ }
+ return result;
+ }
+
+ public static String getUseBeanClassForParsing() {
+ return useBeanClassForParsing;
+ }
+
+ public static void setUseBeanClassForParsing(String useBeanClassForParsing) {
+ OSLC4JUtils.useBeanClassForParsing = useBeanClassForParsing;
+ }
+
/**
* Returns the boolean value of org.eclipse.lyo.oslc4j.disableHostResolution
* Default is false if not set or invalid (hostname resolution will take place)
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java b/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
index 98ec75d..2120b53 100644
--- a/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
@@ -104,6 +104,7 @@ import com.hp.hpl.jena.rdf.model.RSIterator;
import com.hp.hpl.jena.rdf.model.ReifiedStatement;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.SimpleSelector;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
@@ -334,36 +335,75 @@ public final class JenaModelHelper
if (beanClass.getAnnotation(OslcResourceShape.class) != null)
{
- final String qualifiedName = TypeFactory.getQualifiedName(beanClass);
-
- final ResIterator listSubjects = model.listSubjectsWithProperty(RDF.type,
- model.getResource(qualifiedName));
+ ResIterator listSubjects = null;
+
+ // Fix for defect 412755
+ // keep the same behavior, i.e. use the class name to match the resource rdf:type
+ if (!OSLC4JUtils.useBeanClassForParsing()) {
+
+ final String qualifiedName = TypeFactory.getQualifiedName(beanClass);
+ listSubjects = model.listSubjectsWithProperty(RDF.type,
+ model.getResource(qualifiedName));
+ List<Resource> resourceList = listSubjects.toList();
+ createObjectResultList(beanClass, results, resourceList);
+ }
+ else {
+ // get the list of subjects that have rdf:type element
+ listSubjects = model.listSubjectsWithProperty(RDF.type);
+
+ List<Resource> resourceList = new ArrayList<Resource>();
+
+ // iterate over the list of subjects to create a list of
+ // subjects that does not contain inline resources
+ while (listSubjects.hasNext()) {
+ final Resource resource = listSubjects.next();
+
+ // check if the current resource is not an inline resource,
+ // i.e, check if it does not have a parent node
+ SimpleSelector selector = new SimpleSelector(null, null, (RDFNode) resource);
+ StmtIterator listStatements = model.listStatements(selector);
+ if (!listStatements.hasNext()) {
+ // the current resource is not an inline resource, it
+ // should be considered in the list of subjects
+ resourceList.add(resource);
+ }
+ }
+
+ createObjectResultList(beanClass, results, resourceList);
+ }
+
+ }
+ return results.toArray((Object[]) Array.newInstance(beanClass,
+ results.size()));
+ }
- if (listSubjects.hasNext())
- {
- final Map<Class<?>, Map<String, Method>> classPropertyDefinitionsToSetMethods = new HashMap<Class<?>, Map<String, Method>>();
+ private static List<Object> createObjectResultList(final Class<?> beanClass,
+ List<Object> results, List<Resource> listSubjects)
+ throws IllegalAccessException, InstantiationException,
+ DatatypeConfigurationException, InvocationTargetException,
+ OslcCoreApplicationException, URISyntaxException,
+ NoSuchMethodException {
+ if (null != listSubjects) {
+
+ final Map<Class<?>, Map<String, Method>> classPropertyDefinitionsToSetMethods = new HashMap<Class<?>, Map<String, Method>>();
- while (listSubjects.hasNext())
- {
- final Resource resource = listSubjects.next();
- final Object newInstance = beanClass.newInstance();
- final Map<String,Object> visitedResources = new HashMap<String, Object>();
+ for (final Resource resource : listSubjects) {
+ final Object newInstance = beanClass.newInstance();
+ final Map<String,Object> visitedResources = new HashMap<String, Object>();
- fromResource(classPropertyDefinitionsToSetMethods,
- beanClass,
- newInstance,
- resource,
- visitedResources);
+ fromResource(classPropertyDefinitionsToSetMethods,
+ beanClass,
+ newInstance,
+ resource,
+ visitedResources);
- results.add(newInstance);
- }
+ results.add(newInstance);
}
}
- return results.toArray((Object[]) Array.newInstance(beanClass,
- results.size()));
- }
-
+ return results;
+ }
+
@SuppressWarnings("unchecked")
private static void fromResource(final Map<Class<?>, Map<String, Method>> classPropertyDefinitionsToSetMethods,
final Class<?> beanClass,
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java b/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java
index 6fbff5e..cc20595 100644
--- a/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/org/eclipse/lyo/oslc4j/provider/jena/OslcRdfXmlProvider.java
@@ -256,6 +256,11 @@ public class OslcRdfXmlProvider
if ((objects != null) &&
(objects.length > 0))
{
+ // Fix for defect 412755
+ if (OSLC4JUtils.useBeanClassForParsing() && objects.length > 1) {
+ throw new IOException("Object length should not be greater than 1.");
+ }
+
return objects[0];
}