Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[lyo-dev] preserving the order of properties in JenaModelHelper

Hello,

I am new in webservice business and I have a problem with restoring the property order from Jena model, I would appreciate your advice.

Consider the following annotated property of a resource:

@OslcDescription("Links to the requirement parts of this collection.")
@OslcPropertyDefinition(OslcConstants.DCTERMS_NAMESPACE + "hasPart")
@OslcName("hasPart")
@OslcTitle("Has a Part")
@OslcValueType(ValueType.Resource)
@OslcRange(RequirementConstants.TYPE_REQUIREMENT)
public Link[] getHasParts() { return hasParts.toArray(new Link[hasParts.size()]); }


I save the resources like this:

resources = getAllResources();
Model jenamodel = JenaModelHelper.createJenaModel(resources);
if (jenamodel != null) {
       final RDFWriter writer = jenamodel.getWriter(FileUtils.langXMLAbbrev);
       writer.setProperty("showXmlDeclaration", "true");
       writer.write(jenamodel, new FileOutputStream(dbFile), null);
}

And then restore like that:

final Model jenamodel = ModelFactory.createDefaultModel();
jenamodel.read(new FileInputStream(dbFile), null, FileUtils.langXMLAbbrev);
Object[] objects = JenaModelHelper.fromJenaModel(jenamodel, resourceType);


Then the order is messed up in unpredictable ways every time I go through store-load cycle, but I need to preserve the order.

After looking around, I noticed OslcRdfCollectionType annotation, so I got creative and added the following annotation to my hasParts property:

@OslcRdfCollectionType(collectionType="List")

which seems to be default setting anyway (right?) but then it breaks with types like Link.
Here is a stacktrace:

java.lang.NullPointerException
at org.eclipse.lyo.oslc4j.core.exception.OslcCoreInvalidPropertyDefinitionException.<init>(OslcCoreInvalidPropertyDefinitionException.java:35)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.handleLocalResource(JenaModelHelper.java:1856)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.buildAttributeResource(JenaModelHelper.java:1611)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.buildResource(JenaModelHelper.java:1222)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.handleSingleResource(JenaModelHelper.java:313)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.createJenaModel(JenaModelHelper.java:228)
at org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper.createJenaModel(JenaModelHelper.java:155)


whereas OslcCoreInvalidPropertyDefinitionException.java:35 contains this:

super(MESSAGE_KEY, new Object[] {resourceClass.getName(), method.getName(), oslcPropertyDefinition.value()});


which is called from JenaModelHelper:1856 like this:

if (nestedNode != null)
{
  if (rdfNodeContainer != null)
  {
     if (reifiedResource != null)
     {
     // Reified resource is not supported for rdf collection resources
      throw new OslcCoreInvalidPropertyDefinitionException(resourceClass, method, null);
      }


Notice the null parameter which breaks the construction of the exception -- that must be a bug, either in the constructor, or this call.
But then there is this comment saying that "reified resource is not supported".

Is this current implementation limitation or is this somehow wrong and will never be supported? or perhaps I can configure it differently?
Or perhaps I should get a more sophisticated database than just RDF dump?

By the way, what is a difference between "List" and "Seq" collection types?

Best regards,
--
Marius

Back to the top