Return-Path: X-Original-To: apmail-jackrabbit-users-archive@minotaur.apache.org Delivered-To: apmail-jackrabbit-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5987C98F7 for ; Mon, 7 May 2012 22:07:49 +0000 (UTC) Received: (qmail 39121 invoked by uid 500); 7 May 2012 22:07:48 -0000 Delivered-To: apmail-jackrabbit-users-archive@jackrabbit.apache.org Received: (qmail 39058 invoked by uid 500); 7 May 2012 22:07:48 -0000 Mailing-List: contact users-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@jackrabbit.apache.org Delivered-To: mailing list users@jackrabbit.apache.org Received: (qmail 39039 invoked by uid 99); 7 May 2012 22:07:48 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 May 2012 22:07:48 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of fcarriedos@gmail.com designates 209.85.213.170 as permitted sender) Received: from [209.85.213.170] (HELO mail-yx0-f170.google.com) (209.85.213.170) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 May 2012 22:07:42 +0000 Received: by yenl2 with SMTP id l2so2677030yen.1 for ; Mon, 07 May 2012 15:07:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=io3lvQWNHixgS/OwMtiPPkQ/mjl9l4E1vhG02vb/akU=; b=UikKVuDjM2nyEF3TF4NVWuR8medwgmS9gBicO9FtowuUKDjx+MpCjQSDw+TE7zD88l GiRbOal/h0JEJT7gWmM9m/CvvdzqMxq95oGcWBj4v6PTiEZocv39ZyZT4SOg1nGVaVgY e4XGFNS9oSaaGb9rllNN+z57AOrGWkz/Ty6trErTPJgP583lSUXAAUtdDQz6fG+ywrI8 OZBI4+d+Y41UhW8uvAgFSWd40SzZgGayD6SNDn/EcUp/JnbCU3+RUPf5zcbDDU+nYBQr XXdqXM/SD3JLbvAAjB0nEWRHhst6kUhrDv2nQ5dfm+5he6WXK9hSeN5AtkW9g7UmLc/7 7JsQ== Received: by 10.236.72.40 with SMTP id s28mr21588090yhd.21.1336428441233; Mon, 07 May 2012 15:07:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.101.94.3 with HTTP; Mon, 7 May 2012 15:07:01 -0700 (PDT) Reply-To: fcarriedos@gmail.com In-Reply-To: References: From: Francisco Carriedo Scher Date: Tue, 8 May 2012 00:07:01 +0200 Message-ID: Subject: Re: Varying the node primary type To: users@jackrabbit.apache.org Content-Type: multipart/alternative; boundary=20cf3005131481e87a04bf797ef9 --20cf3005131481e87a04bf797ef9 Content-Type: text/plain; charset=ISO-8859-1 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 > On Sun, May 6, 2012 at 9:46 AM, Lukas Kahwe Smith > 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 > > > > > > > --20cf3005131481e87a04bf797ef9--