Home Comments

java annotations in slice

jacekjacek Member Jacek CalaOrganization: Newcastle UniversityProject: A cloud-enabled workflow management system
Hello,

I can see that slice C# mapping allows C# attributes to be added to the generated code (C-Sharp Specific Metadata Directives - Ice 3.4 - ZeroC). Is there any chance to add similar functionality to slice2java (i.e. injecting Java annotations) in the near future?

Best,
Jacek

Comments

  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi Jacek,

    We have this in our TODO list but will not be part of the upcoming 3.5 release, whenever or not this is developed in a near future depends on commercial demand for this feature.

    Can you share with us your use case for this?

    Regards,
    Jose
  • jacekjacek Member Jacek CalaOrganization: Newcastle UniversityProject: A cloud-enabled workflow management system
    Hi Jose,

    Glad to hear it's on your TODOs although I would really like it in 3.5. My scenario is as follows:

    I have an existing web service exposed through a REST-based interface using JAX-RS (more specifically RESTeasy) and was thinking about adding another access method to it via Ice; I can't get rid of the REST-based interface, and so need to build a hybrid.

    Ideally, if I was able to define a common slice interface, generate the Java out of it and then use _MyServiceOperationsNC as the base for the REST interface. However, JAX-RS uses Java annotations extensively, e.g. to map methods to urls:
    @Path("/library")
    public interface ILibrary {
    
       @GET
       @Path("/books")
       String getBooks();
    
       @GET
       @Path("/book/{isbn}")
       String getBook(@PathParam("isbn") String id);
    
       @PUT
       @Path("/book/{isbn}")
       void addBook(@PathParam("isbn") String id, @QueryParam("name") String name);
    
       @DELETE
       @Path("/book/{id}")
       void removeBook(@PathParam("id") String id);
    }
    

    Without slice support for annotations, I can't have a single, "master" interface which I could share between the service and clients. What I would really like then is something like this:
    ['java:annotation:javax.ws.rs.Path("/library")']
    interface ILibrary {
    
       ['java:annotation:javax.ws.rs.GET']
       ['java:annotation:javax.ws.rs.Path("/books")']
       string getBooks();
    
       ['java:annotation:javax.ws.rs.GET']
       ['java:annotation:javax.ws.rs.Path("/book/{isbn}")']
       string getBook(
              ['java:annotation:javax.ws.rs.PathParam("isbn")'] string id);
    
      ...
    }
    

    It means that for proper JAX-RS support slice would need to allow annotations for interfaces, classes, structures, operations and (!) operations arguments.

    What do you think?

    Best,
    Jacek
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi Jacek,

    It seems a good solution for your problem, but i'm afraid this will not be part of Ice 3.5.

    Best Regards,
    Jose
  • jacekjacek Member Jacek CalaOrganization: Newcastle UniversityProject: A cloud-enabled workflow management system
    xdm wrote: »
    It seems a good solution for your problem, but i'm afraid this will not be part of Ice 3.5.

    Thank you Jose for the information. Do you have any plans for including java annotations in 3.6+ releases? Is there any timescale for that?

    Jacek
  • raulgdraulgd Member Raul GuerreroOrganization: JimiProject: RI of mexican standard of Electronic Health Record
    Database entity annotations...

    So, if this is not gonna be part of 3.5 and there's no schedule for this feature, do you guys know a workaround or something for this feature? Any design principle of recommendations?

    Because annotations for this are not only practical for REST, for example, for data structures, there are all the JPA annotations for database persistence, so, pretty much most of the Java enterprise applications make use of JPA, and right now, the only way is to modify the generated Ice java code by hand, and if you modify any of the data structures, do a diff and merge the changes, which is a bit of a pain.
  • jacekjacek Member Jacek CalaOrganization: Newcastle UniversityProject: A cloud-enabled workflow management system
    Any news in this topic?

    Hi Zeroc team,

    Have you any news regarding annotations in slice2java?

    Best regards,
    Jacek
Sign In or Register to comment.