1 23 24 package org.xquark.jdbc.typing; 25 26 import java.io.StringReader ; 27 28 import org.xml.sax.InputSource ; 29 import org.xml.sax.SAXException ; 30 import org.xquark.schema.*; 31 32 36 public class XMLTypeInfo implements SchemaConstants 37 { 38 private static final String RCSRevision = "$Revision: 1.1 $"; 39 private static final String RCSName = "$Name: $"; 40 41 46 protected SimpleType sType; 47 48 protected String stringType; 49 50 protected XMLTypeInfo() {} 54 55 59 public XMLTypeInfo(String XMLType) 60 { 61 setXMLType(XMLType); 62 } 63 64 67 public XMLTypeInfo(SimpleType XMLType) 68 { 69 setXMLType(XMLType); 70 } 71 72 75 public void setXMLType(SimpleType XMLType) 76 { 77 sType = XMLType; 78 } 79 80 83 public SimpleType getXMLType() 84 { 85 return sType; 86 } 87 88 public String getStringXMLType() 89 { 90 return stringType; 91 } 92 93 97 public void setXMLType(String XMLType) 98 { 99 XMLType = XMLType.trim(); 100 stringType = XMLType; 101 102 SchemaManager dummyManager = new SchemaManager(); 103 int offset = XMLType.indexOf(SIMPLE_TYPE_TAG); 104 final String DUMMY_TYPE = "dummyType"; 105 106 if (offset >= 0) { 108 StringBuffer dummySchemaString = new StringBuffer ("<"); 109 dummySchemaString.append(SCHEMA_TAG); 110 dummySchemaString.append(" xmlns=\""); 111 dummySchemaString.append(XMLSCHEMA_URI); 112 dummySchemaString.append("\" "); 113 dummySchemaString.append(TARGET_NAMESPACE_ATTR); 114 dummySchemaString.append("=\"RepositoryTemp\">"); 115 dummySchemaString.append(XMLType.substring(0, offset + SIMPLE_TYPE_TAG.length())); 116 dummySchemaString.append(" name=\""); 117 dummySchemaString.append(DUMMY_TYPE); 118 dummySchemaString.append('"'); 119 dummySchemaString.append(XMLType.substring(offset + SIMPLE_TYPE_TAG.length())); 120 dummySchemaString.append("</"); 121 dummySchemaString.append(SCHEMA_TAG); 122 dummySchemaString.append('>'); 123 124 Schema dummySchema; 126 try { 127 dummySchema = dummyManager.loadSchema(new InputSource (new StringReader (dummySchemaString.toString()))); 128 } 129 catch (SAXException e) { 130 throw new RuntimeException (e.getMessage()); 131 } 132 sType = (SimpleType)dummySchema.getType(DUMMY_TYPE); 133 } 134 else { 136 sType = (SimpleType)dummyManager.getType(XMLSCHEMA_URI, XMLType); 137 if (sType == null) 138 throw new RuntimeException ("Unknown XML Schema predefined datatype \"" + XMLType + "\" in user generator"); 139 } 140 } 141 142 public String toString() 143 { 144 return sType.toString(); 145 } 146 147 } 148 | Popular Tags |