activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1160904 - /activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
Date Tue, 23 Aug 2011 22:12:26 GMT
Author: chirino
Date: Tue Aug 23 22:12:25 2011
New Revision: 1160904

URL: http://svn.apache.org/viewvc?rev=1160904&view=rev
Log:
Add back field traversal and method calling support.

Modified:
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala?rev=1160904&r1=1160903&r2=1160904&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
Tue Aug 23 22:12:25 2011
@@ -38,6 +38,7 @@ import javax.management.openmbean.Compos
 import javax.management.remote.rmi._RMIConnection_Stub
 import org.josql.{QueryResults, Query}
 import java.util.Collections
+import java.util.regex.Pattern
 
 /**
  * <p>
@@ -322,14 +323,26 @@ case class BrokerResource() extends Reso
   }
 
   class JosqlHelper {
+
     def get(o:AnyRef, name:String):AnyRef = {
-      try {
-        o.getClass().getField(name).get(o)
-      } catch {
-        case e:Throwable =>
-          e.printStackTrace()
-          null
+
+      def invoke(o:AnyRef, name:String):Option[AnyRef] = {
+        try {
+          if(name.endsWith("()")) {
+            Option(o.getClass().getMethod(name.stripSuffix("()")).invoke(o))
+          } else {
+            Option(o.getClass().getField(name).get(o))
+          }
+        } catch {
+          case e:Throwable =>
+            None
+        }
       }
+
+      var parts = name.split(Pattern.quote("."))
+      parts.foldLeft(Option(o)) { case(memo, field)=>
+        memo.flatMap(invoke(_, field))
+      }.getOrElse(null)
     }
   }
 



Mime
View raw message