7. Attribute Variables
Aus Hugo Doku
To access the attribute values of the corresponding tag to your Frame use special attribute variables.
Attribute variables are declared as follows:
public @#attr_type attr_name;
HuGo knows the following attribute types:
Attribute Types
| attr_type | Meaning |
|---|---|
| String | a String like in Java |
| int | a int like in Java |
| double | a double like in Java |
| boolean | a boolean like in Java |
Use the types you need within your Frame class instead of just using @#String for all attributes. Thus you do not need to extract e.g. the integer value out of the string, as in the XML syntax all attribute values are written as strings.
The attr_name is identical to the attribute name you use in the .model file. That means the variable is initialized with the value of the corresponding attribute in the tag, which belongs to the Frame class.
The initializing order is as follows:
1. Initialize with init values at declaration.
2. Initialize with values from the model (if attribute value is specified there)
3. call @#constructor
The name of an attribute variable is case sensitiv (analog to other Java variables).
Access to variables
The access to the variables value work like the access to other normal variables. If you are inside a generating method use <!...!> to access it.
Example 7.1. Attributes
The following example shows as well how you can handle optional attributes in the .model file.
The people.model
<model>
<person name="Paul"
age="34"
height="1.84"
/>
</model>
The person.jxgp
package java_frames;
public class person extends Frame
{
@@ Attributes
public @#String name;
public @#int age;
public @#double height;
public @#boolean male=true; @@ optional attribute
@#gen JCLASS<!name+".java","src","JAVA"!>
<#java
public class <!name!>
{
int m_age=<!age!>;
double m_height=<!height!>;
boolean m_male=<!male!>;
}
#>
}
The generated paul.java
public class Paul
{
int m_age=34;
double m_height=1.84;
boolean m_male=true;
}


