empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1331363 - /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/DBELResolver.java
Date Fri, 27 Apr 2012 11:40:15 GMT
Author: doebele
Date: Fri Apr 27 11:40:15 2012
New Revision: 1331363

URL: http://svn.apache.org/viewvc?rev=1331363&view=rev
Log: (empty)

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/DBELResolver.java

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/DBELResolver.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/DBELResolver.java?rev=1331363&r1=1331362&r2=1331363&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/DBELResolver.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/DBELResolver.java
Fri Apr 27 11:40:15 2012
@@ -19,6 +19,7 @@
 package org.apache.empire.jsf2.app;
 
 import java.beans.FeatureDescriptor;
+import java.lang.reflect.Field;
 import java.util.Iterator;
 
 import javax.el.ELContext;
@@ -26,7 +27,7 @@ import javax.el.ELResolver;
 import javax.faces.context.FacesContext;
 
 import org.apache.empire.commons.StringUtils;
-import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBColumnExpr;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBRowSet;
 import org.apache.empire.exceptions.NotSupportedException;
@@ -69,7 +70,9 @@ public class DBELResolver extends ELReso
         if (base instanceof DBRowSet)
         {   // Find matching column
             String   name = StringUtils.toString(property);
-            DBColumn column = ((DBRowSet)base).getColumn(name);
+            DBColumnExpr column = ((DBRowSet)base).getColumn(name);
+            if (column==null)
+                column = findExpressionField(base, name); 
             if (column!=null)
                 context.setPropertyResolved(true); 
             else
@@ -99,6 +102,48 @@ public class DBELResolver extends ELReso
         }
         return null;
     }
+    
+    public static DBColumnExpr findExpressionField(Object rowset, String property)
+    {
+        Class<?> c = rowset.getClass();
+        try
+        {   // Find a matching field name
+            Field f = c.getField(property);
+            if (f==null)
+                return null;
+            Object v = f.get(rowset);
+            if (v==null)
+            {   // invalid data type 
+                log.error("ELResolver error: Field '{}.{}' is null.", c.getSimpleName(),
property);
+                return null;
+            }    
+            if (!(v instanceof DBColumnExpr))
+            {   // invalid data type 
+                log.error("ELResolver error: Field '{}.{}' is not a DBColumnExpr.", c.getSimpleName(),
property);
+                return null;
+            }    
+            return ((DBColumnExpr)v);
+        }
+        catch (SecurityException e)
+        {
+            log.error("ELResolver error: Unable to access field "+c.getSimpleName()+"."+property,
e);
+            return null;
+        }
+        catch (NoSuchFieldException e)
+        {
+            return null;
+        }
+        catch (IllegalArgumentException e)
+        {
+            log.error("ELResolver error: Unable to access field "+c.getSimpleName()+"."+property,
e);
+            return null;
+        }
+        catch (IllegalAccessException e)
+        {
+            log.error("ELResolver error: Unable to access field "+c.getSimpleName()+"."+property,
e);
+            return null;
+        }
+    }
 
     @Override
     public boolean isReadOnly(ELContext context, Object base, Object property)



Mime
View raw message