java - Can I invoke some method from XML mapping file in Hibernate? -


i have xml mapping file. can invoke method it?

idea:

<?xml version="1.0" encoding="utf-8"?>  <!doctype hibernate-mapping     public "-//hibernate/hibernate mapping dtd 3.0//en"     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  <hibernate-mapping>     <class name="pkg.someitem" table="item">          <id name="itemid" column="itemid" unsaved-value="0">             <generator class="increment"/>         </id>          <property name="filesize" invoke="myfilemanager.getactualfilesize(itemid);"/>     </class> </hibernate-mapping> 

use reflection:

// xml parsing code incorrect; illustration purposes string classname = xml.getelement("class").getattribute("name").getvalue(); string methodname = xml.getattribute("invoke").getvalue();  // generic instance of class class<?> c = class.forname(classname); object o = c.newinstance();  // cast instance // (although 'f' of type object, show methods of desired class!) object f = c.cast(o);  method[] methods = f.getclass().getmethods();  (method method:methods) {     if (method.equals(methodname))     {         // invoke desired method         method.invoke(arg0, arg1);     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -