import javax.xml.namespace.QName;\r
\r
import org.simantics.utils.datastructures.BijectionMap;\r
-import org.simantics.utils.datastructures.Pair;\r
import org.simantics.xml.sax.configuration.AttributeComposition;\r
import org.simantics.xml.sax.configuration.Configuration;\r
import org.simantics.xml.sax.configuration.IDProvider;\r
// return "Float.parseFloat(value)";\r
// return "value";\r
// }\r
- protected String getValueGetter(TypeEntry binding,String name) {\r
+ protected String getValueGetterMethod(TypeEntry binding,String name) {\r
if (binding == null)\r
return name+".getValue()";\r
+ return binding.getValueGetterMethod(name);\r
+ }\r
+ \r
+ protected String getValueGetter(TypeEntry binding,String name) {\r
+ if (binding == null)\r
+ return name;\r
return binding.getValueGetter(name);\r
}\r
protected String getValueGetter(TypeEntry binding) {\r
intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
\r
createClassHeader(fw.writer, isList);\r
- writeClass(fw.writer,true, null, className, baseClass, intrerfaces);\r
+ writeClass(fw.writer,false, null, className, baseClass, intrerfaces);\r
\r
writeIDProvider(fw.writer);\r
\r
}\r
} \r
if (simpleType != null) {\r
- Restriction restriction = simpleType.getRestriction();\r
- if (restriction == null)\r
- throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()+ ", SimpleType restriction is unset");\r
- QName base = restriction.getBase();\r
- \r
- \r
- //String binding = getBindingFromPrimitiveType(base);\r
- TypeEntry binding = getTypeEntry(base);\r
- writeAttribute(fw, attrName, relationName, binding, isReference);\r
+ org.w3._2001.xmlschema.List list = simpleType.getList();\r
+ if (list != null) {\r
+ TypeEntry binding = getTypeEntry(new QName(SCHEMA_NS, "string"));\r
+ writeAttribute(fw, attrName, relationName, binding, isReference);\r
+ } else {\r
+ Restriction restriction = simpleType.getRestriction();\r
+ if (restriction == null)\r
+ throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()+ ", SimpleType restriction is unset");\r
+ QName base = restriction.getBase();\r
+ \r
+ \r
+ //String binding = getBindingFromPrimitiveType(base);\r
+ TypeEntry binding = getTypeEntry(base);\r
+ writeAttribute(fw, attrName, relationName, binding, isReference);\r
+ }\r
} else {\r
// TODO : using default String attribute should be configured with rules.\r
//throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());\r
fw.writer.println(" {");\r
fw.writer.println(" Attribute a = element.getAttribute(\"" +attrName+"\");");\r
fw.writer.println(" if (a != null) {");\r
- fw.writer.println(" graph.claimLiteral(element.getData(),"+relationName+","+getValueGetter(binding,"a")+", "+binding.binding+");");\r
+ fw.writer.println(" graph.claimLiteral(element.getData(),"+relationName+","+getValueGetterMethod(binding,"a")+", "+binding.binding+");");\r
if (isReference)\r
fw.writer.println(" idProviderValue = a.getValue();"); \r
fw.writer.println(" }");\r
if (i > 0)\r
fw.writer.print(",");\r
if (defaultValue != null)\r
- fw.writer.print("a"+(i)+"!= null ? "+ getValueGetter(binding,"a"+(i++)) + " : " +defaultValue);\r
+ fw.writer.print("a"+(i)+"!= null ? "+ getValueGetterMethod(binding,"a"+(i++)) + " : " +defaultValue);\r
else\r
- fw.writer.print(getValueGetter(binding,"a"+(i++)));\r
+ fw.writer.print(getValueGetterMethod(binding,"a"+(i++)));\r
}\r
fw.writer.println("};");\r
fw.writer.println(" graph.claimLiteral(element.getData(),"+relationName+", value, "+arrayBinding+");");\r
writers.put(elementObj, fw);\r
boolean isList = false;\r
\r
- Pair<String, Boolean> inhertiance = getElementInheritance(elementObj);\r
- boolean inherited = inhertiance.second;\r
- String baseClass = inhertiance.first;//"org.simantics.xml.sax.base.XMLElementParserBase";\r
- \r
+ Inheritance inhertiance = getElementInheritance(elementObj); \r
\r
provider = getIDProvider(element);\r
List<IDReference> references = getIDReferences(element);\r
intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
\r
createClassHeader(fw.writer, isList);\r
- writeClass(fw.writer,false, element.getName(), className, baseClass, intrerfaces);\r
+ writeClass(fw.writer,false, element.getName(), className, inhertiance.baseClass, intrerfaces);\r
writeIDProvider(fw.writer);\r
fw.writer.println(" @Override");\r
fw.writer.println(" public Resource create(WriteGraph graph, Element element) throws DatabaseException{");\r
\r
fw.writer.println(" @Override");\r
fw.writer.println(" public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException {");\r
- if (inherited) {\r
+ if (inhertiance.type == InheritanceType.ComplexType) {\r
fw.writer.println(" super.configure(graph,parents,element);");\r
}\r
fw.writer.println(" "+getOntologyImport());\r
} \r
fw.writer.println(" }");\r
\r
+ if (inhertiance.type == InheritanceType.AtomicType) {\r
+ fw.writer.println();\r
+ fw.writer.println(" @Override");\r
+ fw.writer.println(" public void configure(WriteGraph graph, Element element, java.lang.String string) throws DatabaseException {");\r
+ fw.writer.println(" graph.claimValue(element.getData(), "+getValueGetter(inhertiance.atomicType,"string")+", "+inhertiance.atomicType.binding+");");\r
+ fw.writer.println(" }");\r
+ }\r
if (simpleType != null) {\r
SchemaObject obj = simpleTypes.get(simpleType);\r
handleElementSimpleTypeAttributes(obj);\r
if (stringWriter.getBuffer().length() > 0) {\r
fw.writer.write(stringWriter.toString());\r
}\r
- if (inherited) {\r
+ if (inhertiance.type == InheritanceType.ComplexType) {\r
fw.writer.println(" return super.connectChild(graph,element,child);"); \r
} else {\r
fw.writer.println(" return false;");\r
ruleClassNames.add(converter.getPluginName()+"."+elementPackageName+"."+name);\r
}\r
\r
- private Pair<String,Boolean> getElementInheritance(SchemaObject topLevelElementObj) {\r
+ private enum InheritanceType{ComplexType,AtomicType,None};\r
+ \r
+ private class Inheritance {\r
+ public String baseClass;\r
+ public InheritanceType type;\r
+ public TypeEntry atomicType;\r
+ \r
+ public Inheritance() {\r
+ baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
+ type = InheritanceType.None;\r
+ }\r
+ }\r
+ \r
+ private Inheritance getElementInheritance(SchemaObject topLevelElementObj) {\r
+ if (topLevelElementObj.getElement() != null && topLevelElementObj.getElement().getName().equals("ByteString"))\r
+ System.out.println();\r
Element topLevelElement = topLevelElementObj.getElement();\r
- String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
- boolean inherited = false;\r
+ Inheritance inheritance = new Inheritance();\r
if (topLevelElement.getType() != null) {\r
QName type = topLevelElement.getType();\r
if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
- baseClass = getName(obj);\r
- inherited = true;\r
- } \r
+// if (obj == null)\r
+// obj = simpleTypeName.get(type.getLocalPart());\r
+ if (obj != null) {\r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ }\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
}\r
- if (!inherited) {\r
+ if (inheritance.type == InheritanceType.None) {\r
QName type = getElementBase(topLevelElement);\r
if (type != null) {\r
if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
- baseClass = getName(obj);\r
- inherited = true;\r
- } \r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
}\r
}\r
- if (!inherited) {\r
+ if (inheritance.type == InheritanceType.None) {\r
QName type = topLevelElement.getSubstitutionGroup();\r
if (type != null) {\r
if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
- baseClass = getName(obj);\r
- inherited = true;\r
- } \r
+ inheritance.baseClass = getName(obj);\r
+ inheritance.type = InheritanceType.ComplexType;\r
+ } else {\r
+ TypeEntry entry = getTypeEntry(type);\r
+ if (entry != null) {\r
+ inheritance.type = InheritanceType.AtomicType;\r
+ inheritance.atomicType = entry;\r
+ }\r
+ }\r
}\r
}\r
\r
- return new Pair<String, Boolean>(baseClass, inherited);\r
+ return inheritance;\r
}\r
\r
private void writeClass(PrintWriter writer,boolean abst, String name, String className, String baseClass, List<String> interfaces) {\r
\r
import java.util.ArrayDeque;\r
import java.util.ArrayList;\r
+import java.util.Base64;\r
import java.util.Deque;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
Map<String,TypeEntry> l0Types = new HashMap<String, SchemaConversionBase.TypeEntry>();\r
typeMap.put(CONVERSION_NS, l0Types);\r
\r
- schemaTypes.put("string", new TypeEntry("L0.String", "Bindings.STRING", "String", "","",""));\r
- schemaTypes.put("NMTOKEN", new TypeEntry("L0.String", "Bindings.STRING", "String", "","",""));\r
- schemaTypes.put("token", new TypeEntry("L0.String", "Bindings.STRING", "String", "","",""));\r
- schemaTypes.put("ID", new TypeEntry("L0.String", "Bindings.STRING", "String", "","","",true));\r
- schemaTypes.put("IDREF", new TypeEntry("L0.String", "Bindings.STRING", "String", "","",""));\r
+ schemaTypes.put("string", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
+ schemaTypes.put("NMTOKEN", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
+ schemaTypes.put("token", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
+ schemaTypes.put("ID", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","","",true));\r
+ schemaTypes.put("IDREF", new TypeEntry("L0.String", "Bindings.STRING", "java.lang.String", "","",""));\r
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(",")"));\r
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(",")"));\r
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(",")"));\r
- schemaTypes.put("anyURI", new TypeEntry("L0.URI", "Bindings.STRING", "String", "","",""));\r
- schemaTypes.put("double", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "Double.NaN","Double.parseDouble(",")"));\r
- schemaTypes.put("float", new TypeEntry("L0.Float", "Bindings.FLOAT", "float", "Float.NaN","Float.parseFloat(",")"));\r
- schemaTypes.put("decimal", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "Double.NaN","Double.parseDouble(",")"));\r
- schemaTypes.put("boolean", new TypeEntry("L0.Boolean", "Bindings.BOOLEAN", "boolean", "false","Boolean.parseBoolean(",")"));\r
- schemaTypes.put("integer", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("unsignedInt", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("int", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("short", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","Integer.parseInt(",")"));\r
- schemaTypes.put("byte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","Byte.parseByte(",")"));\r
- schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","Byte.parseByte(",")"));\r
- schemaTypes.put("long", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","Long.parseLong(",")"));\r
- schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","Long.parseLong(",")"));\r
+ schemaTypes.put("anyURI", new TypeEntry("L0.URI", "Bindings.STRING", "java.lang.String", "","",""));\r
+ schemaTypes.put("double", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")"));\r
+ schemaTypes.put("float", new TypeEntry("L0.Float", "Bindings.FLOAT", "float", "java.lang.Float.NaN","java.lang.Float.parseFloat(",")"));\r
+ schemaTypes.put("decimal", new TypeEntry("L0.Double", "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")"));\r
+ schemaTypes.put("boolean", new TypeEntry("L0.Boolean", "Bindings.BOOLEAN", "boolean", "false","java.lang.Boolean.parseBoolean(",")"));\r
+ schemaTypes.put("integer", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("unsignedInt", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("int", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("short", new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer", "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
+ schemaTypes.put("byte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")"));\r
+ schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte", "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")"));\r
+ schemaTypes.put("long", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")"));\r
+ schemaTypes.put("unsignedLong", new TypeEntry("L0.Long", "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")"));\r
+ schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray", "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","java.util.Base64.getDecoder().decode(",")"));\r
\r
\r
\r
this.getterPostfix = getterPostfix;\r
}\r
\r
- public String getValueGetter(String name) {\r
+ public String getValueGetterMethod(String name) {\r
return getterPrefix + name + ".getValue()"+getterPostfix;\r
}\r
- public String getValueGetter() {\r
- return getterPrefix + "value"+getterPostfix;\r
+ public String getValueGetter(String name) {\r
+ return getterPrefix + name+getterPostfix;\r
+ }\r
+ public String getValueGetter()\r
+ {\r
+ return getValueGetter("value");\r
}\r
\r
}\r