View Javadoc

1   /*
2    * $Source: /usr/cvsroot/melati/maven-dsd-plugin/src/main/java/org/melati/poem/prepro/SearchabilityFieldDef.java,v $
3    * $Revision: 1.15 $
4    *
5    * Copyright (C) 2000 William Chesters
6    *
7    * Part of Melati (http://melati.org), a framework for the rapid
8    * development of clean, maintainable web applications.
9    *
10   * Melati is free software; Permission is granted to copy, distribute
11   * and/or modify this software under the terms either:
12   *
13   * a) the GNU General Public License as published by the Free Software
14   *    Foundation; either version 2 of the License, or (at your option)
15   *    any later version,
16   *
17   *    or
18   *
19   * b) any version of the Melati Software License, as published
20   *    at http://melati.org
21   *
22   * You should have received a copy of the GNU General Public License and
23   * the Melati Software License along with this program;
24   * if not, write to the Free Software Foundation, Inc.,
25   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA to obtain the
26   * GNU General Public License and visit http://melati.org to obtain the
27   * Melati Software License.
28   *
29   * Feel free to contact the Developers of Melati (http://melati.org),
30   * if you would like to work out a different arrangement than the options
31   * outlined here.  It is our intention to allow Melati to be used by as
32   * wide an audience as possible.
33   *
34   * This program is distributed in the hope that it will be useful,
35   * but WITHOUT ANY WARRANTY; without even the implied warranty of
36   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37   * GNU General Public License for more details.
38   *
39   * Contact details for copyright holder:
40   *
41   *     William Chesters <williamc At paneris.org>
42   *     http://paneris.org/~williamc
43   *     Obrechtstraat 114, 2517VX Den Haag, The Netherlands
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   * A definition of a <tt>SearchabilityPoemType</tt> from the DSD.
54   * A <tt>Searchability</tt> is a metadata field used in the 
55   * <tt>ColumnInfo</tt> table.
56   * 
57   * Its member variables are populated from the DSD or defaults.
58   * Its methods are used to generate the java code.
59   */ 
60  public class SearchabilityFieldDef extends FieldDef {
61  
62   /**
63    * Constructor.
64    *
65    * @param lineNo       the line number in the DSD file
66    * @param table        the {@link TableDef} that this <code>Field</code> is 
67    *                     part of 
68    * @param name         the name of this field
69    * @param displayOrder where to place this field in a list
70    * @param qualifiers   all the qualifiers of this field
71    * 
72    * @throws IllegalityException if a semantic inconsistency is detected
73    */
74    public SearchabilityFieldDef(int lineNo, TableDef table, String name, int displayOrder,
75                                 Vector<FieldQualifier> qualifiers) throws IllegalityException {
76      super(lineNo, table, name, "Searchability", "Integer", displayOrder, qualifiers);
77      table.addImport("org.melati.poem.SearchabilityPoemType", 
78                      "table");
79      table.addImport("org.melati.poem.Searchability", 
80                      "table");
81      table.addImport("org.melati.poem.Searchability", 
82                      "persistent");
83    }
84  
85   /**
86    * @param w The base table java file.
87    * @throws IOException 
88    *           if something goes wrong with the file system
89    */   
90    protected void generateColRawAccessors(Writer w) throws IOException {
91      super.generateColRawAccessors(w);
92  
93      w.write(
94        "\n" +
95        "          public Object getRaw(Persistent g)\n" +
96        "              throws AccessPoemException {\n" +
97        "            return ((" + shortestUnambiguousClassname + ")g).get" + capitalisedName + "Index();\n" +
98        "          }\n" +
99        "\n");
100     w.write(
101       "          public void setRaw(Persistent g, Object raw)\n" +
102       "              throws AccessPoemException {\n" +
103       "            ((" + shortestUnambiguousClassname + ")g).set" + capitalisedName + "Index((" +
104                        rawType + ")raw);\n" +
105       "          }\n");
106   }
107 
108  /**
109   * @param w The base persistent java file.
110   * @throws IOException 
111   *           if something goes wrong with the file system
112   */   
113   public void generateBaseMethods(Writer w) throws IOException {
114     super.generateBaseMethods(w);
115 
116 //    String targetTableAccessorMethod = "get" + type + "Table";
117 //    String targetSuffix = type;
118 
119     w.write(
120       "\n /**\n"
121       + "  * Retrieves the " 
122       + capitalisedName 
123       + " index value \n"
124       + "  * of this <code>Persistent</code>.\n" 
125       + ((description != null) ?   "  * Field description: \n" 
126                                  + DSD.javadocFormat(2, 3, description)
127                                  + "  * \n"
128                                : "")
129       + "  * \n"
130       + "  * Generated by " 
131       + "org.melati.poem.prepro.SearchabiltyFieldDef" 
132       + "#generateBaseMethods \n"
133       + "  * @throws AccessPoemException \n"
134       + "  *         if the current <code>AccessToken</code> \n"
135       + "  *         does not confer read access rights\n"
136       + "  * @return the " + rawType + " " + name + "\n"
137       + "  */\n");
138     w.write("\n" +
139             "  public Integer get" + capitalisedName + "Index()\n" +
140             "      throws AccessPoemException {\n" +
141             "    readLock();\n" +
142             "    return get" + capitalisedName + "_unsafe();\n" +
143             "  }\n" +
144             "\n");
145     w.write(
146       "\n /**\n"
147       + "  * Sets the <code>" 
148       + capitalisedName 
149       + "</code> index value, with checking, for this " 
150       + "<code>Persistent</code>.\n"
151       + ((description != null) ?   "  * Field description: \n" 
152                                  + DSD.javadocFormat(2, 3, description)
153                                  + "  * \n"
154                                : "")
155       + "  * \n"
156       + "  * Generated by " 
157       + "org.melati.poem.prepro.SearchabiltyFieldDef" 
158       + "#generateBaseMethods \n"
159       + "  * @param raw  the value to set \n"
160       + "  * @throws AccessPoemException \n"
161       + "  *         if the current <code>AccessToken</code> \n"
162       + "  *         does not confer write access rights\n"
163       + "  */\n");
164     w.write(
165             "  public void set" + capitalisedName + "Index(Integer raw)\n" +
166             "      throws AccessPoemException {\n" +
167             "    " + tableAccessorMethod + "().get" + capitalisedName + "Column()." +
168                      "getType().assertValidRaw(raw);\n" +
169             "    writeLock();\n" +
170             "    set" + capitalisedName + "_unsafe(raw);\n" +
171             "  }\n" +
172             "\n");
173     w.write(
174       "\n /**\n"
175       + "  * Retrieves the " 
176       + capitalisedName 
177       + " value \n"
178       + "  * of this <code>Persistent</code>.\n" 
179       + ((description != null) ?   "  * Field description: \n" 
180                                  + DSD.javadocFormat(2, 3, description)
181                                  + "  * \n"
182                                : "")
183       + "  *\n"
184       + "  * Generated by " 
185       + "org.melati.poem.prepro.SearchabiltyFieldDef" 
186       + "#generateBaseMethods \n"
187       + "  * @throws AccessPoemException \n"
188       + "  *         if the current <code>AccessToken</code> \n"
189       + "  *         does not confer read access rights\n"
190       + "  * @return the " + typeShortName + "\n"
191       + "  */\n");
192     w.write(
193             "  public " + typeShortName + " get" + capitalisedName + "()\n" +
194             "      throws AccessPoemException {\n" +
195             "    Integer index = get" + capitalisedName + "Index();\n" +
196             "    return index == null ? null :\n" +
197             "        Searchability.forIndex(index.intValue());\n" +
198             "  }\n" +
199             "\n");
200     w.write(
201       "\n /**\n"
202       + "  * Sets the <code>" 
203       + capitalisedName 
204       + "</code> value, with checking, for the " 
205       + "<code>Persistent</code> argument.\n"
206       + ((description != null) ?   "  * Field description: \n" 
207                                  + DSD.javadocFormat(2, 3, description)
208                                  + "  * \n"
209                                : "")
210       + "  * \n"
211       + "  * Generated by " 
212       + "org.melati.poem.prepro.SearchabiltyFieldDef" 
213       + "#generateBaseMethods \n"
214       + "  * @param cooked  the value to set \n"
215       + "  * @throws AccessPoemException \n"
216       + "  *         if the current <code>AccessToken</code> \n"
217       + "  *         does not confer write access rights\n"
218       + "  */\n");
219     w.write(
220             "  public void set" + capitalisedName + "(" + typeShortName + " cooked)\n" +
221             "      throws AccessPoemException {\n" +
222             "    set" + capitalisedName + 
223             "Index(cooked == null ? null : cooked.index);\n" +
224             "  }\n");
225   }
226 
227  /**
228   * Write out this <code>Field</code>'s java declaration string.
229   *
230   * @param w The base persistent java file.
231   * @throws IOException 
232   *           if something goes wrong with the file system
233   */   
234   public void generateJavaDeclaration(Writer w) throws IOException {
235     w.write("Integer " + name);
236   }
237 
238  /** @return the Java string for this <code>PoemType</code>. */
239   public String poemTypeJava() {
240     return "new SearchabilityPoemType()";
241   }
242 }