1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  package org.melati.poem.prepro;
47  
48  import java.util.Vector;
49  import java.io.Writer;
50  import java.io.IOException;
51  
52  
53  
54  
55  
56  
57  
58  
59   
60  public class DisplayLevelFieldDef extends FieldDef {
61  
62   
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74    public DisplayLevelFieldDef(int lineNo, TableDef table, String name, int displayOrder,
75                                Vector<FieldQualifier> qualifiers) throws IllegalityException {
76      super(lineNo, table, name, "DisplayLevel", "Integer", displayOrder, qualifiers);
77      table.addImport("org.melati.poem.DisplayLevelPoemType", 
78                      "table");
79      table.addImport("org.melati.poem.DisplayLevel", 
80                      "table");
81      table.addImport("org.melati.poem.DisplayLevel", 
82                      "persistent");
83    }
84  
85   
86  
87  
88  
89  
90     
91    protected void generateColRawAccessors(Writer w) throws IOException {
92      super.generateColRawAccessors(w);
93  
94      w.write(
95        "\n" +
96        "          public Object getRaw(Persistent g)\n" +
97        "              throws AccessPoemException {\n" +
98        "            return ((" + shortestUnambiguousClassname + ")g).get" + capitalisedName + "Index();\n" +
99        "          }\n" +
100       "\n");
101     w.write(
102       "          public void setRaw(Persistent g, Object raw)\n" +
103       "              throws AccessPoemException {\n" +
104       "            ((" + shortestUnambiguousClassname + ")g).set" + capitalisedName + "Index((" +
105                        rawType + ")raw);\n" +
106       "          }\n");
107   }
108 
109  
110 
111 
112 
113 
114    
115   public void generateBaseMethods(Writer w) throws IOException {
116     super.generateBaseMethods(w);
117 
118 
119 
120 
121     w.write(
122       "\n /**\n"
123       + "  * Retrieves the " 
124       + capitalisedName 
125       + " index value \n"
126       + "  * of this <code>Persistent</code>.\n" 
127       + "  * \n"
128       + ((description != null) ? "  * Field description: \n" 
129                                  + DSD.javadocFormat(2, 3, description)
130                                  + "  * \n"
131                                : "")
132       + "  * Generated by " 
133       + "org.melati.poem.prepro.DisplayLevelFieldDef" 
134       + "#generateBaseMethods \n"
135       + "  * @throws AccessPoemException \n"
136       + "  *         if the current <code>AccessToken</code> \n"
137       + "  *         does not confer read access rights\n"
138       + "  * @return the " + rawType + " " + name + "\n"
139       + "  */\n");
140     w.write("\n" +
141             "  public Integer get" + capitalisedName + "Index()\n" +
142             "      throws AccessPoemException {\n" +
143             "    readLock();\n" +
144             "    return get" + capitalisedName + "_unsafe();\n" +
145             "  }\n" +
146             "\n");
147     w.write(
148       "\n /**\n"
149       + "  * Sets the <code>" 
150       + capitalisedName 
151       + "</code> index value, with checking, \n"
152       + "  * for this <code>Persistent</code>.\n"
153       + ((description != null) ? "  * Field description: \n" 
154                                  + DSD.javadocFormat(2, 3, description)
155                                  + "  * \n"
156                                : "")
157       + "  * \n"
158       + "  * Generated by " 
159       + "org.melati.poem.prepro.DisplayLevelFieldDef" 
160       + "#generateBaseMethods \n"
161       + "  * @param raw  the value to set \n"
162       + "  * @throws AccessPoemException \n"
163       + "  *         if the current <code>AccessToken</code> \n"
164       + "  *         does not confer write access rights\n"
165       + "  */\n");
166     w.write(
167       "  public void set" + capitalisedName + "Index(Integer raw)\n" +
168       "      throws AccessPoemException {\n" +
169       "    " + rootTableAccessorMethod + "().get" + capitalisedName + "Column()." +
170                 "getType().assertValidRaw(raw);\n" +
171       "    writeLock();\n" +
172       "    set" + capitalisedName + "_unsafe(raw);\n" +
173       "  }\n" +
174       "\n");
175     w.write(
176       "\n /**\n"
177       + "  * Retrieves the " 
178       + capitalisedName 
179       + " value \n"
180       + "  * of this <code>Persistent</code>.\n" 
181       + ((description != null) ? "  * Field description: \n" 
182                                  + DSD.javadocFormat(2, 3, description)
183                                  + "  * \n"
184                                : "")
185       + "  * \n"
186       + "  * Generated by " 
187       + "org.melati.poem.prepro.DisplayLevelFieldDef" 
188       + "#generateBaseMethods \n"
189       + "  * @throws AccessPoemException \n"
190       + "  *         if the current <code>AccessToken</code> \n"
191       + "  *         does not confer read access rights\n"
192       + "  * @return the " + typeShortName + "\n"
193       + "  */\n");
194     w.write(
195             "  public " + typeShortName + " get" + capitalisedName + "()\n" +
196             "      throws AccessPoemException {\n" +
197             "    Integer index = get" + capitalisedName + "Index();\n" +
198             "    return index == null ? null :\n" +
199             "        DisplayLevel.forIndex(index.intValue());\n" +
200             "  }\n" +
201             "\n");
202     w.write(
203       "\n /**\n"
204       + "  * Sets the <code>" 
205       + capitalisedName 
206       + "</code> value, with checking, for the " 
207       + "<code>Persistent</code> argument.\n"
208       + ((description != null) ? "  * Field description: \n" 
209                                  + DSD.javadocFormat(2, 3, description)
210                                  + "  * \n"
211                                : "")
212       + "  * \n"
213       + "  * Generated by " 
214       + "org.melati.poem.prepro.DisplayLevelFieldDef" 
215       + "#generateBaseMethods \n"
216       + "  * @param cooked  the value to set \n"
217       + "  * @throws AccessPoemException \n"
218       + "  *         if the current <code>AccessToken</code> \n"
219       + "  *         does not confer write access rights\n"
220       + "  */\n");
221     w.write(
222       "  public void set" + capitalisedName + "(" + typeShortName + " cooked)\n" +
223       "      throws AccessPoemException {\n" +
224       "    set" + capitalisedName + 
225       "Index(cooked == null ? null : cooked.index);\n" +
226       "  }\n");
227   }
228 
229  
230 
231 
232 
233 
234 
235    
236   public void generateJavaDeclaration(Writer w) throws IOException {
237     w.write("Integer " + name);
238   }
239 
240  
241   public String poemTypeJava() {
242     return "new DisplayLevelPoemType()";
243   }
244 }