import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.simantics.utils.datastructures.BijectionMap;
import org.simantics.xml.sax.SchemaConversionBase.Inheritance;
-import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;
import org.simantics.xml.sax.SchemaConversionBase.RefType;
import org.simantics.xml.sax.SchemaObject.ObjectType;
import org.simantics.xml.sax.configuration.AttributeComposition;
import org.w3._2001.xmlschema.LocalSimpleType;
import org.w3._2001.xmlschema.NamedAttributeGroup;
import org.w3._2001.xmlschema.NamedGroup;
-import org.w3._2001.xmlschema.Restriction;
import org.w3._2001.xmlschema.Schema;
import org.w3._2001.xmlschema.SimpleType;
writer.println();
ontRoot += ".";
+ writer.println(ontRoot+"SimpleTypes : L0.Library");
writer.println(ontRoot+"ComplexTypes : L0.Library");
writer.println(ontRoot+"AttributeGroups : L0.Library");
writer.println();
base.handle(this);
}
- protected String getType(QName qtype) {
+ protected String getType(QName qtype, String rel) {
String ontType = base.getL0TypeFromPrimitiveType(qtype);
if (ontType != null)
return ontType;
- else if (base.isComplexTypeRef(qtype.getLocalPart()))
- return ontRoot+getComplexTypePrefix()+qtype.getLocalPart();
- else if (base.isSimpleTypeRef(qtype.getLocalPart()))
- return ontRoot+qtype.getLocalPart();
- else if (base.isElementRef(qtype.getLocalPart()))
- return ontRoot+qtype.getLocalPart();
- else if (qtype.getPrefix() != null && qtype.getPrefix().length() > 0) {
- return ontRoot+qtype.getPrefix()+qtype.getLocalPart();
+ else {
+ if (base.isComplexTypeRef(qtype.getLocalPart()))
+ return getName(base.getComplexType(qtype), rel);
+ else if (base.isSimpleTypeRef(qtype.getLocalPart()))
+ return getName(base.getSimpleType(qtype), rel);
+ else if (base.isElementRef(qtype.getLocalPart()))
+ return getName(base.getElement(qtype), rel);
}
throw new RuntimeException("Reference to unknown type " + qtype.getLocalPart());
}
+ public String getSimpleTypePrefix() {
+ return "SimpleTypes.";
+ }
+
public String getComplexTypePrefix() {
return "ComplexTypes.";
}
return "AttributeGroups.";
}
- public void handleChoice(SchemaObject parent, SchemaElement indicator, java.util.List<SchemaElement> elements, String name) {
+ public String handleChoice(SchemaObject parent, SchemaElement indicator, java.util.List<SchemaElement> elements, String name) {
boolean single = true;
for (SchemaElement e : elements) {
if (e.getRestriction().many()) {
}
String relationName = getName(parent)+".has"+name;
writer.print(relationName);
-
- List<String> types = new ArrayList<String>();
- for (SchemaElement e : elements) {
- Element localElement = e.getElement();
- QName refType = null;
- String type = null;
-
- if (localElement.getName() != null) {
- refType = localElement.getType();
- type = base.getL0TypeFromPrimitiveType(refType);
- } else if (localElement.getRef() != null) {
- refType = localElement.getRef();
- type = base.getL0TypeFromPrimitiveType(refType);
- }
- if (type == null) {
- SchemaObject obj = base.getWithName(refType);
- types.add(getName(obj,"has"));
- }
- }
- if (types.size() > 0) {
- for (String type : types) {
- writer.print(" <R " + type);
- }
- } else {
- writer.print(" <R XML.hasElement");
- }
-
+ writer.print(" <R XML.hasElement");
writer.println();
- for (SchemaElement e : elements) {
- Element localElement = e.getElement();
- QName refType = null;
- String type = null;
- if (localElement.getName() != null) {
- refType = localElement.getType();
- type = getType(refType);
- } else if (localElement.getRef() != null) {
- refType = localElement.getRef();
- type = getType(refType);
- }
- if (type != null) {
- writer.println(" --> " + type);
- }
- }
if (!single) {
- writer.println(ontRoot+name+ "List <T XML.ElementList");
- if (types.size() == 0) {
- writer.println(relationName+ "List <R XML.hasElementList : L0.FunctionalRelation");
- } else {
- writer.print(relationName+ "List");
- for (String type : types) {
- writer.print(" <R " + type+"List");
- }
- writer.println(" : L0.FunctionalRelation");
- }
- writer.println(" --> " + ontRoot+name+"List");
+ String elementListType = getName(parent) + "." + name + "List";
+ writer.println(elementListType + " <T XML.ElementList");
+ writer.println(relationName + "List <R XML.hasElementList : L0.FunctionalRelation");
+ writer.println(" --> " + elementListType);
}
+
+ return relationName;
};
@Override
- public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType) {
- if (refType != refType.Element) {
+ public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element, String refName, RefType refType, String baseRelationName) {
+ if (refType != RefType.Element) {
QName referenceType = null;
if (refType == RefType.Type) {
referenceType = element.getElement().getType();
SchemaObject obj = null;
if (type == null) {
obj = base.getWithName(referenceType);
-
- writer.println(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
- writer.println(" --> " + getName(obj));
+ writer.print(getName(parent)+".has"+refName + " <R XML.hasElement <R " + getName(obj,"has"));
+ if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+ writer.println();
} else {
- writer.println(getName(parent)+".has"+refName + " <R XML.hasElement");
- writer.println(" --> " + getType(referenceType));
+ writer.print(getName(parent)+".has"+refName + " <R XML.hasElement");
+ if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+ writer.println();
+ writer.println(" --> " + getType(referenceType, ""));
}
if (base.useElementList(parent, indicator,element, refType == RefType.Reference, refName, referenceType)) {
if (refName == null)
refName = obj.getName();
- writer.println(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
+ writer.print(getName(parent)+".has"+refName + " <R " + getName(obj,"has"));
+ if (baseRelationName != null) writer.print(" <R " + baseRelationName);
+ writer.println();
writer.println(" --> " + getName(obj));
if (base.useElementList(parent, indicator,element, false, refName, new QName(obj.getName()))) {
writer.println(getName(parent)+"."+refName + "List <T XML.ElementList");
} else if (ontType != null) {
writer.println(" --> " + ontType);
} else if (primitiveType != null) {
- writer.println(" <R "+ontRoot+"has"+primitiveType.getLocalPart());
+ writer.println(" <R " + getType(primitiveType, "has"));
}
}
org.w3._2001.xmlschema.List list = simpleType.getList();
if (list != null) {
// TODO : process restriction in lists
- String relationName = ontRoot+"has"+name;
- if (parent != null)
- relationName = getName(parent)+".has"+name;
+ String relationName = getName(simpleTypeObj, "has");
writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");
String ontType = base.getL0Type(new QName(SchemaConversionBase.SCHEMA_NS, "string"));
writer.println(" --> " + ontType);
} else {
- String relationName = ontRoot+"has"+name;
- if (parent != null)
- relationName = getName(parent)+".has"+name;
+ QName base = this.base.getSimpleTypeBase(simpleType);
+ writer.println(getName(simpleTypeObj) + " <T " + getType(base, ""));
- writer.println(relationName+ " <R XML.hasAttribute : L0.FunctionalRelation");
+ String relationName = getName(simpleTypeObj, "has");
- QName base = this.base.getSimpleTypeBase(simpleType);
- Inheritance inheritance = new Inheritance("");
- this.base.getAtomicTypeInheritance(base, inheritance);
- if (inheritance.atomicType == null)
- throw new RuntimeException("Could not locate atomic type for SimpleType " + simpleType.getName());
- writer.println(" --> " + inheritance.atomicType.l0Type);
+ writer.println(relationName+ " : L0.FunctionalRelation");
+ writer.println(" --> " + getName(simpleTypeObj));
// Restriction restriction = simpleType.getRestriction();
// if (restriction != null) {
// if (topLevelComplexType.getName().equals("Reference"))
// System.out.println();
- String relationName = getName(topLevelComplexType,"has");//ontRoot+"has"+name;
-
- writer.println(relationName+ " <R XML.hasComplexType");
- writer.println(relationName+ "List <R XML.hasElementList");
- //writer.println(" --> " + ontRoot+getComplexTypePrefix()+name);
- writer.println(" --> " + name);
- writer.println();
// String baseType = "XML.ComplexType";
//
// QName base = getComplexTypeBase(topLevelComplexType.getComplexType());
// writer.println(name+ " <T "+baseType);
- if(inheritance.type == InheritanceType.AtomicType) {
- writer.println(name+ " <T "+inheritance.baseClass + " <T "+inheritance.atomicType.l0Type);
- } else {
- writer.println(name+ " <T "+inheritance.baseClass);
- }
+ // Type definition
+ writer.println(name+ " <T " + inheritance.baseClass);
+ writer.println(name + "List <T XML.ElementList");
+
+ // Access relations
+ String relationName = getName(topLevelComplexType,"has");
+ writer.println(relationName+ " <R XML.hasComplexType");
+ writer.println(" --> " + name);
+ writer.println(relationName+ "List <R XML.hasElementList");
+ writer.println(" --> " + name + "List");
+ writer.println();
+
+ // Attributes
// if (!baseType.equals(inheritance.baseClass))
// System.out.println();
//super.handleComplexType(topLevelComplexType);
String type = "XML.Element";
Set<String> types = new LinkedHashSet<String>();
if (element.getType() != null) {
- types.add(getType(element.getType()));
+ types.add(getType(element.getType(), ""));
}
QName base = this.base.getElementBase(element);
if (base != null) {
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+obj.getName();
case SIMPLE_TYPE:
- return ontRoot+obj.getName();
+ return ontRoot+getSimpleTypePrefix()+obj.getName();
}
} else {
SchemaObject o = obj;
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+name;
case SIMPLE_TYPE:
- return ontRoot+name;
+ return ontRoot+getSimpleTypePrefix()+name;
}
}
throw new RuntimeException();
}
+ public String getName(SchemaObject parent, SchemaElement e, String rel) {
+ QName ref = e.getElement().getRef();
+ if (ref != null) {
+ return converter.getShortName(ref.getNamespaceURI()) + rel + ref.getLocalPart();
+ }
+ else {
+ return getName(parent, "") + "." + rel + e.getElement().getName();
+ }
+ }
+
public String getName(SchemaObject obj, String rel) {
if (obj.getParent() == null) {
switch (obj.getType()) {
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+rel+obj.getName();
case SIMPLE_TYPE:
- return ontRoot+rel+obj.getName();
+ return ontRoot+getSimpleTypePrefix()+rel+obj.getName();
}
} else {
SchemaObject o = obj;
case ATTRIBUTE_GROUP:
return ontRoot+getAttributeGroupPrefix()+rel+name;
case SIMPLE_TYPE:
- return ontRoot+rel+name;
+ return ontRoot+getSimpleTypePrefix()+rel+name;
}
}
throw new RuntimeException();