>
> My OSGi method returns a Set<ProtocolType>.
>
In Nashorn you can iterate though any Java Collection.

var osgiOutput = callOsgiService( ... );

var protocolNames = []; // this is a JS array

for (item in osgiOutput) {

// 'item' is a ProtocolType Java object.

// You can call Java methods on it. For example if there is a
ProtocolType.getName()
method, then you can call it as 'item.getName()' or simply 'item.name'
protocolNames.push(item.name);

}

Read more on Nashorn extension [1]

[1] https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions

Thanks.

On Fri, Jun 10, 2016 at 12:33 PM, Hemika Kodikara <hem...@wso2.com> wrote:

> Hi All,
>
> I am invoking the callOSGiService method in nashorn to get a list of
> protocols thats in andes of MB.
>
> I am getting the following output after invoking the callOSGiService :
> [AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9]
>
> But need to convert it into a javascript array(Probably a String array).
> Need to bind it to a dropdown(select element).
>
> I tried JSON.parse, but getting the following errors :
>
> jjs> JSON.parse("[AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0,
> AMQP-0-9]");
> <shell>:1 SyntaxError: Invalid JSON: <json>:1:1 Expected json literal but
> found ident
> [AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9]
>  ^
>
> jjs> JSON.parse([AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9]);
> ECMAScript Exception: SyntaxError: <shell>:1:28 Expected an operand but
> found default
> JSON.parse([AMQP-0-10, MQTT-default, AMQP-0-91, AMQP-8-0, AMQP-0-9]);
>                             ^
>
> My OSGi method returns a Set<ProtocolType>.
>
> How can I achieve this ?
>
> Regards,
> Hemika
>
> Hemika Kodikara
> Software Engineer
> WSO2 Inc.
> lean . enterprise . middleware
> http://wso2.com
>
> Mobile : +94777688882
>



-- 
Sajith Janaprasad Ariyarathna
Software Engineer; WSO2, Inc.;  http://wso2.com/
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to