You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Chris Pratt <th...@gmail.com> on 2011/11/11 01:15:43 UTC

[BeanUtils] Debugging BeanMap

I'm having trouble getting BeanMap to work, and what's worse, I can't get
any debug information out of it.  Is there a System Property that has to be
specified somewhere or something to that effect?  I've been looking at the
BeanUtils documentation all day, and it's a bit sparse.
  (*Chris*)

Re: [BeanUtils] [OGNL] Debugging BeanMap

Posted by Chris Pratt <th...@gmail.com>.
Hmmm, I didn't think about OGNL, that might be an interesting thing to
investigate.  At this point, I just wrote my own version of BeanMap that
does support dot notation, and it seems to be working so far.  Thanks for
your help.
  (*Chris*)
On Nov 12, 2011 12:49 AM, "Maurizio Cucchiara" <mc...@apache.org>
wrote:

> Hi Chris,
> I don't know if BUM allows what you are trying to achieve.
> Would you consider to use OGNL instead?
>
>    @Test
>    public void testOGNL() throws Exception {
>        OgnlRuntime.setNullHandler(Student.class, new StudentNullHandler());
>        Student student = new Student();
>        Map<String, Object> context = Ognl.createDefaultContext(student);
>        Ognl.setValue("id", student, 1);
>        Ognl.setValue("course.name", student, "course name");
>        assertEquals(1, student.getId());
>        assertEquals("course name",student.getCourse().getName());
>    }
>
>    private static class StudentNullHandler implements NullHandler {
>        public Object nullMethodResult(Map<String, Object> context,
> Object target, String methodName, Object[] args) {
>            return null;
>        }
>
>        public Object nullPropertyValue(Map<String, Object> context,
> Object target, Object property) {
>            final Course course = new Course();
>            ((Student)target).setCourse(course);
>            return course;
>        }
>    }
>
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
>
> On 11 November 2011 19:43, Chris Pratt <th...@gmail.com> wrote:
> > I simplified my test case and I think I may have found the culprit.  I
> was
> > expecting the BeanMap to handle dot notation properly, but it appears I
> was
> > mistaken.  The following doesn't seem to work:
> >
> >  public static void main (String... args) throws ADKException,
> IOException {
> >    Student student = new Student();
> >    Map studmap = new BeanMap(student);
> >    studmap.put("id",4242);
> >    studmap.put("name.firstname","Chris");
> >    studmap.put("name.lastname","Pratt");
> >    student.dump();
> >  } //main
> >
> >
> > I get an IllegalArgumentException that Student has no property called
> > name.firstname.  Is there any way around this?  BeanMap isn't really
> useful
> > to me if it doesn't support the object hierarchy that a bean engenders?
> >  (*Chris*)
> >
> > On Thu, Nov 10, 2011 at 5:06 PM, Maurizio Cucchiara
> > <mc...@apache.org>wrote:
> >
> >> I'm not sure this is what you are looking for, I'm assuming you are
> >> trying to write into the student bean, I hope this will be useful (it
> >> works on my side):
> >>
> >>    @Test
> >>    public void testBeanMap() throws Exception {
> >>         Student student = new Student();
> >>         BeanMap map = new BeanMap(student);
> >>        assertNotNull(map);
> >>        map.put("id", 1);
> >>        map.put("course", new Course("course name"));
> >>        assertEquals(1, student.getId());
> >>        assertEquals("course name",student.getCourse().getName());
> >>     }
> >>
> >>
> >> Twitter     :http://www.twitter.com/m_cucchiara
> >> G+          :https://plus.google.com/107903711540963855921
> >> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
> >>
> >> Maurizio Cucchiara
> >>
> >>
> >>
> >> On 11 November 2011 01:51, Chris Pratt <th...@gmail.com> wrote:
> >> > StringMapAdaptor
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [BeanUtils] [OGNL] Debugging BeanMap

Posted by Maurizio Cucchiara <mc...@apache.org>.
Hi Chris,
I don't know if BUM allows what you are trying to achieve.
Would you consider to use OGNL instead?

    @Test
    public void testOGNL() throws Exception {
        OgnlRuntime.setNullHandler(Student.class, new StudentNullHandler());
        Student student = new Student();
        Map<String, Object> context = Ognl.createDefaultContext(student);
        Ognl.setValue("id", student, 1);
        Ognl.setValue("course.name", student, "course name");
        assertEquals(1, student.getId());
        assertEquals("course name",student.getCourse().getName());
    }

    private static class StudentNullHandler implements NullHandler {
        public Object nullMethodResult(Map<String, Object> context,
Object target, String methodName, Object[] args) {
            return null;
        }

        public Object nullPropertyValue(Map<String, Object> context,
Object target, Object property) {
            final Course course = new Course();
            ((Student)target).setCourse(course);
            return course;
        }
    }


Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara



On 11 November 2011 19:43, Chris Pratt <th...@gmail.com> wrote:
> I simplified my test case and I think I may have found the culprit.  I was
> expecting the BeanMap to handle dot notation properly, but it appears I was
> mistaken.  The following doesn't seem to work:
>
>  public static void main (String... args) throws ADKException, IOException {
>    Student student = new Student();
>    Map studmap = new BeanMap(student);
>    studmap.put("id",4242);
>    studmap.put("name.firstname","Chris");
>    studmap.put("name.lastname","Pratt");
>    student.dump();
>  } //main
>
>
> I get an IllegalArgumentException that Student has no property called
> name.firstname.  Is there any way around this?  BeanMap isn't really useful
> to me if it doesn't support the object hierarchy that a bean engenders?
>  (*Chris*)
>
> On Thu, Nov 10, 2011 at 5:06 PM, Maurizio Cucchiara
> <mc...@apache.org>wrote:
>
>> I'm not sure this is what you are looking for, I'm assuming you are
>> trying to write into the student bean, I hope this will be useful (it
>> works on my side):
>>
>>    @Test
>>    public void testBeanMap() throws Exception {
>>         Student student = new Student();
>>         BeanMap map = new BeanMap(student);
>>        assertNotNull(map);
>>        map.put("id", 1);
>>        map.put("course", new Course("course name"));
>>        assertEquals(1, student.getId());
>>        assertEquals("course name",student.getCourse().getName());
>>     }
>>
>>
>> Twitter     :http://www.twitter.com/m_cucchiara
>> G+          :https://plus.google.com/107903711540963855921
>> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>>
>> Maurizio Cucchiara
>>
>>
>>
>> On 11 November 2011 01:51, Chris Pratt <th...@gmail.com> wrote:
>> > StringMapAdaptor
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [BeanUtils] Debugging BeanMap

Posted by Chris Pratt <th...@gmail.com>.
I simplified my test case and I think I may have found the culprit.  I was
expecting the BeanMap to handle dot notation properly, but it appears I was
mistaken.  The following doesn't seem to work:

  public static void main (String... args) throws ADKException, IOException {
    Student student = new Student();
    Map studmap = new BeanMap(student);
    studmap.put("id",4242);
    studmap.put("name.firstname","Chris");
    studmap.put("name.lastname","Pratt");
    student.dump();
  } //main


I get an IllegalArgumentException that Student has no property called
name.firstname.  Is there any way around this?  BeanMap isn't really useful
to me if it doesn't support the object hierarchy that a bean engenders?
  (*Chris*)

On Thu, Nov 10, 2011 at 5:06 PM, Maurizio Cucchiara
<mc...@apache.org>wrote:

> I'm not sure this is what you are looking for, I'm assuming you are
> trying to write into the student bean, I hope this will be useful (it
> works on my side):
>
>    @Test
>    public void testBeanMap() throws Exception {
>         Student student = new Student();
>         BeanMap map = new BeanMap(student);
>        assertNotNull(map);
>        map.put("id", 1);
>        map.put("course", new Course("course name"));
>        assertEquals(1, student.getId());
>        assertEquals("course name",student.getCourse().getName());
>     }
>
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
>
> On 11 November 2011 01:51, Chris Pratt <th...@gmail.com> wrote:
> > StringMapAdaptor
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [BeanUtils] Debugging BeanMap

Posted by Maurizio Cucchiara <mc...@apache.org>.
I'm not sure this is what you are looking for, I'm assuming you are
trying to write into the student bean, I hope this will be useful (it
works on my side):

    @Test
    public void testBeanMap() throws Exception {
        Student student = new Student();
        BeanMap map = new BeanMap(student);
        assertNotNull(map);
        map.put("id", 1);
        map.put("course", new Course("course name"));
        assertEquals(1, student.getId());
        assertEquals("course name",student.getCourse().getName());
    }


Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara



On 11 November 2011 01:51, Chris Pratt <th...@gmail.com> wrote:
> StringMapAdaptor

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [BeanUtils] Debugging BeanMap

Posted by Chris Pratt <th...@gmail.com>.
Logging output would be helpful.  I'm basically trying the code below:

      ADK.initialize(SIFVersion.SIF23,SIFDTD.SDO_ETRANSCRIPTS);
      Student student = new Student();
      AgentConfig config = new AgentConfig();
      config.read("mappings.cfg",false);
      SIFVersion version = config.getVersion();
      Mappings def = config.getMappings().getMappings("Default");
      def.select("Default","",version);
      try {
        def.mapInbound(new
SIFDataObjectXML(EtranscriptsDTD.STUDENTRECORDEXCHANGE,getXML(args[0])),new
StringMapAdaptor(new BeanMap(student)));
      } catch(IllegalArgumentException x) {
        log.warn("Illegal Argument",x);
      }
      student.dump();

Which is supposed to map the data in the XML document to the Student object
through the BeanMap, but I'm not getting any debug output whatsoever, so
I'm a bit lost at this point.
  (*Chris*)
On Thu, Nov 10, 2011 at 4:40 PM, Maurizio Cucchiara
<mc...@apache.org>wrote:

> Could you provide some more detail? Maybe some sample code.
> What kind of debug information are you referring? You mean log, etc?
>
>
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
>
> On 11 November 2011 01:15, Chris Pratt <th...@gmail.com> wrote:
> > BeanMap
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: [BeanUtils] Debugging BeanMap

Posted by Maurizio Cucchiara <mc...@apache.org>.
Could you provide some more detail? Maybe some sample code.
What kind of debug information are you referring? You mean log, etc?



Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara



On 11 November 2011 01:15, Chris Pratt <th...@gmail.com> wrote:
> BeanMap

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org