Highlighted

Reserved CF word used in java library

New Here ,
Jul 03, 2019

Copy link to clipboard

Copied

I need to use a java library from Coldfusion 2018.  Everything's great except one method in the library is named ".is()", and Coldfusion throws an error on it thinking it's an operator.  I cannot modify the java library to rename this method.  Is there any other solution to calling it from Coldfusion?

Thanks,

Views

128

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Reserved CF word used in java library

New Here ,
Jul 03, 2019

Copy link to clipboard

Copied

I need to use a java library from Coldfusion 2018.  Everything's great except one method in the library is named ".is()", and Coldfusion throws an error on it thinking it's an operator.  I cannot modify the java library to rename this method.  Is there any other solution to calling it from Coldfusion?

Thanks,

Views

129

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 03, 2019 0
New Here ,
Jul 04, 2019

Copy link to clipboard

Copied

stumbled upon an interesting scenario

this works, Coldfusion interprets "is" as a method:

<cfset local.tsrequest = CreateObject("java", "com.braintreegateway.TransactionSearchRequest").init().customerId()>

<cfset local.tsrequest = local.tsrequest.is(#arguments.customer_id#)>

but this fails, Coldfusion interprets "is" as an operator:

<cfset local.tsrequest = CreateObject("java", "com.braintreegateway.TransactionSearchRequest").init()>

<cfset local.tsrequest = local.tsrequest.customerId().is(#arguments.customer_id#)>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 04, 2019 0
BKBK LATEST
Adobe Community Professional ,
Jul 07, 2019

Copy link to clipboard

Copied

adam20174248  wrote

I need to use a java library from Coldfusion 2018.  Everything's great except one method in the library is named ".is()", and Coldfusion throws an error on it thinking it's an operator.  I cannot modify the java library to rename this method. 

Even if you could, it would be unwise to do so. Modifying a library might lead to unexpected errors. (Recall the O in object-oriented programming's SOLID principles: classes should be Open for extension, but closed for modification)

I would suggest you go with what works. For example, your first code snippet. I suspect it works because, in it, the method is() is called directly on an object defined in integrated Java code. Nevertheless, that is rather circumstantial and therefore unreliable as a solution.

You could create a better, lasting solution as follows:

  • create a java class, say, CFTransactionSearchRequest.class. It imports com.braintreegateway.TransactionSearchRequest and has a method, say, cfIs(). It's unclear from your post whether CustomerId is an object. If it is, you may also have to import its class;
  • cfIs accepts 2 arguments: one of type TransactionSearchRequest, the other of the CustomerId type. The method cfIs has the same return-type as is();
  • compile the Java code and add the new class to ColdFusion's classpath;
  • use the class as follows, for calls to is();

        <cfset local.tsrequest         = createObject("java", "com.braintreegateway.TransactionSearchRequest").init()>

        <cfset local.CFtsrequest    = createObject("java", "CFTransactionSearchRequest")>

        <cfset local.requestResult = local.CFtsrequest.cfIs(local.tsrequest, arguments.customer_id)>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 07, 2019 0