import javax.xml.namespace.QName;\r
\r
import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.SchemaConversionBase.Inheritance;\r
+import org.simantics.xml.sax.SchemaConversionBase.InheritanceType;\r
+import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
+import org.simantics.xml.sax.SchemaConversionBase.TypeEntry;\r
import org.simantics.xml.sax.SchemaObject.ObjectType;\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
import org.simantics.xml.sax.configuration.IDReference;\r
import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
import org.w3._2001.xmlschema.LocalComplexType;\r
import org.w3._2001.xmlschema.LocalSimpleType;\r
import org.w3._2001.xmlschema.NamedAttributeGroup;\r
+import org.w3._2001.xmlschema.NamedGroup;\r
import org.w3._2001.xmlschema.Restriction;\r
-import org.w3._2001.xmlschema.Schema;\r
import org.w3._2001.xmlschema.SimpleType;\r
-import org.w3._2001.xmlschema.TopLevelAttribute;\r
\r
public class ExporterGenerator extends JavaGenerator{\r
\r
- public ExporterGenerator(Configuration configuration) {\r
- super(configuration);\r
+ public ExporterGenerator(SchemaConverter converter, SchemaConversionBase base) {\r
+ super(converter, base);\r
}\r
\r
- \r
- \r
- public void createParser(Schema schema,String ontologyUri, String className, SchemaConverter converter) throws IOException {\r
- this.schema = schema;\r
- this.ontologyClassName = className;\r
- this.converter = converter;\r
- \r
- \r
- String packageParts[] = className.split("\\.");\r
- String name = packageParts[packageParts.length-1];\r
- \r
+ public void createParser() throws IOException {\r
\r
- ontShort = name.substring(0, 3).toUpperCase();\r
- ontShort +=".";\r
String parserPackagePostfix = "_exp";\r
String importerClassPostfix = "Exporter";\r
String parserClassPostfix = "Writer";\r
if (!importParserDir.exists())\r
importParserDir.mkdirs();\r
\r
- handle(schema);\r
+ base.handle(this);\r
// Create Importer class\r
File importerFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+importerClassPostfix+".java");\r
PrintWriter mainWriter = createFile(importerFile);\r
mainWriter.close();\r
}\r
\r
- protected void handle(TopLevelAttribute topLevelAttribute) {\r
-\r
- }\r
+// @Override\r
+// protected void handle(TopLevelAttribute topLevelAttribute) {\r
+//\r
+// }\r
\r
@Override\r
- protected String getBaseClass(ObjectType type) {\r
+ public String getBaseClass(ObjectType type) {\r
return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
}\r
\r
@Override\r
- protected void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
+ public void handleSimpleType(SchemaObject parent, SchemaObject simpleTypeObj) {\r
+ }\r
+ \r
+ @Override\r
+ public void handle(SchemaObject parent, NamedGroup attribute) {\r
+ // TODO Auto-generated method stub\r
+ \r
}\r
\r
@Override\r
- protected void handleComplexType(SchemaObject complexTypeObj) {\r
+ public void handleComplexType(SchemaObject complexTypeObj) {\r
ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
\r
String name = getName(complexTypeObj);\r
// inherited = true;\r
// }\r
// }\r
- Inheritance inheritance = getInheritance(complexTypeObj);\r
+ Inheritance inheritance = base.getInheritance(complexTypeObj);\r
\r
- provider = getIDProvider(topLevelComplexType);\r
+ provider = base.getIDProvider(topLevelComplexType);\r
// List<IDReference> references = getIDReferences(topLevelComplexType);\r
// UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);\r
\r
fw.writer.println(" super(graph);");\r
fw.writer.println(" "+getOntologyImport());\r
\r
- handleComplexTypeExtension(complexTypeObj);\r
+ base.handleComplexTypeExtension(complexTypeObj);\r
\r
fw.writer.println(" }");\r
\r
}\r
fw.writer.println(" "+getOntologyImport());\r
fw.writer.println(" for (Statement attribute : attributes) {");\r
- handleComplexTypeAttributes(complexTypeObj);\r
- handleExtensionAttributes(complexTypeObj);\r
+ base.handleComplexTypeAttributes(complexTypeObj);\r
+ base.handleExtensionAttributes(complexTypeObj);\r
fw.writer.println(" }");\r
fw.writer.println(" }");\r
\r
}\r
\r
@Override\r
- protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) { \r
+ public void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) { \r
// generates overriding method that allows writing any element\r
FileWriter fw = getWriter(parent);\r
fw.delayedWriter2.println(" @Override");\r
}\r
\r
@Override \r
- protected void handle(SchemaObject parent, Attribute attribute) {\r
+ public void handle(SchemaObject parent, Attribute attribute) {\r
+ if (parent == null)\r
+ return;\r
String name = attribute.getName();\r
QName primitiveType = attribute.getType();\r
SimpleType simpleType = attribute.getSimpleType();\r
attrName = ref.getLocalPart();\r
relationName = ontShort+getName(parent)+"_has"+ref.getLocalPart();\r
\r
- Attribute referred = getRefAttribute(ref);\r
+ Attribute referred = base.getRefAttribute(ref);\r
if (referred != null) {\r
primitiveType = referred.getType();\r
simpleType = referred.getSimpleType();\r
if (primitiveType != null) {\r
\r
//String binding = getBindingFromPrimitiveType(primitiveType);\r
- TypeEntry binding = getTypeEntry(primitiveType);\r
+ TypeEntry binding = base.getTypeEntry(primitiveType);\r
\r
if (binding != null) {\r
writeAttribute(fw, attrName, relationName, binding, isReference);\r
return;\r
} else {\r
if (simpleType == null) {\r
- SchemaObject simpleTypeObj = simpleTypeName.get(primitiveType.getLocalPart());\r
+ SchemaObject simpleTypeObj = base.simpleTypeName.get(primitiveType.getLocalPart());\r
if (simpleTypeObj != null)\r
simpleType = simpleTypeObj.getSimpleType();\r
} \r
if (simpleType != null) {\r
org.w3._2001.xmlschema.List list = simpleType.getList();\r
if (list != null) {\r
- TypeEntry binding = getTypeEntry(new QName(SCHEMA_NS, "string"));\r
+ TypeEntry binding = base.getTypeEntry(new QName(SchemaConversionBase.SCHEMA_NS, "string"));\r
writeAttribute(fw, attrName, relationName, binding, isReference);\r
} else {\r
Restriction restriction = simpleType.getRestriction();\r
\r
\r
//String binding = getBindingFromPrimitiveType(base);\r
- TypeEntry binding = getTypeEntry(base);\r
+ TypeEntry binding = this.base.getTypeEntry(base);\r
writeAttribute(fw, attrName, relationName, binding, isReference);\r
}\r
} else {\r
//throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());\r
fw.writer.println(" //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");\r
//writeAttribute(fw, attrName, relationName, "STRING", isReference);\r
- writeAttribute(fw, attrName, relationName, getTypeEntry("string"), isReference);\r
+ writeAttribute(fw, attrName, relationName, base.getTypeEntry("string"), isReference);\r
}\r
}\r
\r
- //private void writeAttribute(FileWriter fw, String attrName, String relationName, String binding, boolean isReference) {\r
private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {\r
fw.writer.println(" {");\r
fw.writer.println(" if (attribute.getPredicate().equals("+relationName+")) {"); \r
}\r
\r
@Override\r
- protected void handleAttributes(SchemaObject simpleTypeObj) {\r
+ public void handleAttributes(SchemaObject simpleTypeObj) {\r
SchemaObject parent = simpleTypeObj.getParent();\r
FileWriter fw = getWriter(parent);\r
\r
\r
\r
//String binding = getBindingFromPrimitiveType(base);\r
- TypeEntry binding = getTypeEntry(base);\r
+ TypeEntry binding = this.base.getTypeEntry(base);\r
\r
fw.writer.println(" @Override");\r
fw.writer.println(" public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
}\r
\r
@Override\r
- protected void handle(SchemaObject parent, AttributeGroup attribute) {\r
+ public void handle(SchemaObject parent, AttributeGroup attribute) {\r
if (parent != null) {\r
FileWriter fw = getWriter(parent);\r
- NamedAttributeGroup group = getAttributeGroup(attribute.getRef().getLocalPart());\r
+ NamedAttributeGroup group = this.base.getAttributeGroup(attribute.getRef().getLocalPart());\r
fw.writer.println(commentTag+" AttributeGroup " + group.getName());\r
SchemaObject obj = new SchemaObject(parent,attribute);\r
for (Annotated annotated : group.getAttributeOrAttributeGroup()) {\r
}\r
\r
@Override\r
- protected void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {\r
+ public void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {\r
FileWriter fw = getWriter(parent);\r
- QName type = new QName(CONVERSION_NS, composition.getType());\r
- TypeEntry typeEntry = getTypeEntry(type);\r
+ QName type = new QName(SchemaConversionBase.CONVERSION_NS, composition.getType());\r
+ TypeEntry typeEntry = this.base.getTypeEntry(type);\r
String arrayBinding = typeEntry.binding;//getBindingFromPrimitiveType(type);\r
String javaType = typeEntry.javaType;//getJavaTypeFromPrimitiveType(type);\r
String name = composition.getName();\r
}\r
\r
protected String getDefaultValue(QName atype) {\r
- Map<String,TypeEntry> types = typeMap.get(atype.getNamespaceURI());\r
+ Map<String,TypeEntry> types = this.base.typeMap.get(atype.getNamespaceURI());\r
if (types == null)\r
return null;\r
TypeEntry entry = types.get(atype.getLocalPart());\r
return entry.defaultValue;\r
}\r
\r
- \r
- \r
- \r
- \r
- \r
IDProvider provider;\r
@Override\r
- protected void handleElement(SchemaObject elementObj) {\r
+ public void handleElement(SchemaObject elementObj) {\r
Element element = elementObj.getElement();\r
\r
String name = getName(elementObj);//topLevelElement.getName();\r
writers.put(elementObj, fw);\r
boolean isList = false;\r
\r
- Inheritance inheritance = getInheritance(elementObj); \r
+ Inheritance inheritance = this.base.getInheritance(elementObj); \r
\r
- provider = getIDProvider(element);\r
- List<IDReference> references = getIDReferences(element);\r
- UnrecognizedChildElement unknownChildElement = getUnknown(element);\r
+ provider = this.base.getIDProvider(element);\r
+ List<IDReference> references = this.base.getIDReferences(element);\r
+ UnrecognizedChildElement unknownChildElement = this.base.getUnknown(element);\r
\r
// List<String> intrerfaces = new ArrayList<String>();\r
// if (references.size() > 0)\r
fw.writer.println(" "+getOntologyImport());\r
fw.writer.println(" for (Statement attribute : attributes) {");\r
if (complexType != null) {\r
- SchemaObject obj = complexTypes.get(complexType);\r
- handleElementComplexTypeAttributes(obj);\r
+ SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ this.base.handleElementComplexTypeAttributes(obj);\r
} \r
fw.writer.println(" }");\r
fw.writer.println(" }");\r
fw.writer.println(" super(graph);");\r
fw.writer.println(" "+getOntologyImport());\r
if (complexType != null) {\r
- SchemaObject obj = complexTypes.get(complexType);\r
- handleComplexTypeExtension(obj);\r
+ SchemaObject obj = this.base.complexTypes.get(complexType);\r
+ this.base.handleComplexTypeExtension(obj);\r
} else if (simpleType != null) {\r
\r
}\r