1 package org.apache.torque.templates.typemapping; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 /** 23 * An enum for all java types known to the generator. 24 * 25 * @version "Id: $ 26 */ 27 public enum JavaType 28 { 29 /** java.lang.String. */ 30 STRING("String", false, false, null), 31 /** java.math.BigDecimal. */ 32 BIG_DECIMAL("BigDecimal", false, true, "java.math."), 33 /** primitive boolean. */ 34 BOOLEAN_PRIMITIVE("boolean", true, false, null), 35 /** java.lang.Boolean. */ 36 BOOLEAN_OBJECT("Boolean", false, false, null), 37 /** primitive byte. */ 38 BYTE_PRIMITIVE("byte", true, true, null), 39 /** java.lang.Byte. */ 40 BYTE_OBJECT("Byte", false, true, null), 41 /** primitive short. */ 42 SHORT_PRIMITIVE("short", true, true, null), 43 /** java.lang.Short. */ 44 SHORT_OBJECT("Short", false, true, null), 45 /** primitive int. */ 46 INTEGER_PRIMITIVE("int", true, true, null), 47 /** java.lang.Integer. */ 48 INTEGER_OBJECT("Integer", false, true, null), 49 /** primitive long. */ 50 LONG_PRIMITIVE("long", true, true, null), 51 /** java.lang.Long. */ 52 LONG_OBJECT("Long", false, true, null), 53 /** primitive float. */ 54 FLOAT_PRIMITIVE("float", true, true, null), 55 /** java.lang.Float. */ 56 FLOAT_OBJECT("Float", false, true, null), 57 /** primitive double. */ 58 DOUBLE_PRIMITIVE("double", true, true, null), 59 /** java.lang.Double. */ 60 DOUBLE_OBJECT("Double", false, true, null), 61 /** primitive char. */ 62 CHAR_PRIMITIVE("char", true, false, null), 63 /** java.lang.Char. */ 64 CHAR_OBJECT("Char", false, false, null), 65 /** primitive byte array. */ 66 BYTE_PRIMITIVE_ARRAY("byte[]", false, false, null), 67 /** java.util.Date. */ 68 // TODO move package prefix to last argument 69 DATE("java.util.Date", false, false, null); 70 71 /** The class name without package name. */ 72 private String className; 73 74 /** Whether the type is a primitive type. */ 75 private boolean primitive; 76 77 /** Whether the type is a number. */ 78 private boolean number; 79 80 /** The package prefix for object types, if different from java.lang. */ 81 private String packagePrefix; 82 83 /** 84 * Constructor. 85 * 86 * @param className the class name, not null. 87 * @param primitive Whether the type is a primitive type. 88 * @param number Whether the type is a number. 89 * @param packagePrefix The package prefix for object types, or null. 90 */ 91 private JavaType( 92 String className, 93 boolean primitive, 94 boolean number, 95 String packagePrefix) 96 { 97 this.className = className; 98 this.primitive = primitive; 99 this.number = number; 100 this.packagePrefix = packagePrefix; 101 } 102 103 /** 104 * Returns whether the type is a primitive type. 105 * 106 * @return true if the type is a primitive type, false otherwise. 107 */ 108 public boolean isPrimitive() 109 { 110 return primitive; 111 } 112 113 /** 114 * Returns whether the type is a number. 115 * 116 * @return true if the type is a number, false otherwise. 117 */ 118 public boolean isNumber() 119 { 120 return number; 121 } 122 123 /** 124 * Returns the class name. 125 * 126 * @return the unqualified class name. 127 */ 128 public String getClassName() 129 { 130 return className; 131 } 132 133 /** 134 * Returns the package prefix. 135 * 136 * @return the package prefix, or null. 137 */ 138 public String getPackagePrefix() 139 { 140 return packagePrefix; 141 } 142 143 /** 144 * Returns the class name, if necessary qualified with the package name. 145 * 146 * @return the full class name. 147 */ 148 public String getFullClassName() 149 { 150 if (packagePrefix == null) 151 { 152 return className; 153 } 154 else 155 { 156 return packagePrefix + className; 157 } 158 } 159 }