apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Munagala Ramanath <...@datatorrent.com>
Subject Re: Setting list and map properties via properties.xml
Date Thu, 17 Mar 2016 23:30:44 GMT
The list initialization only works when I prepopulate the list with enough
elements
to accomodate all the items from the property file; otherwise I get a
failure:
   java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

Ram



On Thu, Mar 17, 2016 at 11:14 AM, Chinmay Kolhatkar <chinmay@apache.org>
wrote:

> @Ram, Ok. The reason why I would prefer to have property as List or Map is
> because individual items may contain characters which might overlap with
> the element separator.
>
> @Thomas, Can you please point me to or type in an example? I'll try that.
> Also, is it suggested to use JSON instead of xml in such cases?
>
> On another note, I was looking into code and ended up with common's
> BeanUtils, in which I found a way to set map and list by properties.xml as
> well.
> Just some special setter method needs to be there.
>
> So in operator, code as be as follows:
>   private List<String> varList = new ArrayList<>();
>   private Map<String, String> varMap = new HashMap<>();
>
>   public void setVarList(List<String> list) { this.varList = list; }
>   public void setVarList(int index, String value)
>   {
>     for (int i=this.list.size(); i<=index; i++) {
>       this.varList.add(null);
>     }
>     this.varList.set(index, value);
>   }
>
>   public void setVarMap(Map<String, String> map) { this.varMap = map; }
>   public void setVarMap(String key, String value) { this.varMap.put(key,
> value); }
>
>
> And XML file can contain property as follows:
>   <property>
>     <name>dt.operator.randomGenerator.varMap(abc)</name>
>     <value>123</value>
>   </property>
>   <property>
>     <name>dt.operator.randomGenerator.varMap(pqr)</name>
>     <value>567</value>
>   </property>
>   <property>
>     <name>dt.operator.randomGenerator.varList[1]</name>
>     <value>test2</value>
>   </property>
>   <property>
>     <name>dt.operator.randomGenerator.varList[0]</name>
>     <value>test1</value>
>   </property>
>
>
> Can you please suggest if this a fine way for exposing complex operator
> properties like map and list?
>
> Thanks,
> Chinmay.
>
>
> On Thu, Mar 17, 2016 at 10:04 PM, Thomas Weise <thomas@datatorrent.com>
> wrote:
>
> > AFAIK there is a way to do it via JSON.
> >
> > --
> > sent from mobile
> > On Mar 17, 2016 9:32 AM, "Munagala Ramanath" <ram@datatorrent.com>
> wrote:
> >
> > > There may be a way to do this with StringCodecs but not sure of the
> > > details.
> > >
> > > You could use arrays of strings as an intermediate type since these can
> > be
> > > populated by comma-separated values in the property files. Then convert
> > > to List/Map as needed.
> > >
> > > Ram
> > >
> > > On Thu, Mar 17, 2016 at 2:11 AM, Chinmay Kolhatkar <chinmay@apache.org
> >
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > I have an operator which has setter method for properties which are
> of
> > > type
> > > > List<String> and Map<String, String>.
> > > >
> > > > Is there any way to set these properties via properties.xml?
> > > >
> > > > Thanks,
> > > > Chinmay.
> > > >
> > >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message