X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2FSchemaConversionBase.java;h=bcff6982821b680ebf230e9c4840c5a30dea5901;hb=47791aa9453c9d90786bc8ca7de102fb3ee90f3b;hp=f35a8845acc74e7a0e081ffdf76498c67b7cf5b9;hpb=ada38ab0a1a98dcb413bef3273064da36ce2d273;p=simantics%2Finterop.git diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java index f35a884..bcff698 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java @@ -2,6 +2,7 @@ package org.simantics.xml.sax; import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Base64; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; @@ -62,36 +63,38 @@ public abstract class SchemaConversionBase { Map l0Types = new HashMap(); typeMap.put(CONVERSION_NS, l0Types); - schemaTypes.put("string", new TypeEntry("L0.String", "STRING", "String", "")); - schemaTypes.put("NMTOKEN", new TypeEntry("L0.String", "STRING", "String", "")); - schemaTypes.put("token", new TypeEntry("L0.String", "STRING", "String", "")); - schemaTypes.put("ID", new TypeEntry("L0.String", "STRING", "String", "",true)); - schemaTypes.put("IDREF", new TypeEntry("L0.String", "STRING", "String", "")); - schemaTypes.put("date", new TypeEntry("L0.String", "STRING", "String", "")); - schemaTypes.put("time", new TypeEntry("L0.String", "STRING", "String", "")); - schemaTypes.put("anyURI", new TypeEntry("L0.URI", "STRING", "String", "")); - schemaTypes.put("double", new TypeEntry("L0.Double", "DOUBLE", "double", "Double.NaN")); - schemaTypes.put("float", new TypeEntry("L0.Float", "FLOAT", "float", "Float.NaN")); - schemaTypes.put("decimal", new TypeEntry("L0.Double", "DOUBLE", "double", "Double.NaN")); - schemaTypes.put("boolean", new TypeEntry("L0.Boolean", "BOOLEAN", "boolean", "false")); - schemaTypes.put("integer", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("unsignedInt", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("int", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("short", new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer", "INTEGER", "int", "0")); - schemaTypes.put("byte", new TypeEntry("L0.Byte", "BYTE", "byte", "0")); - schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "BYTE", "byte", "0")); - schemaTypes.put("long", new TypeEntry("L0.Long", "LONG", "long", "0")); - schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "LONG", "long", "0")); + schemaTypes.put("string", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","")); + schemaTypes.put("NMTOKEN", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","")); + schemaTypes.put("token", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","")); + schemaTypes.put("ID", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","",true)); + schemaTypes.put("IDREF", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","")); + schemaTypes.put("date", new TypeEntry("XML.Date", "org.simantics.xml.sax.base.datatypes.literal.Date.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Date", "","org.simantics.xml.sax.base.datatypes.literal.Date.parseDate(",")")); + schemaTypes.put("time", new TypeEntry("XML.Time", "org.simantics.xml.sax.base.datatypes.literal.Time.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Time", "","org.simantics.xml.sax.base.datatypes.literal.Time.parseTime(",")")); + schemaTypes.put("dateTime", new TypeEntry("XML.DateTime", "org.simantics.xml.sax.base.datatypes.literal.DateTime.BINDING", "org.simantics.xml.sax.base.datatypes.literal.DateTime", "","org.simantics.xml.sax.base.datatypes.literal.DateTime.parseDateTime(",")")); + schemaTypes.put("anyURI", new TypeEntry("L0.URI", "Bindings.STRING", "java.lang.String", "","","")); + schemaTypes.put("double", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")")); + schemaTypes.put("float", new TypeEntry("L0.Float", "Bindings.FLOAT", "float", "java.lang.Float.NaN","java.lang.Float.parseFloat(",")")); + schemaTypes.put("decimal", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")")); + schemaTypes.put("boolean", new TypeEntry("L0.Boolean", "Bindings.BOOLEAN", "boolean", "false","java.lang.Boolean.parseBoolean(",")")); + schemaTypes.put("integer", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("unsignedInt", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("int", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("short", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")")); + schemaTypes.put("byte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")")); + schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")")); + schemaTypes.put("long", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")")); + schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")")); + schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray", "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","",".getBytes(org.simantics.databoard.util.binary.UTF8.CHARSET)")); - l0Types.put("doubleArray", new TypeEntry("L0.DoubleArray", "DOUBLE_ARRAY", "double[]", null)); - l0Types.put("stringArray", new TypeEntry("L0.StringArray", "STRING_ARRAY", "string[]", null)); + l0Types.put("doubleArray", new TypeEntry("L0.DoubleArray", "Bindings.DOUBLE_ARRAY", "double[]", null,null,null)); + l0Types.put("stringArray", new TypeEntry("L0.StringArray", "Bindings.STRING_ARRAY", "string[]", null,null,null)); } @@ -101,7 +104,14 @@ public abstract class SchemaConversionBase { return null; TypeEntry entry = types.get(type.getLocalPart()); return entry; - + } + protected TypeEntry getTypeEntry(String type) { + for (Map types : typeMap.values()) { + TypeEntry entry = types.get(type); + if (entry != null) + return entry; + } + return null; } protected String getL0TypeFromPrimitiveType(QName primitiveType) { @@ -436,6 +446,23 @@ public abstract class SchemaConversionBase { return null; } + protected QName getPrimitiveType(Attribute attribute) { + QName type = getBaseType(attribute); + String b = getBindingFromPrimitiveType(type); + while (b==null && type != null) { + SchemaObject baseType = simpleTypeName.get(type.getLocalPart()); + if (baseType != null) { + Restriction restriction = baseType.getSimpleType().getRestriction(); + if (restriction != null) + if (restriction.getBase() != null) { + type = restriction.getBase(); + b = getBindingFromPrimitiveType(type); + } + } + } + return type; + } + protected Attribute getRefAttribute(QName ref) { for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) { if (attrs instanceof TopLevelAttribute) { @@ -913,22 +940,40 @@ public abstract class SchemaConversionBase { String javaType; String defaultValue; boolean id; - public TypeEntry(String l0Type, String binding, String javaType, String defaultValue) { + String getterPrefix; + String getterPostfix; + public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix) { super(); this.l0Type = l0Type; this.binding = binding; this.javaType = javaType; this.defaultValue = defaultValue; this.id = false; + this.getterPrefix = getterPrefix; + this.getterPostfix = getterPostfix; + } - public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, boolean id) { + public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, boolean id) { super(); this.l0Type = l0Type; this.binding = binding; this.javaType = javaType; this.defaultValue = defaultValue; this.id = id; + this.getterPrefix = getterPrefix; + this.getterPostfix = getterPostfix; + } + + public String getValueGetterMethod(String name) { + return getterPrefix + name + ".getValue()"+getterPostfix; + } + public String getValueGetter(String name) { + return getterPrefix + name+getterPostfix; + } + public String getValueGetter() + { + return getValueGetter("value"); } }