Enum type inside a class (matlab <-> java interface)

  • Follow


Hello,

Let's say I want to define this in java :

package internet;
public class Downloader {
  public enum DownloadStatus { INITIALIZING, IN_PROGRESS, COMPLETE };
}

How do I access the enum from matlab.

It seems that it works if the enum is defined outside of any class
(says Andrew here : http://stackoverflow.com/questions/1223795/using-java-enums-or-public-static-fields-in-matlab
) . But In this case, nothing seems to work in matlab

import internet.Downloader.DownloadStatus; does not work, it is not
recognized
internet.Downloader.DownloadStatus; does not work
internet.Downloader.DownloadStatus.INITIALIZING does not work
creating an empty object Downloader then trying to access
Downloadstatus does not work
I tried even the most stupid things, can't make it work

Why I want to do this ? Because there is a method in a java library
that asks for an enum type defined inside a class, so I need by any
means to create this enum type in matlab and pass it to the method as
a parameter.

Thanks for your help :)
0
Reply sylvain.boltz (1) 12/2/2009 10:38:30 PM

Sylvain <sylvain.boltz@gmail.com> wrote in message <1eea19c7-391b-4b3d-b4e6-1d9240b40410@m25g2000yqc.googlegroups.com>...
> Hello,
> 
> Let's say I want to define this in java :
> 
> package internet;
> public class Downloader {
>   public enum DownloadStatus { INITIALIZING, IN_PROGRESS, COMPLETE };
> }
> 
> How do I access the enum from matlab.
> 
> It seems that it works if the enum is defined outside of any class
> (says Andrew here : http://stackoverflow.com/questions/1223795/using-java-enums-or-public-static-fields-in-matlab
> ) . But In this case, nothing seems to work in matlab
> 
> import internet.Downloader.DownloadStatus; does not work, it is not
> recognized
> internet.Downloader.DownloadStatus; does not work
> internet.Downloader.DownloadStatus.INITIALIZING does not work
> creating an empty object Downloader then trying to access
> Downloadstatus does not work
> I tried even the most stupid things, can't make it work
> 
> Why I want to do this ? Because there is a method in a java library
> that asks for an enum type defined inside a class, so I need by any
> means to create this enum type in matlab and pass it to the method as
> a parameter.
> 
> Thanks for your help :)


You can try 'internet.Downloader$DownloadStatus' within the awtinvoke or javaMethod functions (this should work but I'm not 100% certain).

Alternately, use the method I used for system-tray messages, which has the same issue: http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/

Yair Altman
http://UndocumentedMatlab.com 
 
0
Reply Yair 12/3/2009 7:32:06 AM


"Yair Altman" wrote in message <hf7phm$cn9$1@fred.mathworks.com>...
> Sylvain <sylvain.boltz@gmail.com> wrote in message <1eea19c7-391b-4b3d-b4e6-1d9240b40410@m25g2000yqc.googlegroups.com>...
> > Hello,
> > 
> > Let's say I want to define this in java :
> > 
> > package internet;
> > public class Downloader {
> >   public enum DownloadStatus { INITIALIZING, IN_PROGRESS, COMPLETE };
> > }
> > 
> > How do I access the enum from matlab.
> > 
> > It seems that it works if the enum is defined outside of any class
> > (says Andrew here : http://stackoverflow.com/questions/1223795/using-java-enums-or-public-static-fields-in-matlab
> > ) . But In this case, nothing seems to work in matlab
> > 
> > import internet.Downloader.DownloadStatus; does not work, it is not
> > recognized
> > internet.Downloader.DownloadStatus; does not work
> > internet.Downloader.DownloadStatus.INITIALIZING does not work
> > creating an empty object Downloader then trying to access
> > Downloadstatus does not work
> > I tried even the most stupid things, can't make it work
> > 
> > Why I want to do this ? Because there is a method in a java library
> > that asks for an enum type defined inside a class, so I need by any
> > means to create this enum type in matlab and pass it to the method as
> > a parameter.
> > 
> > Thanks for your help :)
> 
> 
> You can try 'internet.Downloader$DownloadStatus' within the awtinvoke or javaMethod functions (this should work but I'm not 100% certain).
> 
> Alternately, use the method I used for system-tray messages, which has the same issue: http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/
> 
> Yair Altman
> http://UndocumentedMatlab.com 
>  

Based on Yair's suggestion, I found that using the valueOf() method with javaMethod works. For example, javaMethod('valueOf', 'internet.Downloader$DownloadStatus', 'INITIALIZING'). This solves a similar issue I was having, so thanks for the suggestion.

Ben :-)
0
Reply none10 (3395) 11/7/2011 2:23:10 AM

2 Replies
467 Views

(page loaded in 0.394 seconds)

Similiar Articles:













7/22/2012 4:03:44 PM


Reply: