return;\r
} else {\r
if (simpleType == null) {\r
- SchemaObject simpleTypeObj = base.simpleTypeName.get(primitiveType.getLocalPart());\r
+ SchemaObject simpleTypeObj = base.getSimpleType(primitiveType);\r
if (simpleTypeObj != null)\r
simpleType = simpleTypeObj.getSimpleType();\r
} \r
public void handle(SchemaObject parent, AttributeGroup attribute) {\r
if (parent != null) {\r
FileWriter fw = getWriter(parent);\r
- NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef().getLocalPart());\r
+ NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef());\r
fw.writer.println(commentTag+" AttributeGroup " + group.getName());\r
SchemaObject obj = new SchemaObject(parent,attribute);\r
for (Annotated annotated : group.getAttributeOrAttributeGroup()) {\r
fw.writer.println(" "+getOntologyImport());\r
fw.writer.println(" for (Statement attribute : attributes) {");\r
if (complexType != null) {\r
- SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ SchemaObject obj = this.base.getComplexType(complexType);\r
this.base.handleElementComplexTypeAttributes(obj);\r
} \r
fw.writer.println(" }");\r
fw.writer.println(" super(graph);");\r
fw.writer.println(" "+getOntologyImport());\r
if (complexType != null) {\r
- SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ SchemaObject obj = this.base.getComplexType(complexType);\r
this.base.handleComplexTypeExtension(obj);\r
} else if (simpleType != null) {\r
\r
return;\r
} else {\r
if (simpleType == null) {\r
- SchemaObject simpleTypeObj = this.base.simpleTypeName.get(primitiveType.getLocalPart());\r
+ SchemaObject simpleTypeObj = this.base.getSimpleType(primitiveType);//this.base.simpleTypeName.get(primitiveType.getLocalPart());\r
if (simpleTypeObj != null)\r
simpleType = simpleTypeObj.getSimpleType();\r
} \r
public void handle(SchemaObject parent, AttributeGroup attribute) {\r
if (parent != null) {\r
FileWriter fw = getWriter(parent);\r
- NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef().getLocalPart());\r
+ NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef());\r
fw.writer.println(commentTag+" AttributeGroup " + group.getName());\r
SchemaObject obj = new SchemaObject(parent,attribute);\r
for (Annotated annotated : group.getAttributeOrAttributeGroup()) {\r
handle(obj,(AttributeGroup)annotated);\r
}\r
}\r
+ //dd\r
+ if(true)\r
+ System.out.println();\r
fw.writer.println(commentTag+" End of AttributeGroup " + group.getName());\r
}\r
\r
LocalSimpleType simpleType = element.getSimpleType();\r
\r
if (complexType != null) {\r
- SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ SchemaObject obj = this.base.getComplexType(complexType);\r
this.base.handleElementComplexTypeAttributes(obj);\r
} \r
fw.writer.println(" }");\r
fw.writer.println(" super();");\r
\r
if (complexType != null) {\r
- SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ SchemaObject obj = this.base.getComplexType(complexType);\r
this.base.handleComplexTypeExtension(obj);\r
} else if (simpleType != null) {\r
\r
\r
String binding = this.base.getBindingFromPrimitiveType(refType);\r
if (binding == null) {\r
- SchemaObject refElement = this.base.elementName.get(refType.getLocalPart());\r
- SchemaObject refComplexType = this.base.complexTypeName.get(refType.getLocalPart());\r
+ SchemaObject refElement = this.base.getElement(refType);\r
+ SchemaObject refComplexType = this.base.getComplexType(refType);\r
\r
// prefer element reference over complex type reference\r
String primaryClassName = null;\r
type = base.getL0TypeFromPrimitiveType(refType);\r
}\r
if (type == null) {\r
- SchemaObject obj = base.getWithName(parent, refType.getLocalPart());\r
+ SchemaObject obj = base.getWithName(refType);\r
types.add(getName(obj,"has"));\r
} \r
}\r
if (refType == RefType.Type) {\r
referenceType = element.getElement().getType();\r
//refName = element.getElement().getName()\r
- SchemaObject eObj = base.elements.get(element.getElement());\r
+ SchemaObject eObj = base.getElement(element.getElement());//base.elements.get(element.getElement());\r
if (refName == null)\r
refName = eObj.getName();\r
} else {\r
String type = base.getL0TypeFromPrimitiveType(referenceType);\r
SchemaObject obj = null;\r
if (type == null) {\r
- obj = base.getWithName(parent, referenceType.getLocalPart());\r
+ obj = base.getWithName(referenceType);\r
\r
writer.println(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));\r
writer.println(" --> " + getName(obj));\r
LocalSimpleType simpleType = element.getSimpleType();\r
\r
if (complexType != null) {\r
- SchemaObject complexTypeObj = this.base.complexTypes.get(complexType);\r
+ SchemaObject complexTypeObj = this.base.getComplexType(complexType);\r
this.base.handleElementComplexTypeAttributes(complexTypeObj);\r
this.base.handleComplexTypeExtension(complexTypeObj);\r
} else if (simpleType != null) {\r
- SchemaObject simpleTypeObj = this.base.simpleTypes.get(simpleType);\r
+ SchemaObject simpleTypeObj = this.base.getSimpleType(simpleType);\r
this.base.handleElementSimpleTypeAttributes(simpleTypeObj);\r
}\r
\r
}\r
}\r
\r
- protected Map<String,SchemaObject> elementName = new HashMap<>();\r
- protected Map<String,SchemaObject> complexTypeName = new HashMap<>();\r
- protected Map<String,SchemaObject> simpleTypeName = new HashMap<>();\r
- protected Map<String,SchemaObject> modelGroupName = new HashMap<>();\r
- protected Map<Element,SchemaObject> elements = new HashMap<>();\r
- protected Map<ComplexType,SchemaObject> complexTypes = new HashMap<>();\r
- protected Map<SimpleType,SchemaObject> simpleTypes = new HashMap<>();\r
- protected Map<NamedGroup,SchemaObject> modelGroups = new HashMap<>();\r
- \r
- \r
- protected SchemaObject getWithName(SchemaObject referrer, String name) {\r
- SchemaObject obj = elementName.get(name);\r
+ private Map<String,SchemaObject> elementName = new HashMap<>();\r
+ private Map<String,SchemaObject> complexTypeName = new HashMap<>();\r
+ private Map<String,SchemaObject> simpleTypeName = new HashMap<>();\r
+ private Map<String,SchemaObject> modelGroupName = new HashMap<>();\r
+ private Map<Element,SchemaObject> elements = new HashMap<>();\r
+ private Map<ComplexType,SchemaObject> complexTypes = new HashMap<>();\r
+ private Map<SimpleType,SchemaObject> simpleTypes = new HashMap<>();\r
+ private Map<NamedGroup,SchemaObject> modelGroups = new HashMap<>();\r
+ \r
+ private SchemaObject _getWithName(QName name) {\r
+ SchemaObject obj = elementName.get(name.getLocalPart());\r
if (obj == null)\r
- obj = complexTypeName.get(name);\r
+ obj = complexTypeName.get(name.getLocalPart());\r
if (obj == null)\r
- obj = simpleTypeName.get(name);\r
- if (obj == null) {\r
- throw new RuntimeException("Cannot locate referred type " + name + " when handling " + referrer.getName());\r
- }\r
+ obj = simpleTypeName.get(name.getLocalPart());\r
return obj;\r
}\r
\r
- protected SchemaObject getWithName(String name) {\r
- SchemaObject obj = elementName.get(name);\r
- if (obj == null)\r
- obj = complexTypeName.get(name);\r
- if (obj == null)\r
- obj = simpleTypeName.get(name);\r
- if (obj == null) {\r
- throw new RuntimeException("Cannot locate referred type " + name);\r
+ protected SchemaObject getWithName(QName name) {\r
+ SchemaObject obj = _getWithName(name);\r
+ if (obj != null)\r
+ return obj;\r
+ if (name.getNamespaceURI() != null) {\r
+ for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) {\r
+ if (sc.base != null) {\r
+ obj = sc.base._getWithName(name);\r
+ if (obj != null) {\r
+ return obj;\r
+ }\r
+ }\r
+ } \r
}\r
- return obj;\r
+ return null;\r
+ }\r
+ \r
+ private NamedAttributeGroup _getAttributeGroup(QName name) {\r
+ for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {\r
+ if (attrs instanceof NamedAttributeGroup) {\r
+ NamedAttributeGroup group = (NamedAttributeGroup)attrs;\r
+ if (group.getName().equals(name.getLocalPart()))\r
+ return group;\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public NamedAttributeGroup getAttributeGroup(QName name) {\r
+ NamedAttributeGroup group = _getAttributeGroup(name);\r
+ if (group != null)\r
+ return group;\r
+ if (name.getNamespaceURI() != null) {\r
+ for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) {\r
+ if (sc.base != null) {\r
+ group = sc.base._getAttributeGroup(name);\r
+ if (group != null) {\r
+ return group;\r
+ }\r
+ }\r
+ } \r
+ }\r
+ return null;\r
+ }\r
+ \r
+ private SchemaObject _getElement(QName name) {\r
+ return elementName.get(name.getLocalPart());\r
+ }\r
+ \r
+ protected SchemaObject getElement(QName name) {\r
+ SchemaObject obj = _getElement(name);\r
+ if (obj != null)\r
+ return obj;\r
+ if (name.getNamespaceURI() != null) {\r
+ for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) {\r
+ if (sc.base != null) {\r
+ obj = sc.base._getElement(name);\r
+ if (obj != null) {\r
+ return obj;\r
+ }\r
+ }\r
+ } \r
+ }\r
+ return null;\r
+ }\r
+ \r
+ protected SchemaObject getElement(Element element) {\r
+ return elements.get(element);\r
+ }\r
+ \r
+ \r
+ private SchemaObject _getComplexType(QName name) {\r
+ return complexTypeName.get(name.getLocalPart());\r
+ }\r
+ \r
+ protected SchemaObject getComplexType(QName name) {\r
+ SchemaObject obj = _getComplexType(name);\r
+ if (obj != null)\r
+ return obj;\r
+ if (name.getNamespaceURI() != null) {\r
+ for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) {\r
+ if (sc.base != null) {\r
+ obj = sc.base._getComplexType(name);\r
+ if (obj != null) {\r
+ return obj;\r
+ }\r
+ }\r
+ } \r
+ }\r
+ return null;\r
+ }\r
+ \r
+ protected SchemaObject getComplexType(ComplexType complexType) {\r
+ return complexTypes.get(complexType);\r
+ }\r
+ \r
+ private SchemaObject _getSimpleType(QName name) {\r
+ return simpleTypeName.get(name.getLocalPart());\r
+ }\r
+ \r
+ protected SchemaObject getSimpleType(QName name) {\r
+ SchemaObject obj = _getSimpleType(name);\r
+ if (obj != null)\r
+ return obj;\r
+ if (name.getNamespaceURI() != null) {\r
+ for (SchemaConverter sc : converter.getConverter(name.getNamespaceURI())) {\r
+ if (sc.base != null) {\r
+ obj = sc.base._getSimpleType(name);\r
+ if (obj != null) {\r
+ return obj;\r
+ }\r
+ }\r
+ } \r
+ }\r
+ return null;\r
+ }\r
+ \r
+ protected SchemaObject getSimpleType(SimpleType simpleType) {\r
+ return simpleTypes.get(simpleType);\r
}\r
\r
protected SchemaObject getWithObj(SchemaObject referrer, OpenAttrs attrs) {\r
+ // FIXME : this method cannot handle references to other schemas.\r
SchemaObject obj = null;\r
if (attrs instanceof Element)\r
obj = elements.get(attrs);\r
return null;\r
}\r
\r
-\r
- \r
- \r
- \r
- \r
- \r
- \r
private void handleAttributes(SchemaObject complexType, List<Annotated> attributeOrAttributeGroup) {\r
//name = getComplexTypePrefix()+complexType.getName()\r
\r
}\r
}\r
} else {\r
+ if (choices.size() == 1 && sequences.size() == 0 && alls.size() == 0 && groups.size() == 0) {\r
+ // special case: handle lone choice inside sequence with maxOccurs > 1 \r
+ SchemaElement choice = choices.get(0);\r
+ // move multiplicity restrictions to choice\r
+ if (indicator.getRestriction().max == -1 || (choice.getRestriction().max > 0 && indicator.getRestriction().max > choice.getRestriction().max))\r
+ choice.getRestriction().max = indicator.getRestriction().max;\r
+ if (indicator.getRestriction().min == 0 || choice.getRestriction().min > indicator.getRestriction().min)\r
+ choice.getRestriction().min = indicator.getRestriction().min;\r
+ handle(parent, choice, elements);\r
+ return;\r
+ }\r
if (sequences.size() > 0 || choices.size() > 0 || alls.size() > 0 || groups.size() > 0) {\r
throw new RuntimeException("Cannot handle Sequence with inner ExplicitGroups");\r
}\r
return simpleTypeName.containsKey(ref);\r
}\r
\r
- public NamedAttributeGroup getAttributeGroup(String name) {\r
- for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {\r
- if (attrs instanceof NamedAttributeGroup) {\r
- NamedAttributeGroup group = (NamedAttributeGroup)attrs;\r
- if (group.getName().equals(name))\r
- return group;\r
- }\r
- }\r
- return null;\r
- }\r
- \r
public IDProvider getIDProvider(Element element) {\r
List<IDProvider> idProviders = new ArrayList<IDProvider>(2);\r
for (JAXBElement<?> e : configuration.getConversionRule()) {\r
QName type = getElementBase(topLevelElement);\r
if (type != null) {\r
if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
- SchemaObject obj = getWithName(topLevelObj, type.getLocalPart());\r
+ SchemaObject obj = getWithName(type);\r
inheritance.baseClass = getName(obj);\r
inheritance.type = InheritanceType.ComplexType;\r
} else {\r
QName type = topLevelElement.getSubstitutionGroup();\r
if (type != null) {\r
if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
- SchemaObject obj = getWithName(topLevelObj, type.getLocalPart());\r
+ SchemaObject obj = getWithName(type);\r
inheritance.baseClass = getName(obj);\r
inheritance.type = InheritanceType.ComplexType;\r
} else {\r
*/\r
public void getAtomicTypeInheritance(QName type, Inheritance inheritance) {\r
if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
- SchemaObject obj = getWithName(type.getLocalPart());\r
+ SchemaObject obj = getWithName(type);\r
+ System.out.println();\r
if (obj.getType() != ObjectType.SIMPLE_TYPE)\r
throw new RuntimeException("SimpleContent does not use SimpleType definition");\r
SimpleType simpleType = obj.getSimpleType();\r
import javax.xml.bind.JAXBException;\r
import javax.xml.bind.Unmarshaller;\r
\r
+import org.simantics.utils.datastructures.MapList;\r
import org.simantics.xml.sax.configuration.Configuration;\r
import org.w3._2001.xmlschema.Annotation;\r
import org.w3._2001.xmlschema.Import;\r
\r
private List<SchemaConverter> parent = new ArrayList<>();\r
private List<SchemaConverter> subConverters = new ArrayList<>();\r
- private Map<String,SchemaConverter> nameMap;\r
+ private Map<String,SchemaConverter> fileMap;\r
+ private MapList<String,SchemaConverter> schemaNSMap;\r
+ private MapList<String,SchemaConverter> shortNameMap;\r
\r
+ String schemaNs;\r
String ontologyUri;\r
String className;\r
String name;\r
this.parent.add(parent);\r
parent.subConverters.add(this);\r
} else {\r
- nameMap = new HashMap<>();\r
+ fileMap = new HashMap<>();\r
+ schemaNSMap = new MapList<>();\r
+ shortNameMap = new MapList<>();\r
}\r
- getRoot().nameMap.put(schemaFile.getAbsolutePath(), this);\r
+ getRoot().fileMap.put(schemaFile.getAbsolutePath(), this);\r
+ }\r
+ \r
+ public List<SchemaConverter> getConverter(String schemaNS) {\r
+ return getRoot().schemaNSMap.getValues(schemaNS);\r
}\r
\r
public void setFileImport(ManualSchemaFileImport fileImport) {\r
if (!schemaFile.exists())\r
throw new FileNotFoundException(schemaFile.getAbsolutePath());\r
}\r
- SchemaConverter subConverter = getRoot().nameMap.get((schemaFile.getAbsolutePath()));\r
+ SchemaConverter subConverter = getRoot().fileMap.get((schemaFile.getAbsolutePath()));\r
if (subConverter == null) {\r
subConverter = new SchemaConverter(this,schemaFile, conversionFile, outputPlugin);\r
subConverter.createPGraph = this.createPGraph;\r
\r
boolean init = false;\r
\r
+ protected void assignShortName() {\r
+ shortName = name.substring(0, 3).toUpperCase();\r
+ SchemaConverter root = getRoot();\r
+ if (!root.shortNameMap.containsKey(shortName)) {\r
+ root.shortNameMap.add(shortName, this);\r
+ return;\r
+ } else {\r
+ SchemaConverter sc = root.shortNameMap.getValues(shortName).get(0);\r
+ if (sc.schemaNs.equals(schemaNs)) {\r
+ root.shortNameMap.add(shortName, this);\r
+ return;\r
+ }\r
+ }\r
+ int i = 1;\r
+ while (true) {\r
+ String n = shortName+i;\r
+ if (!root.shortNameMap.containsKey(n)) {\r
+ shortName = n;\r
+ root.shortNameMap.add(shortName, this);\r
+ return;\r
+ } else {\r
+ SchemaConverter sc = root.shortNameMap.getValues(n).get(0);\r
+ if (sc.schemaNs.equals(schemaNs)) {\r
+ shortName = n;\r
+ root.shortNameMap.add(shortName, this);\r
+ return;\r
+ }\r
+ }\r
+ i++;\r
+ }\r
+ }\r
+ \r
protected void init() throws IOException, JAXBException {\r
if (init)\r
return;\r
header[2] = "File " + schemaFile.getAbsolutePath();\r
header[3] = "Date " + new Date().toString();\r
\r
- \r
- ontologyUri = schema.getTargetNamespace();\r
+ schemaNs = schema.getTargetNamespace();\r
+ ontologyUri = schemaNs;\r
if (ontologyUri == null) {\r
ontologyUri = getSchemaFile().getName();\r
\r
\r
\r
className = getPluginName() + "." + name;\r
- shortName = name.substring(0, 3).toUpperCase();\r
+ assignShortName();\r
+ if (schemaNs != null)\r
+ getRoot().schemaNSMap.add(schemaNs, this);\r
\r
\r
for (OpenAttrs attrs : schema.getIncludeOrImportOrRedefine()) {\r