public static Object evaluate()

in src/main/java/org/apache/maven/plugin/doap/DoapUtil.java [735:803]


        public static Object evaluate(String expression, Object root, boolean trimRootToken) throws Exception {
            // if the root token refers to the supplied root object parameter, remove it.
            if (trimRootToken) {
                expression = expression.substring(expression.indexOf('.') + 1);
            }

            Object value = root;

            // ----------------------------------------------------------------------
            // Walk the dots and retrieve the ultimate value desired from the
            // MavenProject instance.
            // ----------------------------------------------------------------------

            StringTokenizer parser = new StringTokenizer(expression, ".");

            while (parser.hasMoreTokens()) {
                String token = parser.nextToken();
                if (value == null) {
                    return null;
                }

                StringTokenizer parser2 = new StringTokenizer(token, "[]");
                int index = -1;
                if (parser2.countTokens() > 1) {
                    token = parser2.nextToken();
                    try {
                        index = Integer.parseInt(parser2.nextToken());
                    } catch (NumberFormatException e) {
                        // ignore
                    }
                }

                final ClassMap classMap = getClassMap(value.getClass());

                final String methodBase = StringUtils.capitalizeFirstLetter(token);

                String methodName = "get" + methodBase;

                Method method = classMap.findMethod(methodName, CLASS_ARGS);

                if (method == null) {
                    // perhaps this is a boolean property??
                    methodName = "is" + methodBase;

                    method = classMap.findMethod(methodName, CLASS_ARGS);
                }

                if (method == null) {
                    return null;
                }

                value = method.invoke(value, OBJECT_ARGS);
                if (value == null) {
                    return null;
                }
                if (Collection.class.isAssignableFrom(value.getClass())) {
                    ClassMap classMap2 = getClassMap(value.getClass());

                    Method method2 = classMap2.findMethod("toArray", CLASS_ARGS);

                    value = method2.invoke(value, OBJECT_ARGS);
                }
                if (value.getClass().isArray()) {
                    value = ((Object[]) value)[index];
                }
            }

            return value;
        }