jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francisco Carriedo Scher <fcarrie...@gmail.com>
Subject Re: Varying the node primary type
Date Mon, 07 May 2012 22:07:01 GMT
Thanks you both for your responses.

This is it, i saw that setPrimaryType is defined in the JCR spec, it seems
to be supported. Anyway, i expected a different behaviour. Let me explain
in deeper detail the scenario.

This first code snippet is successfully executed:

        Node fileNode = folderNode.addNode(file.getName(), "nt:file");
        fileNode.addMixin("mix:referenceable");

        // Standard properties
        Node resNode = fileNode.addNode("jcr:content", "nt:resource");
        resNode.addMixin("mix:referenceable");
        *resNode.setProperty("jcr:data", binary);*

Then, the internal behaviour of the line in bold has been modified as
follows:

public Property setProperty(String name, Binary value) throws
RepositoryException {

   if (someCondition) { // This branch creates a reference instead of
adding a binary property

     Node ntFileNode = this.getParent();

     // Undo already added properties before turning this node on to
nt:linkedFile node type
     ntFileNode.removeMixin("mix:referenceable");

     // FROM NOW ON NOT A nt:file ANYMORE, BUT A nt:linkedFile
     ntFileNode.setPrimaryType(JcrConstants.NT_LINKEDFILE);
*// AT THIS POINT I EXPECTED THE PRIMARY TYPE TO BE nt:linkedFile, BUT IT
IS NOT*
     Property theReferenceProperty = ntFileNode.setProperty("jcr:content",
existingFile);

     // Remove the jcr:content node
     this.remove();

     return theReferenceProperty;

     } else {
     // This is the original code flow
     Value v = (value == null ? null :
session.getValueFactory().createValue(value));
     return setProperty(name, v, PropertyType.BINARY);
     }
}

The real problem is that i am trying to achieve this change of nodetype
being transparent to the JCR API user.

Any insight?

Thank you very much for your time!


2012/5/7 Stefan Guggisberg <stefan.guggisberg@gmail.com>

> On Sun, May 6, 2012 at 9:46 AM, Lukas Kahwe Smith <mls@pooteeweet.org>
> wrote:
> >
> > On May 6, 2012, at 09:41 , Francisco Carriedo Scher wrote:
> >
> >> Hi there,
> >>
> >> in a given point after creating a nt:file node i need to change the node
> >> type to nt:linkedFile. Sometimes such node will already have it's proper
> >> sons (a node called jcr:content and property called jcr:data inside this
> >> last one) and sometimes not.
> >
> >
> > the JCR specification does not allow changing the primary node type once
> a node has been created.
>
> wrong, as of JCR 2.0 the primary node type of a node can be set [1].
>
> cheers
> stefan
>
> [1]
> http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setPrimaryType(java.lang.String)
>
> > not sure if there is an established pattern for this case, but all you
> could do is remove the old node and create a new node.
> >
> > regards,
> > Lukas Kahwe Smith
> > mls@pooteeweet.org
> >
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message