OFBiz Java coding question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

OFBiz Java coding question

Ruth Hoffman-2
Hi List:
I was wondering why, under certain conditions the developer used the
"remove" method to get a value from the context instead of the "get"
method. For example, why do this?

    String webSiteId = (String) serviceContext.remove("webSiteId");

Instead of this?

    String webSiteId = (String) serviceContext.get("webSiteId");

What should I be looking for when I'm trying to decide to use either
"get" or "remove"?

TIA
Ruth
Reply | Threaded
Open this post in threaded view
|

Re: OFBiz Java coding question

Scott Gray-2
My guess would be that they've done it for convenience.  The current  
service context has most of the parameters needed by a service that  
the code is planning on calling but some of the parameters that aren't  
required need to be removed before the service can be called.
An example:
Service1 has paramA, paramB and paramC
Service1 needs to call Service2
Service2 needs paramB and paramC

So in order for Service1 to call Service2 you can just copy the  
context map, remove paramA and then call the service.

Regards
Scott

HotWax Media
http://www.hotwaxmedia.com

On 25/10/2009, at 8:10 AM, Ruth Hoffman wrote:

> Hi List:
> I was wondering why, under certain conditions the developer used the  
> "remove" method to get a value from the context instead of the "get"  
> method. For example, why do this?
>
>   String webSiteId = (String) serviceContext.remove("webSiteId");
>
> Instead of this?
>
>   String webSiteId = (String) serviceContext.get("webSiteId");
>
> What should I be looking for when I'm trying to decide to use either  
> "get" or "remove"?
>
> TIA
> Ruth


smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: OFBiz Java coding question

Ruth Hoffman-2
Hi Scott:
That makes sense. Thanks.
Ruth

Scott Gray wrote:

> My guess would be that they've done it for convenience.  The current
> service context has most of the parameters needed by a service that
> the code is planning on calling but some of the parameters that aren't
> required need to be removed before the service can be called.
> An example:
> Service1 has paramA, paramB and paramC
> Service1 needs to call Service2
> Service2 needs paramB and paramC
>
> So in order for Service1 to call Service2 you can just copy the
> context map, remove paramA and then call the service.
>
> Regards
> Scott
>
> HotWax Media
> http://www.hotwaxmedia.com
>
> On 25/10/2009, at 8:10 AM, Ruth Hoffman wrote:
>
>> Hi List:
>> I was wondering why, under certain conditions the developer used the
>> "remove" method to get a value from the context instead of the "get"
>> method. For example, why do this?
>>
>>   String webSiteId = (String) serviceContext.remove("webSiteId");
>>
>> Instead of this?
>>
>>   String webSiteId = (String) serviceContext.get("webSiteId");
>>
>> What should I be looking for when I'm trying to decide to use either
>> "get" or "remove"?
>>
>> TIA
>> Ruth
>
Reply | Threaded
Open this post in threaded view
|

Re: OFBiz Java coding question

Adrian Crum-2
By the way, the ModelService class has a utility method that takes an existing Map and copies the valid service parameters to another Map:

http://api.ofbiz.org/org/ofbiz/service/ModelService.html#makeValid(java.util.Map,%20java.lang.String)

-Adrian

--- On Sat, 10/24/09, Ruth Hoffman <[hidden email]> wrote:

> From: Ruth Hoffman <[hidden email]>
> Subject: Re: OFBiz Java coding question
> To: [hidden email]
> Date: Saturday, October 24, 2009, 12:47 PM
> Hi Scott:
> That makes sense. Thanks.
> Ruth
>
> Scott Gray wrote:
> > My guess would be that they've done it for
> convenience.  The current service context has most of
> the parameters needed by a service that the code is planning
> on calling but some of the parameters that aren't required
> need to be removed before the service can be called.
> > An example:
> > Service1 has paramA, paramB and paramC
> > Service1 needs to call Service2
> > Service2 needs paramB and paramC
> >
> > So in order for Service1 to call Service2 you can just
> copy the context map, remove paramA and then call the
> service.
> >
> > Regards
> > Scott
> >
> > HotWax Media
> > http://www.hotwaxmedia.com
> >
> > On 25/10/2009, at 8:10 AM, Ruth Hoffman wrote:
> >
> >> Hi List:
> >> I was wondering why, under certain conditions the
> developer used the "remove" method to get a value from the
> context instead of the "get" method. For example, why do
> this?
> >>
> >>   String webSiteId = (String)
> serviceContext.remove("webSiteId");
> >>
> >> Instead of this?
> >>
> >>   String webSiteId = (String)
> serviceContext.get("webSiteId");
> >>
> >> What should I be looking for when I'm trying to
> decide to use either "get" or "remove"?
> >>
> >> TIA
> >> Ruth
> >
>