Calling inner class of a Java Class in Railo

Thanks to the Railo documentation on Github, I finally found the answer I was searching for...

Question: how to call an inner Java class of a Java class with Railo?

Answer: use a $ sign: createObject("java", "main.java.class$innerClass")

Long version:

I was busy implementing the javaEWSApi (MS Exchange Web Services API) into a new mobile project, but got stuck on getting the unread-count for the user’s Inbox. An example online said to use the following Java code:

// Get five items from mail box
ItemView view = new ItemView(5);
//Set Filter to Read UnRead emails
SearchFilter itemFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, true);
// Search Inbox
FindItemsResults<item> findResults = service.findItems(WellKnownFolderName.Inbox,itemFilter,view);
// iterate thru items
for (Item item : findResults.getItems()) {
     System.out.println(item.getSubject());
}

All fine and good it seemed. Just change “new ItemView” and “new SearchFilter” to createObject("java", "...") calls, and I would be good to go. Alas, there was a problem.
This is the cfscript code I first created:

public Numeric function getUnreadCount()
{
    local.exchangeService = getExchangeServiceForCurrentUser();

    // Get an item from mail box
    local.itemView = createObject("java", "#variables.msClassPath#ItemView").init(1);

    //Set Filter to Read UnRead emails
    local.msgSchema = createObject("java", "#variables.msClassPath#EmailMessageSchema");
local.itemFilter = createObject("java", "microsoft.exchange.webservices.data.SearchFilter").IsEqualTo(local.msgSchema.IsRead, false);

    // Search Inbox
    local.inbox = createObject("java", "#variables.msClassPath#WellKnownFolderName").Inbox;
    local.findResults = local.exchangeService.findItems(local.inbox, local.itemFilter, local.itemView);
    return local.findResults.getTotal()
}

The code threw an error on the highlighted line, with error: “No matching Method for IsEqualTo(microsoft.exchange.webservices.data.BoolPropertyDefinition, boolean) found for microsoft.exchange.webservices.data.SearchFilter

After quite some googling and trying different constructs, I checked the java source code, and saw the following:

SearchFilter.java
/**************************************************************************
 * copyright file="SearchFilter.java" company="Microsoft"
 *     Copyright (c) Microsoft Corporation.  All rights reserved.
 *
 * Defines the SearchFilter.java.
 **************************************************************************/
public abstract class SearchFilter extends ComplexProperty {
[.........]
    public static class IsEqualTo extends RelationalFilter {
    [.............]
        public IsEqualTo(PropertyDefinitionBase propertyDefinition,
                Object value) {
            super(propertyDefinition, value);
        }
    [...............]
    }
[..............]
}

What was new to me, was the class definition “IsEqualTo” within the class SearchFilter.
But it was a great starting point for a new web search, and led me to https://github.com/getrailo/railo/wiki/Tutorial--Using-Java-in-Railo:

because Occur is an Inner Class of BooleanClause, you will need to reference it via the $ delimiter [...], so the full path for the Occur inner class is org.apache.lucene.search.BooleanClause$Occur
<cfset objBooleanClauseOccur        = createObject( "java", "org.apache.lucene.search.BooleanClause$Occur" )>

Awesome! Lesson learned. Thanks to the Railo team, for creating this invaluable documentation page :-D

del.icio.us Digg StumbleUpon Facebook Technorati Fav reddit Google Bookmarks
| Viewed 7081 times

No comments yet.

(will not be published)
Leave this field empty