Menu

Reading default Attributes from Javadocs

Help
Ayhan Tek
2009-03-04
2013-04-25
  • Ayhan Tek

    Ayhan Tek - 2009-03-04

    I am trying to read all attributes and their default values from a business function. I am able to get the fields using Java Reflection however as far as I know Java Reflection does not allow us to read the Javadocs. And unfortunately annotations like @jameleon.attributes are defined inside a Javadoc:

    /** @jameleon.attribute required="true" default="abc"  */

    So, I am trying to use Jameleon API to get the default value of the Attribute which is "abc" in above example.

    I know that FunctionalPoint class represents tag's attributes. So my question is "how to get a handle of FunctionalPoint" from a Java class so that I can use its get Attributes() method and then use Attribute class' getDefaultValue() method to get the default value? (I realized that in Jameleon GUI while creating the Jameleon Tags Panel, the JameleonTagsPanel class' sendFunctionalPointInfoToUI method is getting the deault attributes in a similar way indicated in code fragment below)

    I tried the following without any luck:
    MyClass{
    // clazz is the class that we will read the attributes from
    // clazz2 is the calling class which is MyClass
    ...........
    FunctionalPoint functionalPoint = null;
    try {
        functionalPoint = JameleonUtility.loadFunctionalPoint(clazz.getName(),
                                                                                                clazz2.toString());
    } catch (JameleonScriptException jse) {
        System.err.println("The error in FP is: " + jse.getMessage());
    } catch (Exception e){...} // I am getting Null Pointer Exception here

    List tagNamesList = functionalPoint.getTagNames();                       
        Iterator it = tagNamesList.iterator();
        it = functionalPoint.getAttributes().keySet().iterator();
        Attribute att = null;
        String defaultValue = "";
        while (it.hasNext()) {
            att = (Attribute) functionalPoint.getAttributes().get(it.next());
            defaultValue = att.getDefaultValue();
                System.out.println("DEFAULT VALUE: " + defaultValue);
        }
    .......

    Or is there a better way to get a handle to the Attribute class' getDefaultValue() method?
    In the future Jameleon releases, is it possible to use pure Annotations to describe attributes and their default values (not from Javadoc)?

    Regards,

     
    • Ayhan Tek

      Ayhan Tek - 2009-03-06

      I still couldn't find a way to get a handle to the Attribute class but I've resolved the problem by using QDox.
      In case this might help someone who wants to read the attributes and their values like "required", "default" etc, here is a summary of what I did:

      JavaDocBuilder builder = new JavaDocBuilder();
      builder.addSourceTree(filesInDir); // java files that I want to read their attributes
      JavaClass cls = builder.getClassByName("myClassToBeRead");
      JavaField[] jf = cls.getFields();
      // Iterate over all the fields and find @jameleon.attribute
      ....
      DocletTag docTag = javaField.getTagByName("jameleon.attribute");
      String default = docTag.getNamedParameter("default"); // This gives the default value

      Hope this helps someone
      Regards,
      Ayhan

       
    • Christian Hargraves

      Check out the JameleonTagSupport (the constructor) and AttributeBroker. Between those two you should be able to figure out how it is done.

       

Log in to post a comment.