From bcfe73ff5f614ff83f20ce7bf5bfc0fa1b045978 Mon Sep 17 00:00:00 2001 From: luukkainen Date: Thu, 4 Feb 2016 12:23:44 +0000 Subject: [PATCH] Schema conversion updates (necessary for Proteus PID Profile schema) refs #6301 git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@32344 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/xml/sax/ImporterGenerator.java | 6 ++++-- .../simantics/xml/sax/OntologyGenerator.java | 4 ++++ .../simantics/xml/sax/SchemaConversionBase.java | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java index cff87ed..eb99b53 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java @@ -525,7 +525,8 @@ public class ImporterGenerator extends SchemaConversionBase{ String binding = getBindingFromPrimitiveType(base); writeAttribute(fw, attrName, relationName, binding, isReference); } else { - throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()); + //throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()); + //writeAttribute(fw, attrName, relationName, binding, isReference); } } @@ -607,7 +608,8 @@ public class ImporterGenerator extends SchemaConversionBase{ // FIXME : handle optional attributes properly. for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute()) { Attribute attribute = ((Attribute)attributes.getRight(a)); - QName atype = getBaseType(attribute); + //QName atype = getBaseType(attribute); + QName atype = getPrimitiveType(attribute); String defaultValue = attribute.getDefault(); if (defaultValue == null) defaultValue = getDefaultValue(atype); diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java index 530798e..0b7aa3c 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java @@ -101,6 +101,7 @@ public class OntologyGenerator extends SchemaConversionBase { version = "1.0"; name = name.replaceAll("\\.", "_"); + name = name.replaceAll(" ", "_"); className = converter.getPluginName() + "." + name; for (String s : converter.getHeader()) { @@ -451,6 +452,9 @@ public class OntologyGenerator extends SchemaConversionBase { protected void handleElement(SchemaObject elementObj) { Element element = elementObj.getElement(); String name = getName(elementObj);//element.getName(); + +// if ("Presentation".equals(name)) +// System.out.println(); // if (parent != null) // name = parent +"_"+name; 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..f523076 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 @@ -436,6 +436,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) { -- 2.47.1