11.4. FrameCommentBlock

Aus Hugo Doku

Wechseln zu: Navigation, Suche

Use FrameCommentBlock as super class, if you want to handle XML comments out of the .model file.

caution Caution

You may only have one Frame class of this type in one HuGo project (analog to FrameTextBlock).

The following files show examplary how you can handle comments:

Example 11.3. Handling of Comments of the model file

The comment.model file:'

<model>
   <class name="Lazy">
           < !-- My very sophisticated class doing .... nothing -- >
                <item name="Max" type="String" default="sleeping">
                            < !-- What Max is doing, per default he is sleeping all the day-- >
                </item>
   </class>	
</model>

The _class.jxgp file:

package java_frames;
public class _class extends FrameDocu
{
  @#slot item_decl;  
  @#slot comment_text; 
  public @#String name;
  
   @#gen JCLASS<!name+".java","src","JAVA"!>
   <#java
       /**
        @#comment_text
       */
       public class <!name!> 
       {
          @#item_decl 
       }
   #>
}


The item.jxgp file:

package java_frames;
public class item extends FrameDocu
{
  public @#String name;
  public @#String type="int";
  public @#String _default="0";
  
  @#slot comment_text;
  
  @#constructor
  {
    blockSlot("comment_text"); @@ stop calling children
    if(type.equals("String")) @@ ensure correct init of default value
    {
       _default="\""+_default+"\"";
    }
  } 
  
  @#gen item_decl
  <#java     
       <!type!> <!name!>=<!_default!>; // @#comment_text 
   #>
}

The comment.jxgp file:

package java_frames;
public class comment extends FrameCommentBlock
{
  @#gen comment_text
  <#java@#text#>
}

The generated Lazy.java file:

/**
My very sophisticated class doing .... nothing
*/
public class Lazy 
{
  String Max="sleeping"; // What Max is doing, per default he is sleeping all the day
}

Remarks:

* In comment.model all comments are below the tag they are commenting. Some people put comments in front of the tag they are commenting; but on the point of view of the XML structure it is better to put it within the tag, because it belongs to it.
* In item.jxgp you have to block the slot comment_text, because otherwise it would be forwarded to its children.
Thus after the comment of the class the comment of the item would be attached. You will see the effect, when you take away the blockSlot() call in the @#constructor.
* The shown example is only a sample for how to access XML comments with HuGo if you need it. But we do not recommend to use comments for information which you want to handle. Use subtags instead. Because then you have much more flexibility of setting semantics within the text by further subtags as shown in Section 11.3.
* You have to derive the father tag above the comment from HuGo base class FrameDocu (analog to FrameTextBlock).


Next: 12. Output Methods
Persönliche Werkzeuge