Author: mmichaud
Date: 2009-06-11 10:15:34 -0700 (Thu, 11 Jun 2009)
New Revision: 16925

Modified:
   core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractHandler.java
   
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
   core3/work-api/trunk/src/main/java/org/cytoscape/work/Handler.java
   core3/work-api/trunk/src/main/java/org/cytoscape/work/HandlerFactory.java
Log:
[]

Modified: 
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractHandler.java
===================================================================
--- core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractHandler.java  
2009-06-11 17:13:22 UTC (rev 16924)
+++ core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractHandler.java  
2009-06-11 17:15:34 UTC (rev 16925)
@@ -2,6 +2,7 @@
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.List;
 
 
@@ -18,9 +19,13 @@
 public abstract class AbstractHandler implements Handler {
 
        protected Field f;
+       protected Method gmethod;
+       protected Method smethod;
        protected Method m;
        protected Object o;
        protected Tunable t;
+       protected Tunable tg;
+       protected Tunable ts;
        protected List<HandlerListener> listeners;
        
 
@@ -34,6 +39,7 @@
                this.f = f;
                this.o = o;
                this.t = t;
+               listeners = new ArrayList<HandlerListener>();
        }
 
        
@@ -49,7 +55,25 @@
                this.t = t;
        }
 
+       
        /**
+        * Handler for 2 Methods values
+        * @param getmethod method that has been annotated as a <i>getter</i>
+        * @param setmethod method that has been annotated as a <i>setter</i>
+        * @param o object contained in methods
+        * @param tg tunable associated to <code>gmethod</code> 
+        * @param ts tunable associated to <code>smethod</code> 
+        */
+       public AbstractHandler(Method getmethod, Method setmethod, Object o, 
Tunable tg, Tunable ts){
+               this.gmethod = getmethod;
+               this.smethod = setmethod;
+               this.o = o;
+               this.tg = tg;
+               this.ts = ts;
+       }
+
+       
+       /**
         * To get <code>Field f</code>
         * @return field component from the handler
         */
@@ -67,6 +91,24 @@
        }
 
        /**
+        * To get <code>Method gmethod</code>
+        * @return method component from the handler
+        */
+       public Method getGetMethod() {
+               return gmethod;
+       }
+       
+       /**
+        * To get <code>Method smethod</code>
+        * @return method component from the handler
+        */
+       public Method getSetMethod() {
+               return smethod;
+       }
+
+       
+       
+       /**
         * To get <code>Object o</code> 
         * @return object component from the handler
         */
@@ -76,6 +118,21 @@
 
        
        /**
+        * To get <code>Tunable tg</code>
+        * @return tunable component from the handler
+        */
+       public Tunable getGetTunable() {
+               return tg;
+       }
+       
+       /**
+        * To get <code>Tunable ts</code>
+        * @return tunable component from the handler
+        */
+       public Tunable getSetTunable() {
+               return ts;
+       }
+       /**
         * To get <code>Tunable t</code>
         * @return tunable component from the handler
         */

Modified: 
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
===================================================================
--- 
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
       2009-06-11 17:13:22 UTC (rev 16924)
+++ 
core3/work-api/trunk/src/main/java/org/cytoscape/work/AbstractTunableInterceptor.java
       2009-06-11 17:15:34 UTC (rev 16925)
@@ -39,7 +39,6 @@
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -74,7 +73,7 @@
        }
 
        /**
-        *      To detect the Field and Method annotated as 
<code>Tunable</code>, create a <code>Handler</code> for each from the factory, 
and store it.
+        *      To detect the Field and Methods annotated as 
<code>Tunable</code>, create a <code>Handler</code> for each from the factory, 
and store it.
         * @param obj A class that contains <code>Tunable</code> that need to 
be caught to interact with the users
         */
        public void loadTunables(Object obj) {
@@ -102,7 +101,14 @@
                                        }
                                }
                        }
+
+                       Map<String, Method> setMethodsMap = new 
HashMap<String,Method>();
+                       Map<String, Method> getMethodsMap = new 
HashMap<String,Method>();
                        
+                       Map<String, Tunable> getTunableMap = new 
HashMap<String,Tunable>();
+                       Map<String, Tunable> setTunableMap = new 
HashMap<String,Tunable>();
+
+                       
                        // Find each public method in the class.
                        for (Method method : obj.getClass().getMethods()) {
        
@@ -110,15 +116,31 @@
                                if (method.isAnnotationPresent(Tunable.class)) {
                                        try {
                                                Tunable tunable = 
method.getAnnotation(Tunable.class);
-                                               
-                                               // Get a handler for this 
particular field type and
-                                               // add it to the list.
-                                               H handler = 
factory.getHandler(method,obj,tunable);
-       
-                                               if ( handler != null ) {
-                                                       handlerList.put( 
method.getName(), handler ); 
+                                               
if(method.getName().startsWith("get")){
+                                                       
getMethodsMap.put(method.getName().substring(3),method);
+                                                       
getTunableMap.put(method.getName().substring(3),tunable);
+                                                       
if(setMethodsMap.containsKey(method.getName().substring(3))){
+                                                               //get a handler 
with the getMethod and setMethod
+                                                               H handler = 
factory.getHandler(getMethodsMap.get(method.getName().substring(3)),setMethodsMap.get(method.getName().substring(3)),
 obj, 
getTunableMap.get(method.getName().substring(3)),setTunableMap.get(method.getName().substring(3)));
+                                                               if ( handler != 
null ) {
+                                                                       
handlerList.put( "getset" + method.getName().substring(3), handler ); 
+                                                               }
+                                                       }
                                                }
-       
+                                               else 
if(method.getName().startsWith("set")){
+                                                       
setMethodsMap.put(method.getName().substring(3),method);
+                                                       
setTunableMap.put(method.getName().substring(3),tunable);
+                                                       
if(getMethodsMap.containsKey(method.getName().substring(3))){
+                                                               //get a handler 
with the getMethod and setMethod
+                                                               H handler = 
factory.getHandler(getMethodsMap.get(method.getName().substring(3)),setMethodsMap.get(method.getName().substring(3)),
 obj, 
getTunableMap.get(method.getName().substring(3)),setTunableMap.get(method.getName().substring(3)));
+                                                               //add it to the 
list
+                                                               if ( handler != 
null ) {
+                                                                       
handlerList.put( "getset" + method.getName().substring(3), handler ); 
+                                                               }
+                                                       }
+                                               }
+                                               else throw new Exception("the 
name of the method has to start with \"set\" or \"get\"");
+
                                        } catch (Throwable ex) {
                                                System.out.println("tunable 
method intercept failed: " + method.toString() );
                                                ex.printStackTrace();
@@ -126,8 +148,28 @@
                                }
                        }
 
+//                             if (method.isAnnotationPresent(Tunable.class)) {
+//                                     try {
+//                                             Tunable tunable = 
method.getAnnotation(Tunable.class);
+//                                             
+//                                             // Get a handler for this 
particular field type and
+//                                             // add it to the list.
+//                                             H handler = 
factory.getHandler(method,obj,tunable);
+//     
+//                                             if ( handler != null ) {
+//                                                     handlerList.put( 
method.getName(), handler ); 
+//                                             }
+//     
+//                                     } catch (Throwable ex) {
+//                                             System.out.println("tunable 
method intercept failed: " + method.toString() );
+//                                             ex.printStackTrace();
+//                                     }
+//                             }
+
                        handlerMap.put(obj, handlerList);
-               } //End of the deleted Loop
+               }
+               else throw new IllegalArgumentException("THE COMMAND IS 
EMPTY\nProvide something!");
+
        }
 
        /**

Modified: core3/work-api/trunk/src/main/java/org/cytoscape/work/Handler.java
===================================================================
--- core3/work-api/trunk/src/main/java/org/cytoscape/work/Handler.java  
2009-06-11 17:13:22 UTC (rev 16924)
+++ core3/work-api/trunk/src/main/java/org/cytoscape/work/Handler.java  
2009-06-11 17:15:34 UTC (rev 16925)
@@ -45,11 +45,37 @@
        
        /**
         * To get the Handler's Tunable
-        * @return Tuanble
+        * @return Tunable
         */
        Tunable getTunable();
        
+       
        /**
+        * To get the handler's GetMethod
+        * @return Method
+        */
+       Method getGetMethod();
+       /**
+        * To get the handler's SetMethod
+        * @return Method
+        */
+       Method getSetMethod();
+       
+       /**
+        * To get the Handler's GetTunable
+        * @return Tunable
+        */
+       Tunable getGetTunable();
+
+       /**
+        * To get the Handler's SetTunable
+        * @return Tunable
+        */
+       Tunable getSetTunable();
+
+       
+       
+       /**
         * To add a <code>HandlerListener</code> to the <code>Handler</code>
         * @param listener      Listener added to the <code>Handler</code>
         */

Modified: 
core3/work-api/trunk/src/main/java/org/cytoscape/work/HandlerFactory.java
===================================================================
--- core3/work-api/trunk/src/main/java/org/cytoscape/work/HandlerFactory.java   
2009-06-11 17:13:22 UTC (rev 16924)
+++ core3/work-api/trunk/src/main/java/org/cytoscape/work/HandlerFactory.java   
2009-06-11 17:15:34 UTC (rev 16925)
@@ -34,4 +34,16 @@
         */
         H getHandler(Method m, Object o, Tunable t);
         
+        
+       /**
+        * This method returns a <code>Handler</code> for the Methods GetMethod 
and SetMethod annotated as <code>Tunable</code>
+        * 
+        * @param gmethod Method that need to have a <code>Handler</code>, 
coupled with the <code>smethod</code>
+        * @param smethod Method that need to have a <code>Handler</code>, 
coupled with the <code>gmethod</code>
+        * @param o Object that is being used inside the Methods
+        * @param tg Tunable that contains all the information concerning the 
getMethod
+        * @param ts Tunable that contains all the information concerning the 
setMethod
+        * @return H The created <code>Handler</code>
+        */
+       H getHandler(Method gmethod, Method smethod, Object o, Tunable tg, 
Tunable ts);  
 }
\ No newline at end of file


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to