ExportOverlays an enums

66 views
Skip to first unread message

Pieter De Graef

unread,
Nov 7, 2011, 10:07:36 AM11/7/11
to gwtexporter
Hi,

for a project, I'm trying to build a JavaScript API around some GWT
services. Ideally I would not have to touch the original services in
any way, so I'm testing out the ExportOverlay option.
Now my problem is that one of these services uses an enum, and I can't
seem to get this enum exported. Any pointers would be greatly
appreciated.

Pieter De Graef

unread,
Nov 8, 2011, 3:41:49 AM11/8/11
to gwtexporter
My bad, I had to cleanup my Eclipse project. The ExportOverlay on
emuns compile just fine now.
My problem now is that I have no idea how to use them in JavaScript...

Manuel Carrasco Moñino

unread,
Nov 8, 2011, 3:51:17 AM11/8/11
to gwtex...@googlegroups.com
Enums are not considered so they should not work, any way, could you send a piece of your code so as I can take a look and propose how can you deal with it?.

- Manolo

Pieter De Graef

unread,
Nov 8, 2011, 3:58:36 AM11/8/11
to gwtexporter
The original enum:
public enum GeometryIndexType {

TYPE_GEOMETRY, TYPE_VERTEX, TYPE_EDGE
}

The overlay:
@Export("GeometryIndexType")
@ExportPackage("org.geomajas.plugin.editing.service")
@Api(allMethods = true)
public enum JsGeometryIndexType implements
ExportOverlay<GeometryIndexType> {
@Export
TYPE_GEOMETRY,

@Export
TYPE_VERTEX,

@Export
TYPE_EDGE
}

The main problem is that this enum is used in a service that I'm
exporting through an overlay and I would prefer not to have to change
the original service just because I want to export it.

On Nov 8, 9:51 am, Manuel Carrasco Moñino <man...@apache.org> wrote:
> Enums are not considered so they should not work, any way, could you send a
> piece of your code so as I can take a look and propose how can you deal
> with it?.
>
> - Manolo
>

Manuel Carrasco Moñino

unread,
Nov 8, 2011, 6:59:34 AM11/8/11
to gwtex...@googlegroups.com
How is this enum used in the service methods?

Pieter De Graef

unread,
Nov 8, 2011, 7:03:58 AM11/8/11
to gwtexporter
Here is a part of an example interface:

public interface GeometryIndexService {

GeometryIndex create(GeometryIndexType type, int... values);
}

Implementation:
public class GeometryIndexServiceImpl implements GeometryIndexService
{

public GeometryIndexImpl create(GeometryIndexType type, int...
values) {
// Not really important...
}
}

JavaScript exportable version:
@Export("GeometryIndexService")
@ExportPackage("org.geomajas.plugin.editing.service")
public class JsGeometryIndexService implements
ExportOverlay<GeometryIndexServiceImpl>, GeometryIndexService {

public GeometryIndex create(GeometryIndexType type, int... values) {
return null;
}
}

On Nov 8, 12:59 pm, Manuel Carrasco Moñino <man...@apache.org> wrote:
> How is this enum used in the service methods?
>

Manuel Carrasco Moñino

unread,
Nov 8, 2011, 9:59:21 AM11/8/11
to gwtex...@googlegroups.com
You have to use the @ExportInstanceMethod annotation and make the implementation in the exportOverlay class translating the arguments, note that the method must be static and the first argument must be the instance.



@Export("GeometryIndexService")
@ExportPackage("org.geomajas.plugin.editing.service")
public class JsGeometryIndexService implements
ExportOverlay<GeometryIndexServiceImpl>, GeometryIndexService {

  @ExportInstanceMethod
   public static GeometryIndex create(GeometryIndexServiceImpl instance, String type, int... values) {
      if ("type_a".equals(type))
        return instance.create( GeometryIndexType.TYPE_A, values)
     [....]
   }
}

Then in javascript you can use the method as usual

var o = new org.geomajas.plugin.editing.service.GeometryIndexService()
o.create("type_a", ...)

BTW: there are annotations for static methods and constructors as well, you have to use last snapshot.


- Manolo

Pieter De Graef

unread,
Nov 8, 2011, 10:04:08 AM11/8/11
to gwtexporter
I had already checked out trunk to see what options there are and I
had just started testing the new annotations.
Thanks a lot for your help.

On Nov 8, 3:59 pm, Manuel Carrasco Moñino <man...@apache.org> wrote:
> You have to use the @ExportInstanceMethod annotation and make the
> implementation in the exportOverlay class translating the arguments, note
> that the method must be static and the first argument must be the instance.
>
> @Export("GeometryIndexService")
> @ExportPackage("org.geomajas.plugin.editing.service")
> public class JsGeometryIndexService implements
> ExportOverlay<GeometryIndexServiceImpl>, GeometryIndexService {
>
>   @ExportInstanceMethod
>    public static GeometryIndex create(GeometryIndexServiceImpl instance,
> String type, int... values) {
>       if ("type_a".equals(type))
>         return instance.create( GeometryIndexType.TYPE_A, values)
>      [....]
>    }
>
> }
>
> Then in javascript you can use the method as usual
>
> var o = new org.geomajas.plugin.editing.service.GeometryIndexService()
> o.create("type_a", ...)
>
> BTW: there are annotations for static methods and constructors as well, you
> have to use last snapshot.
>
> - Manolo
>

Pieter De Graef

unread,
Nov 8, 2011, 10:39:24 AM11/8/11
to gwtexporter
I have successfully used your suggestion by adding such a method using
the @ExportInstanceMethod annotation, but I'm having problems with a
method that returns an enum value:

// Original method as described in the interface:
public GeometryIndexType getType(GeometryIndex index) {
return null;
}

@ExportInstanceMethod
public static String getType(GeometryIndexServiceImpl instance,
GeometryIndex index) {
switch (instance.getType(index)) {
case TYPE_GEOMETRY:
return "geometry";
case TYPE_VERTEX:
return "vertex";
case TYPE_EDGE:
return "edge";
default:
return "unknown";
}
}

This does not seem to work. It gives me the following error:
Can't find exported method for given arguments: 2:2

Pieter De Graef

unread,
Nov 15, 2011, 6:57:21 AM11/15/11
to gwtexporter
This last problem was fixed by removing the original "getType" method.
Reply all
Reply to author
Forward
0 new messages