You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Markus Joschko <ma...@gmail.com> on 2011/04/04 13:13:38 UTC

How to mix structured and unstructured content on a node?

Hi,
I have a node that should mix free and and fixed properties.
For that purpose I created the following nodetype (leaving out the namespace):

[Contact]  >  nt:unstructured, mix:created, mix:lastModified
   - primaryContactDetails (weakreference)

[Individual] > Contact


When I create a node of type Individual and set the
primaryContactDetails property to another referencable node,  it gets
the typ "reference".
Asked for its required type the property returns "undefined" and as
the DeclaringNodeType it returns "nt:unstructured".

When I remove "nt:unstructured" from the inheritance list, I get the
desired "weakreference" and Contact as DeclaringNodeType.

Obviously "nt:unstructure" takes precedence over the defined
properties. Is there an other way to combine defined and undefined
properties in a node?

I currently use jackrabbit 2.1.1


Regards,
 Markus

Re: How to mix structured and unstructured content on a node?

Posted by Markus Joschko <ma...@gmail.com>.
On Mon, Apr 4, 2011 at 5:29 PM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> On 04.04.11 16:11, "Markus Joschko" <ma...@gmail.com> wrote:
>>That theoretically means, that a node inheriting from nt:unstructure
>>shouldn't have
>>any properties because it will always override the catch all of
>>nt:unstructure.
>>How is validation handled? If my subnode defines a simple string
>>property but limits what can be entered.
>>Is validation ignored when getting an instance as nt:unstructured or
>>is the illusion destroyed?
>
> If you want that, the primary node type you want to use should not inherit
> from nt:unstructured in the first place, and only define the properties
> and their constraints that you actually want to allow.

My use case requires a mixed model.
I care about 2-3 properties that must be defined.
The rest can be freely added by the user.

I'll guess I go with nt:unstructure and do all the verification in my
application code.

Regards,
 Markus

>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>

Re: How to mix structured and unstructured content on a node?

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 04.04.11 16:11, "Markus Joschko" <ma...@gmail.com> wrote:
>That theoretically means, that a node inheriting from nt:unstructure
>shouldn't have
>any properties because it will always override the catch all of
>nt:unstructure.
>How is validation handled? If my subnode defines a simple string
>property but limits what can be entered.
>Is validation ignored when getting an instance as nt:unstructured or
>is the illusion destroyed?

If you want that, the primary node type you want to use should not inherit
from nt:unstructured in the first place, and only define the properties
and their constraints that you actually want to allow.

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: How to mix structured and unstructured content on a node?

Posted by Markus Joschko <ma...@gmail.com>.
On Mon, Apr 4, 2011 at 3:24 PM, Alexander Klimetschek
<ak...@adobe.com> wrote:
> On 04.04.11 15:16, "Markus Joschko" <ma...@gmail.com> wrote:
>>When the name is the id I would have expected jcr to check against the
>>definition, notice that the more specific defintion
>>of the property does not match the input and throw an error.
>>
>>Otherwise nt:unstructured is kind of dangerous as it silently swallows
>>everything thrown at it.
>
> The idea is that once you introduce a residual property or child node
> definition, you make it "unstructured", including descendant node types.
>
> IIUC the JCR node typing is in general not allowing to put on more
> constraints on a sub node type - which is in line with how OO in most
> languages work. Otherwise finding e.g. all "nt:unstructured" nodes in the
> repo, but then not being allowed to change properties freely, because some
> of the nodes are of a sub-type with more restrictions, would defeat the
> purpose of the inheritance model.
>

That theoretically means, that a node inheriting from nt:unstructure
shouldn't have
any properties because it will always override the catch all of nt:unstructure.
How is validation handled? If my subnode defines a simple string
property but limits what can be entered.
Is validation ignored when getting an instance as nt:unstructured or
is the illusion destroyed?

> Regards,
> Alex
>
> --
> Alexander Klimetschek
> Developer // Adobe (Day) // Berlin - Basel
>
>
>
>
>

Re: How to mix structured and unstructured content on a node?

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 04.04.11 15:16, "Markus Joschko" <ma...@gmail.com> wrote:
>When the name is the id I would have expected jcr to check against the
>definition, notice that the more specific defintion
>of the property does not match the input and throw an error.
>
>Otherwise nt:unstructured is kind of dangerous as it silently swallows
>everything thrown at it.

The idea is that once you introduce a residual property or child node
definition, you make it "unstructured", including descendant node types.

IIUC the JCR node typing is in general not allowing to put on more
constraints on a sub node type - which is in line with how OO in most
languages work. Otherwise finding e.g. all "nt:unstructured" nodes in the
repo, but then not being allowed to change properties freely, because some
of the nodes are of a sub-type with more restrictions, would defeat the
purpose of the inheritance model.

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel





Re: How to mix structured and unstructured content on a node?

Posted by Markus Joschko <ma...@gmail.com>.
On Mon, Apr 4, 2011 at 2:42 PM, Stefan Guggisberg
<st...@gmail.com> wrote:
> On Mon, Apr 4, 2011 at 2:18 PM, Markus Joschko <ma...@gmail.com> wrote:
>> On Mon, Apr 4, 2011 at 1:56 PM, Stefan Guggisberg
>> <st...@gmail.com> wrote:
>>> On Mon, Apr 4, 2011 at 1:13 PM, Markus Joschko <ma...@gmail.com> wrote:
>>>> Hi,
>>>> I have a node that should mix free and and fixed properties.
>>>> For that purpose I created the following nodetype (leaving out the namespace):
>>>>
>>>> [Contact]  >  nt:unstructured, mix:created, mix:lastModified
>>>>   - primaryContactDetails (weakreference)
>>>>
>>>> [Individual] > Contact
>>>>
>>>>
>>>> When I create a node of type Individual and set the
>>>> primaryContactDetails property to another referencable node,  it gets
>>>> the typ "reference".
>>>> Asked for its required type the property returns "undefined" and as
>>>> the DeclaringNodeType it returns "nt:unstructured".
>>>>
>>>> When I remove "nt:unstructured" from the inheritance list, I get the
>>>> desired "weakreference" and Contact as DeclaringNodeType.
>>>>
>>>> Obviously "nt:unstructure" takes precedence over the defined
>>>> properties.
>>>
>>> no, named definitions should take precedence over residual definitions.
>>> weak reference were introduced in jsr-283 (jcr 2.0). you probably
>>> encountered a problem that is specific to weakreferences.
>>
>> I did some more tests:
>> 1) when using a defined name with the defined type -> the correct
>> nodetype is used
>> 2) when using a residual name -> nt:unstructured is taken as declaring nodetype
>
> what do you mean by 'residual name'? could you please provide
> an example for better understanding?
>
>> 3) when using a defined name but a type that is incompatible with the
>> defintion -> nt:unstructured is used as declaring nodetype
>>
>> Is 3) really a valid behaviour?
>
> yes
>
>> I would expect this to fail.
>
> there's a matching residual definition, why should it fail?

Because I gave more detailed instructions for a property with that name.
Isn't the property name somewhat the key/id of a property or is it
property name + property type?

When the name is the id I would have expected jcr to check against the
definition, notice that the more specific defintion
of the property does not match the input and throw an error.

Otherwise nt:unstructured is kind of dangerous as it silently swallows
everything thrown at it.

I learned my lesson, that I have to be very specific with the type in
combination with nt:unstructured, but I don't find it very intuitive.

>
>> That's not only for weakreferences but for all types I tested. It is
>> especially easy to notice with weakreferences as
>> I can only pass a node to the setProperty method and must rely on
>> jackrabbit to set the correct type.
>
> i can't follow you here. you can use either [1] or [2].
>
> [1] http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setProperty(java.lang.String,
> javax.jcr.Value)
> [2] http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setProperty(java.lang.String,
> java.lang.String, int)

I have completely missed that. That'll work fine.

> cheers
> stefan
>
>>
>>> do you mind filing a jira issue? a simple test case would be great :)
>>
>>>
>>> cheers
>>> stefan
>>>
>>>> Is there an other way to combine defined and undefined
>>>> properties in a node?
>>>>
>>>> I currently use jackrabbit 2.1.1
>>>>
>>>>
>>>> Regards,
>>>>  Markus
>>>>
>>>
>>
>

Re: How to mix structured and unstructured content on a node?

Posted by Stefan Guggisberg <st...@gmail.com>.
On Mon, Apr 4, 2011 at 2:18 PM, Markus Joschko <ma...@gmail.com> wrote:
> On Mon, Apr 4, 2011 at 1:56 PM, Stefan Guggisberg
> <st...@gmail.com> wrote:
>> On Mon, Apr 4, 2011 at 1:13 PM, Markus Joschko <ma...@gmail.com> wrote:
>>> Hi,
>>> I have a node that should mix free and and fixed properties.
>>> For that purpose I created the following nodetype (leaving out the namespace):
>>>
>>> [Contact]  >  nt:unstructured, mix:created, mix:lastModified
>>>   - primaryContactDetails (weakreference)
>>>
>>> [Individual] > Contact
>>>
>>>
>>> When I create a node of type Individual and set the
>>> primaryContactDetails property to another referencable node,  it gets
>>> the typ "reference".
>>> Asked for its required type the property returns "undefined" and as
>>> the DeclaringNodeType it returns "nt:unstructured".
>>>
>>> When I remove "nt:unstructured" from the inheritance list, I get the
>>> desired "weakreference" and Contact as DeclaringNodeType.
>>>
>>> Obviously "nt:unstructure" takes precedence over the defined
>>> properties.
>>
>> no, named definitions should take precedence over residual definitions.
>> weak reference were introduced in jsr-283 (jcr 2.0). you probably
>> encountered a problem that is specific to weakreferences.
>
> I did some more tests:
> 1) when using a defined name with the defined type -> the correct
> nodetype is used
> 2) when using a residual name -> nt:unstructured is taken as declaring nodetype

what do you mean by 'residual name'? could you please provide
an example for better understanding?

> 3) when using a defined name but a type that is incompatible with the
> defintion -> nt:unstructured is used as declaring nodetype
>
> Is 3) really a valid behaviour?

yes

> I would expect this to fail.

there's a matching residual definition, why should it fail?

> That's not only for weakreferences but for all types I tested. It is
> especially easy to notice with weakreferences as
> I can only pass a node to the setProperty method and must rely on
> jackrabbit to set the correct type.

i can't follow you here. you can use either [1] or [2].

[1] http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setProperty(java.lang.String,
javax.jcr.Value)
[2] http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#setProperty(java.lang.String,
java.lang.String, int)

cheers
stefan

>
>> do you mind filing a jira issue? a simple test case would be great :)
>
>>
>> cheers
>> stefan
>>
>>> Is there an other way to combine defined and undefined
>>> properties in a node?
>>>
>>> I currently use jackrabbit 2.1.1
>>>
>>>
>>> Regards,
>>>  Markus
>>>
>>
>

Re: How to mix structured and unstructured content on a node?

Posted by Markus Joschko <ma...@gmail.com>.
On Mon, Apr 4, 2011 at 1:56 PM, Stefan Guggisberg
<st...@gmail.com> wrote:
> On Mon, Apr 4, 2011 at 1:13 PM, Markus Joschko <ma...@gmail.com> wrote:
>> Hi,
>> I have a node that should mix free and and fixed properties.
>> For that purpose I created the following nodetype (leaving out the namespace):
>>
>> [Contact]  >  nt:unstructured, mix:created, mix:lastModified
>>   - primaryContactDetails (weakreference)
>>
>> [Individual] > Contact
>>
>>
>> When I create a node of type Individual and set the
>> primaryContactDetails property to another referencable node,  it gets
>> the typ "reference".
>> Asked for its required type the property returns "undefined" and as
>> the DeclaringNodeType it returns "nt:unstructured".
>>
>> When I remove "nt:unstructured" from the inheritance list, I get the
>> desired "weakreference" and Contact as DeclaringNodeType.
>>
>> Obviously "nt:unstructure" takes precedence over the defined
>> properties.
>
> no, named definitions should take precedence over residual definitions.
> weak reference were introduced in jsr-283 (jcr 2.0). you probably
> encountered a problem that is specific to weakreferences.

I did some more tests:
1) when using a defined name with the defined type -> the correct
nodetype is used
2) when using a residual name -> nt:unstructured is taken as declaring nodetype
3) when using a defined name but a type that is incompatible with the
defintion -> nt:unstructured is used as declaring nodetype

Is 3) really a valid behaviour? I would expect this to fail.
That's not only for weakreferences but for all types I tested. It is
especially easy to notice with weakreferences as
I can only pass a node to the setProperty method and must rely on
jackrabbit to set the correct type.

> do you mind filing a jira issue? a simple test case would be great :)

>
> cheers
> stefan
>
>> Is there an other way to combine defined and undefined
>> properties in a node?
>>
>> I currently use jackrabbit 2.1.1
>>
>>
>> Regards,
>>  Markus
>>
>

Re: How to mix structured and unstructured content on a node?

Posted by Stefan Guggisberg <st...@gmail.com>.
On Mon, Apr 4, 2011 at 1:13 PM, Markus Joschko <ma...@gmail.com> wrote:
> Hi,
> I have a node that should mix free and and fixed properties.
> For that purpose I created the following nodetype (leaving out the namespace):
>
> [Contact]  >  nt:unstructured, mix:created, mix:lastModified
>   - primaryContactDetails (weakreference)
>
> [Individual] > Contact
>
>
> When I create a node of type Individual and set the
> primaryContactDetails property to another referencable node,  it gets
> the typ "reference".
> Asked for its required type the property returns "undefined" and as
> the DeclaringNodeType it returns "nt:unstructured".
>
> When I remove "nt:unstructured" from the inheritance list, I get the
> desired "weakreference" and Contact as DeclaringNodeType.
>
> Obviously "nt:unstructure" takes precedence over the defined
> properties.

no, named definitions should take precedence over residual definitions.
weak reference were introduced in jsr-283 (jcr 2.0). you probably
encountered a problem that is specific to weakreferences.

do you mind filing a jira issue? a simple test case would be great :)

cheers
stefan

> Is there an other way to combine defined and undefined
> properties in a node?
>
> I currently use jackrabbit 2.1.1
>
>
> Regards,
>  Markus
>