{"action":"created","comment":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/comments/33386425","id":33386425,"diff_hunk":"@@ -0,0 +1,146 @@\n+/*\n+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com\n+ * The software in this package is published under the terms of the CPAL v1.0\n+ * license, a copy of which has been included with this distribution in the\n+ * LICENSE.txt file.\n+ */\n+package org.mule.module.extension.internal.runtime.resolver;\n+\n+import static org.mule.util.Preconditions.checkArgument;\n+import org.mule.api.MuleContext;\n+import org.mule.api.MuleEvent;\n+import org.mule.api.MuleException;\n+import org.mule.api.transformer.MessageTransformer;\n+import org.mule.api.transformer.Transformer;\n+import org.mule.api.transformer.TransformerException;\n+import org.mule.extension.introspection.DataType;\n+import org.mule.transformer.types.DataTypeFactory;\n+import org.mule.util.AttributeEvaluator;\n+\n+import java.lang.reflect.ParameterizedType;\n+import java.lang.reflect.Type;\n+\n+import org.apache.commons.lang.StringUtils;\n+\n+/**\n+ * A {@link ValueResolver} which evaluates a MEL expressions and tries\n+ * to ensure that the output is always of a certain type.\n+ * <p/>\n+ * If the MEL expression does not return a value of that type, then it\n+ * tries to locate a {@link Transformer} which can do the transformation\n+ * from the obtained type to the expected one.\n+ * <p/>\n+ * It resolves the expressions by making use of the {@link AttributeEvaluator}\n+ * so that it's compatible with simple expressions and templates alike\n+ *\n+ * @param <T>\n+ * @since 3.7.0\n+ */\n+public class EvaluateAndTransformValueResolver<T> implements ValueResolver<T>\n+{\n+\n+    private final DataType expectedType;\n+    private final AttributeEvaluator evaluator;\n+    private MuleContext muleContext;\n+    private EvaluatorDelegate delegate = new CaptureContextEvaluatorDelegate();\n+\n+    public EvaluateAndTransformValueResolver(String expression, DataType expectedType)\n+    {\n+        checkArgument(!StringUtils.isBlank(expression), \"Expression cannot be blank or null\");\n+        checkArgument(expectedType != null, \"expected type cannot be null\");\n+\n+        this.expectedType = expectedType;\n+        evaluator = new AttributeEvaluator(expression);\n+    }\n+\n+    @Override\n+    public T resolve(MuleEvent event) throws MuleException\n+    {\n+        T evaluated = (T) delegate.resolveValue(event);\n+        return evaluated != null ? transform(evaluated, event) : null;\n+    }\n+\n+    private T transform(T object, MuleEvent event) throws MuleException\n+    {\n+        if (expectedType.getRawType().isInstance(object))\n+        {\n+            return object;\n+        }\n+\n+        Type expectedClass = expectedType.getRawType();\n+        if (expectedClass instanceof ParameterizedType)\n+        {\n+            expectedClass = ((ParameterizedType) expectedClass).getRawType();\n+        }\n+\n+        org.mule.api.transformer.DataType sourceDataType = DataTypeFactory.create(object.getClass());\n+        org.mule.api.transformer.DataType targetDataType = DataTypeFactory.create((Class) expectedClass);\n+\n+        Transformer transformer;\n+        try\n+        {\n+            transformer = muleContext.getRegistry().lookupTransformer(sourceDataType, targetDataType);\n+        }\n+        catch (TransformerException e)\n+        {\n+            // no transformer found. Return the object we have and let's hope for the best\n+            return object;\n+        }\n+\n+        if (transformer != null)","path":"modules/extensions-support/src/main/java/org/mule/module/extension/internal/runtime/resolver/EvaluateAndTransformValueResolver.java","position":90,"original_position":90,"commit_id":"b5caf4587308059931df27df8471d78d02e0c776","original_commit_id":"b5caf4587308059931df27df8471d78d02e0c776","user":{"login":"marianogonzalez","id":1272771,"avatar_url":"https://avatars.githubusercontent.com/u/1272771?v=3","gravatar_id":"","url":"https://api.github.com/users/marianogonzalez","html_url":"https://github.com/marianogonzalez","followers_url":"https://api.github.com/users/marianogonzalez/followers","following_url":"https://api.github.com/users/marianogonzalez/following{/other_user}","gists_url":"https://api.github.com/users/marianogonzalez/gists{/gist_id}","starred_url":"https://api.github.com/users/marianogonzalez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marianogonzalez/subscriptions","organizations_url":"https://api.github.com/users/marianogonzalez/orgs","repos_url":"https://api.github.com/users/marianogonzalez/repos","events_url":"https://api.github.com/users/marianogonzalez/events{/privacy}","received_events_url":"https://api.github.com/users/marianogonzalez/received_events","type":"User","site_admin":false},"body":"no. fixed","created_at":"2015-06-26T19:12:37Z","updated_at":"2015-06-26T19:12:37Z","html_url":"https://github.com/mulesoft/mule/pull/1534#discussion_r33386425","pull_request_url":"https://api.github.com/repos/mulesoft/mule/pulls/1534","_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments/33386425"},"html":{"href":"https://github.com/mulesoft/mule/pull/1534#discussion_r33386425"},"pull_request":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/1534"}}},"pull_request":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/1534","id":32337561,"html_url":"https://github.com/mulesoft/mule/pull/1534","diff_url":"https://github.com/mulesoft/mule/pull/1534.diff","patch_url":"https://github.com/mulesoft/mule/pull/1534.patch","issue_url":"https://api.github.com/repos/mulesoft/mule/issues/1534","number":1534,"state":"open","locked":false,"title":"REVIEW EXT-API... DO NOT MERGE!!!!!!!!","user":{"login":"marianogonzalez","id":1272771,"avatar_url":"https://avatars.githubusercontent.com/u/1272771?v=3","gravatar_id":"","url":"https://api.github.com/users/marianogonzalez","html_url":"https://github.com/marianogonzalez","followers_url":"https://api.github.com/users/marianogonzalez/followers","following_url":"https://api.github.com/users/marianogonzalez/following{/other_user}","gists_url":"https://api.github.com/users/marianogonzalez/gists{/gist_id}","starred_url":"https://api.github.com/users/marianogonzalez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marianogonzalez/subscriptions","organizations_url":"https://api.github.com/users/marianogonzalez/orgs","repos_url":"https://api.github.com/users/marianogonzalez/repos","events_url":"https://api.github.com/users/marianogonzalez/events{/privacy}","received_events_url":"https://api.github.com/users/marianogonzalez/received_events","type":"User","site_admin":false},"body":"you merge it -> you buy both pastries AND Ice cream","created_at":"2015-03-31T16:03:28Z","updated_at":"2015-06-26T19:12:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"efecf521af883136d11b86120aedd6eb75001016","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mulesoft/mule/pulls/1534/commits","review_comments_url":"https://api.github.com/repos/mulesoft/mule/pulls/1534/comments","review_comment_url":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mulesoft/mule/issues/1534/comments","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/b5caf4587308059931df27df8471d78d02e0c776","head":{"label":"mulesoft:ext-api-review","ref":"ext-api-review","sha":"b5caf4587308059931df27df8471d78d02e0c776","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","created_at":"2012-12-07T19:23:06Z","updated_at":"2015-06-24T12:32:05Z","pushed_at":"2015-06-26T09:55:22Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":460020,"stargazers_count":209,"watchers_count":209,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":264,"mirror_url":null,"open_issues_count":15,"forks":264,"open_issues":15,"watchers":209,"default_branch":"mule-3.x"}},"base":{"label":"mulesoft:mule-3.6.x","ref":"mule-3.6.x","sha":"256214089d1240cb837bb2b23343dc89f1a168ef","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","created_at":"2012-12-07T19:23:06Z","updated_at":"2015-06-24T12:32:05Z","pushed_at":"2015-06-26T09:55:22Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":460020,"stargazers_count":209,"watchers_count":209,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":264,"mirror_url":null,"open_issues_count":15,"forks":264,"open_issues":15,"watchers":209,"default_branch":"mule-3.x"}},"_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/1534"},"html":{"href":"https://github.com/mulesoft/mule/pull/1534"},"issue":{"href":"https://api.github.com/repos/mulesoft/mule/issues/1534"},"comments":{"href":"https://api.github.com/repos/mulesoft/mule/issues/1534/comments"},"review_comments":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/1534/comments"},"review_comment":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/1534/commits"},"statuses":{"href":"https://api.github.com/repos/mulesoft/mule/statuses/b5caf4587308059931df27df8471d78d02e0c776"}}}}