Component.getBehaviors

View: New views
3 Messages — Rating Filter:   Alert me  

Component.getBehaviors

by Martin Funk-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

why is Components

        public final List<IBehavior> getBehaviors()
public

and why is

        protected List<IBehavior> getBehaviors(Class<? extends IBehavior> type)
protected?

For example for a Behavior I'd like it to be able to tell if an  
Behavior of its type is already bound to that component.

In its bind() method I'd like to do something like:
                if (component.getBehaviors(SomeBehavior.class).size() > 1) {
                        throw new Error("Ther may only be one");
                }

But I have to do something like:
                for (IBehavior behavior : component.getBehaviors()) {
                        if (behavior instanceof SomeBehavior) {
                                throw new Error("There may only be one");
                        }
                }

So my whish would be to have em both public. I wouldn't mind seeing em  
both final, but that might break existing code.

mf



Re: Component.getBehaviors

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

actually making getbehaviors(class) public will also break code
because any override already in place will then attempt to reduce the
visibility of the method.

add a jira issue, most likely for 1.5 considering 1.4 is already in RC2.

-igor

On Thu, Feb 19, 2009 at 1:24 PM, Martin Funk <mafulafunk@...> wrote:

> Hi,
>
> why is Components
>
>        public final List<IBehavior> getBehaviors()
> public
>
> and why is
>
>        protected List<IBehavior> getBehaviors(Class<? extends IBehavior>
> type)
> protected?
>
> For example for a Behavior I'd like it to be able to tell if an Behavior of
> its type is already bound to that component.
>
> In its bind() method I'd like to do something like:
>                if (component.getBehaviors(SomeBehavior.class).size() > 1) {
>                        throw new Error("Ther may only be one");
>                }
>
> But I have to do something like:
>                for (IBehavior behavior : component.getBehaviors()) {
>                        if (behavior instanceof SomeBehavior) {
>                                throw new Error("There may only be one");
>                        }
>                }
>
> So my whish would be to have em both public. I wouldn't mind seeing em both
> final, but that might break existing code.
>
> mf
>
>
>

Re: Component.getBehaviors

by Antony Stubbs :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

+1

I'd actually forgotten that in my portal-2.0 patch i already changed it to public, and was wondering why i was getting strange errors now :)

I'm surprised this wasn't public from the get go - it's very useful. I'll just have to create a little utility function :)

here's the jira:
http://issues.apache.org/jira/browse/WICKET-2115

igor.vaynberg wrote:
actually making getbehaviors(class) public will also break code
because any override already in place will then attempt to reduce the
visibility of the method.

add a jira issue, most likely for 1.5 considering 1.4 is already in RC2.

-igor

On Thu, Feb 19, 2009 at 1:24 PM, Martin Funk <mafulafunk@googlemail.com> wrote:
> Hi,
>
> why is Components
>
>        public final List<IBehavior> getBehaviors()
> public
>
> and why is
>
>        protected List<IBehavior> getBehaviors(Class<? extends IBehavior>
> type)
> protected?
>
> For example for a Behavior I'd like it to be able to tell if an Behavior of
> its type is already bound to that component.
>
> In its bind() method I'd like to do something like:
>                if (component.getBehaviors(SomeBehavior.class).size() > 1) {
>                        throw new Error("Ther may only be one");
>                }
>
> But I have to do something like:
>                for (IBehavior behavior : component.getBehaviors()) {
>                        if (behavior instanceof SomeBehavior) {
>                                throw new Error("There may only be one");
>                        }
>                }
>
> So my whish would be to have em both public. I wouldn't mind seeing em both
> final, but that might break existing code.
>
> mf
>
>
>
___________________________
http://stubbisms.wordpress.com