]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java
XML data based schema and ontology generation
[simantics/interop.git] / org.simantics.xml.sax / src / org / simantics / xml / sax / SchemaConversionBase.java
index cb0f7629f2ca38f28f16a7d9cc11313f6dc6444c..049b08775cb915dfd28628851f28b38634966c11 100644 (file)
@@ -360,17 +360,17 @@ public final class SchemaConversionBase {
                for (OpenAttrs attrs : schema.getSimpleTypeOrComplexTypeOrGroup()) {
                        if (attrs instanceof Element) {
                                Element element = (Element)attrs;
-                               SchemaObject obj = new SchemaObject(element);
+                               SchemaObject obj = new SchemaObject(this,element);
                                obj.setRename(getRename(element));
                                stack.push(obj);
                        } else if (attrs instanceof ComplexType) {
                                ComplexType complexType = (ComplexType)attrs;
-                               SchemaObject obj = new SchemaObject(complexType);
+                               SchemaObject obj = new SchemaObject(this,complexType);
                                obj.setRename(getRename(complexType));
                                stack.push(obj);
                        } else if (attrs instanceof SimpleType) {
                                SimpleType simpleType = (SimpleType)attrs;
-                               SchemaObject obj = new SchemaObject(simpleType);
+                               SchemaObject obj = new SchemaObject(this,simpleType);
                                stack.push(obj);
                        }  else if (attrs instanceof Attribute) {
                                // Attributes are not cached
@@ -378,7 +378,7 @@ public final class SchemaConversionBase {
                                // Attribute groups are not cached
                        } else if (attrs instanceof NamedGroup) {
                                NamedGroup group = (NamedGroup)attrs;
-                               SchemaObject obj = new SchemaObject(group);
+                               SchemaObject obj = new SchemaObject(this,group);
                                stack.push(obj);
                        } else {
                                System.out.println(attrs.getClass().getName());
@@ -448,9 +448,9 @@ public final class SchemaConversionBase {
                                        elementName.put(e.getName(), object);
                                elements.put(e, object);
                                if (e.getComplexType() != null)
-                                       stack.push(new SchemaObject(object,e.getComplexType()));
+                                       stack.push(new SchemaObject(this,object,e.getComplexType()));
                                if (e.getSimpleType() != null)
-                                       stack.push(new SchemaObject(object,e.getSimpleType()));
+                                       stack.push(new SchemaObject(this,object,e.getSimpleType()));
                                break;
                        } 
                        case SIMPLE_TYPE:{
@@ -476,7 +476,7 @@ public final class SchemaConversionBase {
                                JAXBElement<?> element = (JAXBElement<?>)o;
                                Object elemValue = element.getValue();
                                if (elemValue instanceof Element) {
-                                       SchemaObject obj = new SchemaObject(parent,(Element)elemValue);
+                                       SchemaObject obj = new SchemaObject(this,parent,(Element)elemValue);
                                        obj.setRename(getRename((Element)elemValue));
                                        stack.add(obj);
                                } else if (elemValue instanceof ExplicitGroup) {
@@ -497,7 +497,7 @@ public final class SchemaConversionBase {
        private void preload(SchemaObject parent, RealGroup eg, Deque<SchemaObject> stack) {
                System.out.println(eg); 
                if (eg instanceof NamedGroup) {
-                       SchemaObject obj = new SchemaObject(parent,(NamedGroup)eg);
+                       SchemaObject obj = new SchemaObject(this,parent,(NamedGroup)eg);
                        stack.add(obj);
                }
        }
@@ -952,19 +952,31 @@ public final class SchemaConversionBase {
                }
        }
        
-       protected String getElementName(Element localElement) {
+       protected String getName(Element localElement) {
                if (localElement.getName() != null) {
                        String refName = localElement.getName();
-                       QName refType = localElement.getType();
-                       if (refType != null)
-                               return refName;
+                       return refName.replaceAll("\\.", "_");
                } else if (localElement.getRef() != null) {
                        QName refType = localElement.getRef();
                        if (refType != null)
-                               return refType.getLocalPart();
+                               return getName(refType);
+                               
                }
                return null;
        }
+
+       protected String getName(QName ref) {
+               String n = ref.getLocalPart();
+               return n.replaceAll("\\.", "_");
+       }
+       
+       protected String getName(Attribute ref) {
+               String n = ref.getName();
+               if (n != null)
+                       return n.replaceAll("\\.", "_");
+               else
+                       return null;
+       }
        
        protected String getChoiceName(List<SchemaElement> elements) {
                if (elements.size() == 1) {
@@ -973,7 +985,7 @@ public final class SchemaConversionBase {
                else if (elements.size() > 0 && elements.size() <= 3) {
                        List<String> names = new ArrayList<String>();
                        for (SchemaElement e : elements) {
-                               String name = getElementName(e.getElement());
+                               String name = getName(e.getElement());
                                if (name != null)
                                        names.add(name);
                        }