[
https://issues.apache.org/jira/browse/JEXL-379?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henri Biestro closed JEXL-379.
------------------------------
> Allow new to use class identifier
> ---------------------------------
>
> Key: JEXL-379
> URL: https://issues.apache.org/jira/browse/JEXL-379
> Project: Commons JEXL
> Issue Type: Improvement
> Affects Versions: 3.2.1
> Reporter: Henri Biestro
> Assignee: Henri Biestro
> Priority: Major
> Fix For: 3.3
>
>
> WHAT:
> The Java syntax for new is easier/nicer to use than the current JEXL one that
> forces to use a fully qualified class name (FQCN) to instantiate an object.
> The improvement will allow using the Java new syntax using either an FQCN (as
> identifier) or just an identifier.
> HOW:
> The grammar is augmented to allow the 'new qualified_class_name(<args>)'
> syntax. Provision is to be made to allow an 'import'-like mechanism so class
> identifiers can be resolved (JexlContext extension).
> The pragma 'jexl.import' allows the declaration of packages to visit to find
> the fully-qualified class name from a simple class name.
> Canonical example is:
> {code}
> //-------------------------------------------------------------------
> // send a POST Request
> //-------------------------------------------------------------------
> #pragma jexl.import java.net
> #pragma jexl.import java.io
> {
> "execute" : (sURL, jsonData) -> {
> let url = new URL(sURL);
> let con = url.openConnection();
> con.setRequestMethod("POST");
> con.setRequestProperty("Accept", "application/json");
> // send data
> if (jsonData != null) {
> con.setRequestProperty("Content-Type", "application/json; utf-8");
> con.setDoOutput(true);
> let outputStream = con.getOutputStream();
> let input = jsonData.getBytes("utf-8");
> outputStream.write(input, 0, size(input));
> }
> // read response
> let responseCode = con.getResponseCode();
> let inputStream = con.getInputStream();
> let response = new StringBuffer();
> if (inputStream != null) {
> let in = new BufferedReader(new InputStreamReader(inputStream));
> var inputLine = "";
> while ((inputLine = in.readLine()) != null) {
> response.append(inputLine);
> }
> in.close();
> }
> response.toString();
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)