UnsupportedOperationException in AttributesToMap

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

UnsupportedOperationException in AttributesToMap

Daniel E. Renfer
Hello,

After working with Orbeon Forms for the past few months, I'm now at
the point where I need to write my own custom processor. This is
literally the first thing I've actually had to code in Java aside from
your standard "Hello World", but working with OF and eXist has given
me a pretty good feel for the environment.

Things were going pretty well, but I just ran into a brick wall. I'm
writing an interface between Apache Heraldry's OpenId Consumer class
and OF. The part of the example code that I'm adapting needs to run an
Iterator over the Request attributes.

My Code (severely snipped):
ExternalContext externalContext = (ExternalContext)
context.getAttribute(context.EXTERNAL_CONTEXT);
Map query = Consumer.filterArgs(externalContext.getRequest().getAttributesMap());

Consumer.filterArgs:
public static Map filterArgs(Map args)
{
    Map result = new HashMap();
    Iterator it = args.entrySet().iterator();
    while (it.hasNext())
    {
        Map.Entry e = (Map.Entry)it.next();
        String k = (String)e.getKey();
        String [] v = (String [])e.getValue();
        result.put(k, v[0]);
    }
    return result;
}

and of course, in AttributesToMap.entrySet() we have:
public Set entrySet() {
        // TODO: It's harder than it looks, as changes to the Entry
elements must be reflected in the Map.
        throw new UnsupportedOperationException();
    }

So it looks like this method was never implemented. I'll take Erik's
word for it that this would probably end up being tricky to implement
properly. The thing is, I don't really need write-access to it, so I
don't care if it updates or not.

Does anyone know of a workaround to this? Am I accessing the Request
attributes properly? Can anyone think of a way to re-write filterArgs
so it doesn't use an Iterator? As I previously stated, I'm still
ramping up in my Java knowledge, so I thought I'd ask the list before
I wasted time trying to hack my own work-around.

Thank You for any assistance you may have to give,
Daniel E. Renfer
http://kronkltd.net/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: UnsupportedOperationException in AttributesToMap

Erik Bruchez
Administrator
Daniel,

I doubt it would be THAT hard to do ;-), but there is a workaround: you
can use map.keySet() instead, and then use map.get(key) to get the
associated value.

-Erik

Daniel E. Renfer wrote:

> Hello,
>
> After working with Orbeon Forms for the past few months, I'm now at
> the point where I need to write my own custom processor. This is
> literally the first thing I've actually had to code in Java aside from
> your standard "Hello World", but working with OF and eXist has given
> me a pretty good feel for the environment.
>
> Things were going pretty well, but I just ran into a brick wall. I'm
> writing an interface between Apache Heraldry's OpenId Consumer class
> and OF. The part of the example code that I'm adapting needs to run an
> Iterator over the Request attributes.
>
> My Code (severely snipped):
> ExternalContext externalContext = (ExternalContext)
> context.getAttribute(context.EXTERNAL_CONTEXT);
> Map query =
> Consumer.filterArgs(externalContext.getRequest().getAttributesMap());
>
> Consumer.filterArgs:
> public static Map filterArgs(Map args)
> {
>    Map result = new HashMap();
>    Iterator it = args.entrySet().iterator();
>    while (it.hasNext())
>    {
>        Map.Entry e = (Map.Entry)it.next();
>        String k = (String)e.getKey();
>        String [] v = (String [])e.getValue();
>        result.put(k, v[0]);
>    }
>    return result;
> }
>
> and of course, in AttributesToMap.entrySet() we have:
> public Set entrySet() {
>        // TODO: It's harder than it looks, as changes to the Entry
> elements must be reflected in the Map.
>        throw new UnsupportedOperationException();
>    }
>
> So it looks like this method was never implemented. I'll take Erik's
> word for it that this would probably end up being tricky to implement
> properly. The thing is, I don't really need write-access to it, so I
> don't care if it updates or not.
>
> Does anyone know of a workaround to this? Am I accessing the Request
> attributes properly? Can anyone think of a way to re-write filterArgs
> so it doesn't use an Iterator? As I previously stated, I'm still
> ramping up in my Java knowledge, so I thought I'd ask the list before
> I wasted time trying to hack my own work-around.
>
> Thank You for any assistance you may have to give,
> Daniel E. Renfer
> http://kronkltd.net/
>
>
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

--
Orbeon Forms - XForms Everywhere
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws