db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torque-...@db.apache.org
Subject [DB Torque Wiki] Updated: HarderTorqueFaq
Date Wed, 27 Oct 2004 12:33:17 GMT
   Date: 2004-10-27T05:33:17
   Editor: HansHülf <huelf@hhh.franken.de>
   Wiki: DB Torque Wiki
   Page: HarderTorqueFaq
   URL: http://wiki.apache.org/db-torque/HarderTorqueFaq

   This is my first entry in a Wiki of this kind. Sorry if I did something 'wrong'.

Change Log:

------------------------------------------------------------------------------
@@ -168,3 +168,68 @@
 
 RaphaelMankin
 
+There is a simple solution for creating all the BeanInfo classes for all Tables without too
much overhead.
+
+First, create an abstract base class. This base class constructs the property descriptor
array from the getFields() method. The getTheClass() method provides the class of your concrete
Table class derived from BaseObject.
+
+{{{
+
+package com.gsk.pmf;
+
+import java.beans.*;
+import java.util.*;
+
+/**
+ * @author Hans Hülf
+ */
+public abstract class TorqueBeanInfo extends SimpleBeanInfo {
+
+	abstract protected Class getTheClass();
+	abstract protected Collection getFields();
+	
+	public PropertyDescriptor[] getPropertyDescriptors()
+    {
+            try {
+            		PropertyDescriptor[] pdar = new PropertyDescriptor[getFields().size()];
+            		Iterator it = getFields().iterator();
+            		for (int i = 0; it.hasNext(); i++) {
+						String field = (String) it.next();
+	                    PropertyDescriptor pd = new PropertyDescriptor(field, getTheClass());
+	                    pdar[i]=pd;
+					}
+            		
+            		return pdar;
+            		
+            } catch (IntrospectionException e) {
+                    System.err.println("IntrospectionException"+e.getMessage());
+                    e.printStackTrace();
+            }
+            return null;
+    }
+
+}
+}}}
+
+Then you only have to subclass once for every BaseObject class you have. In this example
the above XML created a class called Modelevent (extends BaseModelevent (extends BaseObject)).

+
+{{{
+
+package com.gsk.pmf;
+
+import java.util.*;
+/**
+ * @author Hans Hülf
+ */
+public class ModeleventBeanInfo extends TorqueBeanInfo {
+	protected Class getTheClass() {
+		return Modelevent.class;
+	}
+	protected Collection getFields(){
+		return Modelevent.getFieldNames();
+	}
+}
+}}}
+
+The advantage of this method is that you don't have to change the BeanInfo classes after
the Table classes have changed. Only if you add new Tables you have to provide a new BeanInfo
class.
+
+HansHülf

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message