1 /* 2 * $Source: /usr/cvsroot/melati/maven-dsd-plugin/src/main/java/org/melati/poem/prepro/BigDecimalFieldDef.java,v $ 3 * $Revision: 1.12 $ 4 * 5 * Copyright (C) 2003 Samuel Goldstein 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 * Samuel Goldstein <samuel At 1969.ws> 42 * http://www.1969.ws 43 * 13101 W. Washington Blvd Suite 248, Los Angeles, CA 90066 USA 44 */ 45 46 package org.melati.poem.prepro; 47 48 import java.util.Vector; 49 50 /** 51 * A definition of a <tt>BigDecimalPoemType</tt> from the DSD. 52 * 53 * Its member variables are populated from the DSD or defaults. Its methods are 54 * used to generate the java code. 55 */ 56 public class BigDecimalFieldDef extends AtomFieldDef { 57 58 private int scale; 59 60 private int precision; 61 62 /** 63 * Constructor. 64 * 65 * @param lineNo 66 * the line number in the DSD file 67 * @param table 68 * the {@link TableDef} that this <code>Field</code> is part of 69 * @param name 70 * the name of this field 71 * @param displayOrder 72 * where to place this field in a list 73 * @param qualifiers 74 * all the qualifiers of this field 75 * 76 * @throws IllegalityException 77 * if a semantic inconsistency is detected 78 */ 79 public BigDecimalFieldDef(int lineNo, TableDef table, String name, 80 int displayOrder, Vector<FieldQualifier> qualifiers) throws IllegalityException { 81 super(lineNo, table, name, "BigDecimal", displayOrder, qualifiers); 82 table.addImport("org.melati.poem.BigDecimalPoemType", "table"); 83 table.addImport("java.math.BigDecimal", "table"); 84 table.addImport("java.math.BigDecimal", "persistent"); 85 } 86 87 /** 88 * @param w 89 * The base persistent java file. 90 * @throws IOException 91 * if something goes wrong with the file system 92 */ 93 // PMD objects to overriding methods which only call super 94 // public void generateBaseMethods(Writer w) throws IOException { 95 // super.generateBaseMethods(w); 96 /* 97 * w.write("\n" + " public final void set" + mixedCaseName + "(double cooked)\n" + " 98 * throws AccessPoemException, ValidationPoemException {\n" + " set" + mixedCaseName + 99 * "(new Double(cooked));\n" + " }\n"); 100 */ 101 // } 102 /** @return the Java string for this <code>PoemType</code>. */ 103 public String poemTypeJava() { 104 return "new BigDecimalPoemType(" + isNullable() + ", " + getPrecision() 105 + ", " + getScale() + ")"; 106 } 107 108 /** 109 * Retrieve the precision. 110 * 111 * @return the precision 112 */ 113 public int getPrecision() { 114 return precision; 115 } 116 117 /** 118 * Set the precision. 119 * 120 * @param precision 121 */ 122 public void setPrecision(int precision) { 123 if (this.precision != 0) 124 throw new IllegalityException(lineNumber, "Redefinition of precision."); 125 this.precision = precision; 126 } 127 128 /** 129 * Retrieve the scale. 130 * 131 * @return the scale 132 */ 133 public int getScale() { 134 return scale; 135 } 136 137 /** 138 * Set the scale. 139 * 140 * @param scale the scale to set 141 */ 142 public void setScale(int scale) { 143 if (this.scale != 0) 144 throw new IllegalityException(lineNumber, "Redefinition of scale."); 145 this.scale = scale; 146 } 147 148 }