You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Marco Mistroni <mm...@waersystems.com> on 2004/04/30 10:03:47 UTC

wrap a Map into a DynaBean

Hi all,
	Is there any way, using beanutils package, to 'wrap' a Map
Into a DynaBean or something similar? 
>From errors that I have, answer is no, but maybe some of you know
Some alternatives..
Issue is that I am receiving different objects from my db layer, and
I am wrapping them into a DynaBean to avoid calling specific methods
For retrieving properties.
But in one case out of 10 I am receiving an HashMap, and it looks like
I cannot wrap an HashMap with a DynaBean

Anyone has any suggestions?

Thanx in advance and regards
	Marco



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


Re: Help with digester!

Posted by José Antonio Pérez Testa <ja...@indra.es>.
It looks like everything is ok.
Look at the logs and see what's happening.
Maybe some problem with the arguments types. Try the method 
addCallMethod(String pattern, String methodName, int paramCount, 
String[] paramTypes)
and explicitly set the argument types. I've found a similar problem in 
calling ArrayList.add and it is because of the argument being 
java.lang.Object

Good luck.

Marco Mistroni wrote:

>Hi all,
>	I am experiencing problem with digester when I use
>The xml files for the rules.
>
>I have following SQL file :
>
><?xml version="1.0" encoding="UTF-8"?>
><sql>
>  <statement>
>     <name>getUsers</name>
>     <value>select * from user_details</value>
>  </statement>
>  <statement>
>     <name>getContact</name>
>     <value>select *  from contact WHERE contact_ref = ? </value>
>  </statement>
></sql>
>
>I want, for each statement, to populate an Hashtable with name as key
>and
>Value as index.
>
>When running normal digester and setting rules in java code
>digester.addObjectCreate("sql", java.util.Hashtable.class);
>			digester.addCallMethod("sql/statement",
>"put",2);
>			digester.addCallParam("sql/statement/name", 0);
>			digester.addCallParam("sql/statement/value",1);
>		} catch(Exception e) {
>
>the problem is that either I don't know how to do the same in an xml
>file
>or my xml file for rules is incorrect.
>I have tried with the following
>
><?xml version="1.0"?>
><digester-rules>
>  <pattern value="sql">
>      <object-create-rule classname="java.util.Hashtable" />
>	   <set-properties-rule />
>	   <call-method-rule pattern="statement" methodname="put"
>             paramcount="2" />
>              <call-param-rule pattern="statement/name"
>paramnumber="0"/>
>              <call-param-rule pattern="statement/value"
>paramnumber="1"/>
>     
>  </pattern>
></digester-rules>
>
>can anyone help?
>
>Thanx in advance and regards
>	Marco
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>

-------------------------------------------------------------------------------------------------------------------
Este correo electr�nico y, en su caso, cualquier fichero anexo al mismo, contiene informaci�n de car�cter confidencial exclusivamente dirigida a su destinatario o destinatarios. Queda prohibida su divulgaci�n, copia o distribuci�n a terceros sin la previa autorizaci�n escrita de Indra. En el caso de haber recibido este correo electr�nico por error, se ruega notificar inmediatamente esta circunstancia mediante reenv�o a la direcci�n electr�nica del remitente.

The information in this e-mail and in any attachments is confidential and solely for the attention and use of the named addressee(s). You are hereby notified that any dissemination, distribution or copy of this communication is prohibited without the prior written consent of Indra. If you have received this communication in error, please, notify the sender by reply e-mail

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


Help with digester!

Posted by Marco Mistroni <mm...@waersystems.com>.
Hi all,
	I am experiencing problem with digester when I use
The xml files for the rules.

I have following SQL file :

<?xml version="1.0" encoding="UTF-8"?>
<sql>
  <statement>
     <name>getUsers</name>
     <value>select * from user_details</value>
  </statement>
  <statement>
     <name>getContact</name>
     <value>select *  from contact WHERE contact_ref = ? </value>
  </statement>
</sql>

I want, for each statement, to populate an Hashtable with name as key
and
Value as index.

When running normal digester and setting rules in java code
digester.addObjectCreate("sql", java.util.Hashtable.class);
			digester.addCallMethod("sql/statement",
"put",2);
			digester.addCallParam("sql/statement/name", 0);
			digester.addCallParam("sql/statement/value",1);
		} catch(Exception e) {

the problem is that either I don't know how to do the same in an xml
file
or my xml file for rules is incorrect.
I have tried with the following

<?xml version="1.0"?>
<digester-rules>
  <pattern value="sql">
      <object-create-rule classname="java.util.Hashtable" />
	   <set-properties-rule />
	   <call-method-rule pattern="statement" methodname="put"
             paramcount="2" />
              <call-param-rule pattern="statement/name"
paramnumber="0"/>
              <call-param-rule pattern="statement/value"
paramnumber="1"/>
     
  </pattern>
</digester-rules>

can anyone help?

Thanx in advance and regards
	Marco




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


Re: wrap a Map into a DynaBean

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Marco Mistroni wrote:

>Hi all,
>	Is there any way, using beanutils package, to 'wrap' a Map
>Into a DynaBean or something similar? 
>
It would certainly be possible to create such an implementation, but 
there's nothing like that already available in the standard [beanutils] 
package.  You'd need to implement both a DynaClass and a DynaBean ... 
and could probably start with how WrapDynaClass and WrapDynaBean provide 
wrappers for POJOs.

Craig



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


Re: wrap a Map into a DynaBean

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
It is really easier just to write your own tag for these specialty 
needs.  Tag writing is relatively easy to do.

At 01:03 AM 4/30/2004, Marco Mistroni wrote:
>Hi all,
>         Is there any way, using beanutils package, to 'wrap' a Map
>Into a DynaBean or something similar?
> >From errors that I have, answer is no, but maybe some of you know
>Some alternatives..
>Issue is that I am receiving different objects from my db layer, and
>I am wrapping them into a DynaBean to avoid calling specific methods
>For retrieving properties.
>But in one case out of 10 I am receiving an HashMap, and it looks like
>I cannot wrap an HashMap with a DynaBean
>
>Anyone has any suggestions?
>
>Thanx in advance and regards
>         Marco
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org