OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 180
Line 125... Line 125...
125
            final String targetClass = getAttributeValue(elem, "class");
125
            final String targetClass = getAttributeValue(elem, "class");
126
            final Object target = targetClass == null ? context.peek() : Class.forName(targetClass);
126
            final Object target = targetClass == null ? context.peek() : Class.forName(targetClass);
127
            final String propAttr = getAttributeValue(elem, "property");
127
            final String propAttr = getAttributeValue(elem, "property");
128
            final String indexAttr = getAttributeValue(elem, "index");
128
            final String indexAttr = getAttributeValue(elem, "index");
129
            final String methodAttr = getAttributeValue(elem, "method");
129
            final String methodAttr = getAttributeValue(elem, "method");
-
 
130
            final String fieldAttr = getAttributeValue(elem, "field");
130
 
131
 
131
            // statement or expression
132
            // statement or expression
132
            final Object res = evalContainer(elem, context, ids, new ExnTransformer<List<Object>, Object, Exception>() {
133
            final Object res = evalContainer(elem, context, ids, new ExnTransformer<List<Object>, Object, Exception>() {
133
                @Override
134
                @Override
134
                public Object transformChecked(List<Object> args) throws Exception {
135
                public Object transformChecked(List<Object> args) throws Exception {
Line 155... Line 156...
155
                            res = invoke(Array.class, methodName, args);
156
                            res = invoke(Array.class, methodName, args);
156
                        } else
157
                        } else
157
                            throw new IllegalStateException("use index with neither List nor array: " + target);
158
                            throw new IllegalStateException("use index with neither List nor array: " + target);
158
                    } else if (methodAttr != null) {
159
                    } else if (methodAttr != null) {
159
                        res = invoke(target, methodAttr, args);
160
                        res = invoke(target, methodAttr, args);
-
 
161
                    } else if (fieldAttr != null) {
-
 
162
                        res = ((Class<?>) target).getField(fieldAttr).get(null);
160
                    } else
163
                    } else {
161
                        res = getCtor((Class<?>) target, args).newInstance(args.toArray());
164
                        res = getCtor((Class<?>) target, args).newInstance(args.toArray());
-
 
165
                    }
162
                    return res;
166
                    return res;
163
                }
167
                }
164
            });
168
            });
165
            // not very functional but it works
169
            // not very functional but it works
166
            if (id != null)
170
            if (id != null)
Line 281... Line 285...
281
        final CacheResult<Constructor<?>> cacheRes = cacheCtor.check(key);
285
        final CacheResult<Constructor<?>> cacheRes = cacheCtor.check(key);
282
        if (cacheRes.getState() == CacheResult.State.VALID)
286
        if (cacheRes.getState() == CacheResult.State.VALID)
283
            return cacheRes.getRes();
287
            return cacheRes.getRes();
284
 
288
 
285
        final Constructor res = findCtor(clazz, actualClasses);
289
        final Constructor res = findCtor(clazz, actualClasses);
-
 
290
        if (res == null)
-
 
291
            throw new IllegalStateException("No constructor in " + clazz + " for arguments " + actualClasses);
286
        cacheCtor.put(key, res);
292
        cacheCtor.put(key, res);
287
        return res;
293
        return res;
288
    }
294
    }
289
 
295
 
290
    private static final List<Class<?>> objectsToClasses(List<Object> actualArgs) {
296
    private static final List<Class<?>> objectsToClasses(List<Object> actualArgs) {