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=600d13fd7dc91e35989375d8f3df4afe86fb63bb;hb=dd3b2c7ecd5f4b60734f2602b16637aa8be2a263;hp=bcff6982821b680ebf230e9c4840c5a30dea5901;hpb=47791aa9453c9d90786bc8ca7de102fb3ee90f3b;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 bcff698..600d13f 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,7 +2,6 @@ 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; @@ -21,6 +20,7 @@ import org.simantics.xml.sax.configuration.Configuration; import org.simantics.xml.sax.configuration.IDProvider; import org.simantics.xml.sax.configuration.IDReference; import org.simantics.xml.sax.configuration.OrderedChild; +import org.simantics.xml.sax.configuration.Rename; import org.simantics.xml.sax.configuration.UnrecognizedChildElement; import org.w3._2001.xmlschema.All; import org.w3._2001.xmlschema.Annotated; @@ -63,38 +63,38 @@ public abstract class SchemaConversionBase { Map l0Types = new HashMap(); typeMap.put(CONVERSION_NS, l0Types); - 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)")); + 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(",")","(",").toString()")); + 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(",")","(",").toString()")); + 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(",")","(",").toString()")); + 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(",")","java.lang.Double.toString(",")")); + schemaTypes.put("float", new TypeEntry("L0.Float", "Bindings.FLOAT", "float", "java.lang.Float.NaN","java.lang.Float.parseFloat(",")","java.lang.Float.toString(",")")); + schemaTypes.put("decimal", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")","java.lang.Double.toString(",")")); + schemaTypes.put("boolean", new TypeEntry("L0.Boolean", "Bindings.BOOLEAN", "boolean", "false","java.lang.Boolean.parseBoolean(",")","java.lang.Boolean.toString(",")")); + schemaTypes.put("integer", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("unsignedInt", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("int", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("short", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")")); + schemaTypes.put("byte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")")); + schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")")); + schemaTypes.put("long", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")")); + schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")")); + schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray", "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","",".getBytes(org.simantics.databoard.util.binary.UTF8.CHARSET)","new java.lang.String(",", org.simantics.databoard.util.binary.UTF8.CHARSET)")); - 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)); + l0Types.put("doubleArray", new TypeEntry("L0.DoubleArray", "Bindings.DOUBLE_ARRAY", "double[]", null,null,null,"java.lang.Double.toString(",")")); + l0Types.put("stringArray", new TypeEntry("L0.StringArray", "Bindings.STRING_ARRAY", "string[]", null,null,null,"","")); } @@ -216,10 +216,12 @@ public abstract class SchemaConversionBase { if (attrs instanceof Element) { Element element = (Element)attrs; SchemaObject obj = new SchemaObject(element); + obj.setRename(getRename(element)); stack.push(obj); } else if (attrs instanceof ComplexType) { ComplexType complexType = (ComplexType)attrs; SchemaObject obj = new SchemaObject(complexType); + obj.setRename(getRename(complexType)); stack.push(obj); } else if (attrs instanceof SimpleType) { SimpleType simpleType = (SimpleType)attrs; @@ -287,7 +289,9 @@ public abstract class SchemaConversionBase { JAXBElement element = (JAXBElement)o; Object elemValue = element.getValue(); if (elemValue instanceof Element) { - stack.add(new SchemaObject(parent,(Element)elemValue)); + SchemaObject obj = new SchemaObject(parent,(Element)elemValue); + obj.setRename(getRename((Element)elemValue)); + stack.add(obj); } else if (elemValue instanceof All) { preload(parent,(All)elemValue, stack); } else if (elemValue instanceof ExplicitGroup) { @@ -509,7 +513,6 @@ public abstract class SchemaConversionBase { Object elemValue = element.getValue(); if (elemValue instanceof LocalElement) { LocalElement localElement = (LocalElement)elemValue; - elements.add(new SchemaElement(indicator,localElement, ElementType.ELEMENT)); } else if (elemValue instanceof All) { alls.add(new SchemaElement(indicator,(All)elemValue, ElementType.ALL)); @@ -603,14 +606,14 @@ public abstract class SchemaConversionBase { protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) { Element localElement = element.getElement(); if (localElement.getName() != null) { - String refName = localElement.getName(); + SchemaObject eObj = elements.get(localElement); // FIXME: handleIndicator should be refactored, not this methdof must be overridden in JavaGenerator to handle renaming of Elements properly + String refName = eObj.getName();//localElement.getName(); QName refType = localElement.getType(); if (refType != null) handleIndicator(parent, indicator, element, false, refName, refType); else { - handleElement(elements.get(localElement)); + handleElement(eObj); handleIndicator(parent, indicator, element, false, refName, localElement); - //FIXME: } } else if (localElement.getRef() != null) { QName refType = localElement.getRef(); @@ -814,11 +817,11 @@ public abstract class SchemaConversionBase { public UnrecognizedChildElement getUnknown(ComplexType complexType) { for (JAXBElement e : configuration.getConversionRule()) { if (e.getValue() instanceof UnrecognizedChildElement) { - UnrecognizedChildElement ref = (UnrecognizedChildElement)e.getValue(); - org.simantics.xml.sax.configuration.ComplexType complexType2 = ref.getComplexType(); + UnrecognizedChildElement rule = (UnrecognizedChildElement)e.getValue(); + org.simantics.xml.sax.configuration.ComplexType complexType2 = rule.getComplexType(); if (complexType2 != null) { if (complexType.getName().equals(complexType2.getName())) - return ref; + return rule; } } } @@ -828,17 +831,65 @@ public abstract class SchemaConversionBase { public UnrecognizedChildElement getUnknown(Element element) { for (JAXBElement e : configuration.getConversionRule()) { if (e.getValue() instanceof UnrecognizedChildElement) { - UnrecognizedChildElement ref = (UnrecognizedChildElement)e.getValue(); - org.simantics.xml.sax.configuration.Element element2 = ref.getElement(); + UnrecognizedChildElement rule = (UnrecognizedChildElement)e.getValue(); + org.simantics.xml.sax.configuration.Element element2 = rule.getElement(); if (element2 != null) { if (element.getName().equals(element2.getName())) - return ref; + return rule; } } } return null; } + public Rename getRename(Attribute element) { + for (JAXBElement e : configuration.getConversionRule()) { + if (e.getValue() instanceof Rename) { + Rename rule = (Rename)e.getValue(); + Object ref = rule.getElementOrComplexTypeOrAttribute().get(0); + if (!(ref instanceof org.simantics.xml.sax.configuration.Attribute)) + continue; + org.simantics.xml.sax.configuration.Attribute element2 = (org.simantics.xml.sax.configuration.Attribute)ref; + if (element2.getName().equals(element.getName())) { + return rule; + } + } + } + return null; + } + + public Rename getRename(ComplexType element) { + for (JAXBElement e : configuration.getConversionRule()) { + if (e.getValue() instanceof Rename) { + Rename rule = (Rename)e.getValue(); + Object ref = rule.getElementOrComplexTypeOrAttribute().get(0); + if (!(ref instanceof org.simantics.xml.sax.configuration.ComplexType)) + continue; + org.simantics.xml.sax.configuration.ComplexType element2 = (org.simantics.xml.sax.configuration.ComplexType)ref; + if (element2.getName().equals(element.getName())) { + return rule; + } + } + } + return null; + } + + public Rename getRename(Element element) { + for (JAXBElement e : configuration.getConversionRule()) { + if (e.getValue() instanceof Rename) { + Rename rule = (Rename)e.getValue(); + Object ref = rule.getElementOrComplexTypeOrAttribute().get(0); + if (!(ref instanceof org.simantics.xml.sax.configuration.Element)) + continue; + org.simantics.xml.sax.configuration.Element element2 = (org.simantics.xml.sax.configuration.Element)ref; + if (element2.getName().equals(element.getName())) { + return rule; + } + } + } + return null; + } + public boolean useOriginalList(SchemaObject parent, SchemaElement indicator, SchemaElement element, boolean reference, String ref, QName refType) { if (parent.getName() == null) @@ -942,7 +993,9 @@ public abstract class SchemaConversionBase { boolean id; String getterPrefix; String getterPostfix; - public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix) { + String stringPrefix; + String stringPostfix; + public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, String stringPrefix, String stringPostfix) { super(); this.l0Type = l0Type; this.binding = binding; @@ -951,10 +1004,11 @@ public abstract class SchemaConversionBase { this.id = false; this.getterPrefix = getterPrefix; this.getterPostfix = getterPostfix; - + this.stringPrefix = stringPrefix; + this.stringPostfix = stringPostfix; } - public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, boolean id) { + public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, String stringPrefix, String stringPostfix, boolean id) { super(); this.l0Type = l0Type; this.binding = binding; @@ -963,6 +1017,8 @@ public abstract class SchemaConversionBase { this.id = id; this.getterPrefix = getterPrefix; this.getterPostfix = getterPostfix; + this.stringPrefix = stringPrefix; + this.stringPostfix = stringPostfix; } public String getValueGetterMethod(String name) { @@ -976,6 +1032,14 @@ public abstract class SchemaConversionBase { return getValueGetter("value"); } + public String getToString(String name) { + return stringPrefix +"("+javaType+")"+name+stringPostfix; + } + + public String getElementToString(String name) { + return stringPrefix + name+stringPostfix; + } + } }