You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by David Kennedy <da...@us.ibm.com> on 2006/06/19 23:18:27 UTC

Multivalue or single?

If I have a node, the name of a property and a single value, how can I 
determine if I need to add the value to an array and use the multivalue 
setter or not?  Using 
getProperty(propertyName).getDefinition().isMultiple() won't work since 
the property may not exist (it was set to null...PathNotFoundException). 
Invoking setProperty(propertyName, value) and catching the 
ValueFormatException doesn't work since you don't know if the exception 
came from the property being multivalued or from a conversion error. 
Iterating over the propertyDefinitions from the nodetype (and mixins) 
isn't efficient.   What's the recommended way to determine whether to use 
the multivalue or single value setProperty method?

David

Re: Multivalue or single?

Posted by Martin Perez <mp...@gmail.com>.
The only solution to your problem would be to have some metadata info about
them, and so you could look if the property was single or multivalued.

Obviously the real problem is how to find if a property is single/multiple
if such property does not exist so I cannot agree more with Jukka. Having a
getPropertyDefinition method would be really nice.

Martin

On 6/19/06, Jukka Zitting <ju...@gmail.com> wrote:
>
> Hi,
>
> On 6/20/06, David Kennedy <da...@us.ibm.com> wrote:
> > If I have a node, the name of a property and a single value, how can I
> > determine if I need to add the value to an array and use the multivalue
> > setter or not?
>
> Good question. Perhaps we should add something like a
> getPropertyDefinition(String name) method to a JackrabbitNode
> extension interface. This might also be a good suggestion to JSR 283
> unless someone has a better idea.
>
> BR,
>
> Jukka Zitting
>
> --
> Yukatan - http://yukatan.fi/ - info@yukatan.fi
> Software craftsmanship, JCR consulting, and Java development
>

Re: Multivalue or single?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 6/20/06, David Kennedy <da...@us.ibm.com> wrote:
> If I have a node, the name of a property and a single value, how can I
> determine if I need to add the value to an array and use the multivalue
> setter or not?

Good question. Perhaps we should add something like a
getPropertyDefinition(String name) method to a JackrabbitNode
extension interface. This might also be a good suggestion to JSR 283
unless someone has a better idea.

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development

Re: Multivalue or single?

Posted by Tobias Bocanegra <to...@day.com>.
i think this is only a theoretical problem. usualy the application
knows with what kind of properties it deals.

regards, toby

On 6/20/06, Jukka Zitting <ju...@gmail.com> wrote:
> Hi,
>
> On 6/20/06, Marcel Reutegger <ma...@day.com> wrote:
> > On 6/19/06, David Kennedy <da...@us.ibm.com> wrote:
> > > If I have a node, the name of a property and a single value, how can I
> > > determine if I need to add the value to an array and use the multivalue
> > > setter or not?
> >
> > You'll have to ask the NodeType of the node:
>
> The difficulty lies in the fact that the property could be specified
> either in the primary type or in one of the mixin types. Iterating
> through them is a bit cumbersome and error-prone.
>
> BR,
>
> Jukka Zitting
>
> --
> Yukatan - http://yukatan.fi/ - info@yukatan.fi
> Software craftsmanship, JCR consulting, and Java development
>


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: Multivalue or single?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On 6/20/06, Marcel Reutegger <ma...@day.com> wrote:
> On 6/19/06, David Kennedy <da...@us.ibm.com> wrote:
> > If I have a node, the name of a property and a single value, how can I
> > determine if I need to add the value to an array and use the multivalue
> > setter or not?
>
> You'll have to ask the NodeType of the node:

The difficulty lies in the fact that the property could be specified
either in the primary type or in one of the mixin types. Iterating
through them is a bit cumbersome and error-prone.

BR,

Jukka Zitting

-- 
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftsmanship, JCR consulting, and Java development

Re: Multivalue or single?

Posted by Marcel Reutegger <ma...@day.com>.
On 6/19/06, David Kennedy <da...@us.ibm.com> wrote:
> If I have a node, the name of a property and a single value, how can I
> determine if I need to add the value to an array and use the multivalue
> setter or not?

You'll have to ask the NodeType of the node:

NodeType nt = node.getPrimaryNodeType();
if (nt.canSetProperty("propName", mySingleValue)) {
  node.setProperty("propName", mySingleValue);
} else {
  node.setProperty("propName", new Value[]{mySingleValue});
}

regards
 marcel