+ private org.w3._2001.xmlschema.Attribute updateAttributeType(org.w3._2001.xmlschema.Attribute schemaAttribute, QName newType) {
+
+ QName currentType = schemaAttribute.getType();
+ if (currentType == null && schemaAttribute.getRef() != null) {
+ Schema schema = schemaMap.get(schemaAttribute.getRef().getNamespaceURI());
+
+ schemaAttribute = attributeMap.get(schema).get(schemaAttribute.getRef().getLocalPart());
+ currentType = schemaAttribute.getType();
+ }
+ if (currentType == null)
+ throw new RuntimeException("Could not resolve attribute");
+
+
+ schemaAttribute.setType(mergePrimitiveType(currentType, newType));
+ return schemaAttribute;
+
+ }
+
+ private QName mergePrimitiveType(QName currentType, QName newType) {
+ if (!newType.getLocalPart().equals(currentType.getLocalPart())) {
+
+
+ if (currentType.getLocalPart().equals("integer") && newType.getLocalPart().equals("double")) {
+ // change integer to double
+ return newType;
+ } else if (currentType.getLocalPart().equals("double") && newType.getLocalPart().equals("integer")) {
+ // nothing to do, integer can be parsed as double
+ return currentType;
+ } else if (currentType.getLocalPart().equals("boolean") && newType.getLocalPart().equals("integer")) {
+ // change boolean to int
+ return newType;
+ } else if (currentType.getLocalPart().equals("integer") && newType.getLocalPart().equals("boolean")) {
+ // nothing to do, boolean (0 & 1) can be parsed as integer.
+ // FIXME : what about true / false? Now type detection system does not accept 0 or 1 as boolean values, while XML supports it. See method: QName getType(String value)
+ // FIXME : also, if we support 0 & 1 as booleans, we need to consider possible double values as well.
+ return currentType;
+ } else if (!currentType.getLocalPart().equals("string")){
+ return new QName(SchemaConversionBase.SCHEMA_NS, "string");
+ }
+ }
+ return currentType;
+ }
+