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 Fri, 18 Mar 2016 16:10:56 GMT
The example was not working for me; after some back-and-forth with Chinmay,
figured out that
it works with  Java 7 but fails with Java 8; the issue is described here:

http://stackoverflow.com/questions/30663238/java-jdk-8-indexedpropertydescriptor-has-changed-since-jdk-7-with-list-object

If this setter is commented out (leaving only the indexed setter) it works
with Java 8:
public void setVarList(List<String> list) { this.varList = list; }

Ram

On Fri, Mar 18, 2016 at 4:25 AM, Chinmay Kolhatkar <chinmay@apache.org>
wrote:

> That's true.. But with the setter method mentioned above for list variable,
> its taken care of. Though its a hack, it works..
>
> On Fri, Mar 18, 2016 at 5:00 AM, Munagala Ramanath <ram@datatorrent.com>
> wrote:
>
> > 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