1 23 24 package org.xquark.jdbc.typing; 25 26 import org.xquark.schema.SimpleType; 27 import org.xquark.schema.datatypes.PrimitiveType; 28 29 33 public class JavaTypeInfo extends XMLTypeInfo 34 { 35 private static final String RCSRevision = "$Revision: 1.1 $"; 36 private static final String RCSName = "$Name: $"; 37 38 public final static int JAVA_STRING = 0; 42 public final static int JAVA_BOOLEAN = 1; 43 public final static int JAVA_BIG_DECIMAL = 2; 44 public final static int JAVA_FLOAT = 3; 45 public final static int JAVA_DOUBLE = 4; 46 public final static int JAVA_LONG = 5; 47 48 50 public final static int JAVA_LIST = 6; 51 public final static int JAVA_UNKNOWN = 7; 52 53 public final static int SCHEMA_DURATION = 8; 54 public final static int SCHEMA_DATETIME = 9; 55 public final static int SCHEMA_BYTE_ARRAY = 10; 56 public final static int SCHEMA_URI = 11; 57 public final static int SCHEMA_QNAME = 12; 58 59 62 public static int JAVA_TYPE_BINDINGS[] = new int[33]; 64 static 65 { 66 JAVA_TYPE_BINDINGS[PrimitiveType.STRING] = JAVA_STRING; 68 JAVA_TYPE_BINDINGS[PrimitiveType.BOOLEAN] = JAVA_BOOLEAN; 69 JAVA_TYPE_BINDINGS[PrimitiveType.DECIMAL] = JAVA_BIG_DECIMAL; JAVA_TYPE_BINDINGS[PrimitiveType.FLOAT] = JAVA_FLOAT; 71 JAVA_TYPE_BINDINGS[PrimitiveType.DOUBLE] = JAVA_DOUBLE; 72 JAVA_TYPE_BINDINGS[PrimitiveType.QNAME] = SCHEMA_QNAME; 73 JAVA_TYPE_BINDINGS[PrimitiveType.NOTATION] = SCHEMA_QNAME; 74 JAVA_TYPE_BINDINGS[PrimitiveType.DURATION] = SCHEMA_DURATION; 75 JAVA_TYPE_BINDINGS[PrimitiveType.DATE_TIME] = SCHEMA_DATETIME; 76 JAVA_TYPE_BINDINGS[PrimitiveType.TIME] = SCHEMA_DATETIME; 77 JAVA_TYPE_BINDINGS[PrimitiveType.DATE] = SCHEMA_DATETIME; 78 JAVA_TYPE_BINDINGS[PrimitiveType.GYEAR_MONTH] = SCHEMA_DATETIME; 79 JAVA_TYPE_BINDINGS[PrimitiveType.GYEAR] = SCHEMA_DATETIME; 80 JAVA_TYPE_BINDINGS[PrimitiveType.GMONTH_DAY] = SCHEMA_DATETIME; 81 JAVA_TYPE_BINDINGS[PrimitiveType.GDAY] = SCHEMA_DATETIME; 82 JAVA_TYPE_BINDINGS[PrimitiveType.GMONTH] = SCHEMA_DATETIME; 83 JAVA_TYPE_BINDINGS[PrimitiveType.HEX_BINARY] = SCHEMA_BYTE_ARRAY; 84 JAVA_TYPE_BINDINGS[PrimitiveType.BASE64_BINARY] = SCHEMA_BYTE_ARRAY; 85 JAVA_TYPE_BINDINGS[PrimitiveType.ANY_URI] = SCHEMA_URI; 86 JAVA_TYPE_BINDINGS[PrimitiveType.UNION] = JAVA_UNKNOWN; 87 JAVA_TYPE_BINDINGS[PrimitiveType.LIST] = JAVA_LIST; 88 JAVA_TYPE_BINDINGS[PrimitiveType.ANYSIMPLETYPE] = JAVA_STRING; 89 90 } 91 92 96 98 protected int javaType = JAVA_STRING; 100 101 protected JavaTypeInfo() {} 105 106 public JavaTypeInfo(String XMLType) { setXMLType(XMLType);} 107 108 public JavaTypeInfo(SimpleType XMLType) { setXMLType(XMLType);} 109 110 public void setXMLType(String XMLType) 111 { 112 super.setXMLType(XMLType); 113 initialize(); 114 } 115 116 public void setXMLType(SimpleType XMLType) 117 { 118 super.setXMLType(XMLType); 119 initialize(); 120 } 121 122 125 private void initialize() 126 { 127 javaType = JAVA_TYPE_BINDINGS[sType.getPrimitive().getType()]; 128 } 129 130 public int getJavaType() 134 { 135 return javaType; 136 } 137 138 public String toString() 142 { 143 StringBuffer buf = new StringBuffer (); 144 buf.append("# NativeTypeInfo\n"); 145 buf.append("\tXML = "); 146 147 PrimitiveType pType = sType.getPrimitive(); 148 buf.append(pType); 149 buf.append("[maxLen="); 150 buf.append(pType.getMaxLength()); 151 buf.append(", totDig="); 152 buf.append(pType.getTotalDigits()); 153 buf.append(", fracDig="); 154 buf.append(pType.getFractionDigits()); 155 buf.append(", min="); 156 buf.append(pType.getMinValue()); 157 buf.append(", max="); 158 buf.append(pType.getMaxValue()); 159 160 buf.append("]\n"); 161 buf.append("\tJAVA = "); 162 buf.append(javaType); 163 buf.append("\n\n"); 164 165 return buf.toString(); 166 } 167 } 168 | Popular Tags |