Revision: 17437
          http://sourceforge.net/p/gate/code/17437
Author:   ian_roberts
Date:     2014-02-26 15:12:08 +0000 (Wed, 26 Feb 2014)
Log Message:
-----------
When calculating a value from a string for parameters that are GATE resource
types, treat a null string as a null value rather than the previous behaviour
of picking the first loaded instance of the target type even when the supplied
value was null.

Modified Paths:
--------------
    gate/trunk/src/main/gate/creole/Parameter.java

Modified: gate/trunk/src/main/gate/creole/Parameter.java
===================================================================
--- gate/trunk/src/main/gate/creole/Parameter.java      2014-02-26 14:52:59 UTC 
(rev 17436)
+++ gate/trunk/src/main/gate/creole/Parameter.java      2014-02-26 15:12:08 UTC 
(rev 17437)
@@ -24,6 +24,7 @@
 import gate.Factory;
 import gate.FeatureMap;
 import gate.Gate;
+import gate.Resource;
 import gate.util.*;
 
 
@@ -111,7 +112,7 @@
     Object value = null;
 
     // get the Class for the parameter via Class.forName or CREOLE register
-    Class paramClass = getParameterClass();
+    Class<?> paramClass = getParameterClass();
     if(substituteClasses.containsKey(paramClass)) {
       paramClass = substituteClasses.get(paramClass);
     }
@@ -125,9 +126,9 @@
     if (Collection.class.isAssignableFrom(paramClass) &&
             !paramClass.isInterface()){
       // Create an collection object belonging to paramClass
-      Collection colection = null;
+      Collection<?> colection = null;
       try{
-        colection = (Collection)paramClass.getConstructor(new Class[]{}).
+        colection = paramClass.asSubclass(Collection.class).getConstructor(new 
Class[]{}).
                                   newInstance(new Object[]{});
       } catch(Exception ex){
           throw new ParameterException("Could not construct an object of type "
@@ -144,10 +145,10 @@
                                                       stringValue,";");
         while(strTokenizer.hasMoreTokens()){
           String itemStringValue = strTokenizer.nextToken();
-          colection.add(itemStringValue);
+          ((Collection<String>)colection).add(itemStringValue);
         }// End while
       }else{
-        Class itemClass = null;
+        Class<?> itemClass = null;
         try{
           itemClass = Gate.getClassLoader().loadClass(itemClassName);
         }catch(ClassNotFoundException e){
@@ -173,7 +174,7 @@
             typeName);
           }// End try
           // Add the item value object to the collection
-          colection.add(itemValue);
+          ((Collection<Object>)colection).add(itemValue);
         }// End while
       }// End if(itemClassName == null)
       return colection;
@@ -190,7 +191,7 @@
       }
       else {
         try{
-          fm = (FeatureMap)paramClass.getConstructor(new Class[]{}).
+          fm = paramClass.asSubclass(FeatureMap.class).getConstructor(new 
Class[]{}).
                                     newInstance(new Object[]{});
         } catch(Exception ex){
             throw new ParameterException("Could not construct an object of 
type "
@@ -227,7 +228,7 @@
       }
       else {
         try {
-          value = Enum.valueOf(paramClass, stringValue);
+          value = Enum.valueOf(paramClass.asSubclass(Enum.class), stringValue);
         }
         catch(IllegalArgumentException e) {
           throw new ParameterException("Invalid enum constant name "
@@ -284,15 +285,19 @@
       }
     } else {
       // non java types
-      if(resData == null)
-        resData = (ResourceData) Gate.getCreoleRegister().get(typeName);
-      if(resData == null){
-        //unknown type
-        return null;
+      // null string value means null target value
+      if(stringValue != null) {
+        // otherwise, if it's a GATE resource type pick the first registered 
instance 
+        if(resData == null)
+          resData = (ResourceData) Gate.getCreoleRegister().get(typeName);
+        if(resData == null){
+          //unknown type
+          return null;
+        }
+  
+        List<Resource> instantiations = resData.getInstantiations();
+        if(! instantiations.isEmpty()) value = instantiations.get(0);
       }
-
-      List instantiations = resData.getInstantiations();
-      if(! instantiations.isEmpty()) value = instantiations.get(0);
     }
 
     return value;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to