• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Changeset
  • Next Changeset →

Changeset 1353

Show
Ignore:
Timestamp:
03/08/07 19:09:12 (21 months ago)
Author:
jmoore
Message:

#625 Better handling of Sets in IceMapper? and other minor fixes.

Location:
trunk/components/blitz/src
Files:
3 modified

  • ome/services/icy/impl/Interceptor.java (modified) (1 diff)
  • ome/services/icy/util/IceMethodInvoker.java (modified) (5 diffs)
  • omero/util/IceMapper.java (modified) (8 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/blitz/src/ome/services/icy/impl/Interceptor.java

    r1306 r1353  
    103103 
    104104    public Object invoke(MethodInvocation mi) throws Throwable { 
     105 
     106        Object retVal = null; 
     107        try { 
     108            Object[] args = mi.getArguments(); 
     109            Ice.Current __current = (Ice.Current) args[args.length-1]; 
     110            Object[] strippedArgs = strip(args); 
    105111         
    106         Object[] args = mi.getArguments(); 
    107         Ice.Current __current = (Ice.Current) args[args.length-1]; 
    108         Object[] strippedArgs = strip(args); 
    109          
    110         IceMapper mapper = new IceMapper(); 
    111         ServiceInterface service = servantHelper.getService(key,__current); 
    112         Object retVal = invoker.invoke(service, __current, mapper, strippedArgs); 
     112            IceMapper mapper = new IceMapper(); 
     113            ServiceInterface service = servantHelper.getService(key,__current); 
     114            retVal = invoker.invoke(service, __current, mapper, strippedArgs); 
     115        } catch (Throwable t) { 
     116            t.printStackTrace(); 
     117            throw t; 
     118        } 
    113119        servantHelper.throwIfNecessary(retVal); 
    114120        return retVal; 
  • trunk/components/blitz/src/ome/services/icy/util/IceMethodInvoker.java

    r1312 r1353  
    33import java.io.PrintWriter; 
    44import java.io.StringWriter; 
     5import java.lang.reflect.InvocationTargetException; 
    56import java.lang.reflect.Method; 
     7import java.util.ArrayList; 
    68import java.util.Collection; 
    79import java.util.Collections; 
    … …  
    151153            Object arg = args[i]; 
    152154            objs[i] = handleInput(mapper, p, arg); 
    153             if (null != objs[i] && !isPrimitive(p) && // FIXME need way to check autoboxing. 
    154                     !p.isAssignableFrom(objs[i].getClass())) { 
    155                 throw new IllegalStateException(String.format( 
    156                         "Cannot assign %s to %s",objs[i],p)); 
    157             } 
     155// This check duplicates what should be in handleInput 
     156//            if (null != objs[i] && !isPrimitive(p) && // FIXME need way to check autoboxing. 
     157//                    !p.isAssignableFrom(objs[i].getClass())) { 
     158//                throw new IllegalStateException(String.format( 
     159//                        "Cannot assign %s to %s",objs[i],p)); 
     160//            } 
    158161        } 
    159162 
    … …  
    215218            return mapper.convert((omero.sys.Parameters) arg); 
    216219        } else if (List.class.isAssignableFrom(p)) { 
    217             return mapper.reverse(new HashSet((List) arg)); // Necessary since Ice doesn't support Sets. 
     220            return mapper.reverse((Collection) arg); 
    218221        } else if (Set.class.isAssignableFrom(p)) { 
    219             return mapper.reverse((Collection) arg); 
     222            return mapper.reverse(new HashSet((Collection) arg)); // Necessary since Ice doesn't support Sets. 
    220223        } else if (Map.class.isAssignableFrom(p)) { 
    221224            return mapper.reverse((Map) arg); 
    … …  
    241244        } else if (EventContext.class.isAssignableFrom(type)) { 
    242245            return mapper.convert((EventContext)o); 
     246        } else if (Set.class.isAssignableFrom(type)) { 
     247            return mapper.map(new ArrayList((Set)o)); // Necessary since Ice doesn't support Sets. 
    243248        } else if (Collection.class.isAssignableFrom(type)) { 
    244249            return mapper.map((Collection) o); 
    … …  
    254259    protected Ice.UserException handleException(Throwable t) { 
    255260 
     261        // Getting rid of the reflection wrapper. 
     262        if (InvocationTargetException.class.isAssignableFrom(t.getClass())) { 
     263            t = t.getCause(); 
     264        } 
     265 
    256266        if (log.isInfoEnabled()) { 
    257267            log.info("Handling:", t); 
    258268        } 
    259  
     269         
    260270        Class c = t.getClass(); 
    261271        if (ome.conditions.ValidationException.class.isAssignableFrom(c)) { 
  • trunk/components/blitz/src/omero/util/IceMapper.java

    r1312 r1353  
    1313import java.lang.reflect.InvocationTargetException; 
    1414import java.lang.reflect.Method; 
     15import java.sql.Timestamp; 
    1516import java.util.ArrayList; 
    1617import java.util.Collection; 
    … …  
    176177    } 
    177178     
    178     public static ome.parameters.Parameters convert(Parameters params)  
     179    public ome.parameters.Parameters convert(Parameters params)  
    179180    throws ApiUsageException { 
    180181         
    … …  
    182183         
    183184        ome.parameters.Parameters p = new ome.parameters.Parameters(); 
    184         if (params.p != null) { 
    185             for (Object obj : params.p.values()) { 
     185        if (params.map != null) { 
     186            for (Object obj : params.map.values()) { 
    186187                QueryParam qp = (QueryParam) obj; 
    187188                p.add(convert(qp)); 
    188189            } 
    189190        } 
     191        if (params.filt != null) { 
     192            p.setFilter(convert(params.filt)); 
     193        } 
    190194        return p; 
    191195    } 
    192196 
    193     public static ome.parameters.QueryParameter convert(QueryParam qParam)  
     197    public ome.parameters.QueryParameter convert(QueryParam qParam)  
    194198    throws ApiUsageException { 
    195199         
    … …  
    229233                klass = Class.class; 
    230234                break; 
    231             case Type._objectType: // Not currently supported 
     235            case Type._timeType: 
     236                omero.RTime rt = qParam.timeVal; 
     237                value = (rt == null ? null : rt._null ? null : new Timestamp(rt.val.val)); 
     238                klass = Timestamp.class; 
     239                break; 
     240            case Type._objectType: 
     241                omero.RObject ro = qParam.objectVal; 
     242                value = (ro == null ? null : ro._null ? null : reverse(ro.val)); 
     243                klass = IObject.class; 
     244                break; 
    232245            default: 
    233246                throw new IllegalArgumentException("Unknown type code:" + t); 
    … …  
    284297    } 
    285298     
    286     public Object reverse(Object source) { 
     299    public Object reverse(Object source) throws ApiUsageException { 
    287300        if (source == null) { 
    288301            return null; 
    … …  
    293306        } else if (isImmutable(source)) { 
    294307            return source; 
     308        } else if (QueryParam.class.isAssignableFrom(source.getClass())) { 
     309            return convert((QueryParam)source); 
    295310        } else { 
    296311            throw new IllegalArgumentException("Don't know how to reverse "+source); 
    … …  
    325340            } 
    326341            target2model.put(source, target); 
    327             for (Object object : source) { 
    328                 target.add(reverse(object)); 
     342            try { 
     343                for (Object object : source) { 
     344                    target.add(reverse(object)); 
     345                }  
     346            } catch (ApiUsageException aue) { // FIXME reverse can't throw ServerErrors! 
     347                convertAndThrow(aue); 
    329348            } 
    330349        } 
    331350        return target; 
    332351    } 
    333      
     352 
    334353    public Map reverse(Map map) { 
     354        if (map == null) return null; 
    335355        Map<Object, Object> target = new HashMap<Object, Object>(); 
    336         for (Object key : map.keySet()) { 
    337             Object value = map.get(key); 
    338             Object targetKey = reverse(key); 
    339             Object targetValue = reverse(value); 
    340             target.put(targetKey, targetValue); 
     356        try { 
     357            for (Object key : map.keySet()) { 
     358                Object value = map.get(key); 
     359                Object targetKey = reverse(key); 
     360                Object targetValue = reverse(value); 
     361                target.put(targetKey, targetValue); 
     362            } 
     363        } catch (ApiUsageException aue) { 
     364            convertAndThrow(aue); 
    341365        } 
    342366        return target; 
    … …  
    405429    } 
    406430 
     431    private void convertAndThrow(ApiUsageException aue) { 
     432        InternalException ie = new InternalException(aue.getMessage()); 
     433        ie.setStackTrace(aue.getStackTrace()); 
     434    } 
     435     
    407436} 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/