Announcement Announcement Module
Collapse
No announcement yet.
roo advanced add-on - using annotation attributes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 (http://static.springsource.org/sprin...dvanced-addons). 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:

    Code:
    @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
        		) {
        	operations.annotateType(entity_class);
    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 AddonOperationsImpl.java file. Something like:

    Code:
     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);
               
                classOrInterfaceTypeDetailsBuilder.addAnnotation(annotationBuilder.build());
                typeManagementService.createOrUpdateTypeOnDisk(classOrInterfaceTypeDetailsBuilder.build());
            }
    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 AddonMetadataProvider.java file and then pass the results to the getMetadata() constructor from the AddonMetadata.java 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.

    Radu

  • #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 AddonMetadata.java file (not the provider one) like this :

    Code:
    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.

    Regards,
    --
    Laurent

    Comment


    • #3
      Hello Laurent,

      Many thanks for your explanations. They were very useful.

      Best regards,
      Radu

      Comment

      Working...
      X