Announcement Announcement Module
No announcement yet.
roo advanced add-on - using annotation attributes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • roo advanced add-on - using annotation attributes

    Hi all,

    I am using roo for different experiments for the past half a year, and recently I came to the point where I need to create some add-ons.
    While the simple add-ons seem quite clear (I have experimented a couple of them) for the advanced one there is no documentation ( I tried to look through the examples available on the internet, but I've hit on a problem which I cannot solve:

    Suppose I create an add-on having a command like:

    @CliCommand(value = "connect gw")
        public void addClassGwConnectivity(
        		@CliOption(key = "entity", mandatory = true, help = "Entity name") JavaType entity_class,
        		@CliOption(key = "URL", mandatory = true, help = "OData Endpoint URL") String url
        		) {
    So I have the entity and URL as mandatory parameters. I am adding them an annotation containing the URL attribute for the targeted entity, in the file. Something like:

     public void annotateType(JavaType javaType, final String url) {
            Validate.notNull(javaType, "Java type required");
            Validate.notNull(url, "URL required");
            ClassOrInterfaceTypeDetails existing = typeLocationService.getTypeDetails(javaType);
            if (existing != null && MemberFindingUtils.getAnnotationOfType(existing.getAnnotations(), new JavaType(RooAddon.class.getName())) == null) {
                ClassOrInterfaceTypeDetailsBuilder classOrInterfaceTypeDetailsBuilder = new ClassOrInterfaceTypeDetailsBuilder(existing);
                JavaType rooRooAddon = new JavaType(RooAddon.class.getName());
                AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(rooRooAddon);
                annotationBuilder.addStringAttribute("URL", url);
    Now comes my question. How do I parse the attribute I have set on this annotation in order to create specific code in the ITD for the targeted entity? I know I should do the parsing in the file and then pass the results to the getMetadata() constructor from the file.
    But how to obtain the values of the attributes from the annotation, is very unclear to me. It seems it is contained in the governorPhysicalTypeMetadata variable, but I cannot get around it.

    My goal is to create methods with specific code, depending on the parameters of the commands that are given.

    Any help would be highly appreciated.


  • #2
    Hi Radu,

    you're on the right track : information is contained into the governorPhysicalTypeMetadata.
    You just have to use it from the constructor of your file (not the provider one) like this :

    String url = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getAnnotation(rooRooAddon).getAttribute("URL").toString();
    Then, you'd have to give the url to the methods generating your ITD fields or methods.



    • #3
      Hello Laurent,

      Many thanks for your explanations. They were very useful.

      Best regards,